Search in sources :

Example 1 with GelfOperation

use of com.nextdoor.bender.operation.gelf.GelfOperation in project bender by Nextdoor.

the class GelfOperationFactoryTest method foo.

@Test
public void foo() {
    GelfOperationConfig config = new GelfOperationConfig();
    config.setSrcHostField("foo_host");
    config.setSrcShortMessageField("foo_short_message");
    config.setSrcFileField("filename");
    GelfOperationFactory factory = new GelfOperationFactory();
    factory.setConf(config);
    GelfOperation op = factory.newInstance();
    ArrayList<SubstitutionSpec> actual = op.getSubSpecs();
    ArrayList<SubstitutionSpec> expected = new ArrayList<SubstitutionSpec>();
    expected.add(new SubstitutionSpec("host", "foo_host", Interpreter.FIELD));
    expected.add(new SubstitutionSpec("file", "filename", Interpreter.FIELD));
    expected.add(new SubstitutionSpec("short_message", "foo_short_message", Interpreter.FIELD));
    expected.add(new SubstitutionSpec("version", "1.1", Interpreter.STATIC));
    Collections.sort(expected, Comparator.comparingInt(Object::hashCode));
    Collections.sort(actual, Comparator.comparingInt(Object::hashCode));
    assertEquals(expected, actual);
}
Also used : GelfOperationConfig(com.nextdoor.bender.operation.gelf.GelfOperationConfig) GelfOperation(com.nextdoor.bender.operation.gelf.GelfOperation) ArrayList(java.util.ArrayList) GelfOperationFactory(com.nextdoor.bender.operation.gelf.GelfOperationFactory) SubstitutionSpec(com.nextdoor.bender.operation.substitution.SubstitutionSpec) Test(org.junit.Test)

Example 2 with GelfOperation

use of com.nextdoor.bender.operation.gelf.GelfOperation 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 3 with GelfOperation

use of com.nextdoor.bender.operation.gelf.GelfOperation in project bender by Nextdoor.

the class GelfOperationTest method testFlattenPrefix.

@Test
public void testFlattenPrefix() throws JsonSyntaxException, UnsupportedEncodingException, IOException {
    JsonParser parser = new JsonParser();
    JsonElement input = parser.parse(getResourceString("flatten_prefixed_input.json"));
    String expectedOutput = getResourceString("flatten_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)

Aggregations

GelfOperation (com.nextdoor.bender.operation.gelf.GelfOperation)3 Test (org.junit.Test)3 JsonElement (com.google.gson.JsonElement)2 JsonParser (com.google.gson.JsonParser)2 InternalEvent (com.nextdoor.bender.InternalEvent)2 OperationTest (com.nextdoor.bender.operations.json.OperationTest)2 GelfOperationConfig (com.nextdoor.bender.operation.gelf.GelfOperationConfig)1 GelfOperationFactory (com.nextdoor.bender.operation.gelf.GelfOperationFactory)1 SubstitutionSpec (com.nextdoor.bender.operation.substitution.SubstitutionSpec)1 ArrayList (java.util.ArrayList)1