KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > nbbuild > ConvertImportTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.nbbuild;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.PrintStream JavaDoc;
25 import junit.framework.*;
26 import org.netbeans.junit.*;
27
28 /**
29  *
30  * @author pzajac
31  */

32 public class ConvertImportTest extends NbTestCase {
33     private File JavaDoc testFile;
34     public ConvertImportTest(java.lang.String JavaDoc testName) {
35         super(testName);
36     }
37
38     
39     public void testConvertImport() throws IOException JavaDoc {
40        String JavaDoc xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
41            "<project name=\"ant/freeform/test-unit\" basedir=\".\" default=\"all\">\n" +
42            "<import file=\"../../../nbbuild/templates/xtest-unit.xml\"/>\n" +
43            "</project>";
44        String JavaDoc xmlOut = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
45            "<project name=\"ant/freeform/test-unit\" basedir=\".\" default=\"all\">\n" +
46            "<import file=\"../templates/xtest-unit.xml\"/>\n" +
47            "</project>";
48
49        String JavaDoc xmlOutPrefix = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
50            "<project name=\"ant/freeform/test-unit\" basedir=\".\" default=\"all\">\n" +
51            "<import file=\"${test.dist.dir}/templates/xtest-unit.xml\"/>\n" +
52            "</project>";
53        
54        createFile(xml);
55        
56        ConvertImport convert = new ConvertImport();
57        convert.setFile(testFile);
58        convert.setOldName("templates/xtest-unit.xml");
59        convert.setNewPath("../templates/xtest-unit.xml");
60        convert.execute();
61        assertNewXml(xmlOut);
62        
63        createFile(xml);
64        convert.setPropertyPrefixName("test.dist.dir");
65        convert.setNewPath("templates/xtest-unit.xml");
66        convert.execute();
67        assertNewXml(xmlOutPrefix);
68  
69         xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
70            "<project name=\"ant/freeform/test-unit\" basedir=\".\" default=\"all\">\n" +
71            "<!-- <import file=\"../../../nbbuild/templates/xtest-unit.xml\"/>\n-->" +
72            "</project>";
73        createFile(xml);
74        convert.execute();
75        assertNewXml(xml);
76
77        xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
78               "<!-- file -->" +
79            "<project name=\"ant/freeform/test-unit\" basedir=\".\" default=\"all\">\n" +
80            "<import file=\"../../../nbbuild/templates/xtest-unit.xml\"/>\n" +
81            "</project>";
82        xmlOut = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
83               "<!-- file -->" +
84            "<project name=\"ant/freeform/test-unit\" basedir=\".\" default=\"all\">\n" +
85            "<import file=\"${test.dist.dir}/xx\"/>\n" +
86            "</project>";
87        createFile(xml);
88        convert.setNewPath("xx");
89        convert.execute();
90        assertNewXml(xmlOut);
91        
92     }
93
94     private File JavaDoc createFile(String JavaDoc xml) throws IOException JavaDoc {
95        testFile = new File JavaDoc(getWorkDir(),"testFile.xml");
96        PrintStream JavaDoc ps = new PrintStream JavaDoc(testFile);
97        ps.print(xml);
98        ps.close();
99        return testFile;
100     }
101
102     private void assertNewXml(String JavaDoc xmlOut) throws IOException JavaDoc {
103         File JavaDoc file = new File JavaDoc(getWorkDir(),"ref.xml");
104         PrintStream JavaDoc ps = new PrintStream JavaDoc(file);
105         ps.print(xmlOut);
106         assertFile(testFile,file);
107     }
108 }
109
Popular Tags