use of loghub.Event in project LogHub by fbacchella.
the class TestVarExtractor method test2.
@Test
public void test2() throws ProcessorException {
VarExtractor t = new VarExtractor();
t.setField("message");
t.setParser("(?<name>[a-z]+)[=:](?<value>[^;]+);?");
Event e = Tools.getEvent();
e.put("message", "a=1;b:2");
e.process(t);
System.out.println(e);
Assert.assertEquals("key a not found", "1", e.get("a"));
Assert.assertEquals("key b found", "2", e.get("b"));
Assert.assertNull("key message found", e.get("message"));
}
use of loghub.Event in project LogHub by fbacchella.
the class TestVarExtractor method test1.
@Test
public void test1() throws ProcessorException {
VarExtractor t = new VarExtractor();
t.setPath("sub");
t.setField(".message");
t.setParser("(?<name>[a-z]+)[=:](?<value>[^;]+);?");
Event e = Tools.getEvent();
e.put("message", "a=1;b:2;c");
Assert.assertTrue(e.process(t));
System.out.println(e);
@SuppressWarnings("unchecked") Map<String, Object> sub = (Map<String, Object>) e.get("sub");
Assert.assertEquals("key a not found", "1", sub.get("a"));
Assert.assertEquals("key b not found", "2", sub.get("b"));
Assert.assertEquals("key message not found", "c", e.get("message"));
}
use of loghub.Event in project LogHub by fbacchella.
the class TestHttp method testHttpPostJson.
@Test
public void testHttpPostJson() throws IOException {
makeReceiver(i -> {
});
doRequest(new URL("http", hostname, port, "/"), "{\"a\": 1}".getBytes("UTF-8"), i -> {
try {
i.setRequestMethod("PUT");
i.setRequestProperty("Content-Type", "application/json");
} catch (ProtocolException e1) {
throw new UncheckedIOException(e1);
}
}, 200);
Event e = queue.poll();
logger.debug(e.getClass());
Integer a = (Integer) e.get("a");
Assert.assertEquals(1, a.intValue());
}
use of loghub.Event in project LogHub by fbacchella.
the class TestHttp method testHttpGet.
@Test
public void testHttpGet() throws IOException {
makeReceiver(i -> {
});
doRequest(new URL("http", hostname, port, "/?a=1"), new byte[] {}, i -> {
}, 200);
Event e = queue.poll();
logger.debug(e.getClass());
String a = (String) e.get("a");
Assert.assertEquals("1", a);
}
use of loghub.Event in project LogHub by fbacchella.
the class TestHttp method testGoodAuthentication.
@Test
public void testGoodAuthentication() throws IOException {
makeReceiver(i -> {
i.setUser("user");
i.setPassword("password");
});
URL dest = new URL("http", hostname, port, "/?a=1");
doRequest(dest, new byte[] {}, i -> {
String authStr = Base64.getEncoder().encodeToString("user:password".getBytes());
i.setRequestProperty("Authorization", "Basic " + authStr);
}, 200);
Event e = queue.poll();
Assert.assertEquals("1", e.get("a"));
}
Aggregations