From: Laramie Crocker Date: Sat, 30 Apr 2011 05:32:20 +0000 (+0000) Subject: CSPACE-3739 Including completion of CSPACE-3863 and CSPACE-3862 X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=f21ece18c53ef10184628733fe21220bf440065f;p=tmp%2Fjakarta-migration.git CSPACE-3739 Including completion of CSPACE-3863 and CSPACE-3862 --- diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/ServiceResult.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/ServiceResult.java index 1604da1ea..38b20a42e 100755 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/ServiceResult.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/ServiceResult.java @@ -59,6 +59,10 @@ public class ServiceResult { public String failureReason = ""; public Header[] responseHeaders = new Header[0]; public List expectedCodes = new ArrayList(); + public Map vars = new HashMap(); + public void addVars(Map newVars){ + vars.putAll(newVars); + } private Map partSummaries = new HashMap(); public void addPartSummary(String label, TreeWalkResults list){ partSummaries.put(label, list); @@ -220,7 +224,7 @@ public class ServiceResult { + ( Tools.notEmpty(location) ? "; location.CSID:"+location : "" ) + ( Tools.notEmpty(error) ? "; ERROR:"+error : "" ) + "; gotExpected:"+gotExpectedResult() - +";result:"+result+";" + //+";result:"+result+";" + ( partsSummary(true)) +"}" + ( includePayloads && Tools.notBlank(requestPayload) ? LINE+"requestPayload:"+LINE+CRLF+requestPayload+LINE : "" ) @@ -294,4 +298,29 @@ public class ServiceResult { return "ERROR reading request value: "+e; } } + + public String get(String what){ + if ("CSID".equals(what)){ + return CSID; + } else if ("location".equals(what)){ + return location; + } else if ("testID".equals(what)){ + return testID; + } else if ("testGroupID".equals(what)){ + return testGroupID; + } else if ("fullURL".equals(what)){ + return fullURL; + } else if ("deleteURL".equals(what)){ + return deleteURL; + } else if ("responseCode".equals(what)){ + return ""+responseCode; + } else if ("method".equals(what)){ + return method; + } + if (vars.containsKey(what)){ + return vars.get(what); + } + return ""; + } + } diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/TreeWalkResults.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/TreeWalkResults.java index b7c10e817..021dfe66e 100755 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/TreeWalkResults.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/TreeWalkResults.java @@ -26,6 +26,8 @@ package org.collectionspace.services.IntegrationTests.xmlreplay; import org.collectionspace.services.common.api.Tools; import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; /** * User: laramie @@ -33,6 +35,56 @@ import java.util.ArrayList; * $LastChangedDate: $ */ public class TreeWalkResults extends ArrayList { + public String toString(String LEAD){ + StringBuffer res = new StringBuffer(); + for (TreeWalkResults.TreeWalkEntry entry: this) { + res.append(entry.toString(LEAD)); + } + return res.toString(); + } + + /** This cllass has two public Lists: you can construct your own to set the acceptable and unacceptable STATUS codes. + * They are defaulted to R_ADDED being acceptable. */ + public static class MatchSpec { + public static final TreeWalkEntry.STATUS[] defaultAcceptableStatiArray = {TreeWalkEntry.STATUS.INFO, + TreeWalkEntry.STATUS.MATCHED, + TreeWalkEntry.STATUS.R_ADDED}; + + public static final TreeWalkEntry.STATUS[] defaultErrorStatiArray = {TreeWalkEntry.STATUS.R_MISSING, + TreeWalkEntry.STATUS.NESTED_ERROR, + TreeWalkEntry.STATUS.TEXT_DIFFERENT, + TreeWalkEntry.STATUS.DOC_ERROR}; + public List errorStati; + + public static MatchSpec createDefault(){ + MatchSpec result = new MatchSpec(); + result.errorStati = Arrays.asList(defaultErrorStatiArray); + return result; + } + public static MatchSpec create(TreeWalkEntry.STATUS[] statiArray){ + MatchSpec result = new MatchSpec(); + result.errorStati = Arrays.asList(statiArray); + return result; + } + public void removeErrorFromSpec(TreeWalkEntry.STATUS status){ + ArrayList arrayList = new ArrayList(errorStati); + arrayList.remove(status); + errorStati = arrayList; + } + public String toString(){ + StringBuffer buff = new StringBuffer("{"); + int i = 0; + for (TreeWalkEntry.STATUS status : errorStati){ + if (i>0) buff.append(","); + String foo = status.toString(); + buff.append(foo); + i++; + } + buff.append("}"); + return buff.toString(); + } + + } public static class TreeWalkEntry { public String lpath = ""; @@ -43,24 +95,28 @@ public class TreeWalkResults extends ArrayList { public String actual = ""; public String message = ""; public String errmessage = ""; - public static enum STATUS {INFO, MATCHED, R_MISSING, R_ADDED, DOC_ERROR, TEXT_DIFFERENT}; + public TreeWalkResults nested; + public static enum STATUS {INFO, MATCHED, R_MISSING, R_ADDED, DOC_ERROR, TEXT_DIFFERENT, NESTED_ERROR}; public STATUS status; public String toString(){ + return toString("\r\n"); + } + public String toString(String LEAD){ + String INDENT = " "; return - "{" + LEAD + "{" +status.name() +(Tools.notEmpty(lpath) ? ", L.path:"+lpath : "") +(Tools.notEmpty(rpath) ? ", R.path:"+rpath : "") +(Tools.notEmpty(message) ? ", message:"+message : "") +(Tools.notEmpty(errmessage) ? ", errmessage:"+errmessage : "") +", status:"+status - +((status != STATUS.MATCHED) && Tools.notEmpty(ltextTrimmed) ? ",\r\n L.trimmed:"+ltextTrimmed : "") - +((status != STATUS.MATCHED) && Tools.notEmpty(rtextTrimmed) ? ",\r\n R.trimmed:"+rtextTrimmed : "") - +((status != STATUS.MATCHED) && Tools.notEmpty(expected) ? "\r\nEXPECTED:\r\n------------------\r\n"+expected.trim()+"\r\n------------------" : "") - +((status != STATUS.MATCHED) && Tools.notEmpty(actual) ? "\r\nACTUAL:\r\n------------------\r\n"+actual.trim()+"\r\n------------------\r\n" : "") - + +((status != STATUS.MATCHED) && Tools.notEmpty(ltextTrimmed) ? ","+LEAD+" L.trimmed:"+ltextTrimmed : "") + +((status != STATUS.MATCHED) && Tools.notEmpty(rtextTrimmed) ? ","+LEAD+" R.trimmed:"+rtextTrimmed : "") + +((status != STATUS.MATCHED) && Tools.notEmpty(expected) ? LEAD+"EXPECTED:"+LEAD+"------------------"+LEAD+expected.trim()+LEAD+"------------------" : "") + +((status != STATUS.MATCHED) && Tools.notEmpty(actual) ? LEAD+"ACTUAL:"+LEAD+"------------------"+LEAD+actual.trim()+LEAD+"------------------"+LEAD : "") + +((status != STATUS.MATCHED) && (nested != null) ? LEAD+"NESTED:"+LEAD+"------------------"+LEAD+nested.toString(LEAD+INDENT)+LEAD+"------------------"+LEAD : "") +"}"; - } } @@ -127,6 +183,15 @@ public class TreeWalkResults extends ArrayList { return true; } + public boolean treesMatch(MatchSpec matchSpec) { + for (TreeWalkEntry entry : this) { + if (matchSpec.errorStati.contains(entry.status)) { + return false; + } + } + return true; + } + public int countFor(TreeWalkEntry.STATUS status){ int count = 0; for (TreeWalkEntry entry : this){ diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlCompareJdom.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlCompareJdom.java index b747cf3cf..fd49f9358 100755 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlCompareJdom.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlCompareJdom.java @@ -60,7 +60,7 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser return doc; } - public static TreeWalkResults compareParts(String expectedContent, String leftID, String actualPartContent, String rightID, String startElement){ + public static TreeWalkResults compareParts(String expectedContent, String leftID, String actualPartContent, String rightID, String startElement, TreeWalkResults.MatchSpec matchSpec){ TreeWalkResults list = new TreeWalkResults(); try { @@ -85,7 +85,7 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser } else { Document expected = getDocumentFromContent(expectedContent); Document actual = getDocumentFromContent(actualPartContent); - treeWalk(expected, actual, list, startElement); + treeWalk(expected, actual, list, startElement, matchSpec); } } catch (Throwable t){ String msg = "ERROR in XmlReplay.compareParts(): "+t; @@ -135,7 +135,7 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser xpath.addNamespace("x", d.getRootElement().getNamespaceUri()); */ - public static boolean treeWalk(Document left, Document right, TreeWalkResults list, String startElement) throws Exception { + public static boolean treeWalk(Document left, Document right, TreeWalkResults list, String startElement, TreeWalkResults.MatchSpec matchSpec) throws Exception { Element leftElement = left.getRootElement(); Element rightElement = right.getRootElement(); if (Tools.notBlank(startElement)) { @@ -149,11 +149,11 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser rightElement = (Element)rtest; } } - boolean res = treeWalk(leftElement, rightElement, "/", list); + boolean res = treeWalk(leftElement, rightElement, "/", list, matchSpec); return res; } - public static boolean treeWalk(Element left, Element right, String parentPath, TreeWalkResults msgList) throws Exception { + public static boolean treeWalk(Element left, Element right, String parentPath, TreeWalkResults msgList, TreeWalkResults.MatchSpec matchSpec) throws Exception { String SPACE = " "; if (left == null && right == null){ return true; @@ -191,7 +191,7 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser //System.out.println("-----------------doRepeating------"+leftChildPath); foundRepeatingList.add(leftChildPath); boolean repeatingIdentical = - doRepeatingFieldComparison(leftlist, leftChildPath, leftChildName, left, right, msgList, namespace) ; //todo: deal with foundRightMap in this repeating field block. + doRepeatingFieldComparison(leftlist, leftChildPath, leftChildName, left, right, msgList, namespace, matchSpec) ; //todo: deal with foundRightMap in this repeating field block. if ( ! repeatingIdentical ){ //System.out.println("\r\n\r\n\r\n*****************************\r\nOne repeating field failed: "+msgList); return false; @@ -223,7 +223,7 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser msgList.add(entry); } //============ DIVE !! ===================================================== - result = result && treeWalk( leftChild, rightChild, leftChildPath, msgList); + result = result && treeWalk( leftChild, rightChild, leftChildPath, msgList, matchSpec); } } for (Object r : right.getChildren()){ @@ -253,7 +253,14 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser return outputter.outputString(el); } - public static boolean doRepeatingFieldComparison(List leftList, String leftChildPath, String leftChildName, Element left, Element right, TreeWalkResults msgList, Namespace namespace) + public static boolean doRepeatingFieldComparison(List leftList, + String leftChildPath, + String leftChildName, + Element left, + Element right, + TreeWalkResults msgList, + Namespace namespace, + TreeWalkResults.MatchSpec matchSpec) throws Exception { //todo: deal with foundRightMap in this repeating field block. List rightList = select(right, leftChildName, namespace); @@ -274,7 +281,7 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser twe.status = TreeWalkEntry.STATUS.R_ADDED; twe.message = "Repeating field count not matched. Field: "+leftChildPath+" Left: "+leftList.size()+" Right: "+rightList.size(); msgList.add(twe); - return false; + //LC 20110429 return false; } for (Object le : leftList){ @@ -285,18 +292,28 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser Element rightEl = (Element)re; //pl("right", rightEl); TreeWalkResults msgListInner = new TreeWalkResults(); - treeWalk(leftEl, rightEl, leftChildPath, msgListInner); - if (msgListInner.isStrictMatch()){ + //========== DIVE !!! ======================= + treeWalk(leftEl, rightEl, leftChildPath, msgListInner, matchSpec); + //======================================== + + if (msgListInner.treesMatch(matchSpec)){ //if (msgListInner.isStrictMatch()){ found = true; TreeWalkEntry twe = new TreeWalkEntry(); twe.lpath = leftChildPath; twe.status = TreeWalkEntry.STATUS.MATCHED; msgList.add(twe); - //System.out.println("===========================\r\nfound match for "+leftEl+"\r\n===========================\r\n"); rightList.remove(re); //found it, don't need to inspect this element again. Since we are breaking from loop, removing element won't mess up iterator--we get a new one on the next loop. break; + } else { + TreeWalkEntry twe = new TreeWalkEntry(); + twe.lpath = leftChildPath; + twe.status = TreeWalkEntry.STATUS.NESTED_ERROR; + twe.nested = msgListInner; + msgList.add(twe); + //String line = "\r\n\r\n*********************************\r\n"; + //System.out.println(line+"TreeWalkResults: from walking rightEl: "+rightEl+" leftEl: "+leftEl + " msgListInner:"+ msgListInner+line); } - } + } // END for(rightList) if ( ! found){ TreeWalkEntry twe = new TreeWalkEntry(); twe.lpath = leftChildPath; @@ -305,7 +322,7 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser msgList.add(twe); return false; } - } + } // END for(leftLlist) return true; } diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java index 32eba083c..463cf0437 100755 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java @@ -379,12 +379,14 @@ public class XmlReplay { if (Tools.notBlank(partLabel)) startElement = "/document/*[local-name()='"+partLabel+"']"; } + TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault(); TreeWalkResults list = XmlCompareJdom.compareParts(expectedPartContent, leftID, serviceResult.result, rightID, - startElement); + startElement, + matchSpec); serviceResult.addPartSummary(label, list); return OK; } @@ -541,12 +543,16 @@ public class XmlReplay { } else if (isPUT) { uri = fromTestID(uri, testNode, serviceResultsMap); } + //vars only make sense in two contexts: POST/PUT, because you are submitting another file with internal expressions, + // and in nodes. For GET, DELETE, there is no payload, so all the URLs with potential expressions are right there in the testNode. Map vars = null; if (parts.varsList.size()>0){ vars = parts.varsList.get(0); } serviceResult = XmlReplayTransport.doPOST_PUTFromXML(parts.responseFilename, vars, protoHostPort, uri, method, XmlReplayTransport.APPLICATION_XML, evalStruct, authForTest, testIDLabel); - + if (vars!=null) { + serviceResult.addVars(vars); + } results.add(serviceResult); //if (isPOST){ serviceResultsMap.put(testID, serviceResult); //PUTs do not return a Location, so don't add PUTs to serviceResultsMap. diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTest.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTest.java index e9b4ca645..641e2cbd7 100755 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTest.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTest.java @@ -69,109 +69,126 @@ public class XmlReplayTest { public static XmlReplay createXmlReplayUsingIntegrationTestsModule(String relToServicesRoot) throws Exception { String thisDir = Tools.glue(relToServicesRoot, "/", "IntegrationTests"); String pwd = (new File(thisDir)).getCanonicalPath(); - System.out.println("createXmlReplayUsingIntegrationTestsModule.pwd: "+pwd); + //System.out.println("createXmlReplayUsingIntegrationTestsModule.pwd: "+pwd); XmlReplay replay = new XmlReplay(pwd+XMLREPLAY_REL_DIR_TO_MODULE); - System.out.println("XmlReplay: "+replay); + //System.out.println("XmlReplay: "+replay); return replay; } public static void logTest(ServiceResult sresult, String testname){ - ResultSummary summary = resultSummary(sresult); + ResultSummary summary = resultSummary(sresult, HTML); org.testng.Reporter.log(summary.table); - Assert.assertEquals(summary.oks, summary.total, "Expected all "+summary.total+ " XmlReplay tests to pass. See Output from test '"+testname+"'."); + Assert.assertEquals(summary.oks, summary.total, "Expected all "+summary.total+ " XmlReplay tests to pass. See Output from test '"+testname+"'. "+summary.errorTests); } public static void logTest(List list, String testname){ - ResultSummary summary = resultSummary(list); + ResultSummary summary = resultSummary(list, HTML); org.testng.Reporter.log(summary.table); - Assert.assertEquals(summary.oks, summary.total, "Expected all "+summary.total+ " XmlReplay tests to pass. See Output from test '"+testname+"'."); + Assert.assertEquals(summary.oks, summary.total, "Expected all "+summary.total+ " XmlReplay tests to pass. See Output from test '"+testname+"'. "+summary.errorTests); } public static void logTestForGroup(List> list, String testname){ - ResultSummary summary = resultSummaryForGroup(list); + ResultSummary summary = resultSummaryForGroup(list, HTML); org.testng.Reporter.log(summary.table); - Assert.assertEquals(summary.oks, summary.total, "Expected all "+summary.total+ " XmlReplay tests to pass. See Output from test '"+testname+"'."); + ResultSummary textSummary = resultSummaryForGroup(list, TEXT); + System.out.println("SUMMARY: \r\n"+textSummary.table); + Assert.assertEquals(summary.oks, summary.total, "Expected all "+summary.total+ " XmlReplay tests to pass. See Output from test '"+testname+"'. "+summary.errorTests); } //============== HELPERS AND FORMATTING ===================================================== + public static class FORMAT { + private static final String TBLSTART = ""; + private static final String ROWSTART = "\r\n "; + private static final String ROWSTARTRED = "\r\n ** "; + private static final String SEP = " | "; + private static final String ROWEND = ""; + private static final String ROWENDRED = ""; + private static final String TBLEND = ""; - private static final String TBLSTART = ""; - private static final String ROWSTART = ""; - private static final String ROWENDRED = ""; - private static final String TBLEND = "
"; - private static final String ROWSTARTRED = "
"; - private static final String SEP = ""; - private static final String ROWEND = "
"; + } + public static final FORMAT TEXT = new FORMAT(); + public static class HTML_FORMAT extends FORMAT { + private static final String TBLSTART = ""; + private static final String ROWSTART = ""; + private static final String ROWENDRED = ""; + private static final String TBLEND = "
"; + private static final String ROWSTARTRED = "
"; + private static final String SEP = ""; + private static final String ROWEND = "
"; + } + public static final FORMAT HTML = new HTML_FORMAT(); public static class ResultSummary { public long oks = 0; public long total = 0; public String table = ""; public List groups = new ArrayList(); + public List errorTests = new ArrayList(); } - public static ResultSummary resultSummaryForGroup(List> list){ + public static ResultSummary resultSummaryForGroup(List> list, FORMAT format){ ResultSummary summary = new ResultSummary(); summary.oks = 0; summary.total = 0; StringBuffer buff = new StringBuffer(); - buff.append(TBLSTART); + buff.append(format.TBLSTART); for (List serviceResults : list){ String groupID = ""; if (serviceResults.size()>0){ groupID = serviceResults.get(0).testGroupID; summary.groups.add(groupID); } - buff.append(ROWSTART+"XmlReplay testGroup "+groupID+ROWEND); + buff.append(format.ROWSTART+"XmlReplay testGroup "+groupID+format.ROWEND); for (ServiceResult serviceResult : serviceResults){ summary.total++; if (serviceResult.gotExpectedResult()){ summary.oks++; - buff.append(ROWSTART+serviceResult.minimal()+ROWEND); + buff.append(format.ROWSTART+serviceResult.minimal()+format.ROWEND); } else { - buff.append(ROWSTARTRED+serviceResult.minimal()+ROWENDRED); + buff.append(format.ROWSTARTRED+serviceResult.minimal()+format.ROWENDRED); + summary.errorTests.add(serviceResult.testGroupID+':'+serviceResult.testID+':'+serviceResult.fullURL); } } } - buff.append(TBLEND); + buff.append(format.TBLEND); summary.table = buff.toString(); return summary; } - public static ResultSummary resultSummary(List serviceResults){ + public static ResultSummary resultSummary(List serviceResults, FORMAT format){ ResultSummary summary = new ResultSummary(); summary.oks = 0; summary.total = 0; StringBuffer buff = new StringBuffer(); - buff.append(TBLSTART); + buff.append(format.TBLSTART); for (ServiceResult serviceResult : serviceResults){ summary.total++; if (serviceResult.gotExpectedResult()){ summary.oks++; - buff.append(ROWSTART+serviceResult.minimal()+ROWEND); + buff.append(format.ROWSTART+serviceResult.minimal()+format.ROWEND); } else { - buff.append(ROWSTARTRED+serviceResult.minimal()+ROWENDRED); + buff.append(format.ROWSTARTRED+serviceResult.minimal()+format.ROWENDRED); } } - buff.append(TBLEND); + buff.append(format.TBLEND); summary.table = buff.toString(); return summary; } - public static ResultSummary resultSummary(ServiceResult serviceResult){ + public static ResultSummary resultSummary(ServiceResult serviceResult, FORMAT format){ ResultSummary summary = new ResultSummary(); summary.oks = 0; summary.total = 1; StringBuffer buff = new StringBuffer(); - buff.append(TBLSTART); + buff.append(format.TBLSTART); if (serviceResult.gotExpectedResult()){ summary.oks = 1; - buff.append(ROWSTART+serviceResult.minimal()+ROWEND); + buff.append(format.ROWSTART+serviceResult.minimal()+format.ROWEND); } else { - buff.append(ROWSTARTRED+serviceResult.minimal()+ROWENDRED); + buff.append(format.ROWSTARTRED+serviceResult.minimal()+format.ROWENDRED); } - buff.append(TBLEND); + buff.append(format.TBLEND); summary.table = buff.toString(); return summary; } diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlCompareJdomRepeatingTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlCompareJdomRepeatingTest.java new file mode 100644 index 000000000..634b96f56 --- /dev/null +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlCompareJdomRepeatingTest.java @@ -0,0 +1,102 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright (c) 2009 Regents of the University of California + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.IntegrationTests.test; + +import org.collectionspace.services.IntegrationTests.xmlreplay.TreeWalkResults; +import org.collectionspace.services.IntegrationTests.xmlreplay.XmlCompareJdom; +import org.collectionspace.services.common.api.FileTools; +import org.collectionspace.services.common.api.Tools; +import org.testng.annotations.Test; + +import java.io.File; + +/** + * User: laramie + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class XmlCompareJdomRepeatingTest { + + private static String getDirectory(){ + String dataDir = "src/test/resources/test-data/xmlreplay/XmlCompareJdom"; // this dir lives under service/IntegrationTests + String pwd = "."; + try { + pwd = (new File(".")).getCanonicalPath(); + } catch (Exception e){ + System.err.println("Error trying to find current working directory: "+e); + } + String thisDir = Tools.glue(pwd, "/", dataDir); + return thisDir; + } + + private void testBanner(String msg){ + String BANNER ="-------------------------------------------------------"; + String R = "\r\n"; + System.out.println(BANNER + + R +" TEST CLASS: "+this.getClass().getName() + + R +" TEST NAME: "+msg + + R +" TEST DATA DIR: "+getDirectory() + + R + +BANNER); + } + + @Test + public void testLeftAndRightSame(){ + testBanner("testLeftAndRightSame"); + String dir = getDirectory(); + String expectedPartContent = FileTools.readFile(dir, "1-left.xml"); + String fromServerContent = FileTools.readFile(dir, "1-right.xml"); + String startPath = "/document/*[local-name()='relations-common-list']"; + TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault(); + TreeWalkResults results = + XmlCompareJdom.compareParts(expectedPartContent, + "expected", + fromServerContent, + "from-server", + startPath, + matchSpec); + XmlCompareJdomTest.assertTreeWalkResults(results,1,0,0,false, matchSpec); + // addedRight,missingRight,textMismatches,strictMatch,treesMatch + } + + @Test + public void testLeftAndRightSameNoStartElement(){ + testBanner("testLeftAndRightSameNoStartElement"); + String dir = getDirectory(); + String expectedPartContent = FileTools.readFile(dir, "2-left.xml"); + String fromServerContent = FileTools.readFile(dir, "2-right.xml"); + String startPath = "/document"; + TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault(); + TreeWalkResults results = + XmlCompareJdom.compareParts(expectedPartContent, + "expected", + fromServerContent, + "from-server", + startPath, + matchSpec); + XmlCompareJdomTest.assertTreeWalkResults(results,0,0,0,true,matchSpec); + // addedRight,missingRight,textMismatches,strictMatch,treesMatch + } + + +} diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlCompareJdomTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlCompareJdomTest.java index dbc9c018d..93cb23430 100755 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlCompareJdomTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlCompareJdomTest.java @@ -39,53 +39,54 @@ public class XmlCompareJdomTest { String BANNER ="-------------------------------------------------------"; System.out.println(BANNER+"\r\n"+this.getClass().getName()+"\r\n"+msg+"\r\n"+BANNER); } - private void printTreeWalkResults(TreeWalkResults list){ + public static void printTreeWalkResults(TreeWalkResults list){ for (TreeWalkResults.TreeWalkEntry entry : list){ System.out.println(entry.toString()); } } - private void assertTreeWalkResults(TreeWalkResults results, - int addedRight, - int missingRight, - int textMismatches, - boolean strictMatch, - boolean treesMatch){ - System.out.println("assertTreeWalkResults: "); + static void assertTrue(boolean stmt, String msg, TreeWalkResults results){ + if (!stmt){ + System.out.println("=====> Assertion Failed: "+msg); + printTreeWalkResults(results); + } + Assert.assertTrue(stmt, msg); + } + static void assertEquals(Object o1, Object o2, String msg, TreeWalkResults results){ + if ( ! o1.equals(o2)) { + System.out.println("=====> Assertion Equals Failed: "+" o1: {"+o1+"} o2: {"+o2+"}"+"\r\n "+msg); + printTreeWalkResults(results); + } + Assert.assertEquals(o1, o2, msg); + } + public static void assertTreeWalkResults(TreeWalkResults results, + int addedRight, + int missingRight, + int textMismatches, + boolean strictMatch, + TreeWalkResults.MatchSpec matchSpec){ int addedr = results.countFor(TreeWalkResults.TreeWalkEntry.STATUS.R_ADDED); int missingr = results.countFor(TreeWalkResults.TreeWalkEntry.STATUS.R_MISSING); int tdiff = results.countFor(TreeWalkResults.TreeWalkEntry.STATUS.TEXT_DIFFERENT); int badCount = results.getMismatchCount(); boolean strict = results.isStrictMatch(); - boolean treeOK = results.treesMatch(); + boolean treeOK = results.treesMatch(matchSpec); - String expected = " expected: addedRight:"+addedRight+",missingRight:"+missingRight+",textMismatches:"+textMismatches - +",strictMatch:"+strictMatch+",treesMatch:"+treesMatch; - - String actual = " actual: addedRight:"+addedr+",missingRight:"+missingr+",textMismatches:"+tdiff - +",strictMatch:"+strict+",treesMatch:"+treeOK; + String expected = "\r\n expected: addedRight:"+addedRight+",missingRight:"+missingRight+",textMismatches:"+textMismatches + +",strictMatch:"+strictMatch+",matchSpec:"+matchSpec; + String actual = "\r\n actual: addedRight:"+addedr+",missingRight:"+missingr+",textMismatches:"+tdiff + +",strictMatch:"+strict+",matchSpec:"+matchSpec; String exp_act = expected +"\r\n"+actual+"\r\n"; - System.out.print(exp_act); - - printTreeWalkResults(results); - - boolean done = false; try { - Assert.assertEquals(addedr, addedRight, "assertTreeWalkResults:R_ADDED mismatch."+exp_act); - - Assert.assertEquals(missingr, missingRight, "assertTreeWalkResults:R_MISSING mismatch."+exp_act); - - Assert.assertEquals(tdiff, textMismatches, "assertTreeWalkResults:TEXT_DIFFERENT mismatch."+exp_act); - - - Assert.assertTrue((strict==strictMatch), "assertTreeWalkResults:strictMatch mismatch."+exp_act); - - Assert.assertTrue((treeOK==treesMatch), "assertTreeWalkResults:treesMatch mismatch."+exp_act); - - System.out.println("SUCCESS: assertTreeWalkResults done.\r\n"); + assertEquals(addedr, addedRight, "assertTreeWalkResults:R_ADDED mismatch." + exp_act, results); + assertEquals(missingr, missingRight, "assertTreeWalkResults:R_MISSING mismatch." + exp_act, results); + assertEquals(tdiff, textMismatches, "assertTreeWalkResults:TEXT_DIFFERENT mismatch." + exp_act, results); + assertTrue((strict == strictMatch), "assertTreeWalkResults:strictMatch mismatch." + exp_act, results); + assertTrue((treeOK), "assertTreeWalkResults:treesMatch("+matchSpec+") returned false."+exp_act, results); + //System.out.println("SUCCESS: assertTreeWalkResults done.\r\n"); done = true; } finally { if (!done) System.out.println("FAILURE: assertTreeWalkResults failed an assertion. See surefire report.\r\n"); @@ -95,26 +96,31 @@ public class XmlCompareJdomTest { @Test public void testXmlCompareJdom(){ testBanner("testXmlCompareJdom"); + TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault(); TreeWalkResults results = XmlCompareJdom.compareParts(expectedPartContent, "expected", partFromServer, "from-server", - exPARTNAME); - assertTreeWalkResults(results,0,0,0,true,true); + exPARTNAME, + matchSpec); + assertTreeWalkResults(results,0,0,0,true,matchSpec); // addedRight,missingRight,textMismatches,strictMatch,treesMatch } @Test public void testTextContentDifferent(){ testBanner("testTextContentDifferent"); + TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault(); + matchSpec.removeErrorFromSpec(TreeWalkResults.TreeWalkEntry.STATUS.TEXT_DIFFERENT); TreeWalkResults results = XmlCompareJdom.compareParts(expectedPartContent, "expected", srvHEAD+srvEN2+srvDEPOSITOR+srvFOOT, "from-server", - exPARTNAME); - assertTreeWalkResults(results,0,0,1,false,true); + exPARTNAME, + matchSpec); + assertTreeWalkResults(results,0,0,1,false,matchSpec); // addedRight,missingRight,textMismatches,strictMatch,treesMatch } @@ -122,13 +128,15 @@ public class XmlCompareJdomTest { @Test public void testAddedR(){ testBanner("testAddedR"); + TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault(); TreeWalkResults results = XmlCompareJdom.compareParts(expectedPartContent, "expected", srvHEAD+srvEN+exNEWTREE+srvDEPOSITOR+exNEW+srvFOOT, "from-server", - exPARTNAME); - assertTreeWalkResults(results,2,0,0,false,false); + exPARTNAME, + matchSpec); + assertTreeWalkResults(results,2,0,0,false,matchSpec); // addedRight,missingRight,textMismatches,strictMatch,treesMatch } @@ -136,26 +144,32 @@ public class XmlCompareJdomTest { @Test public void testAddedL(){ testBanner("testAddedL"); + TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault(); + matchSpec.removeErrorFromSpec(TreeWalkResults.TreeWalkEntry.STATUS.R_MISSING); + TreeWalkResults results = XmlCompareJdom.compareParts(exHEAD + exEN_WCH + exNEWTREE + exDEP + exNEW + exFOOT, "expected", partFromServer, "from-server", - exPARTNAME); - assertTreeWalkResults(results,0,3,0,false,false); + exPARTNAME, + matchSpec); + assertTreeWalkResults(results,0,3,0,false,matchSpec); // addedRight,missingRight,textMismatches,strictMatch,treesMatch } @Test public void testChildrenReordered(){ testBanner("testChildrenReordered"); + TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault(); TreeWalkResults results = XmlCompareJdom.compareParts(exHEAD + exDEP + exEN + exFOOT, "expected", partFromServer, "from-server", - exPARTNAME); - assertTreeWalkResults(results,0,0,0,true,true); + exPARTNAME, + matchSpec); + assertTreeWalkResults(results,0,0,0,true,matchSpec); // addedRight,missingRight,textMismatches,strictMatch,treesMatch } diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/1-left.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/1-left.xml new file mode 100644 index 000000000..f400b9d6a --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/1-left.xml @@ -0,0 +1,37 @@ + + + johnWayneActorChild + + + 0 + 2 + 2 + subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object + + 1deda741-3b08-41ca-9681 + hasBroader + d19bf94c-53c3-4295-8e5c + + 1deda741-3b08-41ca-9681 + johnWayneActorChild2 + + + d19bf94c-53c3-4295-8e5c + johnWayneActor + + + + 6e951b58-2087-4eea-a6b1 + hasBroader + d19bf94c-53c3-4295-8e5c + + 6e951b58-2087-4eea-a6b1 + johnWayneActorChild3 + + + d19bf94c-53c3-4295-8e5c + johnWayneActor + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/1-right.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/1-right.xml new file mode 100644 index 000000000..e69e2f2df --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/1-right.xml @@ -0,0 +1,111 @@ + + + + Wayne + Winterset, Iowa + June 11, 1979 + + johnWayneActorChild + JohnWayne + + male + May 26, 1907 + John + + Irish + Scottish + + + born Marion Robert Morrison and betterknown by his stage name John Wayne, was an American film actor, director and producer. He epitomized rugged masculinity and has become an enduring American icon. He is famous for his distinctive + voice, walk and height. He was also known for his conservative political views and his support in the 1950s for anti-communist positions. + false + 28d949e9-794b-457a-93fe + false + 53ef7d20-4154-4ce9-952d + urn:cspace:org.collectionspace.demo:personauthority:name(CSPACE3739PersonAuthority):person:name(johnWayneActorChild)'John Wayne' + John Wayne + + + 1 + 2011-04-28T23:46:08Z + 2011-04-28T23:46:08Z + + + + 74bb3d58-a8cb-4367-86da-d48f8fa5aece + admin@collectionspace.org + + + 71 + c5509eda-9e3f-4cad-91ea-4efeedc650c4 + persons + CRUDL + + + 70 + fcfec805-ee00-4888-8196-0389d30ca5fa + /personauthorities/*/items/*/workflow/ + CRUDL + + + + 0 + 40 + 2 + 2 + subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object + + /relations/2f1bacd7-6fc6-41bf-a8d6 + 2f1bacd7-6fc6-41bf-a8d6 + 1deda741-3b08-41ca-9681 + hasBroader + hasBroader + d19bf94c-53c3-4295-8e5c + + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/1deda741-3b08-41ca-9681 + 1deda741-3b08-41ca-9681 + Person + John Wayne + johnWayneActorChild2 + Person + Person + + + /persons/53ef7d20-4154-4ce9-952d/items/d19bf94c-53c3-4295-8e5c + d19bf94c-53c3-4295-8e5c + Person + John Wayne + johnWayneActor + Person + Person + + + + /relations/46aa804f-53e0-4c42-aa2b + 46aa804f-53e0-4c42-aa2b + 6e951b58-2087-4eea-a6b1 + hasBroader + hasBroader + d19bf94c-53c3-4295-8e5c + + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/6e951b58-2087-4eea-a6b1 + 6e951b58-2087-4eea-a6b1 + Person + John Wayne + johnWayneActorChild3 + Person + Person + + + /persons/53ef7d20-4154-4ce9-952d/items/d19bf94c-53c3-4295-8e5c + d19bf94c-53c3-4295-8e5c + Person + John Wayne + johnWayneActor + Person + Person + + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/2-left.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/2-left.xml new file mode 100644 index 000000000..380a43573 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/2-left.xml @@ -0,0 +1,26 @@ + + + 0 + 2 + 2 + subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object + + AA + + + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/6e951b58-2087-4eea-a6b1 + + + + + BB + + + + + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/2-right.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/2-right.xml new file mode 100644 index 000000000..c574fa949 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/2-right.xml @@ -0,0 +1,27 @@ + + + + 0 + 2 + 2 + subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object + + AA + + + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/6e951b58-2087-4eea-a6b1 + + + + + BB + + + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/6e951b58-2087-4eea-a6b1 + + + + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml index 56e80ff96..ea2cc929b 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml @@ -12,7 +12,7 @@ http://localhost:8180 - + YWRtaW5AY29sbGVjdGlvbnNwYWNlLm9yZzpBZG1pbmlzdHJhdG9y @@ -92,6 +92,7 @@ + --> diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/objectexit/object-exit.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/objectexit/object-exit.xml index 1f2cb1044..3ef6018f4 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/objectexit/object-exit.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/objectexit/object-exit.xml @@ -90,9 +90,9 @@ objectexit/res/oe35.res.xml - ${oe35.CSID} + ${oe35.CSID} - //objectexit-list-item[./exitNumber='checkList-1234'] diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/objectexit/res/oe35.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/objectexit/res/oe35.res.xml index 85d4af99b..7062c6b39 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/objectexit/res/oe35.res.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/objectexit/res/oe35.res.xml @@ -7,7 +7,7 @@ exitNumber|currentOwner|uri|csid ${exitNumber} - /objectexit/${CSID} - ${CSID} + /objectexit/${targetCSID} + ${targetCSID} diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml index c48d38088..840bbc84e 100755 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml @@ -172,6 +172,12 @@ /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}?showRelations=true + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${PersonChild.CSID}?showSiblings=true + + + PUT /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${Person1.CSID} @@ -275,6 +281,17 @@ + + POST + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/ + person/persons_common.xml + + ${PersonAuth1.CSID} + CSPACE3739PersonAuthority + johnWayneActorChild3 + + + POST /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/ @@ -283,13 +300,15 @@ ${PersonAuth1.CSID} CSPACE3739PersonAuthority johnWayneActor - ${itemCSID} + ${PersonParent.CSID} /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${PersonParent.CSID} ${PersonChild.CSID} /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${PersonChild.CSID} ${PersonChild2.CSID} /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${PersonChild2.CSID} + ${PersonChild3.CSID} + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${PersonChild3.CSID} @@ -298,5 +317,54 @@ /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}?showRelations=true + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${PersonChild.CSID}?showSiblings=true + + + person/res/GETpostPerson_siblings.res.xml + + ${Person1.CSID} + ${PersonChild.CSID} + ${PersonChild2.CSID} + ${PersonChild3.CSID} + + /document/*[local-name()='relations-common-list'] + + + + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}?showAllRelations=true + + + person/res/showAllRelations.res.xml + + /document/*[local-name()='relations-common-list'] + + + + + + GET + /cspace-services/relations/ + + + + GET + /cspace-services/relations?sbj=${PersonAuth1.CSID} + + + + GET + /cspace-services/relations?obj=${PersonAuth1.CSID} + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations_POST.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations_POST.xml index b37fc2b58..a76a9881e 100755 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations_POST.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations_POST.xml @@ -21,7 +21,10 @@ born Marion Robert Morrison and betterknown by his stage name John Wayne, was an American film actor, director and producer. He epitomized rugged masculinity and has become an enduring American icon. He is famous for his distinctive voice, walk and height. He was also known for his conservative political views and his support in the 1950s for anti-communist positions. - + 0 40 @@ -48,7 +51,7 @@ ${childCSID} ${childUri} Person - John Wayne 2, the evil twin, child + John Wayne 1, the evil twin, child ${itemCSID} @@ -70,6 +73,20 @@ John Wayne + + hasBroader + + ${child3Uri} + ${child3CSID} + Person + John Wayne 3, the evil twin, child + + + ${itemCSID} + Person + John Wayne + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/GETpostPerson_siblings.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/GETpostPerson_siblings.res.xml new file mode 100644 index 000000000..bdb943479 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/GETpostPerson_siblings.res.xml @@ -0,0 +1,38 @@ + + + johnWayneActorChild + + + 0 + 2 + 2 + subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object + + ${child2CSID} + hasBroader + ${personCSID} + + ${child2CSID} + johnWayneActorChild2 + + + ${personCSID} + johnWayneActor + + + + ${child3CSID} + hasBroader + ${personCSID} + + ${child3CSID} + johnWayneActorChild3 + + + ${personCSID} + johnWayneActor + + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/showAllRelations.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/showAllRelations.res.xml new file mode 100644 index 000000000..3f0505624 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/showAllRelations.res.xml @@ -0,0 +1,66 @@ + + + + 4 + + + + + ${Person1.CSID} + ${PersonParent.CSID} + hasBroader + + ${Person1.CSID} + + + ${PersonParent.CSID} + + + + + ${PersonChild.CSID} + ${Person1.CSID} + hasBroader + + ${PersonChild.CSID} + + + ${Person1.CSID} + + + + + ${PersonChild2.CSID} + ${Person1.CSID} + hasBroader + + + ${PersonChild2.CSID} + + + ${Person1.CSID} + + + + + ${PersonChild3.CSID} + ${Person1.CSID} + hasBroader + + ${PersonChild3.CSID} + + + ${Person1.CSID} + + + + diff --git a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index 50231e04d..e4965263d 100644 --- a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -202,16 +202,52 @@ public abstract class AuthorityItemDocumentModelHandler objectProps.remove(AuthorityItemJAXBSchema.CSID); } - @Override - public void extractAllParts(DocumentWrapper wrapDoc) - throws Exception { + @Override + public void extractAllParts(DocumentWrapper wrapDoc) throws Exception { MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext(); super.extractAllParts(wrapDoc); - String showRelations = ctx.getQueryParams().getFirst(CommonAPI.showRelations_QP); - if (!Tools.isTrue(showRelations)){ - return; - } - String thisCSID = NuxeoUtils.getCsid(wrapDoc.getWrappedObject()); + + String showSiblings = ctx.getQueryParams().getFirst(CommonAPI.showSiblings_QP); + if (Tools.isTrue(showSiblings)) { + showSiblings(wrapDoc, ctx); + return; // actual result is returned on ctx.addOutputPart(); + } + + String showRelations = ctx.getQueryParams().getFirst(CommonAPI.showRelations_QP); + if (Tools.isTrue(showRelations)) { + showRelations(wrapDoc, ctx); + return; // actual result is returned on ctx.addOutputPart(); + } + + String showAllRelations = ctx.getQueryParams().getFirst(CommonAPI.showAllRelations_QP); + if (Tools.isTrue(showAllRelations)) { + showAllRelations(wrapDoc, ctx); + return; // actual result is returned on ctx.addOutputPart(); + } + } + + /** @return null on parent not found + */ + protected String getParentCSID(String thisCSID) throws Exception { + String parentCSID = null; + try { + String predicate = RelationshipType.HAS_BROADER.value(); + RelationsCommonList parentListOuter = getRelations(thisCSID, null, predicate); + List parentList = parentListOuter.getRelationListItem(); + if (parentList != null) { + RelationsCommonList.RelationListItem relationListItem = parentList.get(0); + parentCSID = relationListItem.getObjectCsid(); + } + return parentCSID; + } catch (Exception e) { + logger.error("Could not find parent for this: "+thisCSID, e); + return null; + } + } + + public void showRelations(DocumentWrapper wrapDoc, + MultipartServiceContext ctx) throws Exception { + String thisCSID = NuxeoUtils.getCsid(wrapDoc.getWrappedObject()); String predicate = RelationshipType.HAS_BROADER.value(); RelationsCommonList parentListOuter = getRelations(thisCSID, null, predicate); @@ -236,6 +272,62 @@ public abstract class AuthorityItemDocumentModelHandler ctx.addOutputPart(relationsPart); } + public void showSiblings(DocumentWrapper wrapDoc, + MultipartServiceContext ctx) throws Exception { + String thisCSID = NuxeoUtils.getCsid(wrapDoc.getWrappedObject()); + String parentCSID = getParentCSID(thisCSID); + if (parentCSID == null){ + logger.warn("~~~~~\r\n~~~~ Could not find parent for this: "+thisCSID); + return; + } + + String predicate = RelationshipType.HAS_BROADER.value(); + RelationsCommonList siblingListOuter = getRelations(null, parentCSID, predicate); + List siblingList = siblingListOuter.getRelationListItem(); + + List toRemoveList = newList(); + + + RelationsCommonList.RelationListItem item = null; + for (RelationsCommonList.RelationListItem sibling : siblingList) { + if (thisCSID.equals(sibling.getSubjectCsid())){ + toRemoveList.add(sibling); //IS_A copy of the main item, i.e. I have a parent that is my parent, so I'm in the list from the above query. + } + } + //rather than create an immutable iterator, I'm just putting the items to remove on a separate list, then looping over that list and removing. + for (RelationsCommonList.RelationListItem self : toRemoveList) { + removeFromList(siblingList, self); + } + + long siblingSize = siblingList.size(); + siblingListOuter.setTotalItems(siblingSize); + siblingListOuter.setItemsInPage(siblingSize); + + PayloadOutputPart relationsPart = new PayloadOutputPart(RelationClient.SERVICE_COMMON_LIST_NAME,siblingListOuter); + ctx.addOutputPart(relationsPart); + } + + public void showAllRelations(DocumentWrapper wrapDoc, MultipartServiceContext ctx) throws Exception { + String thisCSID = NuxeoUtils.getCsid(wrapDoc.getWrappedObject()); + + RelationsCommonList subjectListOuter = getRelations(thisCSID, null, null); // nulls are wildcards: predicate=*, and object=* + List subjectList = subjectListOuter.getRelationListItem(); + + RelationsCommonList objectListOuter = getRelations(null, thisCSID, null); // nulls are wildcards: subject=*, and predicate=* + List objectList = objectListOuter.getRelationListItem(); + + // MERGE LISTS: + subjectList.addAll(objectList); + + //now subjectList actually has records BOTH where thisCSID is subject and object. + long relatedSize = subjectList.size(); + subjectListOuter.setTotalItems(relatedSize); + subjectListOuter.setItemsInPage(relatedSize); + + PayloadOutputPart relationsPart = new PayloadOutputPart(RelationClient.SERVICE_COMMON_LIST_NAME,subjectListOuter); + ctx.addOutputPart(relationsPart); + } + public void fillAllParts(DocumentWrapper wrapDoc, Action action) throws Exception { super.fillAllParts(wrapDoc, action); ServiceContext ctx = getServiceContext(); diff --git a/services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java b/services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java index d08232e0b..b64d98db1 100755 --- a/services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java @@ -11,6 +11,9 @@ public class CommonAPI { return COMMON_API; } public static String AuthorityItemCSID_REPLACE="${itemCSID}"; + public static String showRelations_QP = "showRelations"; + public static String showSiblings_QP = "showSiblings"; + public static String showAllRelations_QP = "showAllRelations"; }