Skip to content

Commit

Permalink
fallback to original behavior for getParameterAsString
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-mlb committed Jan 17, 2025
1 parent 5d50541 commit e5f33ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/main/java/emissary/core/BaseDataObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,8 @@ public boolean appendUniqueParameter(final String key, final CharSequence value)
public String getParameterAsString(final String key) {
final var obj = getParameterAsStrings(key);
if (obj.size() > 1) {
logger.warn("Multiple values for parameter, returning the first - parameter:{}, number of values:{}", key, obj.size());
logger.warn("Multiple values for parameter, parameter:{}, number of values:{}", key, obj.size());
return getParameterAsConcatString(key);
}
return obj.stream().findFirst().orElse(null);
}
Expand Down
22 changes: 11 additions & 11 deletions src/test/java/emissary/core/BaseDataObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -852,10 +852,10 @@ void testPutParametersWithPolicy() {

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("uno;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("deux;dos", 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");
Expand Down Expand Up @@ -952,7 +952,7 @@ void testAppendDuplicateParameters() {
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");
assertEquals("GABBA;GABBA", this.b.getParameterAsString("YO"), "Appended duplicate parameters first value should be preserved");
assertTrue(this.b.hasParameter("YO"), "HasParameter should be true");
}

Expand Down Expand Up @@ -983,7 +983,7 @@ void testParametersWithMixtureOfSingleValuesAndLists() {
assertEquals("FOO1;FOO2;FOO3;FOO4",
this.b.getParameterAsConcatString("FOO"),
"Returned string should be combination of initial list and added value");
assertEquals("FOO1",
assertEquals("FOO1;FOO2;FOO3;FOO4",
this.b.getParameterAsString("FOO"),
"Returned string should be first value from combination of initial list and added value");
}
Expand All @@ -1002,7 +1002,7 @@ void testParametersWithMixtureOfSingleValuesAndSets() {
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"),
assertEquals("FOO1;FOO2;FOO3;FOO4", this.b.getParameterAsString("FOO"),
"Returned string should be first value from combination of initial set and added value");
}

Expand Down Expand Up @@ -1036,7 +1036,7 @@ void testAppendParameter() {
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");
assertEquals("YOU;FOO", this.b.getParameterAsString("ME"), "Appended parameter value");
}

@Test
Expand All @@ -1045,7 +1045,7 @@ void testAppendParameterIterables() {
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");
assertEquals("YOU;FOO;BAR;BAZ", this.b.getParameterAsString("ME"), "First value from appended parameter value");

final Set<String> s = new TreeSet<>();
s.add("ZAB");
Expand All @@ -1055,7 +1055,7 @@ void testAppendParameterIterables() {

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");
assertEquals("YOU;FOO;BAR;BAZ;OOF;RAB;ZAB", this.b.getParameterAsString("ME"), "First value from appended set parameter value");
}

@Test
Expand Down Expand Up @@ -1422,11 +1422,11 @@ void testGetParameterAsString() throws IOException {
this.b.putParameter("A", 1L);
this.b.appendParameter("A", "TWO");
this.b.appendParameter("A", "THREE");
assertEquals("1", this.b.getParameterAsString("A"));
assertEquals("1;TWO;THREE", 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);
"Multiple values for parameter, parameter:A, number of values:3", null);
logbackTester.checkLogList(Collections.singletonList(logEvent));
}

Expand Down Expand Up @@ -1457,7 +1457,7 @@ void testGetParameterAsString() throws IOException {
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.getParameterAsString("A"));
assertEquals("null;FOUR; ", this.b.getParameterAsConcatString("A"));
assertEquals("null;FOUR; ", this.b.getStringParameter("A"));
}
Expand Down

0 comments on commit e5f33ce

Please sign in to comment.