001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.dependency;
034:
035: import java.io.*;
036:
037: import javax.xml.parsers.*;
038:
039: import org.xml.sax.*;
040:
041: import junit.framework.*;
042:
043: public class TestNodeLoader extends TestCase {
044: private static final String MY_PACKAGE_NAME = "mypackage";
045: private static final String MY_CLASS_NAME = "mypackage.MyClass";
046: private static final String MY_FEATURE_NAME = "mypackage.MyClass.myFeature";
047: private static final String OTHER_PACKAGE_NAME = "otherpackage";
048: private static final String OTHER_CLASS_NAME = "otherpackage.OtherClass";
049: private static final String OTHER_FEATURE_NAME = "otherpackage.OtherClass.otherFeature";
050:
051: public void testReadDocument() throws IOException,
052: ParserConfigurationException, SAXException {
053: StringBuffer xml = new StringBuffer();
054:
055: xml.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
056: xml.append("\n");
057: xml
058: .append("<!DOCTYPE dependencies SYSTEM \"http://depfind.sourceforge.net/dtd/dependencies.dtd\">\n");
059: xml.append("\n");
060: xml.append("<dependencies>\n");
061: xml.append(" <package confirmed=\"yes\">\n");
062: xml.append(" <name>").append(MY_PACKAGE_NAME).append(
063: "</name>\n");
064: xml.append(
065: " <outbound type=\"package\" confirmed=\"no\">")
066: .append(OTHER_PACKAGE_NAME).append("</outbound>\n");
067: xml.append(" <class confirmed=\"yes\">\n");
068: xml.append(" <name>").append(MY_CLASS_NAME).append(
069: "</name>\n");
070: xml
071: .append(
072: " <outbound type=\"class\" confirmed=\"no\">")
073: .append(OTHER_CLASS_NAME).append("</outbound>\n");
074: xml.append(" <feature confirmed=\"yes\">\n");
075: xml.append(" <name>").append(MY_FEATURE_NAME)
076: .append("</name>\n");
077: xml
078: .append(
079: " <outbound type=\"feature\" confirmed=\"no\">")
080: .append(OTHER_FEATURE_NAME).append("</outbound>\n");
081: xml.append(" </feature>\n");
082: xml.append(" </class>\n");
083: xml.append(" </package>\n");
084: xml.append(" <package confirmed=\"no\">\n");
085: xml.append(" <name>").append(OTHER_PACKAGE_NAME).append(
086: "</name>\n");
087: xml.append(
088: " <inbound type=\"package\" confirmed=\"yes\">")
089: .append(MY_PACKAGE_NAME).append("</inbound>\n");
090: xml.append(" <class confirmed=\"no\">\n");
091: xml.append(" <name>").append(OTHER_CLASS_NAME)
092: .append("</name>\n");
093: xml
094: .append(
095: " <inbound type=\"class\" confirmed=\"yes\">")
096: .append(MY_CLASS_NAME).append("</inbound>\n");
097: xml.append(" <feature confirmed=\"no\">\n");
098: xml.append(" <name>").append(OTHER_FEATURE_NAME)
099: .append("</name>\n");
100: xml
101: .append(
102: " <inbound type=\"feature\" confirmed=\"yes\">")
103: .append(MY_FEATURE_NAME).append("</inbound>\n");
104: xml.append(" </feature>\n");
105: xml.append(" </class>\n");
106: xml.append(" </package>\n");
107: xml.append("</dependencies>\n");
108:
109: NodeLoader loader = new NodeLoader();
110: NodeFactory factory = loader.load(new StringReader(xml
111: .toString()));
112:
113: assertEquals("nb packages", 2, factory.getPackages().size());
114: assertNotNull("missing package", factory.getPackages().get(
115: MY_PACKAGE_NAME));
116: assertTrue("package is inferred", ((Node) factory.getPackages()
117: .get(MY_PACKAGE_NAME)).isConfirmed());
118: assertNotNull("missing package", factory.getPackages().get(
119: OTHER_PACKAGE_NAME));
120: assertFalse("package is confirmed", ((Node) factory
121: .getPackages().get(OTHER_PACKAGE_NAME)).isConfirmed());
122:
123: assertEquals("nb classes", 2, factory.getClasses().size());
124: assertNotNull("missing class", factory.getClasses().get(
125: MY_CLASS_NAME));
126: assertTrue("class is inferred", ((Node) factory.getClasses()
127: .get(MY_CLASS_NAME)).isConfirmed());
128: assertNotNull("missing class", factory.getClasses().get(
129: OTHER_CLASS_NAME));
130: assertFalse("class is confirmed", ((Node) factory.getClasses()
131: .get(OTHER_CLASS_NAME)).isConfirmed());
132:
133: assertEquals("nb features", 2, factory.getFeatures().size());
134: assertNotNull("missing feature", factory.getFeatures().get(
135: MY_FEATURE_NAME));
136: assertTrue("feature is inferred", ((Node) factory.getFeatures()
137: .get(MY_FEATURE_NAME)).isConfirmed());
138: assertNotNull("missing feature", factory.getFeatures().get(
139: OTHER_FEATURE_NAME));
140: assertFalse("feature is confirmed", ((Node) factory
141: .getFeatures().get(OTHER_FEATURE_NAME)).isConfirmed());
142: }
143: }
|