]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
634b96f566bba22cf8f620e6339fc2e835038353
[tmp/jakarta-migration.git] /
1 /**\r
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
5  *\r
6  * http://www.collectionspace.org\r
7  * http://wiki.collectionspace.org\r
8  *\r
9  * Copyright (c) 2009 Regents of the University of California\r
10  *\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
13  *\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
16  *\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
22  */\r
23 package org.collectionspace.services.IntegrationTests.test;\r
24 \r
25 import org.collectionspace.services.IntegrationTests.xmlreplay.TreeWalkResults;\r
26 import org.collectionspace.services.IntegrationTests.xmlreplay.XmlCompareJdom;\r
27 import org.collectionspace.services.common.api.FileTools;\r
28 import org.collectionspace.services.common.api.Tools;\r
29 import org.testng.annotations.Test;\r
30 \r
31 import java.io.File;\r
32 \r
33 /**\r
34  * User: laramie\r
35  * $LastChangedRevision:  $\r
36  * $LastChangedDate:  $\r
37  */\r
38 public class XmlCompareJdomRepeatingTest {\r
39 \r
40     private static String getDirectory(){\r
41         String dataDir = "src/test/resources/test-data/xmlreplay/XmlCompareJdom";   // this dir lives under service/IntegrationTests\r
42         String pwd = ".";\r
43         try {\r
44             pwd = (new File(".")).getCanonicalPath();\r
45         } catch (Exception e){\r
46             System.err.println("Error trying to find current working directory: "+e);\r
47         }\r
48         String thisDir = Tools.glue(pwd, "/", dataDir);\r
49         return thisDir;\r
50     }\r
51 \r
52     private void testBanner(String msg){\r
53         String BANNER ="-------------------------------------------------------";\r
54         String R = "\r\n";\r
55         System.out.println(BANNER\r
56                                      + R +" TEST CLASS: "+this.getClass().getName()\r
57                                      + R +" TEST NAME: "+msg\r
58                                      + R +" TEST DATA DIR: "+getDirectory()\r
59                                      + R\r
60                                      +BANNER);\r
61     }\r
62 \r
63     @Test\r
64     public void testLeftAndRightSame(){\r
65         testBanner("testLeftAndRightSame");\r
66         String dir = getDirectory();\r
67         String expectedPartContent = FileTools.readFile(dir, "1-left.xml");\r
68         String fromServerContent = FileTools.readFile(dir, "1-right.xml");\r
69         String startPath = "/document/*[local-name()='relations-common-list']";\r
70         TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault();\r
71         TreeWalkResults results =\r
72             XmlCompareJdom.compareParts(expectedPartContent,\r
73                                         "expected",\r
74                                         fromServerContent,\r
75                                         "from-server",\r
76                                         startPath,\r
77                                         matchSpec);\r
78         XmlCompareJdomTest.assertTreeWalkResults(results,1,0,0,false, matchSpec);\r
79                                    // addedRight,missingRight,textMismatches,strictMatch,treesMatch\r
80     }\r
81 \r
82     @Test\r
83     public void testLeftAndRightSameNoStartElement(){\r
84         testBanner("testLeftAndRightSameNoStartElement");\r
85         String dir = getDirectory();\r
86          String expectedPartContent = FileTools.readFile(dir, "2-left.xml");\r
87         String fromServerContent = FileTools.readFile(dir, "2-right.xml");\r
88         String startPath = "/document";\r
89         TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault();\r
90         TreeWalkResults results =\r
91             XmlCompareJdom.compareParts(expectedPartContent,\r
92                                         "expected",\r
93                                         fromServerContent,\r
94                                         "from-server",\r
95                                         startPath,\r
96                                         matchSpec);\r
97         XmlCompareJdomTest.assertTreeWalkResults(results,0,0,0,true,matchSpec);\r
98                                    // addedRight,missingRight,textMismatches,strictMatch,treesMatch\r
99     }\r
100 \r
101 \r
102 }\r