forked from opensearch-project/data-prepper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Krishna Kondaka <[email protected]>
- Loading branch information
Krishna Kondaka
committed
Oct 18, 2023
1 parent
ad8faa3
commit fb82aca
Showing
22 changed files
with
188 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
data-prepper-api/src/main/java/org/opensearch/dataprepper/model/codec/HasByteDecoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.model.codec; | ||
|
||
public interface HasByteDecoder { | ||
default ByteDecoder getDecoder() { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...-prepper-api/src/test/java/org/opensearch/dataprepper/model/codec/HasByteDecoderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.model.codec; | ||
|
||
import org.junit.Assert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.mockito.Mockito.spy; | ||
|
||
public class HasByteDecoderTest { | ||
|
||
@Test | ||
public void testGetDecoder() { | ||
final HasByteDecoder hasByteDecoder = spy(HasByteDecoder.class); | ||
|
||
Assert.assertEquals(null, hasByteDecoder.getDecoder()); | ||
} | ||
|
||
} | ||
|
50 changes: 50 additions & 0 deletions
50
data-prepper-api/src/test/java/org/opensearch/dataprepper/model/codec/JsonDecoderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.opensearch.dataprepper.model.codec; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.opensearch.dataprepper.model.event.Event; | ||
import org.opensearch.dataprepper.model.record.Record; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.util.Map; | ||
import java.util.Random; | ||
import java.util.UUID; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.assertNotEquals; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
public class JsonDecoderTest { | ||
private JsonDecoder jsonDecoder; | ||
private Record<Event> receivedRecord; | ||
|
||
private JsonDecoder createObjectUnderTest() { | ||
return new JsonDecoder(); | ||
} | ||
|
||
@BeforeEach | ||
void setup() { | ||
jsonDecoder = createObjectUnderTest(); | ||
receivedRecord = null; | ||
} | ||
|
||
@Test | ||
void test_basicJsonDecoder() { | ||
String stringValue = UUID.randomUUID().toString(); | ||
Random r = new Random(); | ||
int intValue = r.nextInt(); | ||
String inputString = "[{\"key1\":\""+stringValue+"\", \"key2\":"+intValue+"}]"; | ||
try { | ||
jsonDecoder.parse(new ByteArrayInputStream(inputString.getBytes()), (record) -> { | ||
receivedRecord = record; | ||
}); | ||
} catch (Exception e){} | ||
|
||
assertNotEquals(receivedRecord, null); | ||
Map<String, Object> map = receivedRecord.getData().toMap(); | ||
assertThat(map.get("key1"), equalTo(stringValue)); | ||
assertThat(map.get("key2"), equalTo(intValue)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.