PathValueEventFilter implements Predicate<T> { @Override public boolean apply(Object input) { JXPathContext jxpath = JXPathContext.newContext(input); jxpath.setLenient(true); @SuppressWarnings("unchecked") T value = (T)jxpath.getValue(xpath); return predicate.apply(value); } PathValueEventFilter(String path, ValuePredicate<T> predicate); @Override boolean apply(Object input); String getXpath(); ValuePredicate<?> getPredicate(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void testNonExistentValueShouldBeFiltered(){ MockRequestTrace requestTrace = Mockito.mock(MockRequestTrace.class); Predicate<Object> filter = new PathValueEventFilter(" assertFalse(filter.apply(requestTrace)); }
@Test public void testNullValueCanBeAccepted(){ MockRequestTrace requestTrace = Mockito.mock(MockRequestTrace.class); Predicate<Object> filter = new PathValueEventFilter(" assertTrue(filter.apply(requestTrace)); }
@Test public void testPositiveSelection() { MockRequestTrace requestTrace = Mockito.mock(MockRequestTrace.class); when(requestTrace.getClientInfoHostName()).thenReturn("localhost"); Map<String, Object> clientInfoMap = Maps.newHashMap(); clientInfoMap.put("clientName", "client"); clientInfoMap.put("clientId", (long) 10); when(requestTrace.getClientInfoMap()).thenReturn(clientInfoMap); Predicate<Object> filter = new PathValueEventFilter(" assertTrue("Filter should return true as the client ID is 10, greater than 5", filter.apply(requestTrace)); filter = new PathValueEventFilter(" assertTrue("Filter should return true as client name is 'client'", filter.apply(requestTrace)); filter = new PathValueEventFilter(" assertTrue("Filter should return tre as clientInfoHostName is localhost", filter.apply(requestTrace)); }