1 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 MY_PACKAGE_NAME = "mypackage"; 43 private static final String MY_CLASS_NAME = "mypackage.MyClass"; 44 private static final String MY_FEATURE_NAME = "mypackage.MyClass.myFeature"; 45 private static final String OTHER_PACKAGE_NAME = "otherpackage"; 46 private static final String OTHER_CLASS_NAME = "otherpackage.OtherClass"; 47 private static final String OTHER_FEATURE_NAME = "otherpackage.OtherClass.otherFeature"; 48 49 public void testReadDocument() throws IOException, SAXException { 50 StringBuffer xml = new StringBuffer (); 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 |