1+ package org .opensearch .dataprepper .expression ;
2+
3+ import org .opensearch .dataprepper .model .event .Event ;
4+ import org .opensearch .dataprepper .model .event .JacksonEvent ;
5+ import org .junit .jupiter .api .Test ;
6+ import static org .hamcrest .CoreMatchers .equalTo ;
7+ import static org .hamcrest .MatcherAssert .assertThat ;
8+ import static org .junit .jupiter .api .Assertions .assertThrows ;
9+
10+ import java .util .List ;
11+ import java .util .Map ;
12+ import java .util .function .Function ;
13+
14+ class GetEventTypeExpressionFunctionTest {
15+
16+ private GetEventTypeExpressionFunction createObjectUnderTest () {
17+ return new GetEventTypeExpressionFunction ();
18+ }
19+
20+ private Event createTestEvent (final String eventType ) {
21+ return JacksonEvent .builder ()
22+ .withEventType (eventType )
23+ .withData (Map .of ())
24+ .build ();
25+ }
26+
27+ @ Test
28+ void testGetEventTypeReturnsCorrectType () {
29+ GetEventTypeExpressionFunction function = createObjectUnderTest ();
30+ Event testEvent = createTestEvent ("LOG" );
31+
32+ Object result = function .evaluate (List .of (), testEvent , Function .identity ());
33+
34+ assertThat (result , equalTo ("LOG" ));
35+ }
36+
37+ @ Test
38+ void testGetEventTypeThrowsExceptionWhenArgumentsProvided () {
39+ GetEventTypeExpressionFunction function = createObjectUnderTest ();
40+ Event testEvent = createTestEvent ("LOG" );
41+
42+ assertThrows (RuntimeException .class , () -> function .evaluate (List .of ("arg1" ), testEvent , Function .identity ()));
43+ }
44+
45+ @ Test
46+ void testGetEventTypeReturnsNullForNullEventType () {
47+ GetEventTypeExpressionFunction function = createObjectUnderTest ();
48+ Event testEvent = createTestEvent (null );
49+
50+ Object result = function .evaluate (List .of (), testEvent , Function .identity ());
51+
52+ assertThat (result , equalTo (null ));
53+ }
54+ }
0 commit comments