@Test public void testGetNullValues() { final Event testEvent = Event.create("type").value("key1", "val1").build(); assertTrue(testEvent.getValue("key1").isPresent()); assertFalse(testEvent.getValue("key2").isPresent()); }
private Event createTestEvent() { return Event.create("type") .distributed(true) .value("key1", "val1") .value("key2", "val2") .build(); }
@Test public void testClone() { final Event event = this.createTestEvent(); final Event clonedEvent = Event.create(event).build(); assertEquals(event.getType(), clonedEvent.getType()); assertEquals(event.isDistributed(), clonedEvent.isDistributed()); assertEquals(event.getData(), clonedEvent.getData()); assertEquals(event, clonedEvent); }
@Test public void testGetValueAs() { final Event testEvent = Event.create("type") .value("int1", 1) .value("long1", 10L) .value("obj1", ContentId.from("testId")) .build(); assertTrue(testEvent.getValueAs(Double.class, "int1").get() != null); assertTrue(testEvent.getValueAs(Boolean.class, "long1").get() != null); assertTrue(testEvent.getValueAs(ContentId.class, "obj1").get() != null); assertFalse(testEvent.getValueAs(ContentId.class, "obj2").isPresent()); }
@Test public void testSubTypes() { final Event testEvent = Event.create("type1.type2.type3.type4").build(); assertTrue(testEvent.isSubType("type1")); assertTrue(testEvent.isSubType("type1.type2")); assertTrue(testEvent.isSubType("type1.type2.type3")); assertFalse(testEvent.isSubType("type1.type3")); assertFalse(testEvent.isSubType("type2")); assertFalse(testEvent.isSubType("type4")); assertFalse(testEvent.isSubType("type2.type3.type4")); assertFalse(testEvent.isSubType("type1.type2.type3.type4")); assertFalse(testEvent.isSubType("type2.type3")); assertTrue(testEvent.isType("type1.type2.type3.type4")); assertFalse(testEvent.isType("type1.type2.type3")); }
@Test public void testDataValues() { final Event testEvent = Event.create("type") .distributed(true) .value("int1", 1) .value("long1", 10L) .value("bool1", false) .value("obj1", this.createTestEvent()) .build(); assertTrue(testEvent.hasValue("int1")); assertTrue(testEvent.hasValue("long1")); assertTrue(testEvent.hasValue("bool1")); assertTrue(testEvent.hasValue("obj1")); assertTrue(testEvent.getValue("int1").get() instanceof Integer); assertTrue(testEvent.getValue("long1").get() instanceof Long); assertTrue(testEvent.getValue("bool1").get() instanceof Boolean); assertTrue(testEvent.getValue("obj1").get() instanceof String); }