Search in sources :

Example 1 with KeyNameOperation

use of com.nextdoor.bender.operation.json.key.KeyNameOperation 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 2 with KeyNameOperation

use of com.nextdoor.bender.operation.json.key.KeyNameOperation in project bender by Nextdoor.

the class KeyNameMutatorTest method testMutatePayload.

@Test
public void testMutatePayload() throws JsonSyntaxException, IOException, OperationException {
    JsonParser parser = new JsonParser();
    JsonElement input = parser.parse(getResourceString("basic_input.json"));
    String expectedOutput = getResourceString("basic_output_key_name.json");
    DummpyEvent devent = new DummpyEvent();
    devent.payload = input.getAsJsonObject();
    KeyNameOperation operation = new KeyNameOperation();
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    operation.perform(ievent);
    assertEquals(expectedOutput, input.toString());
}
Also used : JsonElement(com.google.gson.JsonElement) KeyNameOperation(com.nextdoor.bender.operation.json.key.KeyNameOperation) JsonParser(com.google.gson.JsonParser) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test) OperationTest(com.nextdoor.bender.operations.json.OperationTest)

Example 3 with KeyNameOperation

use of com.nextdoor.bender.operation.json.key.KeyNameOperation in project bender by Nextdoor.

the class PayloadOperationTest method testNullPayload.

@Test
public void testNullPayload() {
    KeyNameOperation operation = new KeyNameOperation();
    DummpyEvent devent = new DummpyEvent();
    devent.payload = null;
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    InternalEvent output = operation.perform(ievent);
    assertEquals(null, output);
}
Also used : KeyNameOperation(com.nextdoor.bender.operation.json.key.KeyNameOperation) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Aggregations

InternalEvent (com.nextdoor.bender.InternalEvent)3 KeyNameOperation (com.nextdoor.bender.operation.json.key.KeyNameOperation)3 Test (org.junit.Test)3 JsonElement (com.google.gson.JsonElement)1 JsonParser (com.google.gson.JsonParser)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 OperationTest (com.nextdoor.bender.operations.json.OperationTest)1