@Override public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) { if (COUNTED_COMPARISONS.contains(comparison.getType()) && comparison.getControlDetails().getValue() != null) { return outcome; } return ComparisonResult.EQUAL; } };
Comparison.Detail cd = comp.getControlDetails(); Comparison.Detail td = comp.getTestDetails(); if (ZERO.equals(cd.getValue()) || ZERO.equals(td.getValue())) { diffs.add(new Difference(HAS_CHILD_NODES, new NodeDetail(String .valueOf(!ZERO .equals(cd .getValue())), cd.getTarget(), cd.getXPath()), .valueOf(!ZERO .equals(td .getValue())), td.getTarget(), td.getXPath())));
if( isAttrAdded( comparison ) ) { final String nodeText = printNode.nodeToString( xmlDomUtils.findNode( testDoc, comparison.getTestDetails().getParentXPath() ) ); final String attributeText = printNode.attrToString( comparison.getTestDetails().getTarget(), (QName)comparison.getTestDetails().getValue() ); output.startSpan( "MODIFIED ; new attribute [" + attributeText + "] <!-- xpath: " + comparison.getTestDetails().getXPath() + " -->" ); output.writeRaw( " . " ); final String controlAttributeText = printNode.attrToString( comparison.getControlDetails().getTarget(), (QName)comparison.getControlDetails().getValue() ); output.startSpan( "MODIFIED ; removed attribute [" + controlAttributeText + "] <!-- xpath: " + comparison.getControlDetails().getXPath() + " -->" ); output.writeRaw( " . " );
@Override public String getDescription(Comparison difference) { final ComparisonType type = difference.getType(); String description = type.getDescription(); final Detail controlDetails = difference.getControlDetails(); final Detail testDetails = difference.getTestDetails(); final String controlTarget = getDetails(difference.getControlDetails(), type, true); final String testTarget = getDetails(difference.getTestDetails(), type, true); if (type == ComparisonType.ATTR_NAME_LOOKUP) { return String.format("Expected %s '%s'\nEXPEXTED:\n%s\nFOUND:\n%s", description, controlDetails.getXPath(), controlTarget, testTarget); } return String.format("Expected %s '%s' but was '%s'\nEXPEXTED:\n%s\nFOUND:\n%s", description, getValue(controlDetails.getValue(), type), getValue(testDetails.getValue(), type), controlTarget, testTarget); }
/** * Compares the detail values for object equality, lets the * difference evaluator and comparison controller evaluate the * result, notifies all listeners and returns the outcome. * * @return the outcome as pair of result and a flag that says * "stop the whole comparison process" when true. */ protected final ComparisonState compare(Comparison comp) { Object controlValue = comp.getControlDetails().getValue(); Object testValue = comp.getTestDetails().getValue(); boolean equal = controlValue == null ? testValue == null : controlValue.equals(testValue); ComparisonResult initial = equal ? ComparisonResult.EQUAL : ComparisonResult.DIFFERENT; ComparisonResult altered = getDifferenceEvaluator().evaluate(comp, initial); listeners.fireComparisonPerformed(comp, altered); return altered != ComparisonResult.EQUAL && getComparisonController().stopDiffing(new Difference(comp, altered)) ? new FinishedComparisonState(altered) : new OngoingComparisonState(altered); }
public void printChildNodesChanged( final Comparison comparison ) { final String parentNodeXpath = comparison.getTestDetails().getXPath(); final int sizeControl = (int)comparison.getControlDetails().getValue(); final int sizeTest = (int)comparison.getTestDetails().getValue(); if( sizeTest > sizeControl ) { // nodes added output.startSpan( String.format( ". %s node(s) added: %s <!-- %s -->", sizeTest - sizeControl, printNode.printNodeSignature( comparison.getTestDetails().getTarget() ), parentNodeXpath ) ); output.writeRaw( " * " ); output.endSpan(); } else { // nodes removed output.startSpan( String.format( ". %s node(s) removed: %s <!-- %s -->", sizeControl - sizeTest, printNode.printNodeSignature( comparison.getTestDetails().getTarget() ), parentNodeXpath ) ); output.writeRaw( " * " ); output.endSpan(); } final NodeChangesHolder changeHolder = semanticDiff.updateHolder( semanticDiff.addChangeHolder( XmlDomUtils.wideContext( parentNodeXpath ) ), NodeChangesHolder.OpType.ADDED, holderNodeText( testDoc, comparison.getTestDetails() ) ); semanticDiff.updateHolder( changeHolder, NodeChangesHolder.OpType.REMOVED, holderNodeText( controlDoc, comparison.getControlDetails() ) ); changeHolder.attachAutoDiffs(); semanticDiff.updateHolder( semanticDiff.addChangeHolder( XmlDomUtils.wideContext( comparison.getControlDetails().getXPath() ) ), NodeChangesHolder.OpType.REMOVED, holderNodeText( controlDoc, comparison.getControlDetails() ) ); }
public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) { if (outcome == ComparisonResult.EQUAL) { return outcome; } if (comparison.getType() == ComparisonType.CHILD_LOOKUP && (isDoctype(comparison.getControlDetails()) || isDoctype(comparison.getTestDetails()))) { return ComparisonResult.EQUAL; } if (comparison.getType() == ComparisonType.CHILD_NODELIST_LENGTH && isDocumentWithDocTypeDifference(comparison) && Math.abs((Integer) comparison.getControlDetails().getValue() - (Integer) comparison.getTestDetails().getValue()) == 1) { return ComparisonResult.EQUAL; } if (comparison.getType() == ComparisonType.CHILD_NODELIST_SEQUENCE && isDocumentWithDocTypeDifference(comparison)) { return ComparisonResult.EQUAL; } return outcome; }
private static boolean isAttrAdded( final Comparison comparison ) { return comparison.getControlDetails().getValue() == null; }
private static boolean isAttrDeleted( final Comparison comparison ) { return comparison.getTestDetails().getValue() == null; }