PageRenderTime 39ms CodeModel.GetById 22ms app.highlight 15ms RepoModel.GetById 1ms 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*/
 22package org.jboss.as.config.assembly;
 23
 24import java.io.BufferedReader;
 25import java.io.BufferedWriter;
 26import java.io.File;
 27import java.io.FileNotFoundException;
 28import java.io.FileReader;
 29import java.io.IOException;
 30import java.io.StringWriter;
 31import java.net.MalformedURLException;
 32import java.net.URISyntaxException;
 33import java.net.URL;
 34
 35import junit.framework.Assert;
 36
 37import org.junit.Test;
 38
 39/**
 40 *
 41 * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
 42 */
 43public class ConfigurationAssemblerTestCase {
 44
 45    @Test
 46    public void testStandaloneConfigurationAssembly() throws Exception {
 47        File baseDir = getFileForResource("standalone-template.xml").getAbsoluteFile().getParentFile();
 48        File outputFile = new File(new File(".").getParentFile(), "target/output/standalone.xml");
 49        ConfigurationAssembler assembler = new ConfigurationAssembler(
 50                baseDir,
 51                getFileForResource("standalone-template.xml"),
 52                "server",
 53                getFileForResource("subsystems.xml"),
 54                outputFile);
 55        assembler.assemble();
 56
 57        String outputXml = readOutputFile(outputFile);
 58    }
 59
 60    @Test
 61    public void testDomainAssembly() throws Exception {
 62        File baseDir = getFileForResource("domain-template.xml").getAbsoluteFile().getParentFile();
 63        File outputFile = new File(new File(".").getParentFile(), "target/output/domain.xml");
 64
 65        ConfigurationAssembler assembler = new ConfigurationAssembler(
 66                baseDir,
 67                getFileForResource("domain-template.xml"),
 68                "server",
 69                getFileForResource("subsystems.xml"),
 70                outputFile);
 71        assembler.assemble();
 72
 73        String outputXml = readOutputFile(outputFile);
 74    }
 75
 76    @Test
 77    public void testStandalone2ConfigurationAssembly() throws Exception {
 78        File baseDir = getFileForResource("standalone-template.xml").getAbsoluteFile().getParentFile();
 79        File outputFile = new File(new File(".").getParentFile(), "target/output/standalone2.xml");
 80        ConfigurationAssembler assembler = new ConfigurationAssembler(
 81                baseDir,
 82                getFileForResource("standalone-template.xml"),
 83                "server",
 84                getFileForResource("subsystems2.xml"),
 85                outputFile);
 86        assembler.assemble();
 87
 88        String outputXml = readOutputFile(outputFile);
 89
 90    }
 91
 92    @Test
 93    public void testEmptyStandaloneConfigurationAssembly() throws Exception {
 94        File baseDir = getFileForResource("standalone-template.xml").getAbsoluteFile().getParentFile();
 95        File outputFile = new File(new File(".").getParentFile(), "target/output/standalone2.xml");
 96        ConfigurationAssembler assembler = new ConfigurationAssembler(
 97                baseDir,
 98                getFileForResource("standalone-template.xml"),
 99                "server",
100                getFileForResource("subsystems-empty.xml"),
101                outputFile);
102        assembler.assemble();
103
104        String outputXml = readOutputFile(outputFile);
105        Assert.assertFalse(outputXml.contains("extensions"));
106        Assert.assertFalse(outputXml.contains("profile"));
107
108    }
109
110
111    private File getFileForResource(String name) throws MalformedURLException, URISyntaxException {
112        URL url = this.getClass().getResource(name);
113        return new File(url.toURI());
114    }
115
116    private String readOutputFile(File outputFile) throws IOException, FileNotFoundException {
117        BufferedReader reader = new BufferedReader(new FileReader(outputFile));
118        StringWriter output = new StringWriter();
119        BufferedWriter writer = new BufferedWriter(output);
120        try {
121            String line = reader.readLine();
122            while (line != null) {
123                writer.write(line);
124                writer.write("\n");
125                line = reader.readLine();
126            }
127        } finally {
128            try {
129                reader.close();
130            } catch (Exception ignore) {
131            }
132            try {
133                writer.close();
134            } catch (Exception ignore) {
135            }
136        }
137        return output.toString();
138    }
139}