diff --git a/src/main/java/emissary/core/BaseDataObject.java b/src/main/java/emissary/core/BaseDataObject.java index ce755643c1..69d752f613 100755 --- a/src/main/java/emissary/core/BaseDataObject.java +++ b/src/main/java/emissary/core/BaseDataObject.java @@ -972,7 +972,7 @@ public String getParameterAsString(final String key) { if (obj.size() > 1) { logger.warn("Multiple values for parameter, returning the first - parameter:{}, number of values:{}", key, obj.size()); } - return StringUtils.trimToNull(obj.stream().findFirst().orElse(null)); + return obj.stream().findFirst().orElse(null); } /** diff --git a/src/main/java/emissary/core/IBaseDataObject.java b/src/main/java/emissary/core/IBaseDataObject.java index 50571089d1..c973a495f3 100755 --- a/src/main/java/emissary/core/IBaseDataObject.java +++ b/src/main/java/emissary/core/IBaseDataObject.java @@ -4,7 +4,6 @@ import emissary.directory.DirectoryEntry; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; import java.io.IOException; import java.io.InputStream; @@ -14,6 +13,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; @@ -358,7 +358,7 @@ enum MergePolicy { */ @Deprecated default String getStringParameter(final String key) { - return getParameterAsConcatString(key); + return getStringParameter(key, DEFAULT_PARAM_SEPARATOR); } /** @@ -370,8 +370,27 @@ default String getStringParameter(final String key) { * @deprecated use {@link #getParameterAsConcatString(String, String)} */ @Deprecated + @Nullable default String getStringParameter(final String key, final String sep) { - return getParameterAsConcatString(key, sep); + final List obj = getParameter(key); + if (obj == null) { + return null; + } else if (obj.isEmpty()) { + return null; + } else if ((obj.size() == 1) && (obj.get(0) instanceof String)) { + return (String) obj.get(0); + } else if ((obj.size() == 1) && (obj.get(0) == null)) { + return null; + } else { + final StringBuilder sb = new StringBuilder(); + for (final Object item : obj) { + if (sb.length() > 0) { + sb.append(sep); + } + sb.append(item); + } + return sb.toString(); + } } /** @@ -418,8 +437,11 @@ default String getParameterAsConcatString(final String key) { */ @Nullable default String getParameterAsConcatString(final String key, final String sep) { - final var strParameter = String.join(sep, getParameterAsStrings(key)); - return StringUtils.isBlank(strParameter) ? null : strParameter; + Collection strings = getParameterAsStrings(key); + if (strings.stream().anyMatch(Objects::nonNull)) { + return String.join(sep, strings); + } + return null; } /** diff --git a/src/test/java/emissary/core/BaseDataObjectTest.java b/src/test/java/emissary/core/BaseDataObjectTest.java index 12df2bb119..cd695b6615 100755 --- a/src/test/java/emissary/core/BaseDataObjectTest.java +++ b/src/test/java/emissary/core/BaseDataObjectTest.java @@ -505,12 +505,24 @@ void testSetParameters() { void testStringParameterOnNonStringValue() { this.b.putParameter("A", 1L); assertEquals("1", this.b.getStringParameter("A"), "Non-string parameters must call toString method"); + assertEquals("1", this.b.getParameterAsConcatString("A"), "Non-string parameters must call toString method"); + assertEquals("1", this.b.getParameterAsString("A"), "Non-string parameters must call toString method"); } @Test void testStringParameterOnNullValue() { this.b.putParameter("A", null); assertNull(this.b.getStringParameter("A"), "Null parameter must be returned as null"); + assertNull(this.b.getParameterAsConcatString("A"), "Null parameter must be returned as null"); + assertNull(this.b.getParameterAsString("A"), "Null parameter must be returned as null"); + } + + @Test + void testStringParameterOnEmptyValue() { + this.b.putParameter("A", ""); + assertEquals("", this.b.getStringParameter("A"), "Empty parameter must be returned as empty string"); + assertEquals("", this.b.getParameterAsConcatString("A"), "Empty parameter must be returned as empty string"); + assertEquals("", this.b.getParameterAsString("A"), "Empty parameter must be returned as empty string"); } @Test @@ -795,8 +807,14 @@ void testMergeParameters() { this.b.mergeParameters(map); assertEquals("uno", this.b.getStringParameter("ONE"), "When merging parameters previous values must override"); + assertEquals("uno", this.b.getParameterAsConcatString("ONE"), "When merging parameters previous values must override"); + assertEquals("uno", this.b.getParameterAsString("ONE"), "When merging parameters previous values must override"); assertEquals("deux", this.b.getStringParameter("TWO"), "When merging parameters previous values must override"); + assertEquals("deux", this.b.getParameterAsConcatString("TWO"), "When merging parameters previous values must override"); + assertEquals("deux", this.b.getParameterAsString("TWO"), "When merging parameters previous values must override"); assertEquals("tres", this.b.getStringParameter("THREE"), "When merging parameters new keys must be stored"); + assertEquals("tres", this.b.getParameterAsConcatString("THREE"), "When merging parameters new keys must be stored"); + assertEquals("tres", this.b.getParameterAsString("THREE"), "When merging parameters new keys must be stored"); } @Test @@ -813,8 +831,14 @@ void testPutParametersWithPolicy() { this.b.putParameters(map, IBaseDataObject.MergePolicy.KEEP_ALL); assertEquals("uno;uno", this.b.getStringParameter("ONE"), "When specifying KEEP_ALL values must all stay"); + assertEquals("uno;uno", this.b.getParameterAsConcatString("ONE"), "When specifying KEEP_ALL values must all stay"); + assertEquals("uno", this.b.getParameterAsString("ONE"), "When specifying KEEP_ALL first value should be retained"); assertEquals("deux;dos", this.b.getStringParameter("TWO"), "When specifying KEEP_ALL values must all stay"); + assertEquals("deux;dos", this.b.getParameterAsConcatString("TWO"), "When specifying KEEP_ALL values must all stay"); + assertEquals("deux", this.b.getParameterAsString("TWO"), "When specifying KEEP_ALL first value should be retained"); assertEquals("tres", this.b.getStringParameter("THREE"), "When specifying KEEP_ALL new keys must be stored"); + assertEquals("tres", this.b.getParameterAsConcatString("THREE"), "When specifying KEEP_ALL new keys must be stored"); + assertEquals("tres", this.b.getParameterAsString("THREE"), "When specifying KEEP_ALL first value should be retained"); } @Test @@ -844,15 +868,25 @@ void testPutParametersWithMultimapAsMap() { void testParameters() { this.b.putParameter("ME", "YOU"); assertEquals("YOU", this.b.getStringParameter("ME"), "Gotten parameter"); + assertEquals("YOU", this.b.getParameterAsConcatString("ME"), "Gotten parameter"); + assertEquals("YOU", this.b.getParameterAsString("ME"), "Gotten parameter"); final Map map = new HashMap<>(); map.put("ONE", "uno"); map.put("TWO", "dos"); map.put("THREE", "tres"); this.b.putParameters(map); assertEquals("uno", this.b.getStringParameter("ONE"), "Map put parameter gotten"); + assertEquals("uno", this.b.getParameterAsConcatString("ONE"), "Map put parameter gotten"); + assertEquals("uno", this.b.getParameterAsString("ONE"), "Map put parameter gotten"); assertEquals("dos", this.b.getStringParameter("TWO"), "Map put parameter gotten"); + assertEquals("dos", this.b.getParameterAsConcatString("TWO"), "Map put parameter gotten"); + assertEquals("dos", this.b.getParameterAsString("TWO"), "Map put parameter gotten"); assertEquals("tres", this.b.getStringParameter("THREE"), "Map put parameter gotten"); + assertEquals("tres", this.b.getParameterAsConcatString("THREE"), "Map put parameter gotten"); + assertEquals("tres", this.b.getParameterAsString("THREE"), "Map put parameter gotten"); assertEquals("YOU", this.b.getStringParameter("ME"), "Gotten parameter"); + assertEquals("YOU", this.b.getParameterAsConcatString("ME"), "Gotten parameter"); + assertEquals("YOU", this.b.getParameterAsString("ME"), "Gotten parameter"); // Deletes this.b.deleteParameter("THREE"); @@ -861,6 +895,8 @@ void testParameters() { // Overwrite this.b.putParameter("ME", "THEM"); assertEquals("THEM", this.b.getStringParameter("ME"), "Gotten parameter"); + assertEquals("THEM", this.b.getParameterAsConcatString("ME"), "Gotten parameter"); + assertEquals("THEM", this.b.getParameterAsString("ME"), "Gotten parameter"); // Clear this.b.clearParameters(); @@ -895,6 +931,8 @@ void testAppendDuplicateParameters() { this.b.appendParameter("YO", "GABBA"); this.b.appendParameter("YO", "GABBA"); assertEquals("GABBA;GABBA", this.b.getStringParameter("YO"), "Appended duplicate parameters should be preserved"); + assertEquals("GABBA;GABBA", this.b.getParameterAsConcatString("YO"), "Appended duplicate parameters should be preserved"); + assertEquals("GABBA", this.b.getParameterAsString("YO"), "Appended duplicate parameters first value should be preserved"); assertTrue(this.b.hasParameter("YO"), "HasParameter should be true"); } @@ -902,7 +940,9 @@ void testAppendDuplicateParameters() { void testAppendUniqueParameters() { this.b.appendUniqueParameter("YO", "GABBA"); this.b.appendUniqueParameter("YO", "GABBA"); - assertEquals("GABBA", this.b.getStringParameter("YO"), "Appended unique parameters should be collapsed"); + assertEquals("GABBA", this.b.getStringParameter("YO"), "Appended unique parameters should be collapsed"); + assertEquals("GABBA", this.b.getParameterAsConcatString("YO"), "Appended unique parameters should be collapsed"); + assertEquals("GABBA", this.b.getParameterAsString("YO"), "Appended unique parameters should be collapsed"); assertTrue(this.b.hasParameter("YO"), "HasParameter should be true"); } @@ -920,6 +960,12 @@ void testParametersWithMixtureOfSingleValuesAndLists() { assertEquals("FOO1;FOO2;FOO3;FOO4", this.b.getStringParameter("FOO"), "Returned string should be combination of initial list and added value"); + assertEquals("FOO1;FOO2;FOO3;FOO4", + this.b.getParameterAsConcatString("FOO"), + "Returned string should be combination of initial list and added value"); + assertEquals("FOO1", + this.b.getParameterAsString("FOO"), + "Returned string should be first value from combination of initial list and added value"); } @Test @@ -934,6 +980,10 @@ void testParametersWithMixtureOfSingleValuesAndSets() { assertEquals(3, this.b.getParameter("FOO").size(), "Returned list size should match what was put in"); this.b.appendParameter("FOO", "FOO4"); assertEquals("FOO1;FOO2;FOO3;FOO4", this.b.getStringParameter("FOO"), "Returned string should be combination of initial set and added value"); + assertEquals("FOO1;FOO2;FOO3;FOO4", this.b.getParameterAsConcatString("FOO"), + "Returned string should be combination of initial set and added value"); + assertEquals("FOO1", this.b.getParameterAsString("FOO"), + "Returned string should be first value from combination of initial set and added value"); } @Test @@ -965,6 +1015,8 @@ void testAppendParameter() { this.b.putParameter("ME", "YOU"); this.b.appendParameter("ME", "FOO"); assertEquals("YOU;FOO", this.b.getStringParameter("ME"), "Appended parameter value"); + assertEquals("YOU;FOO", this.b.getParameterAsConcatString("ME"), "Appended parameter value"); + assertEquals("YOU", this.b.getParameterAsString("ME"), "Appended parameter value"); } @Test @@ -972,6 +1024,8 @@ void testAppendParameterIterables() { this.b.putParameter("ME", "YOU"); this.b.appendParameter("ME", Arrays.asList("FOO", "BAR", "BAZ")); assertEquals("YOU;FOO;BAR;BAZ", this.b.getStringParameter("ME"), "Appended parameter value"); + assertEquals("YOU;FOO;BAR;BAZ", this.b.getParameterAsConcatString("ME"), "Appended parameter value"); + assertEquals("YOU", this.b.getParameterAsString("ME"), "First value from appended parameter value"); final Set s = new TreeSet<>(); s.add("ZAB"); @@ -979,13 +1033,17 @@ void testAppendParameterIterables() { s.add("OOF"); this.b.appendParameter("ME", s); - assertEquals("YOU;FOO;BAR;BAZ;OOF;RAB;ZAB", this.b.getStringParameter("ME"), "Appended set paramter value"); + assertEquals("YOU;FOO;BAR;BAZ;OOF;RAB;ZAB", this.b.getStringParameter("ME"), "Appended set parameter value"); + assertEquals("YOU;FOO;BAR;BAZ;OOF;RAB;ZAB", this.b.getParameterAsConcatString("ME"), "Appended set parameter value"); + assertEquals("YOU", this.b.getParameterAsString("ME"), "First value from appended set parameter value"); } @Test void testAppendParameterOntoEmpty() { this.b.appendParameter("ME", "FOO"); assertEquals("FOO", this.b.getStringParameter("ME"), "Appended parameter value"); + assertEquals("FOO", this.b.getParameterAsConcatString("ME"), "Appended parameter value"); + assertEquals("FOO", this.b.getParameterAsString("ME"), "First value from appended parameter value"); } @@ -1346,6 +1404,7 @@ void testGetParameterAsString() throws IOException { this.b.appendParameter("A", "THREE"); assertEquals("1", this.b.getParameterAsString("A")); assertEquals("1;TWO;THREE", this.b.getParameterAsConcatString("A")); + assertEquals("1;TWO;THREE", this.b.getStringParameter("A")); LogbackTester.SimplifiedLogEvent logEvent = new LogbackTester.SimplifiedLogEvent(Level.WARN, "Multiple values for parameter, returning the first - parameter:A, number of values:3", null); logbackTester.checkLogList(Collections.singletonList(logEvent)); @@ -1354,27 +1413,33 @@ void testGetParameterAsString() throws IOException { this.b.putParameter("A", 2L); assertEquals("2", this.b.getParameterAsString("A")); assertEquals("2", this.b.getParameterAsConcatString("A")); + assertEquals("2", this.b.getStringParameter("A")); this.b.putParameter("A", "THREE"); assertEquals("THREE", this.b.getParameterAsString("A")); assertEquals("THREE", this.b.getParameterAsConcatString("A")); + assertEquals("THREE", this.b.getStringParameter("A")); this.b.putParameter("A", null); assertNull(this.b.getParameterAsString("A")); assertNull(this.b.getParameterAsConcatString("A")); + assertNull(this.b.getStringParameter("A")); this.b.putParameter("A", ""); - assertNull(this.b.getParameterAsString("A")); - assertNull(this.b.getParameterAsConcatString("A")); + assertEquals("", this.b.getParameterAsString("A")); + assertEquals("", this.b.getParameterAsConcatString("A")); + assertEquals("", this.b.getStringParameter("A")); assertNull(this.b.getParameterAsString("DNE")); assertNull(this.b.getParameterAsConcatString("DNE")); + assertNull(this.b.getStringParameter("DNE")); this.b.putParameter("A", null); this.b.appendParameter("A", "FOUR"); this.b.appendParameter("A", " "); assertEquals("null", this.b.getParameterAsString("A")); assertEquals("null;FOUR; ", this.b.getParameterAsConcatString("A")); + assertEquals("null;FOUR; ", this.b.getStringParameter("A")); } } diff --git a/src/test/java/emissary/kff/KffDataObjectHandlerTest.java b/src/test/java/emissary/kff/KffDataObjectHandlerTest.java index 33286da14e..ee8565c65e 100644 --- a/src/test/java/emissary/kff/KffDataObjectHandlerTest.java +++ b/src/test/java/emissary/kff/KffDataObjectHandlerTest.java @@ -121,12 +121,24 @@ void testHashMethod() { payload.setParameter(KffDataObjectHandler.KFF_PARAM_KNOWN_FILTER_NAME, "test.filter"); kff.hash(payload); assertEquals("test.filter", payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_KNOWN_FILTER_NAME)); + assertEquals("test.filter", payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_KNOWN_FILTER_NAME)); + assertEquals("test.filter", payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_KNOWN_FILTER_NAME)); assertTrue(KffDataObjectHandler.hashPresent(payload)); assertEquals(DATA_MD5, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_MD5)); + assertEquals(DATA_MD5, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_MD5)); + assertEquals(DATA_MD5, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_MD5)); assertEquals(DATA_CRC32, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_CRC32)); + assertEquals(DATA_CRC32, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_CRC32)); + assertEquals(DATA_CRC32, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_CRC32)); assertEquals(DATA_SSDEEP, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertEquals(DATA_SSDEEP, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertEquals(DATA_SSDEEP, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); assertEquals(DATA_SHA1, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertEquals(DATA_SHA1, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertEquals(DATA_SHA1, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA1)); assertEquals(DATA_SHA256, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertEquals(DATA_SHA256, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertEquals(DATA_SHA256, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA256)); assertEquals(KffDataObjectHandler.KFF_DUPE_CURRENT_FORM, payload.getFileType()); assertArrayEquals(new byte[0], payload.data()); } @@ -140,21 +152,41 @@ void testHashMethodCalledTwice() { assertNull(payload.getStringParameter(KffDataObjectHandler.MD5_ORIGINAL), "MD5_ORIGINAL should only be populated if hashing more than once"); + assertNull(payload.getParameterAsConcatString(KffDataObjectHandler.MD5_ORIGINAL), + "MD5_ORIGINAL should only be populated if hashing more than once"); + assertNull(payload.getParameterAsString(KffDataObjectHandler.MD5_ORIGINAL), + "MD5_ORIGINAL should only be populated if hashing more than once"); // hash again, to see the effect on the hash-related params. // none of the parameters should have a duplicated value kff.hash(payload); assertEquals("test.filter", payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_KNOWN_FILTER_NAME)); + assertEquals("test.filter", payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_KNOWN_FILTER_NAME)); + assertEquals("test.filter", payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_KNOWN_FILTER_NAME)); assertTrue(KffDataObjectHandler.hashPresent(payload)); assertEquals(DATA_MD5, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_MD5)); + assertEquals(DATA_MD5, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_MD5)); + assertEquals(DATA_MD5, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_MD5)); assertEquals(DATA_CRC32, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_CRC32)); + assertEquals(DATA_CRC32, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_CRC32)); + assertEquals(DATA_CRC32, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_CRC32)); assertEquals(DATA_SSDEEP, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertEquals(DATA_SSDEEP, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertEquals(DATA_SSDEEP, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); assertEquals(DATA_SHA1, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertEquals(DATA_SHA1, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertEquals(DATA_SHA1, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA1)); assertEquals(DATA_SHA256, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertEquals(DATA_SHA256, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertEquals(DATA_SHA256, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA256)); assertEquals(KffDataObjectHandler.KFF_DUPE_CURRENT_FORM, payload.getFileType()); assertNull(payload.getStringParameter(KffDataObjectHandler.MD5_ORIGINAL), "MD5_ORIGINAL should not be populated if hash called more than once but data hasn't changed"); + assertNull(payload.getParameterAsConcatString(KffDataObjectHandler.MD5_ORIGINAL), + "MD5_ORIGINAL should not be populated if hash called more than once but data hasn't changed"); + assertNull(payload.getParameterAsString(KffDataObjectHandler.MD5_ORIGINAL), + "MD5_ORIGINAL should not be populated if hash called more than once but data hasn't changed"); } @Test @@ -165,14 +197,30 @@ void testHashMethodAgainAfterModifyingData() { kff.hash(payload); assertEquals("test.filter", payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_KNOWN_FILTER_NAME)); + assertEquals("test.filter", payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_KNOWN_FILTER_NAME)); + assertEquals("test.filter", payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_KNOWN_FILTER_NAME)); assertTrue(KffDataObjectHandler.hashPresent(payload)); assertEquals(DATA_MD5, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_MD5)); + assertEquals(DATA_MD5, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_MD5)); + assertEquals(DATA_MD5, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_MD5)); assertEquals(DATA_CRC32, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_CRC32)); + assertEquals(DATA_CRC32, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_CRC32)); + assertEquals(DATA_CRC32, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_CRC32)); assertEquals(DATA_SSDEEP, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertEquals(DATA_SSDEEP, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertEquals(DATA_SSDEEP, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); assertEquals(DATA_SHA1, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertEquals(DATA_SHA1, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertEquals(DATA_SHA1, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA1)); assertEquals(DATA_SHA256, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertEquals(DATA_SHA256, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertEquals(DATA_SHA256, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA256)); assertNull(payload.getStringParameter(KffDataObjectHandler.MD5_ORIGINAL), "MD5_ORIGINAL should only be populated if hashing more than once and data has changed"); + assertNull(payload.getParameterAsConcatString(KffDataObjectHandler.MD5_ORIGINAL), + "MD5_ORIGINAL should only be populated if hashing more than once and data has changed"); + assertNull(payload.getParameterAsString(KffDataObjectHandler.MD5_ORIGINAL), + "MD5_ORIGINAL should only be populated if hashing more than once and data has changed"); payload.setData("This is a changed data".getBytes()); // hash again, to see the effect on the hash-related params. @@ -180,23 +228,51 @@ void testHashMethodAgainAfterModifyingData() { kff.hash(payload); assertEquals("test.filter", payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_KNOWN_FILTER_NAME)); + assertEquals("test.filter", payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_KNOWN_FILTER_NAME)); + assertEquals("test.filter", payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_KNOWN_FILTER_NAME)); assertTrue(KffDataObjectHandler.hashPresent(payload)); assertNotNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_MD5)); + assertNotNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_MD5)); + assertNotNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_MD5)); assertNotNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_CRC32)); + assertNotNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_CRC32)); + assertNotNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_CRC32)); assertNotNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertNotNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertNotNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); assertNotNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertNotNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertNotNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA1)); assertNotNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertNotNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertNotNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA256)); assertNotEquals(DATA_MD5, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_MD5)); + assertNotEquals(DATA_MD5, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_MD5)); + assertNotEquals(DATA_MD5, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_MD5)); assertNotEquals(DATA_CRC32, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_CRC32)); + assertNotEquals(DATA_CRC32, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_CRC32)); + assertNotEquals(DATA_CRC32, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_CRC32)); assertNotEquals(DATA_SSDEEP, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertNotEquals(DATA_SSDEEP, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertNotEquals(DATA_SSDEEP, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); assertNotEquals(DATA_SHA1, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertNotEquals(DATA_SHA1, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertNotEquals(DATA_SHA1, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA1)); assertNotEquals(DATA_SHA256, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertNotEquals(DATA_SHA256, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertNotEquals(DATA_SHA256, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA256)); assertEquals(KffDataObjectHandler.KFF_DUPE_CURRENT_FORM, payload.getFileType()); // make sure we've correctly populated MD5_ORIGINAL assertNotNull(payload.getStringParameter(KffDataObjectHandler.MD5_ORIGINAL), "MD5_ORIGINAL should be populated if hash called more than once"); + assertNotNull(payload.getParameterAsConcatString(KffDataObjectHandler.MD5_ORIGINAL), + "MD5_ORIGINAL should be populated if hash called more than once"); + assertNotNull(payload.getParameterAsString(KffDataObjectHandler.MD5_ORIGINAL), + "MD5_ORIGINAL should be populated if hash called more than once"); assertEquals(DATA_MD5, payload.getStringParameter(KffDataObjectHandler.MD5_ORIGINAL)); + assertEquals(DATA_MD5, payload.getParameterAsConcatString(KffDataObjectHandler.MD5_ORIGINAL)); + assertEquals(DATA_MD5, payload.getParameterAsString(KffDataObjectHandler.MD5_ORIGINAL)); } @Test @@ -204,6 +280,8 @@ void testParentToChildMethod() { payload.setParameter(KffDataObjectHandler.KFF_PARAM_DUPE_HIT, payload); KffDataObjectHandler.parentToChild(payload); assertNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_DUPE_HIT)); + assertNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_DUPE_HIT)); + assertNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_DUPE_HIT)); } @Test @@ -233,12 +311,24 @@ void testWithChannelFactory() { payload.setChannelFactory(SBC_DATA); kff.hash(payload); assertEquals("test.filter", payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_BASE + "FILTERED_BY")); + assertEquals("test.filter", payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_BASE + "FILTERED_BY")); + assertEquals("test.filter", payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_BASE + "FILTERED_BY")); assertTrue(KffDataObjectHandler.hashPresent(payload)); assertEquals(DATA_MD5, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_MD5)); + assertEquals(DATA_MD5, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_MD5)); + assertEquals(DATA_MD5, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_MD5)); assertEquals(DATA_CRC32, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_BASE + "CRC32")); + assertEquals(DATA_CRC32, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_BASE + "CRC32")); + assertEquals(DATA_CRC32, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_BASE + "CRC32")); assertEquals(DATA_SSDEEP, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertEquals(DATA_SSDEEP, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertEquals(DATA_SSDEEP, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); assertEquals(DATA_SHA1, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertEquals(DATA_SHA1, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertEquals(DATA_SHA1, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA1)); assertEquals(DATA_SHA256, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertEquals(DATA_SHA256, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertEquals(DATA_SHA256, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA256)); assertEquals(KffDataObjectHandler.KFF_DUPE_CURRENT_FORM, payload.getFileType()); assertArrayEquals(new byte[0], payload.data()); } @@ -250,12 +340,24 @@ void testWithEmptyChannelFactory() { payload.setChannelFactory(SeekableByteChannelHelper.EMPTY_CHANNEL_FACTORY); kff.hash(payload); assertEquals("test.filter", payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_BASE + "FILTERED_BY")); + assertEquals("test.filter", payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_BASE + "FILTERED_BY")); + assertEquals("test.filter", payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_BASE + "FILTERED_BY")); assertFalse(KffDataObjectHandler.hashPresent(payload)); assertNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_MD5)); + assertNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_MD5)); + assertNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_MD5)); assertNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_BASE + "CRC32")); + assertNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_BASE + "CRC32")); + assertNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_BASE + "CRC32")); assertNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); assertNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA1)); assertNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA256)); assertEquals("test", payload.getFileType()); assertArrayEquals(new byte[0], payload.data()); assertEquals(SeekableByteChannelHelper.EMPTY_CHANNEL_FACTORY, payload.getChannelFactory()); @@ -288,24 +390,48 @@ protected long sizeImpl() throws IOException { payload.setChannelFactory(exceptionSbcf); kff.hash(payload); assertNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_BASE + "FILTERED_BY")); + assertNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_BASE + "FILTERED_BY")); + assertNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_BASE + "FILTERED_BY")); assertFalse(KffDataObjectHandler.hashPresent(payload)); assertNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_MD5)); + assertNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_MD5)); + assertNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_MD5)); assertNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_BASE + "CRC32")); + assertNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_BASE + "CRC32")); + assertNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_BASE + "CRC32")); assertNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); assertNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA1)); assertNull(payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertNull(payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertNull(payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA256)); assertNotEquals(KffDataObjectHandler.KFF_DUPE_CURRENT_FORM, payload.getFileType()); payload.setParameter(KffDataObjectHandler.KFF_PARAM_KNOWN_FILTER_NAME, "test.filter"); payload.setChannelFactory(SBC_DATA); kff.hash(payload); assertEquals("test.filter", payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_BASE + "FILTERED_BY")); + assertEquals("test.filter", payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_BASE + "FILTERED_BY")); + assertEquals("test.filter", payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_BASE + "FILTERED_BY")); assertTrue(KffDataObjectHandler.hashPresent(payload)); assertEquals(DATA_MD5, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_MD5)); + assertEquals(DATA_MD5, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_MD5)); + assertEquals(DATA_MD5, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_MD5)); assertEquals(DATA_CRC32, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_BASE + "CRC32")); + assertEquals(DATA_CRC32, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_BASE + "CRC32")); + assertEquals(DATA_CRC32, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_BASE + "CRC32")); assertEquals(DATA_SSDEEP, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertEquals(DATA_SSDEEP, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); + assertEquals(DATA_SSDEEP, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SSDEEP)); assertEquals(DATA_SHA1, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertEquals(DATA_SHA1, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA1)); + assertEquals(DATA_SHA1, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA1)); assertEquals(DATA_SHA256, payload.getStringParameter(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertEquals(DATA_SHA256, payload.getParameterAsConcatString(KffDataObjectHandler.KFF_PARAM_SHA256)); + assertEquals(DATA_SHA256, payload.getParameterAsString(KffDataObjectHandler.KFF_PARAM_SHA256)); assertEquals(KffDataObjectHandler.KFF_DUPE_CURRENT_FORM, payload.getFileType()); } diff --git a/src/test/java/emissary/output/DropOffUtilTest.java b/src/test/java/emissary/output/DropOffUtilTest.java index 1e81e10283..a65aad53f5 100644 --- a/src/test/java/emissary/output/DropOffUtilTest.java +++ b/src/test/java/emissary/output/DropOffUtilTest.java @@ -107,6 +107,8 @@ void testGetBestId() { String id = this.util.getBestId(this.payload, tld); assertTrue(id.startsWith("ABCD"), "auto gen id should start with a (truncated to 4 char) prefix"); assertEquals("yes", this.payload.getStringParameter("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); + assertEquals("yes", this.payload.getParameterAsConcatString("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); + assertEquals("yes", this.payload.getParameterAsString("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); // Test auto gen without prefix ////////////////////////////// @@ -116,6 +118,8 @@ void testGetBestId() { this.payload = DataObjectFactory.getInstance("This is a test".getBytes(), "/eat/prefix/testPath", "UNKNOWN"); assertNotNull(this.util.getBestId(this.payload, tld)); assertEquals("yes", this.payload.getStringParameter("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); + assertEquals("yes", this.payload.getParameterAsConcatString("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); + assertEquals("yes", this.payload.getParameterAsString("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); // Test get ID from parameter ////////////////////////////// cfg = new ServiceConfigGuide(); @@ -132,6 +136,8 @@ void testGetBestId() { id = this.util.getBestId(this.payload, tld); assertNull(this.payload.getStringParameter("AUTO_GENERATED_ID"), "an auto gen id parameter should NOT have been set"); + assertNull(this.payload.getParameterAsConcatString("AUTO_GENERATED_ID"), "an auto gen id parameter should NOT have been set"); + assertNull(this.payload.getParameterAsString("AUTO_GENERATED_ID"), "an auto gen id parameter should NOT have been set"); assertEquals("672317892139", id, "the MY_ID parameter should have been used"); // Test shortname ////////////////////////////// @@ -148,6 +154,8 @@ void testGetBestId() { id = this.util.getBestId(this.payload, tld); assertNull(this.payload.getStringParameter("AUTO_GENERATED_ID"), "an auto gen id parameter should NOT have been set"); + assertNull(this.payload.getParameterAsConcatString("AUTO_GENERATED_ID"), "an auto gen id parameter should NOT have been set"); + assertNull(this.payload.getParameterAsString("AUTO_GENERATED_ID"), "an auto gen id parameter should NOT have been set"); assertEquals("testPath", id, "the SHORTNAME parameter should have been used"); // Test force auto gen by specifying a blank shortname @@ -167,6 +175,8 @@ void testGetBestId() { id = this.util.getBestId(this.payload, tld); assertEquals("yes", this.payload.getStringParameter("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); + assertEquals("yes", this.payload.getParameterAsConcatString("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); + assertEquals("yes", this.payload.getParameterAsString("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); assertNotEquals("testPath", id, "the SHORTNAME parameter should NOT have been used"); assertTrue(id.startsWith("ABCD"), "auto gen id should start with a (truncated to 4 char) prefix"); @@ -186,6 +196,8 @@ void testGetBestId() { id = this.util.getBestId(this.payload, tld); assertEquals("yes", this.payload.getStringParameter("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); + assertEquals("yes", this.payload.getParameterAsConcatString("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); + assertEquals("yes", this.payload.getParameterAsString("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); assertNotEquals("testPath", id, "the SHORTNAME parameter should NOT have been used"); assertTrue(id.startsWith("ABCD"), "auto gen id should start with a (truncated to 4 char) prefix"); } @@ -212,6 +224,8 @@ void testGetBestIdFrom() { String id = this.util.getBestIdFrom(this.payload); assertTrue(id.startsWith("ABCD"), "auto gen id should start with a (truncated to 4 char) prefix"); assertEquals("yes", this.payload.getStringParameter("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); + assertEquals("yes", this.payload.getParameterAsConcatString("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); + assertEquals("yes", this.payload.getParameterAsString("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); // Test auto gen without prefix ////////////////////////////// @@ -222,6 +236,8 @@ void testGetBestIdFrom() { id = this.util.getBestIdFrom(this.payload); assertFalse(id.startsWith("ABCD"), "auto gen id should NOT start with a (truncated to 4 char) prefix"); assertEquals("yes", this.payload.getStringParameter("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); + assertEquals("yes", this.payload.getParameterAsConcatString("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); + assertEquals("yes", this.payload.getParameterAsString("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); // Test get ID from parameter ////////////////////////////// cfg = new ServiceConfigGuide(); @@ -238,6 +254,8 @@ void testGetBestIdFrom() { id = this.util.getBestIdFrom(this.payload); assertNull(this.payload.getStringParameter("AUTO_GENERATED_ID"), "an auto gen id parameter should NOT have been set"); + assertNull(this.payload.getParameterAsConcatString("AUTO_GENERATED_ID"), "an auto gen id parameter should NOT have been set"); + assertNull(this.payload.getParameterAsString("AUTO_GENERATED_ID"), "an auto gen id parameter should NOT have been set"); assertEquals("672317892139", id, "the MY_ID parameter should have been used"); // Test shortname ////////////////////////////// @@ -254,6 +272,8 @@ void testGetBestIdFrom() { id = this.util.getBestIdFrom(this.payload); assertNull(this.payload.getStringParameter("AUTO_GENERATED_ID"), "an auto gen id parameter should NOT have been set"); + assertNull(this.payload.getParameterAsConcatString("AUTO_GENERATED_ID"), "an auto gen id parameter should NOT have been set"); + assertNull(this.payload.getParameterAsString("AUTO_GENERATED_ID"), "an auto gen id parameter should NOT have been set"); assertEquals("testPath", id, "the SHORTNAME parameter should have been used"); // Test force auto gen by specifying a blank shortname @@ -273,6 +293,8 @@ void testGetBestIdFrom() { id = this.util.getBestIdFrom(this.payload); assertEquals("yes", this.payload.getStringParameter("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); + assertEquals("yes", this.payload.getParameterAsConcatString("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); + assertEquals("yes", this.payload.getParameterAsString("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); assertNotEquals("testPath", id, "the SHORTNAME parameter should NOT have been used"); assertTrue(id.startsWith("ABCD"), "auto gen id should start with a (truncated to 4 char) prefix"); @@ -292,6 +314,8 @@ void testGetBestIdFrom() { id = this.util.getBestIdFrom(this.payload); assertEquals("yes", this.payload.getStringParameter("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); + assertEquals("yes", this.payload.getParameterAsConcatString("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); + assertEquals("yes", this.payload.getParameterAsString("AUTO_GENERATED_ID"), "an auto gen id parameter should have been set"); assertNotEquals("testPath", id, "the SHORTNAME parameter should NOT have been used"); assertTrue(id.startsWith("ABCD"), "auto gen id should start with a (truncated to 4 char) prefix"); } @@ -314,6 +338,8 @@ void testGetExistingIds() { String[] values = this.util.getExistingIds(this.payload); assertNull(this.payload.getStringParameter("AUTO_GENERATED_ID"), "an auto gen id parameter should not have been set"); + assertNull(this.payload.getParameterAsConcatString("AUTO_GENERATED_ID"), "an auto gen id parameter should not have been set"); + assertNull(this.payload.getParameterAsString("AUTO_GENERATED_ID"), "an auto gen id parameter should not have been set"); assertEquals("672317892139", values[0], "the MY_ID parameter should have been used FIRST"); assertEquals("testPath", values[1], "the SHORTNAME should have been used SECOND"); assertEquals(2, values.length, "the size of the return values is incorrect"); @@ -374,19 +400,35 @@ void testMetadataPreparation() { this.util.processMetadata(family); assertEquals("gz", parent.getStringParameter("FILEXT"), "Parent should have filext of gz"); + assertEquals("gz", parent.getParameterAsConcatString("FILEXT"), "Parent should have filext of gz"); + assertEquals("gz", parent.getParameterAsString("FILEXT"), "Parent should have filext of gz"); assertEquals("docx", child.getStringParameter("FILEXT"), "Child should have filext of docx"); + assertEquals("docx", child.getParameterAsConcatString("FILEXT"), "Child should have filext of docx"); + assertEquals("docx", child.getParameterAsString("FILEXT"), "Child should have filext of docx"); assertNull(parent.getParameter("EXTENDED_FILETYPE"), "Parent should not have extended filetype"); assertEquals("CHILD_FTYPE//myFoo//myBar1//myBar2", child.getStringParameter("EXTENDED_FILETYPE"), "Child EXTENDED_FILETYPE should handle deduplication and collections"); + assertEquals("CHILD_FTYPE//myFoo//myBar1//myBar2", + child.getParameterAsConcatString("EXTENDED_FILETYPE"), + "Child EXTENDED_FILETYPE should handle deduplication and collections"); + assertEquals("CHILD_FTYPE//myFoo//myBar1//myBar2", + child.getParameterAsString("EXTENDED_FILETYPE"), + "Child EXTENDED_FILETYPE should handle deduplication and collections"); assertNull(parent.getParameter("PARENT_FOO"), "Parent should not get PARENT_* values"); assertEquals("PARENT_FOO", child.getStringParameter("PARENT_FOO"), "Child should get PARENT_FOO type"); + assertEquals("PARENT_FOO", child.getParameterAsConcatString("PARENT_FOO"), "Child should get PARENT_FOO type"); + assertEquals("PARENT_FOO", child.getParameterAsString("PARENT_FOO"), "Child should get PARENT_FOO type"); assertEquals("PARENT_FOO", parent.getStringParameter("FOO"), "Parent FOO should not be changed"); + assertEquals("PARENT_FOO", parent.getParameterAsConcatString("FOO"), "Parent FOO should not be changed"); + assertEquals("PARENT_FOO", parent.getParameterAsString("FOO"), "Parent FOO should not be changed"); assertEquals("CHILD_FOO", child.getStringParameter("FOO"), "Child FOO should not be changed"); + assertEquals("CHILD_FOO", child.getParameterAsConcatString("FOO"), "Child FOO should not be changed"); + assertEquals("CHILD_FOO", child.getParameterAsString("FOO"), "Child FOO should not be changed"); } @Test @@ -427,14 +469,34 @@ void testMetadataPreparationWithConfiguredValues() { assertEquals("FOO", child.getStringParameter("PARENT_FOO"), "Propagation of configured parent type must use closest available entry on child"); + assertEquals("FOO", + child.getParameterAsConcatString("PARENT_FOO"), + "Propagation of configured parent type must use closest available entry on child"); + assertEquals("FOO", + child.getParameterAsString("PARENT_FOO"), + "Propagation of configured parent type must use closest available entry on child"); assertEquals("CHILD_FOO", childRecords.get(0) .getStringParameter("PARENT_FOO"), "Propagation of configured parent type must use closest available entry on child records"); + assertEquals("CHILD_FOO", childRecords.get(0) + .getParameterAsConcatString("PARENT_FOO"), "Propagation of configured parent type must use closest available entry on child records"); + assertEquals("CHILD_FOO", childRecords.get(0) + .getParameterAsString("PARENT_FOO"), "Propagation of configured parent type must use closest available entry on child records"); // Child 2 subtree only has the TLD FOO param to use assertEquals("FOO", child2.getStringParameter("PARENT_FOO"), "Propagation of configured parent type must fall back to TLD on child"); + assertEquals("FOO", child2.getParameterAsConcatString("PARENT_FOO"), "Propagation of configured parent type must fall back to TLD on child"); + assertEquals("FOO", child2.getParameterAsString("PARENT_FOO"), "Propagation of configured parent type must fall back to TLD on child"); assertEquals("FOO", grandchild.getStringParameter("PARENT_FOO"), "Propagation of configured parent type must fall back to TLD on grandchild"); + assertEquals("FOO", grandchild.getParameterAsConcatString("PARENT_FOO"), + "Propagation of configured parent type must fall back to TLD on grandchild"); + assertEquals("FOO", grandchild.getParameterAsString("PARENT_FOO"), + "Propagation of configured parent type must fall back to TLD on grandchild"); assertEquals("FOO", gchildRecords.get(0) .getStringParameter("PARENT_FOO"), "Propagation of configured parent type must use closest available entry on grandchild records"); + assertEquals("FOO", gchildRecords.get(0).getParameterAsConcatString("PARENT_FOO"), + "Propagation of configured parent type must use closest available entry on grandchild records"); + assertEquals("FOO", gchildRecords.get(0).getParameterAsString("PARENT_FOO"), + "Propagation of configured parent type must use closest available entry on grandchild records"); } @Test diff --git a/src/test/java/emissary/place/MultiFileUnixCommandPlaceTest.java b/src/test/java/emissary/place/MultiFileUnixCommandPlaceTest.java index e26f32134a..cc17826466 100644 --- a/src/test/java/emissary/place/MultiFileUnixCommandPlaceTest.java +++ b/src/test/java/emissary/place/MultiFileUnixCommandPlaceTest.java @@ -96,7 +96,11 @@ void testMultiFileUnixCommandPlaceStdout() throws Exception { assertEquals(1, att.get(0).currentFormSize(), "Single form for child"); assertEquals("copy value", att.get(0).getStringParameter("COPY_THIS"), "Child should have propagating metadata value"); + assertEquals("copy value", att.get(0).getParameterAsConcatString("COPY_THIS"), "Child should have propagating metadata value"); + assertEquals("copy value", att.get(0).getParameterAsString("COPY_THIS"), "Child should have propagating metadata value"); assertNull(att.get(0).getStringParameter("IGNORE_THIS"), "Child should not have non-propagating metadata value"); + assertNull(att.get(0).getParameterAsConcatString("IGNORE_THIS"), "Child should not have non-propagating metadata value"); + assertNull(att.get(0).getParameterAsString("IGNORE_THIS"), "Child should not have non-propagating metadata value"); } @Test @@ -114,7 +118,11 @@ void testMultiFileUnixCommandPlaceFile() throws Exception { assertEquals(1, att.get(0).currentFormSize(), "Single form for child"); assertEquals("copy value", att.get(0).getStringParameter("COPY_THIS"), "Child should have propagating metadata value"); + assertEquals("copy value", att.get(0).getParameterAsConcatString("COPY_THIS"), "Child should have propagating metadata value"); + assertEquals("copy value", att.get(0).getParameterAsString("COPY_THIS"), "Child should have propagating metadata value"); assertNull(att.get(0).getStringParameter("IGNORE_THIS"), "Child should not have non-propagating metadata value"); + assertNull(att.get(0).getParameterAsConcatString("IGNORE_THIS"), "Child should not have non-propagating metadata value"); + assertNull(att.get(0).getParameterAsString("IGNORE_THIS"), "Child should not have non-propagating metadata value"); } @Test @@ -130,7 +138,11 @@ void testMultiFileUnixCommandPlaceFileWithSingleChildHandling() throws Exception assertEquals(1, payload.currentFormSize(), "Single form remaining for parent"); assertEquals("copy value", payload.getStringParameter("COPY_THIS"), "Parent should have propagating metadata value"); + assertEquals("copy value", payload.getParameterAsConcatString("COPY_THIS"), "Parent should have propagating metadata value"); + assertEquals("copy value", payload.getParameterAsString("COPY_THIS"), "Parent should have propagating metadata value"); assertEquals("ignore value", payload.getStringParameter("IGNORE_THIS"), "Parent should still have non-propagating metadata value"); + assertEquals("ignore value", payload.getParameterAsConcatString("IGNORE_THIS"), "Parent should still have non-propagating metadata value"); + assertEquals("ignore value", payload.getParameterAsString("IGNORE_THIS"), "Parent should still have non-propagating metadata value"); } @Test