Search in sources :

Example 16 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class GeoIpOperationTest method testMissingField.

@Test(expected = OperationException.class)
public void testMissingField() throws Throwable {
    GeoIpOperation op = setup(Arrays.asList(GeoProperty.LOCATION), true);
    DummpyEvent devent = spy(new DummpyEvent());
    when(devent.getField("ip_address")).thenThrow(new NoSuchElementException(""));
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    op.perform(ievent);
}
Also used : NoSuchElementException(java.util.NoSuchElementException) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 17 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class GelfOperationTest method testPrefixing.

@Test
public void testPrefixing() throws JsonSyntaxException, UnsupportedEncodingException, IOException {
    JsonParser parser = new JsonParser();
    JsonElement input = parser.parse(getResourceString("prefixed_input.json"));
    String expectedOutput = getResourceString("prefixed_output.json");
    DummpyEvent devent = new DummpyEvent();
    devent.payload = input.getAsJsonObject();
    GelfOperation op = new GelfOperation(new ArrayList<>());
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    op.perform(ievent);
    assertEquals(parser.parse(expectedOutput), input);
}
Also used : JsonElement(com.google.gson.JsonElement) GelfOperation(com.nextdoor.bender.operation.gelf.GelfOperation) JsonParser(com.google.gson.JsonParser) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test) OperationTest(com.nextdoor.bender.operations.json.OperationTest)

Example 18 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class PayloadOperationTest method testNonJsonObject.

@Test(expected = OperationException.class)
public void testNonJsonObject() {
    KeyNameOperation operation = new KeyNameOperation();
    DummpyEvent devent = new DummpyEvent();
    devent.payload = new JsonPrimitive("foo");
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    operation.perform(ievent);
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) KeyNameOperation(com.nextdoor.bender.operation.json.key.KeyNameOperation) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 19 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class SubstitutionOperationTest method testKnownField.

@Test
public void testKnownField() {
    ArrayList<SubstitutionSpec> subSpecs = new ArrayList<SubstitutionSpec>();
    subSpecs.add(new SubstitutionSpec("bar", "foo", Interpreter.FIELD));
    DummpyEvent devent = new DummpyEvent();
    devent.setField("foo", "1234");
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    SubstitutionOperation op = new SubstitutionOperation(subSpecs);
    op.perform(ievent);
    assertEquals("1234", devent.getField("bar"));
    assertEquals("1234", devent.getField("foo"));
}
Also used : ArrayList(java.util.ArrayList) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 20 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class GeoIpOperationTest method testUnkownIpPass.

@Test
public void testUnkownIpPass() throws Throwable {
    GeoIpOperation op = setup(Arrays.asList(GeoProperty.LOCATION), false);
    DummpyEvent devent = new DummpyEvent();
    devent.setField("ip_address", "10.0.0.1");
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    op.perform(ievent);
}
Also used : InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Aggregations

InternalEvent (com.nextdoor.bender.InternalEvent)68 Test (org.junit.Test)67 LinkedHashMap (java.util.LinkedHashMap)17 HashMap (java.util.HashMap)13 ArrayList (java.util.ArrayList)12 TestContext (com.nextdoor.bender.aws.TestContext)10 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)9 UploadPartRequest (com.amazonaws.services.s3.model.UploadPartRequest)9 DummyDeserializedEvent (com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyDeserializedEvent)9 JsonElement (com.google.gson.JsonElement)7 JsonParser (com.google.gson.JsonParser)7 OperationTest (com.nextdoor.bender.operations.json.OperationTest)7 DummyOperationFactory (com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory)6 GenericTransportBuffer (com.nextdoor.bender.ipc.generic.GenericTransportBuffer)5 GenericTransportSerializer (com.nextdoor.bender.ipc.generic.GenericTransportSerializer)5 DummyOperation (com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperation)4 UploadPartResult (com.amazonaws.services.s3.model.UploadPartResult)3 Stat (com.nextdoor.bender.monitoring.Stat)3 KeyNameOperation (com.nextdoor.bender.operation.json.key.KeyNameOperation)3 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)3