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
24 package org.collectionspace.services.IntegrationTests.xmlreplay;
\r
26 import org.collectionspace.services.common.api.Tools;
\r
28 import java.util.ArrayList;
\r
32 * $LastChangedRevision: $
\r
33 * $LastChangedDate: $
\r
35 public class TreeWalkResults extends ArrayList<TreeWalkResults.TreeWalkEntry> {
\r
37 public static class TreeWalkEntry {
\r
38 public String lpath = "";
\r
39 public String rpath = "";
\r
40 public String ltextTrimmed = "";
\r
41 public String rtextTrimmed = "";
\r
42 public String message = "";
\r
43 public String errmessage = "";
\r
44 public static enum STATUS {INFO, MATCHED, R_MISSING, R_ADDED, DOC_ERROR, TEXT_DIFFERENT};
\r
45 public STATUS status;
\r
46 public String toString(){
\r
50 +(Tools.notEmpty(lpath) ? ", L.path:"+lpath : "")
\r
51 +(Tools.notEmpty(rpath) ? ", R.path:"+rpath : "")
\r
52 +(Tools.notEmpty(message) ? ", message:"+message : "")
\r
53 +(Tools.notEmpty(errmessage) ? ", errmessage:"+errmessage : "")
\r
54 +((status != STATUS.MATCHED) && Tools.notEmpty(ltextTrimmed) ? ",\r\n L.trimmed:"+ltextTrimmed : "")
\r
55 +((status != STATUS.MATCHED) && Tools.notEmpty(rtextTrimmed) ? ",\r\n R.trimmed:"+rtextTrimmed : "")
\r
61 public boolean hasDocErrors(){
\r
62 for (TreeWalkEntry entry : this){
\r
63 if (entry.status == TreeWalkEntry.STATUS.DOC_ERROR){
\r
70 public String getErrorMessages(){
\r
71 StringBuffer buf = new StringBuffer();
\r
72 boolean first = true;
\r
73 for (TreeWalkEntry entry : this){
\r
74 if ( Tools.notEmpty(entry.errmessage)){
\r
76 buf.append(",errors:");
\r
80 buf.append('\''+entry.errmessage+"\'");
\r
84 return buf.toString();
\r
89 public boolean isStrictMatch(){
\r
90 for (TreeWalkEntry entry : this){
\r
91 if (entry.status == TreeWalkEntry.STATUS.DOC_ERROR){
\r
94 if ( !( entry.status == TreeWalkEntry.STATUS.MATCHED
\r
95 || entry.status == TreeWalkEntry.STATUS.INFO)){
\r
101 public int getMismatchCount(){
\r
103 for (TreeWalkEntry entry : this){
\r
104 if ( entry.status == TreeWalkEntry.STATUS.DOC_ERROR
\r
105 || entry.status != TreeWalkEntry.STATUS.MATCHED
\r
106 || entry.status != TreeWalkEntry.STATUS.INFO){
\r
112 /** For our purposes, trees match if they have the same element tree structure - no checking is done for text node changes. */
\r
113 public boolean treesMatch(){
\r
114 for (TreeWalkEntry entry : this){
\r
115 if (entry.status == TreeWalkEntry.STATUS.DOC_ERROR
\r
116 || entry.status == TreeWalkEntry.STATUS.R_MISSING
\r
117 || entry.status == TreeWalkEntry.STATUS.R_ADDED ){
\r
124 public int countFor(TreeWalkEntry.STATUS status){
\r
126 for (TreeWalkEntry entry : this){
\r
127 if (entry.status.equals(status)){
\r
134 public String miniSummary(){
\r
135 //MATCHED, INFO, R_MISSING, R_ADDED, TEXT_DIFFERENT};
\r
136 StringBuffer buf = new StringBuffer();
\r
138 boolean nextline = false;
\r
139 for (TreeWalkEntry.STATUS st : TreeWalkEntry.STATUS.values()){
\r
140 if (nextline) buf.append(',');
\r
141 buf.append(st.name()+':'+countFor(st));
\r
144 buf.append(getErrorMessages());
\r
146 return buf.toString();
\r
149 public String fullSummary(){
\r
150 StringBuffer buf = new StringBuffer();
\r
151 for (TreeWalkResults.TreeWalkEntry entry : this){
\r
152 buf.append(entry.toString()).append("\r\n");
\r
154 return buf.toString();
\r
158 public String leftID;
\r
159 public String rightID;
\r