2 * This document is a part of the source code and related artifacts
\r
3 * for CollectionSpace, an open source collections management system
\r
4 * for museums and related institutions:
\r
6 * http://www.collectionspace.org
\r
7 * http://wiki.collectionspace.org
\r
9 * Copyright (c) 2009 Regents of the University of California
\r
11 * Licensed under the Educational Community License (ECL), Version 2.0.
\r
12 * You may not use this file except in compliance with this License.
\r
14 * You may obtain a copy of the ECL 2.0 License at
\r
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
\r
17 * Unless required by applicable law or agreed to in writing, software
\r
18 * distributed under the License is distributed on an "AS IS" BASIS,
\r
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
20 * See the License for the specific language governing permissions and
\r
21 * limitations under the License.
\r
23 package org.collectionspace.services.IntegrationTests.test;
\r
25 import org.collectionspace.services.IntegrationTests.xmlreplay.TreeWalkResults;
\r
26 import org.collectionspace.services.IntegrationTests.xmlreplay.XmlCompareJdom;
\r
27 import org.testng.Assert;
\r
28 import org.testng.annotations.Test;
\r
32 * $LastChangedRevision: $
\r
33 * $LastChangedDate: $
\r
35 public class XmlCompareJdomTest {
\r
38 private void testBanner(String msg){
\r
39 String BANNER ="-------------------------------------------------------";
\r
40 System.out.println(BANNER+"\r\n"+this.getClass().getName()+"\r\n"+msg+"\r\n"+BANNER);
\r
42 private void printTreeWalkResults(TreeWalkResults list){
\r
43 for (TreeWalkResults.TreeWalkEntry entry : list){
\r
44 System.out.println(entry.toString());
\r
48 private void assertTreeWalkResults(TreeWalkResults results,
\r
52 boolean strictMatch,
\r
53 boolean treesMatch){
\r
54 System.out.println("assertTreeWalkResults: ");
\r
56 int addedr = results.countFor(TreeWalkResults.TreeWalkEntry.STATUS.R_ADDED);
\r
57 int missingr = results.countFor(TreeWalkResults.TreeWalkEntry.STATUS.R_MISSING);
\r
58 int tdiff = results.countFor(TreeWalkResults.TreeWalkEntry.STATUS.TEXT_DIFFERENT);
\r
59 int badCount = results.getMismatchCount();
\r
60 boolean strict = results.isStrictMatch();
\r
61 boolean treeOK = results.treesMatch();
\r
63 String expected = " expected: addedRight:"+addedRight+",missingRight:"+missingRight+",textMismatches:"+textMismatches
\r
64 +",strictMatch:"+strictMatch+",treesMatch:"+treesMatch;
\r
66 String actual = " actual: addedRight:"+addedr+",missingRight:"+missingr+",textMismatches:"+tdiff
\r
67 +",strictMatch:"+strict+",treesMatch:"+treeOK;
\r
69 String exp_act = expected +"\r\n"+actual+"\r\n";
\r
70 System.out.print(exp_act);
\r
72 printTreeWalkResults(results);
\r
75 boolean done = false;
\r
77 Assert.assertEquals(addedr, addedRight, "assertTreeWalkResults:R_ADDED mismatch."+exp_act);
\r
79 Assert.assertEquals(missingr, missingRight, "assertTreeWalkResults:R_MISSING mismatch."+exp_act);
\r
81 Assert.assertEquals(tdiff, textMismatches, "assertTreeWalkResults:TEXT_DIFFERENT mismatch."+exp_act);
\r
84 Assert.assertTrue((strict==strictMatch), "assertTreeWalkResults:strictMatch mismatch."+exp_act);
\r
86 Assert.assertTrue((treeOK==treesMatch), "assertTreeWalkResults:treesMatch mismatch."+exp_act);
\r
88 System.out.println("SUCCESS: assertTreeWalkResults done.\r\n");
\r
91 if (!done) System.out.println("FAILURE: assertTreeWalkResults failed an assertion. See surefire report.\r\n");
\r
96 public void testXmlCompareJdom(){
\r
97 testBanner("testXmlCompareJdom");
\r
98 TreeWalkResults results =
\r
99 XmlCompareJdom.compareParts(expectedPartContent,
\r
103 assertTreeWalkResults(results,0,0,0,true,true);
\r
104 // addedRight,missingRight,textMismatches,strictMatch,treesMatch
\r
108 public void testTextContentDifferent(){
\r
109 testBanner("testTextContentDifferent");
\r
110 TreeWalkResults results =
\r
111 XmlCompareJdom.compareParts(expectedPartContent,
\r
113 srvHEAD+srvEN2+srvDEPOSITOR+srvFOOT,
\r
115 assertTreeWalkResults(results,0,0,1,false,true);
\r
116 // addedRight,missingRight,textMismatches,strictMatch,treesMatch
\r
121 public void testAddedR(){
\r
122 testBanner("testAddedR");
\r
123 TreeWalkResults results =
\r
124 XmlCompareJdom.compareParts(expectedPartContent,
\r
126 srvHEAD+srvEN+exNEWTREE+srvDEPOSITOR+exNEW+srvFOOT,
\r
128 assertTreeWalkResults(results,2,0,0,false,false);
\r
129 // addedRight,missingRight,textMismatches,strictMatch,treesMatch
\r
134 public void testAddedL(){
\r
135 testBanner("testAddedL");
\r
136 TreeWalkResults results =
\r
137 XmlCompareJdom.compareParts(exHEAD + exEN_WCH + exNEWTREE + exDEP + exNEW + exFOOT,
\r
141 assertTreeWalkResults(results,0,3,0,false,false);
\r
142 // addedRight,missingRight,textMismatches,strictMatch,treesMatch
\r
146 public void testChildrenReordered(){
\r
147 testBanner("testChildrenReordered");
\r
148 TreeWalkResults results =
\r
149 XmlCompareJdom.compareParts(exHEAD + exDEP + exEN + exFOOT,
\r
153 assertTreeWalkResults(results,0,0,0,true,true);
\r
154 // addedRight,missingRight,textMismatches,strictMatch,treesMatch
\r
158 // ============ expected part, will be used as LEFT tree ==========================================================
\r
159 private static String exHEAD ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
\r
160 +"<ns2:objectexit_common \r\n"
\r
161 +" xmlns:ns2=\"http://collectionspace.org/services/objectexit\" \r\n"
\r
162 +" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \r\n"
\r
163 +" xsi:schemaLocation=\"http://collectionspace.org/services/objectexit http://services.collectionspace.org/objectexit/objectexit_common.xsd\">\r\n";
\r
164 private static String exEN =" <exitNumber>objectexitNumber-1290026472360</exitNumber>\r\n";
\r
165 private static String exEN_WCH =" <exitNumber>objectexitNumber-1290026472360\r\n"
\r
167 +" enChild content\r\n"
\r
169 +" </exitNumber>\r\n";
\r
170 private static String exNEWTREE =" <first>\r\n"
\r
172 +" second content\r\n"
\r
175 private static String exDEP =" <depositor>urn:cspace:org.collectionspace.demo:orgauthority:name(TestOrgAuth):organization:name(Northern Climes Museum)'Northern Climes Museum'</depositor>\r\n";
\r
176 private static String exNEW =" <newField>objectexitNumber-1290026472360</newField>\r\n";
\r
177 private static String exFOOT ="</ns2:objectexit_common>";
\r
179 private static String expectedPartContent = exHEAD + exEN + exDEP + exFOOT;
\r
182 // ============ from-server part, will be used as RIGHT tree ==========================================================
\r
184 private static String srvHEAD = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
\r
185 +"<ns2:objectexit_common xmlns:ns2=\"http://collectionspace.org/services/objectexit\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://collectionspace.org/services/objectexit http://services.collectionspace.org/objectexit/objectexit_common.xsd\">\r\n";
\r
186 private static String srvEN = "<exitNumber>objectexitNumber-1290026472360</exitNumber>\r\n";
\r
187 private static String srvEN2 = "<exitNumber>objectexitNumber-9999999999999</exitNumber>\r\n";
\r
188 private static String srvDEPOSITOR = "<depositor>urn:cspace:org.collectionspace.demo:orgauthority:name(TestOrgAuth):organization:name(Northern Climes Museum)'Northern Climes Museum'</depositor>\r\n";
\r
189 private static String srvFOOT = "</ns2:objectexit_common>\r\n";
\r
191 private static String partFromServer = srvHEAD+srvEN+srvDEPOSITOR+srvFOOT;
\r