1 package org.netbeans.modules.xml.xdm.diff; 2 3 import java.util.List ; 4 import junit.framework.*; 5 import org.netbeans.modules.xml.xdm.Util; 6 import org.netbeans.modules.xml.xdm.XDMModel; 7 import javax.swing.text.Document ; 8 import org.netbeans.modules.xml.xam.ModelSource; 9 import org.netbeans.modules.xml.xam.dom.ElementIdentity; 10 import org.openide.util.Lookup; 11 import org.openide.util.lookup.Lookups; 12 13 18 public class DiffFinderTest extends TestCase { 19 20 public DiffFinderTest(String testName) { 21 super(testName); 22 } 23 24 protected void setUp() throws Exception { 25 } 26 27 protected void tearDown() throws Exception { 28 } 29 30 public static Test suite() { 31 TestSuite suite = new TestSuite(); 33 suite.addTest(new DiffFinderTest("testFindDiff1")); 34 suite.addTest(new DiffFinderTest("testFindDiff2")); 35 suite.addTest(new DiffFinderTest("testFindDiff3")); 36 suite.addTest(new DiffFinderTest("testFindDiffPerf")); 37 suite.addTest(new DiffFinderTest("testFindDiffPerf2")); 38 suite.addTest(new DiffFinderTest("testElementAddedBeforeChildAttributeChange")); 39 suite.addTest(new DiffFinderTest("testElementAddedBeforeChildAttributeChange2")); 40 return suite; 41 } 42 43 public void testFindDiff1() throws Exception { 44 String FILE1 = "diff/schema3.xsd"; 45 Document d1 = Util.getResourceAsDocument(FILE1); 46 Lookup lookup = Lookups.singleton(d1); 47 ModelSource ms = new ModelSource(lookup, true); 48 XDMModel m1 = new XDMModel(ms); 49 m1.sync(); 50 51 String FILE2 = "diff/schema4.xsd"; 52 Document d2 = Util.getResourceAsDocument(FILE2); 53 lookup = Lookups.singleton(d2); 54 ms = new ModelSource(lookup, true); 55 XDMModel m2 = new XDMModel(ms); 56 m2.sync(); 57 58 DefaultElementIdentity eID = new DefaultElementIdentity(); 60 eID.addIdentifier( "id" ); 61 eID.addIdentifier( "name" ); 62 eID.addIdentifier( "ref" ); 63 64 DiffFinder dv = new DiffFinder(eID); 66 List <Difference> deList = dv.findDiff(m1.getDocument(), m2.getDocument()); 67 72 assertEquals( 7 , deList.size() ); 73 74 } 76 77 public void testFindDiff2() throws Exception { 78 String FILE1 = "diff/schema3.xsd"; 79 Document d1 = Util.getResourceAsDocument(FILE1); 80 Lookup lookup = Lookups.singleton(d1); 81 ModelSource ms = new ModelSource(lookup, true); 82 XDMModel m1 = new XDMModel(ms); 83 m1.sync(); 84 85 String FILE2 = "diff/schema5.xsd"; 86 Document d2 = Util.getResourceAsDocument(FILE2); 87 lookup = Lookups.singleton(d2); 88 ms = new ModelSource(lookup, true); 89 XDMModel m2 = new XDMModel(ms); 90 m2.sync(); 91 92 DefaultElementIdentity eID = new DefaultElementIdentity(); 94 eID.addIdentifier( "id" ); 95 eID.addIdentifier( "name" ); 96 eID.addIdentifier( "ref" ); 97 98 DiffFinder dv = new DiffFinder(eID); 100 List <Difference> deList = dv.findDiff(m1.getDocument(), m2.getDocument()); 101 106 assertEquals( 10, deList.size()); 107 } 109 110 public void testFindDiff3() throws Exception { 111 String FILE1 = "diff/PurchaseOrder.xsd"; 112 Document d1 = Util.getResourceAsDocument(FILE1); 113 Lookup lookup = Lookups.singleton(d1); 114 ModelSource ms = new ModelSource(lookup, true); 115 XDMModel m1 = new XDMModel(ms); 116 m1.sync(); 117 118 String FILE2 = "diff/PurchaseOrderSyncTest.xsd"; 119 Document d2 = Util.getResourceAsDocument(FILE2); 120 lookup = Lookups.singleton(d2); 121 ms = new ModelSource(lookup, true); 122 XDMModel m2 = new XDMModel(ms); 123 m2.sync(); 124 125 DefaultElementIdentity eID = new DefaultElementIdentity(); 127 eID.addIdentifier( "id" ); 128 eID.addIdentifier( "name" ); 129 eID.addIdentifier( "ref" ); 130 131 DiffFinder dv = new DiffFinder( eID ); 133 List <Difference> deList = dv.findDiff(m1.getDocument(), m2.getDocument()); 134 assertEquals(deList.toString(), 11, deList.size() ); 140 } 141 142 public void testFindDiffPerf() throws Exception { 143 String FILE1 = "perf/J1_TravelItinerary.xsd"; 144 Document d1 = Util.getResourceAsDocument(FILE1); 145 Lookup lookup = Lookups.singleton(d1); 146 ModelSource ms = new ModelSource(lookup, true); 147 XDMModel m1 = new XDMModel(ms); 148 m1.sync(); 149 150 String FILE2 = "perf/J1_TravelItinerary.xsd"; 151 Document d2 = Util.getResourceAsDocument(FILE2); 152 lookup = Lookups.singleton(d2); 153 ms = new ModelSource(lookup, true); 154 XDMModel m2 = new XDMModel(ms); 155 m2.sync(); 156 157 DefaultElementIdentity eID = new DefaultElementIdentity(); 159 eID.addIdentifier( "id" ); 160 eID.addIdentifier( "name" ); 161 eID.addIdentifier( "ref" ); 162 163 long startTime=System.currentTimeMillis(); 164 DiffFinder dv = new DiffFinder( eID ); 165 List <Difference> deList = dv.findDiff(m1.getDocument(), m2.getDocument()); 166 assertEquals( 0, deList.size() ); 173 } 174 175 public void testFindDiffPerf2() throws Exception { 176 List <Difference> diffs = Util.diff("diff/TravelItinerary1.xsd", "diff/TravelItinerary2.xsd"); 177 assertEquals(diffs.toString(), 4, diffs.size() ); 178 } 179 180 public void testElementAddedBeforeChildAttributeChange() throws Exception { 181 List <Difference> diffs = Util.diff("diff/test1.xml", "diff/test1_1.xml"); 182 assertEquals(diffs.toString(), 3, diffs.size() ); 183 assertTrue(((Change)diffs.get(2)).isAttributeChanged()); 184 } 185 186 public void testElementAddedBeforeChildAttributeChange2() throws Exception { 187 List <Difference> diffs = Util.diff("diff/test2.xml", "diff/test2_1.xml"); 188 assertEquals(diffs.toString(), 9, diffs.size()); 189 assertTrue(((Change)diffs.get(3)).isAttributeChanged()); 190 assertFalse(((Change)diffs.get(3)).isPositionChanged()); 191 assertFalse(((Change)diffs.get(4)).isAttributeChanged()); 192 assertTrue(((Change)diffs.get(4)).isPositionChanged()); 193 } 194 195 String SCHEMA_URI = "http://www.w3.org/2001/XMLSchema"; 196 } 197 | Popular Tags |