From 9c948447f11aa831b0e567d374e8d0b02be62b3d Mon Sep 17 00:00:00 2001 From: James Cover jdcove2 Date: Tue, 4 Feb 2025 21:10:47 +0000 Subject: [PATCH] Specify difference messages in test code for IBaseDataObjectDiffHelper. --- .../core/IBaseDataObjectDiffHelperTest.java | 141 +++++++++++------- 1 file changed, 88 insertions(+), 53 deletions(-) diff --git a/src/test/java/emissary/core/IBaseDataObjectDiffHelperTest.java b/src/test/java/emissary/core/IBaseDataObjectDiffHelperTest.java index 7077201919..d9ebfb8175 100644 --- a/src/test/java/emissary/core/IBaseDataObjectDiffHelperTest.java +++ b/src/test/java/emissary/core/IBaseDataObjectDiffHelperTest.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Set; @@ -25,6 +26,7 @@ import javax.annotation.Nullable; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertIterableEquals; import static org.junit.jupiter.api.Assertions.assertThrows; class IBaseDataObjectDiffHelperTest extends UnitTest { @@ -46,27 +48,42 @@ void setup() { differences = new ArrayList<>(); } - private void verifyDiff(final int expectedDifferences) { - verifyDiff(expectedDifferences, EMPTY_OPTIONS); + private void verifyDiff(final List expectedDifferencesForward, final List expectedDifferencesReverse) { + verifyDiff(expectedDifferencesForward, expectedDifferencesReverse, EMPTY_OPTIONS); } - private void verifyDiff(final int expectedDifferences, final DiffCheckConfiguration options) { + private void verifyDiff(final List expectedDifferencesForward, final List expectedDifferencesReverse, + final DiffCheckConfiguration options) { IBaseDataObjectDiffHelper.diff(ibdo1, ibdo1, differences, options); assertEquals(0, differences.size()); IBaseDataObjectDiffHelper.diff(ibdo1, ibdo2, differences, options); - assertEquals(expectedDifferences, differences.size()); + replaceVariableText(differences); + assertIterableEquals(expectedDifferencesForward, differences); differences.clear(); IBaseDataObjectDiffHelper.diff(ibdo2, ibdo1, differences, options); - assertEquals(expectedDifferences, differences.size()); + replaceVariableText(differences); + assertIterableEquals(expectedDifferencesReverse, differences); differences.clear(); } - private void verifyDiffList(final int expectedDifferences, @Nullable final List list1, + private static void replaceVariableText(final List differences) { + for (int i = 0; i < differences.size(); i++) { + final String difference = differences.remove(i); + final String differenceNohash = difference.replaceAll("@[0-9a-fA-F]{5,8}", "@xxxxxxxx"); + final String differenceNohashNouuid = + differenceNohash.replaceAll("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}", + "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); + + differences.add(i, differenceNohashNouuid); + } + } + + private void verifyDiffList(final List expectedDifferences, @Nullable final List list1, @Nullable final List list2) { IBaseDataObjectDiffHelper.diff(list1, list1, "test", differences, EMPTY_OPTIONS); assertEquals(0, differences.size()); IBaseDataObjectDiffHelper.diff(list1, list2, "test", differences, EMPTY_OPTIONS); - assertEquals(expectedDifferences, differences.size()); + assertIterableEquals(expectedDifferences, differences); differences.clear(); } @@ -104,11 +121,13 @@ void testDiffArguments() { @Test void testDiffChannelFactory() { ibdo2.setData(new byte[1]); - verifyDiff(1, CHECK_DATA); + verifyDiff(List.of("data not equal. sbcf1=null sbcf2=emissary.core.channels.ImmutableChannelFactory$ImmutableChannelFactoryImpl@xxxxxxxx"), + List.of("data not equal. sbcf1=emissary.core.channels.ImmutableChannelFactory$ImmutableChannelFactoryImpl@xxxxxxxx sbcf2=null"), + CHECK_DATA); ibdo1.setChannelFactory(InMemoryChannelFactory.create("0123456789".getBytes(StandardCharsets.US_ASCII))); ibdo2.setChannelFactory(InMemoryChannelFactory.create("9876543210".getBytes(StandardCharsets.US_ASCII))); - verifyDiff(1, CHECK_DATA); + verifyDiff(List.of("data not equal. 1.cs=10 2.cs=10"), List.of("data not equal. 1.cs=10 2.cs=10"), CHECK_DATA); ibdo2.setChannelFactory(new SeekableByteChannelFactory() { @Override @@ -132,7 +151,8 @@ protected long sizeImpl() throws IOException { } }); - verifyDiff(1, CHECK_DATA); + verifyDiff(List.of("Failed to compare data: Test SBC that always throws IOException!"), + List.of("Failed to compare data: Test SBC that always throws IOException!"), CHECK_DATA); } @Test @@ -140,7 +160,7 @@ void testDiffCurrentForm() { ibdo1.pushCurrentForm("AAA"); ibdo1.pushCurrentForm("BBB"); ibdo1.pushCurrentForm("CCC"); - verifyDiff(1); + verifyDiff(List.of("currentForm are not equal: CCC : "), List.of("currentForm are not equal: : CCC")); } @Test @@ -148,7 +168,8 @@ void testDiffHistory() { ibdo1.appendTransformHistory("AAA", false); ibdo1.appendTransformHistory("BBB", true); final DiffCheckConfiguration checkTransformHistory = DiffCheckConfiguration.configure().enableTransformHistory().build(); - verifyDiff(1, checkTransformHistory); + verifyDiff(List.of("transformHistory are not equal: [AAA] : []"), List.of("transformHistory are not equal: [] : [AAA]"), + checkTransformHistory); } @Test @@ -159,9 +180,13 @@ void testDiffParameters() { ibdo1.putParameter("STRING", "string"); ibdo1.putParameter("LIST", Arrays.asList("first", "second", "third")); - verifyDiff(1); - verifyDiff(1, checkKeyValueDiffParameter); - verifyDiff(1, checkDetailedDiffParameter); + verifyDiff(List.of("meta are not equal-Differing Keys: [LIST, STRING] : []"), + List.of("meta are not equal-Differing Keys: [] : [LIST, STRING]")); + verifyDiff(List.of("meta are not equal-Differing Keys/Values: {LIST=[first, second, third], STRING=[string]} : {}"), + List.of("meta are not equal-Differing Keys/Values: {} : {LIST=[first, second, third], STRING=[string]}"), + checkKeyValueDiffParameter); + verifyDiff(List.of("meta are not equal: {LIST=[first, second, third], STRING=[string]} : {}"), + List.of("meta are not equal: {} : {LIST=[first, second, third], STRING=[string]}"), checkDetailedDiffParameter); ibdo1.clearParameters(); ibdo2.clearParameters(); @@ -169,9 +194,11 @@ void testDiffParameters() { ibdo1.putParameter("Integer", Integer.valueOf(1)); ibdo2.putParameter("STRING", "string"); - verifyDiff(1); - verifyDiff(1, checkKeyValueDiffParameter); - verifyDiff(1, checkDetailedDiffParameter); + verifyDiff(List.of("meta are not equal-Differing Keys: [Integer] : []"), List.of("meta are not equal-Differing Keys: [] : [Integer]")); + verifyDiff(List.of("meta are not equal-Differing Keys/Values: {Integer=[1]} : {}"), + List.of("meta are not equal-Differing Keys/Values: {} : {Integer=[1]}"), checkKeyValueDiffParameter); + verifyDiff(List.of("meta are not equal: {Integer=[1], STRING=[string]} : {STRING=[string]}"), + List.of("meta are not equal: {STRING=[string]} : {Integer=[1], STRING=[string]}"), checkDetailedDiffParameter); ibdo1.clearParameters(); ibdo2.clearParameters(); @@ -179,18 +206,20 @@ void testDiffParameters() { ibdo2.putParameter("STRING", "string"); ibdo2.putParameter("Integer", Integer.valueOf(1)); - verifyDiff(1); - verifyDiff(1, checkKeyValueDiffParameter); - verifyDiff(1, checkDetailedDiffParameter); + verifyDiff(List.of("meta are not equal-Differing Keys: [] : [Integer]"), List.of("meta are not equal-Differing Keys: [Integer] : []")); + verifyDiff(List.of("meta are not equal-Differing Keys/Values: {} : {Integer=[1]}"), + List.of("meta are not equal-Differing Keys/Values: {Integer=[1]} : {}"), checkKeyValueDiffParameter); + verifyDiff(List.of("meta are not equal: {STRING=[string]} : {Integer=[1], STRING=[string]}"), + List.of("meta are not equal: {Integer=[1], STRING=[string]} : {STRING=[string]}"), checkDetailedDiffParameter); ibdo1.clearParameters(); ibdo2.clearParameters(); ibdo1.putParameter("STRING", "string"); ibdo2.putParameter("STRING", "string"); - verifyDiff(0); - verifyDiff(0, checkKeyValueDiffParameter); - verifyDiff(0, checkDetailedDiffParameter); + verifyDiff(Collections.emptyList(), Collections.emptyList()); + verifyDiff(Collections.emptyList(), Collections.emptyList(), checkKeyValueDiffParameter); + verifyDiff(Collections.emptyList(), Collections.emptyList(), checkDetailedDiffParameter); } @Test @@ -198,25 +227,27 @@ void testDiffAlternateViews() { ibdo1.addAlternateView("AAA", "AAA".getBytes(StandardCharsets.US_ASCII)); ibdo1.addAlternateView("BBB", "BBB".getBytes(StandardCharsets.US_ASCII)); ibdo1.addAlternateView("CCC", "CCC".getBytes(StandardCharsets.US_ASCII)); - verifyDiff(1); + verifyDiff(List.of("view are not equal"), List.of("view are not equal")); ibdo2.addAlternateView("DDD", "DDD".getBytes(StandardCharsets.US_ASCII)); ibdo2.addAlternateView("EEE", "EEE".getBytes(StandardCharsets.US_ASCII)); ibdo2.addAlternateView("FFF", "FFF".getBytes(StandardCharsets.US_ASCII)); - verifyDiff(1); + verifyDiff(List.of("view are not equal"), List.of("view are not equal")); } @Test void testDiffPriority() { ibdo1.setPriority(13); - verifyDiff(1); + verifyDiff(List.of("priority are not equal"), List.of("priority are not equal")); } @Test void testDiffCreationTimestamp() { ibdo1.setCreationTimestamp(Instant.ofEpochSecond(1234567890)); + ibdo2.setCreationTimestamp(Instant.ofEpochSecond(1234567891)); final DiffCheckConfiguration options = DiffCheckConfiguration.configure().enableTimestamp().build(); - verifyDiff(1, options); + verifyDiff(List.of("creationTimestamp are not equal: 2009-02-13T23:31:30Z : 2009-02-13T23:31:31Z"), + List.of("creationTimestamp are not equal: 2009-02-13T23:31:31Z : 2009-02-13T23:31:30Z"), options); } @Test @@ -224,117 +255,121 @@ void testDiffExtractedRecords() { ibdo1.addExtractedRecord(new BaseDataObject()); ibdo1.addExtractedRecord(new BaseDataObject()); ibdo1.addExtractedRecord(new BaseDataObject()); - verifyDiff(1); + verifyDiff(List.of("extractedRecords are not equal: 1.s=3 2.s=0"), List.of("extractedRecords are not equal: 1.s=0 2.s=3")); } @Test void testDiffFilename() { ibdo1.setFilename("filename"); - verifyDiff(2); + verifyDiff(List.of("filename are not equal: filename : null", "shortName are not equal: filename : null"), + List.of("filename are not equal: null : filename", "shortName are not equal: null : filename")); } @Test void testDiffInternalId() { final DiffCheckConfiguration options = DiffCheckConfiguration.configure().enableInternalId().build(); - verifyDiff(1, options); + verifyDiff(List.of("internalId are not equal: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"), + List.of("internalId are not equal: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"), + options); } @Test void testDiffProcessingError() { ibdo1.addProcessingError("processing_error"); - verifyDiff(1); + verifyDiff(List.of("processingError are not equal: processing_error\n : null"), + List.of("processingError are not equal: null : processing_error\n")); } @Test void testDiffFontEncoding() { ibdo1.setFontEncoding("font_encoding"); - verifyDiff(1); + verifyDiff(List.of("fontEncoding are not equal: font_encoding : null"), List.of("fontEncoding are not equal: null : font_encoding")); } @Test void testDiffNumChildren() { ibdo1.setNumChildren(13); - verifyDiff(1); + verifyDiff(List.of("numChildren are not equal"), List.of("numChildren are not equal")); } @Test void testDiffNumSiblings() { ibdo1.setNumSiblings(13); - verifyDiff(1); + verifyDiff(List.of("numSiblings are not equal"), List.of("numSiblings are not equal")); } @Test void testDiffBirthOrder() { ibdo1.setBirthOrder(13); - verifyDiff(1); + verifyDiff(List.of("birthOrder are not equal"), List.of("birthOrder are not equal")); } @Test void testDiffHeader() { ibdo1.setHeader("header".getBytes(StandardCharsets.US_ASCII)); - verifyDiff(1); + verifyDiff(List.of("header are not equal: [B@xxxxxxxx : null"), List.of("header are not equal: null : [B@xxxxxxxx")); } @Test void testDiffFooter() { ibdo1.setFooter("footer".getBytes(StandardCharsets.US_ASCII)); - verifyDiff(1); + verifyDiff(List.of("footer are not equal: [B@xxxxxxxx : null"), List.of("footer are not equal: null : [B@xxxxxxxx")); } @Test void testDiffHeaderEncoding() { ibdo1.setHeaderEncoding("header_encoding"); - verifyDiff(1); + verifyDiff(List.of("headerEncoding are not equal: header_encoding : null"), List.of("headerEncoding are not equal: null : header_encoding")); } @Test void testDiffClassification() { ibdo1.setClassification("classification"); - verifyDiff(1); + verifyDiff(List.of("classification are not equal: classification : null"), List.of("classification are not equal: null : classification")); } @Test void testDiffBroken() { ibdo1.setBroken("broken"); - verifyDiff(1); + verifyDiff(List.of("broken are not equal"), List.of("broken are not equal")); } @Test void testDiffOutputable() { ibdo1.setOutputable(false); - verifyDiff(1); + verifyDiff(List.of("outputable are not equal"), List.of("outputable are not equal")); } @Test void testDiffId() { ibdo1.setId("id"); - verifyDiff(1); + verifyDiff(List.of("id are not equal: id : null"), List.of("id are not equal: null : id")); } @Test void testDiffWorkBundleId() { ibdo1.setWorkBundleId("workbundle_id"); - verifyDiff(1); + verifyDiff(List.of("workBundleId are not equal: workbundle_id : null"), List.of("workBundleId are not equal: null : workbundle_id")); } @Test void testDiffTransactionId() { ibdo1.setTransactionId("transaction_id"); - verifyDiff(1); + verifyDiff(List.of("transactionId are not equal: transaction_id : null"), List.of("transactionId are not equal: null : transaction_id")); } @Test void testDiffList() { final List ibdoList3 = Arrays.asList(ibdo1, ibdo2); - verifyDiffList(0, null, null); - verifyDiffList(0, new ArrayList<>(), null); - verifyDiffList(0, null, new ArrayList<>()); - verifyDiffList(0, ibdoList1, ibdoList1); - verifyDiffList(1, ibdoList3, ibdoList2); - verifyDiffList(1, ibdoList1, ibdoList3); + verifyDiffList(Collections.emptyList(), null, null); + verifyDiffList(Collections.emptyList(), new ArrayList<>(), null); + verifyDiffList(Collections.emptyList(), null, new ArrayList<>()); + verifyDiffList(Collections.emptyList(), ibdoList1, ibdoList1); + verifyDiffList(List.of("test are not equal: 1.s=2 2.s=1"), ibdoList3, ibdoList2); + verifyDiffList(List.of("test are not equal: 1.s=1 2.s=2"), ibdoList1, ibdoList3); ibdo2.setClassification("classification"); - verifyDiffList(1, ibdoList1, ibdoList2); + verifyDiffList(List.of("test : 0 : classification are not equal: null : classification"), ibdoList1, ibdoList2); } @Test @@ -354,7 +389,7 @@ void testParamSort() { } @Test - void testDecoderIOExceptions() throws IOException { + void testDecoderIOExceptions() { assertThrows(IOException.class, () -> IBaseDataObjectXmlCodecs.DEFAULT_BOOLEAN_DECODER.decode(null, null, "badMethodName")); assertThrows(IOException.class, () -> IBaseDataObjectXmlCodecs.DEFAULT_SEEKABLE_BYTE_CHANNEL_FACTORY_DECODER.decode(null, null, "badMethodName"));