PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/config-assembly/src/test/java/org/jboss/as/config/assembly/ConfigurationAssemblerTestCase.java

#
Java | 139 lines | 96 code | 18 blank | 25 comment | 2 complexity | e2b3f372824f8092f6716a5a1e39e880 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2012, Red Hat Middleware LLC, and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.config.assembly;
  23. import java.io.BufferedReader;
  24. import java.io.BufferedWriter;
  25. import java.io.File;
  26. import java.io.FileNotFoundException;
  27. import java.io.FileReader;
  28. import java.io.IOException;
  29. import java.io.StringWriter;
  30. import java.net.MalformedURLException;
  31. import java.net.URISyntaxException;
  32. import java.net.URL;
  33. import junit.framework.Assert;
  34. import org.junit.Test;
  35. /**
  36. *
  37. * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
  38. */
  39. public class ConfigurationAssemblerTestCase {
  40. @Test
  41. public void testStandaloneConfigurationAssembly() throws Exception {
  42. File baseDir = getFileForResource("standalone-template.xml").getAbsoluteFile().getParentFile();
  43. File outputFile = new File(new File(".").getParentFile(), "target/output/standalone.xml");
  44. ConfigurationAssembler assembler = new ConfigurationAssembler(
  45. baseDir,
  46. getFileForResource("standalone-template.xml"),
  47. "server",
  48. getFileForResource("subsystems.xml"),
  49. outputFile);
  50. assembler.assemble();
  51. String outputXml = readOutputFile(outputFile);
  52. }
  53. @Test
  54. public void testDomainAssembly() throws Exception {
  55. File baseDir = getFileForResource("domain-template.xml").getAbsoluteFile().getParentFile();
  56. File outputFile = new File(new File(".").getParentFile(), "target/output/domain.xml");
  57. ConfigurationAssembler assembler = new ConfigurationAssembler(
  58. baseDir,
  59. getFileForResource("domain-template.xml"),
  60. "server",
  61. getFileForResource("subsystems.xml"),
  62. outputFile);
  63. assembler.assemble();
  64. String outputXml = readOutputFile(outputFile);
  65. }
  66. @Test
  67. public void testStandalone2ConfigurationAssembly() throws Exception {
  68. File baseDir = getFileForResource("standalone-template.xml").getAbsoluteFile().getParentFile();
  69. File outputFile = new File(new File(".").getParentFile(), "target/output/standalone2.xml");
  70. ConfigurationAssembler assembler = new ConfigurationAssembler(
  71. baseDir,
  72. getFileForResource("standalone-template.xml"),
  73. "server",
  74. getFileForResource("subsystems2.xml"),
  75. outputFile);
  76. assembler.assemble();
  77. String outputXml = readOutputFile(outputFile);
  78. }
  79. @Test
  80. public void testEmptyStandaloneConfigurationAssembly() throws Exception {
  81. File baseDir = getFileForResource("standalone-template.xml").getAbsoluteFile().getParentFile();
  82. File outputFile = new File(new File(".").getParentFile(), "target/output/standalone2.xml");
  83. ConfigurationAssembler assembler = new ConfigurationAssembler(
  84. baseDir,
  85. getFileForResource("standalone-template.xml"),
  86. "server",
  87. getFileForResource("subsystems-empty.xml"),
  88. outputFile);
  89. assembler.assemble();
  90. String outputXml = readOutputFile(outputFile);
  91. Assert.assertFalse(outputXml.contains("extensions"));
  92. Assert.assertFalse(outputXml.contains("profile"));
  93. }
  94. private File getFileForResource(String name) throws MalformedURLException, URISyntaxException {
  95. URL url = this.getClass().getResource(name);
  96. return new File(url.toURI());
  97. }
  98. private String readOutputFile(File outputFile) throws IOException, FileNotFoundException {
  99. BufferedReader reader = new BufferedReader(new FileReader(outputFile));
  100. StringWriter output = new StringWriter();
  101. BufferedWriter writer = new BufferedWriter(output);
  102. try {
  103. String line = reader.readLine();
  104. while (line != null) {
  105. writer.write(line);
  106. writer.write("\n");
  107. line = reader.readLine();
  108. }
  109. } finally {
  110. try {
  111. reader.close();
  112. } catch (Exception ignore) {
  113. }
  114. try {
  115. writer.close();
  116. } catch (Exception ignore) {
  117. }
  118. }
  119. return output.toString();
  120. }
  121. }