KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > dependency > TestNodeLoader


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.jeantessier.dependency;
34
35 import java.io.*;
36
37 import org.xml.sax.*;
38
39 import junit.framework.*;
40
41 public class TestNodeLoader extends TestCase {
42     private static final String JavaDoc MY_PACKAGE_NAME = "mypackage";
43     private static final String JavaDoc MY_CLASS_NAME = "mypackage.MyClass";
44     private static final String JavaDoc MY_FEATURE_NAME = "mypackage.MyClass.myFeature";
45     private static final String JavaDoc OTHER_PACKAGE_NAME = "otherpackage";
46     private static final String JavaDoc OTHER_CLASS_NAME = "otherpackage.OtherClass";
47     private static final String JavaDoc OTHER_FEATURE_NAME = "otherpackage.OtherClass.otherFeature";
48     
49     public void testReadDocument() throws IOException, SAXException {
50         StringBuffer JavaDoc xml = new StringBuffer JavaDoc();
51
52         xml.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
53         xml.append("\n");
54         xml.append("<!DOCTYPE dependencies SYSTEM \"http://depfind.sourceforge.net/dtd/dependencies.dtd\">\n");
55         xml.append("\n");
56         xml.append("<dependencies>\n");
57         xml.append(" <package confirmed=\"yes\">\n");
58         xml.append(" <name>").append(MY_PACKAGE_NAME).append("</name>\n");
59         xml.append(" <outbound type=\"package\" confirmed=\"no\">").append(OTHER_PACKAGE_NAME).append("</outbound>\n");
60         xml.append(" <class confirmed=\"yes\">\n");
61         xml.append(" <name>").append(MY_CLASS_NAME).append("</name>\n");
62         xml.append(" <outbound type=\"class\" confirmed=\"no\">").append(OTHER_CLASS_NAME).append("</outbound>\n");
63         xml.append(" <feature confirmed=\"yes\">\n");
64         xml.append(" <name>").append(MY_FEATURE_NAME).append("</name>\n");
65         xml.append(" <outbound type=\"feature\" confirmed=\"no\">").append(OTHER_FEATURE_NAME).append("</outbound>\n");
66         xml.append(" </feature>\n");
67         xml.append(" </class>\n");
68         xml.append(" </package>\n");
69         xml.append(" <package confirmed=\"no\">\n");
70         xml.append(" <name>").append(OTHER_PACKAGE_NAME).append("</name>\n");
71         xml.append(" <inbound type=\"package\" confirmed=\"yes\">").append(MY_PACKAGE_NAME).append("</inbound>\n");
72         xml.append(" <class confirmed=\"no\">\n");
73         xml.append(" <name>").append(OTHER_CLASS_NAME).append("</name>\n");
74         xml.append(" <inbound type=\"class\" confirmed=\"yes\">").append(MY_CLASS_NAME).append("</inbound>\n");
75         xml.append(" <feature confirmed=\"no\">\n");
76         xml.append(" <name>").append(OTHER_FEATURE_NAME).append("</name>\n");
77         xml.append(" <inbound type=\"feature\" confirmed=\"yes\">").append(MY_FEATURE_NAME).append("</inbound>\n");
78         xml.append(" </feature>\n");
79         xml.append(" </class>\n");
80         xml.append(" </package>\n");
81         xml.append("</dependencies>\n");
82         
83         NodeLoader loader = new NodeLoader();
84         NodeFactory factory = loader.load(new StringReader(xml.toString()));
85
86         assertEquals("nb packages", 2, factory.getPackages().size());
87         assertNotNull("missing package", factory.getPackages().get(MY_PACKAGE_NAME));
88         assertTrue("package is inferred", ((Node) factory.getPackages().get(MY_PACKAGE_NAME)).isConfirmed());
89         assertNotNull("missing package", factory.getPackages().get(OTHER_PACKAGE_NAME));
90         assertFalse("package is confirmed", ((Node) factory.getPackages().get(OTHER_PACKAGE_NAME)).isConfirmed());
91
92         assertEquals("nb classes", 2, factory.getClasses().size());
93         assertNotNull("missing class", factory.getClasses().get(MY_CLASS_NAME));
94         assertTrue("class is inferred", ((Node) factory.getClasses().get(MY_CLASS_NAME)).isConfirmed());
95         assertNotNull("missing class", factory.getClasses().get(OTHER_CLASS_NAME));
96         assertFalse("class is confirmed", ((Node) factory.getClasses().get(OTHER_CLASS_NAME)).isConfirmed());
97
98         assertEquals("nb features", 2, factory.getFeatures().size());
99         assertNotNull("missing feature", factory.getFeatures().get(MY_FEATURE_NAME));
100         assertTrue("feature is inferred", ((Node) factory.getFeatures().get(MY_FEATURE_NAME)).isConfirmed());
101         assertNotNull("missing feature", factory.getFeatures().get(OTHER_FEATURE_NAME));
102         assertFalse("feature is confirmed", ((Node) factory.getFeatures().get(OTHER_FEATURE_NAME)).isConfirmed());
103     }
104 }
105
Popular Tags