Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Gray <[email protected]>
  • Loading branch information
graytaylor0 committed Feb 19, 2024
1 parent 9fb1a9d commit fc66ad1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion data-prepper-expression/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jacocoTestCoverageVerification {
violationRules {
rule { //in addition to core projects rule - this one checks for 100% code coverage for this project
limit {
minimum = 0.9 // lowered because ParseTreeCoercionServiceTest does not mock enough, and it is not possible to induce a failure
minimum = 1.0 // lowered because ParseTreeCoercionServiceTest does not mock enough, and it is not possible to induce a failure
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.stream.Stream;

Expand Down Expand Up @@ -186,6 +187,32 @@ void testCoerceTerminalNodeEscapeJsonPointerTypeSupportedValues(final Object tes
}
}

@Test
void testCoerceTerminalNodeEscapeJsonPointerTypeUnSupportedValues() {
final String testKey = "testKey";
final AtomicBoolean testValue = new AtomicBoolean();
final String testEscapeJsonPointerKey = String.format("\"/%s\"", testKey);
final Event testEvent = createInvalidTestEvent(Map.of(testKey, testValue));
when(token.getType()).thenReturn(DataPrepperExpressionParser.EscapedJsonPointer);
when(terminalNode.getSymbol()).thenReturn(token);
when(terminalNode.getText()).thenReturn(testEscapeJsonPointerKey);
assertThrows(ExpressionCoercionException.class, () -> objectUnderTest.coercePrimaryTerminalNode(terminalNode, testEvent));
}

@Test
void testCoerceTerminalNodeJsonPointerTypeUnSupportedValues() {
final String testKey1 = "key1";
final String testKey2 = "key2";
final AtomicBoolean testValue = new AtomicBoolean();
final String testJsonPointerKey = String.format("/%s/%s", testKey1, testKey2);

final Event testEvent = createInvalidTestEvent(Map.of(testKey1, testValue));
when(token.getType()).thenReturn(DataPrepperExpressionParser.JsonPointer);
when(terminalNode.getSymbol()).thenReturn(token);
when(terminalNode.getText()).thenReturn(testJsonPointerKey);
assertThrows(ExpressionCoercionException.class, () -> objectUnderTest.coercePrimaryTerminalNode(terminalNode, testEvent));
}

@Test
void testCoerceTerminalNodeUnsupportedType() {
final Event testEvent = createTestEvent(new HashMap<>());
Expand Down Expand Up @@ -306,6 +333,12 @@ private Event createTestEvent(final Object data) {
return event;
}

private Event createInvalidTestEvent(final Object data) {
final Event event = mock(Event.class);
lenient().when(event.get(anyString(), any())).thenReturn(new AtomicBoolean());
return event;
}

private static Stream<Arguments> provideKeys() {
return Stream.of(
Arguments.of("test key", "\"/test key\""),
Expand Down

0 comments on commit fc66ad1

Please sign in to comment.