private static boolean isDeleted( final Comparison comparison ) { return comparison.getTestDetails().getTarget() == null; }
private static boolean isAttrDeleted( final Comparison comparison ) { return comparison.getTestDetails().getValue() == null; }
@Override public void describeMismatch(final Object item, final Description description) { final Comparison difference = firstComparison(); final String controlString = comparisonFormatter.getDetails(difference.getTestDetails(), difference.getType(), formatXml); description.appendText(String.format("result was: \n%s", controlString)); }
private void printNodeDiff( final Comparison comparison ) { final String oldText = printNode.nodeToString( comparison.getControlDetails().getTarget() ); final String newText = printNode.nodeToString( comparison.getTestDetails().getTarget() ); printFullNodeDiff( testDoc, comparison, oldText, newText ); }
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; }
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() ) ); }
private static boolean belongsToProlog(Comparison comparison, boolean ignoreDoctypeDeclarationAsWell) { if (comparison.getType().isDoctypeComparison()) { return ignoreDoctypeDeclarationAsWell; } return belongsToProlog(comparison.getControlDetails().getTarget(), ignoreDoctypeDeclarationAsWell) || belongsToProlog(comparison.getTestDetails().getTarget(), ignoreDoctypeDeclarationAsWell); }
private boolean isDocumentWithDocTypeDifference(Comparison comparison) { if (!(comparison.getControlDetails().getTarget() instanceof Document)) { return false; } return hasDoctypeChild(comparison.getControlDetails().getTarget()) || hasDoctypeChild(comparison.getTestDetails().getTarget()); }
case CHILD_NODELIST_LENGTH: Comparison.Detail cd = comp.getControlDetails(); Comparison.Detail td = comp.getTestDetails(); if (ZERO.equals(cd.getValue()) || ZERO.equals(td.getValue())) { toNodeDetail(comp.getTestDetails())));
/** * @return an instants of {@link org.junit.ComparisonFailure} or <code>null</code> if the class is not available. */ private AssertionError createComparisonFailure() { final Comparison difference = firstComparison(); final String reason = createReasonPrefix(diffResult.getControlSource().getSystemId(), difference); final String controlString = comparisonFormatter.getDetails(difference.getControlDetails(), difference .getType(), formatXml); final String testString = comparisonFormatter.getDetails(difference.getTestDetails(), difference.getType(), formatXml); return createComparisonFailure(reason, controlString, testString); }
/** * 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); }
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( " . " ); output.endSpan(); final String parentNodeXpath = XmlDomUtils.wideContext( comparison.getTestDetails().getXPath() ); final NodeChangesHolder changeHolder = semanticDiff.updateHolder( semanticDiff.addChangeHolder( parentNodeXpath ), NodeChangesHolder.OpType.ADDED, holderNodeText( testDoc, comparison.getTestDetails() ) ); changeHolder.addedAttribute( nodeText, attributeText ); changeHolder.removedAttribute( controlNodeText, controlAttributeText ); semanticDiff.updateHolder( changeHolder, NodeChangesHolder.OpType.ADDED, holderNodeText( testDoc, comparison.getTestDetails() ) ); final String nodeText = printNode.nodeToString( xmlDomUtils.findNode( testDoc, comparison.getTestDetails().getParentXPath() ) ); final String attributeText = printNode.attrToString( (Attr)comparison.getTestDetails().getTarget() ); output.startSpan( "MODIFIED ; changed attribute [" + attributeText + "] <!-- xpath: " + comparison.getTestDetails().getXPath() + " -->" ); output.writeRaw( " . " ); output.endSpan(); final String parentNodeXpath = XmlDomUtils.wideContext( comparison.getTestDetails().getXPath() ); final NodeChangesHolder changeHolder = semanticDiff.updateHolder( semanticDiff.addChangeHolder( parentNodeXpath ), NodeChangesHolder.OpType.ADDED, holderNodeText( testDoc, comparison.getTestDetails() ) ); changeHolder.addedAttribute( nodeText, attributeText );
String description = type.getDescription(); final Detail controlDetails = difference.getControlDetails(); final Detail testDetails = difference.getTestDetails(); final String controlTarget = getShortString(controlDetails.getTarget(), controlDetails.getXPath(),
@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); }
.getControlDetails().getValue(); Short test = (Short) comparison .getTestDetails().getValue(); if ((control.equals(TEXT) && test.equals(CDATA)) ||
private void printAddedNode( final Comparison comparison ) { final Comparison.Detail details = comparison.getTestDetails(); final Node parentNode = xmlDomUtils.findNode( testDoc, details.getParentXPath() ); final String nodeText = printNode.nodeToString( xmlDomUtils.findNode( testDoc, details.getXPath() ) ); output.startSpan( "ADDED <!-- xpath: " + details.getXPath() + " (parent node: "+printNode.printNodeSignature( parentNode )+" - "+details.getParentXPath()+" ) -->"); output.writeRaw( "+ " ); output.endSpan(); // don't need to output anything //~ output.addedPart( nodeText ); //~ output.newline(); if( ! semanticDiff.markNodeAdded( XmlDomUtils.wideContext( details.getParentXPath() ), nodeText, testDoc ) ) { semanticDiff.markNodeAdded( details.getXPath(), nodeText, testDoc ); // make sure change is not lost } }
private void printModifiedNode( final Comparison comparison ) { final Comparison.Detail details = comparison.getControlDetails(); if( XmlDomUtils.xpathDepth( details.getXPath() ) == 1 ) { output.startSpan( "MODIFIED ; " + details.getXPath() + "." ); output.writeRaw( " _ " ); output.endSpan(); } else { if( comparison.getType() == ComparisonType.CHILD_NODELIST_SEQUENCE ) { output.startSpan( ". node order different: " + comparison.getTestDetails().getXPath() ); output.writeRaw( " * " ); output.endSpan(); } else if( comparison.getType() == ComparisonType.CHILD_NODELIST_LENGTH ) { printChildNodesChanged( comparison ); } else if( comparison.getType() == ComparisonType.ATTR_NAME_LOOKUP || comparison.getType() == ComparisonType.ATTR_VALUE ) { printAttrChanged( comparison ); } else { printNodeDiff( comparison ); } } }