KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > dd > api > webservices > DDProviderTest


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.modules.j2ee.dd.api.webservices;
21
22 import java.io.BufferedInputStream JavaDoc;
23 import java.io.BufferedOutputStream JavaDoc;
24 import java.io.File JavaDoc;
25 import java.io.FileInputStream JavaDoc;
26 import java.io.FileOutputStream JavaDoc;
27 import junit.framework.Test;
28 import junit.framework.TestSuite;
29 import org.netbeans.junit.NbTestCase;
30 import org.openide.filesystems.FileObject;
31 import org.openide.filesystems.FileUtil;
32 import org.xml.sax.InputSource JavaDoc;
33
34 /*
35  * DDProviderTest.java
36  * JUnit based test
37  *
38  * Created on 16 December 2005, 14:15
39  */

40
41 /**
42  *
43  * @author jungi
44  */

45 public class DDProviderTest extends NbTestCase {
46
47     private DDProvider dd;
48     
49     public DDProviderTest(String JavaDoc testName) {
50         super(testName);
51     }
52
53     protected void setUp() throws Exception JavaDoc {
54         super.setUp();
55         dd = DDProvider.getDefault();
56         assertNotNull("DDProvider cannot be null.", dd);
57     }
58
59     protected void tearDown() throws Exception JavaDoc {
60         super.tearDown();
61         dd = null;
62     }
63
64     public static Test suite() {
65         TestSuite suite = new TestSuite(DDProviderTest.class);
66         return suite;
67     }
68
69     /**
70      * Test of getDDRoot method, of class org.netbeans.modules.j2ee.dd.api.webservices.DDProvider.
71      */

72     public void testGetDDRootFromFOWHandler() throws Exception JavaDoc {
73         File JavaDoc f = new File JavaDoc(getDataDir(), "wHandler/webservices.xml").getAbsoluteFile();
74         readWriteDD(f, true);
75     }
76
77     /**
78      * Test of getDDRoot method, of class org.netbeans.modules.j2ee.dd.api.webservices.DDProvider.
79      */

80     public void testGetDDRootFromInputSourceWHandler() throws Exception JavaDoc {
81         File JavaDoc f = new File JavaDoc(getDataDir(), "wHandler/webservices.xml").getAbsoluteFile();
82         readWriteDD(f, false);
83     }
84     
85     /**
86      * Test of getDDRoot method, of class org.netbeans.modules.j2ee.dd.api.webservices.DDProvider.
87      */

88     public void testGetDDRootFromFOWoHandler() throws Exception JavaDoc {
89         File JavaDoc f = new File JavaDoc(getDataDir(), "woHandler/webservices.xml").getAbsoluteFile();
90         readWriteDD(f, true);
91     }
92
93     /**
94      * Test of getDDRoot method, of class org.netbeans.modules.j2ee.dd.api.webservices.DDProvider.
95      */

96     public void testGetDDRootFromInputSourceWoHandler() throws Exception JavaDoc {
97         File JavaDoc f = new File JavaDoc(getDataDir(), "woHandler/webservices.xml").getAbsoluteFile();
98         readWriteDD(f, false);
99     }
100     
101     private void readWriteDD(File JavaDoc ddFile, boolean useFO) throws Exception JavaDoc {
102         Webservices result = null;
103         if (!useFO) {
104             InputSource JavaDoc is = new InputSource JavaDoc(new BufferedInputStream JavaDoc(new FileInputStream JavaDoc(ddFile)));
105             result = dd.getDDRoot(is);
106         } else {
107             FileObject fo = FileUtil.toFileObject(ddFile);
108             result = dd.getDDRoot(fo);
109         }
110         assertNotNull("Result cannot be null.", result);
111         assertEquals(Webservices.STATE_VALID, result.getStatus());
112         File JavaDoc dest = new File JavaDoc(getWorkDir(), "webservices.xml");
113         File JavaDoc diff = new File JavaDoc(getWorkDir(), "webservices.xml.diff");
114         assertTrue(dest.createNewFile());
115         assertTrue(diff.createNewFile());
116         result.write(new BufferedOutputStream JavaDoc(new FileOutputStream JavaDoc(dest)));
117         assertFile(dest, ddFile, diff);
118     }
119 }
120
Popular Tags