01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.pluto.util.assemble.file;
18:
19: import java.io.File;
20: import java.io.FileReader;
21: import java.net.URL;
22:
23: import org.apache.commons.io.FileUtils;
24: import org.apache.pluto.util.assemble.AssemblerConfig;
25: import org.custommonkey.xmlunit.XMLTestCase;
26: import org.custommonkey.xmlunit.XMLUnit;
27:
28: /**
29: * @version $Revision: 516149 $
30: */
31: public class FileAssemblerTest extends XMLTestCase {
32: private File webXmlFile;
33: private File portletXmlFile;
34: private File assembledWebXmlFile;
35:
36: protected void setUp() throws Exception {
37: XMLUnit.setIgnoreWhitespace(true);
38:
39: final URL webXmlUrl = this .getClass().getResource(
40: "/org/apache/pluto/util/assemble/file/web.xml");
41: this .webXmlFile = new File(webXmlUrl.getFile());
42:
43: final URL portletXmlUrl = this .getClass().getResource(
44: "/org/apache/pluto/util/assemble/file/portlet.xml");
45: this .portletXmlFile = new File(portletXmlUrl.getFile());
46:
47: final URL assembledWebXmlUrl = this
48: .getClass()
49: .getResource(
50: "/org/apache/pluto/util/assemble/file/assembled.web.xml");
51: this .assembledWebXmlFile = new File(assembledWebXmlUrl
52: .getFile());
53: }
54:
55: protected void tearDown() throws Exception {
56: this .webXmlFile = null;
57: this .portletXmlFile = null;
58: }
59:
60: public void testAssembleToNewDirectory() throws Exception {
61: AssemblerConfig config = new AssemblerConfig();
62:
63: final File webXmlFileDest = File.createTempFile(this .webXmlFile
64: .getName()
65: + ".", ".xml");
66: webXmlFileDest.deleteOnExit();
67:
68: config.setWebappDescriptor(this .webXmlFile);
69: config.setPortletDescriptor(this .portletXmlFile);
70: config.setDestination(webXmlFileDest);
71:
72: FileAssembler assembler = new FileAssembler();
73: assembler.assemble(config);
74:
75: assertXMLEqual(new FileReader(this .assembledWebXmlFile),
76: new FileReader(webXmlFileDest));
77: }
78:
79: public void testAssembleOverSelf() throws Exception {
80: AssemblerConfig config = new AssemblerConfig();
81:
82: final File webXmlFileCopy = File.createTempFile(this .webXmlFile
83: .getName()
84: + ".", ".source.xml");
85: webXmlFileCopy.deleteOnExit();
86:
87: FileUtils.copyFile(this .webXmlFile, webXmlFileCopy);
88:
89: config.setWebappDescriptor(webXmlFileCopy);
90: config.setPortletDescriptor(this .portletXmlFile);
91: config.setDestination(webXmlFileCopy);
92:
93: FileAssembler assembler = new FileAssembler();
94: assembler.assemble(config);
95:
96: assertXMLEqual(new FileReader(this .assembledWebXmlFile),
97: new FileReader(webXmlFileCopy));
98: }
99: }
|