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.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 +((status != STATUS.MATCHED) && Tools.notEmpty(ltextTrimmed) ? ",\r\n L.trimmed:"+ltextTrimmed : "")
\r
54 +((status != STATUS.MATCHED) && Tools.notEmpty(rtextTrimmed) ? ",\r\n R.trimmed:"+rtextTrimmed : "")
\r
60 public boolean hasDocErrors(){
\r
61 for (TreeWalkEntry entry : this){
\r
62 if (entry.status == TreeWalkEntry.STATUS.DOC_ERROR){
\r
69 public String getErrorMessages(){
\r
70 StringBuffer buf = new StringBuffer();
\r
71 boolean first = true;
\r
72 for (TreeWalkEntry entry : this){
\r
73 if ( Tools.notEmpty(entry.errmessage)){
\r
75 buf.append(",errors:");
\r
79 buf.append('\''+entry.errmessage+"\'");
\r
83 return buf.toString();
\r
88 public boolean isStrictMatch(){
\r
89 for (TreeWalkEntry entry : this){
\r
90 if (entry.status == TreeWalkEntry.STATUS.DOC_ERROR){
\r
93 if ( !( entry.status == TreeWalkEntry.STATUS.MATCHED
\r
94 || entry.status == TreeWalkEntry.STATUS.INFO)){
\r
100 public int getMismatchCount(){
\r
102 for (TreeWalkEntry entry : this){
\r
103 if ( entry.status == TreeWalkEntry.STATUS.DOC_ERROR
\r
104 || entry.status != TreeWalkEntry.STATUS.MATCHED
\r
105 || entry.status != TreeWalkEntry.STATUS.INFO){
\r
111 /** For our purposes, trees match if they have the same element tree structure - no checking is done for text node changes. */
\r
112 public boolean treesMatch(){
\r
113 for (TreeWalkEntry entry : this){
\r
114 if (entry.status == TreeWalkEntry.STATUS.DOC_ERROR
\r
115 || entry.status == TreeWalkEntry.STATUS.R_MISSING
\r
116 || entry.status == TreeWalkEntry.STATUS.R_ADDED ){
\r
123 public int countFor(TreeWalkEntry.STATUS status){
\r
125 for (TreeWalkEntry entry : this){
\r
126 if (entry.status.equals(status)){
\r
133 public String miniSummary(){
\r
134 //MATCHED, INFO, R_MISSING, R_ADDED, TEXT_DIFFERENT};
\r
135 StringBuffer buf = new StringBuffer();
\r
137 boolean nextline = false;
\r
138 for (TreeWalkEntry.STATUS st : TreeWalkEntry.STATUS.values()){
\r
139 if (nextline) buf.append(',');
\r
140 buf.append(st.name()+':'+countFor(st));
\r
143 buf.append(getErrorMessages());
\r
145 return buf.toString();
\r
148 public String fullSummary(){
\r
149 StringBuffer buf = new StringBuffer();
\r
150 for (TreeWalkResults.TreeWalkEntry entry : this){
\r
151 buf.append(entry.toString()).append("\r\n");
\r
153 return buf.toString();
\r
157 public String leftID;
\r
158 public String rightID;
\r