use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.
the class PredicateTest method testContextualQuerySpecialNotMatch.
@Test
public void testContextualQuerySpecialNotMatch() throws IOException {
for (String term : Arrays.asList(LEADING_TERM, TRAILING_TERM, EMBEDDED_TERM)) {
for (Character specialChar : ContextualTokenizer.SPECIAL_CHARACTERS_SET) {
String phrase = String.format(term, specialChar);
for (Character differentSpecialChar : ContextualTokenizer.SPECIAL_CHARACTERS_SET) {
if (specialChar != differentSpecialChar) {
String metadata = String.format(METADATA_FORMAT, StringEscapeUtils.escapeXml(String.format(term, differentSpecialChar)));
Predicate predicate = getPredicate("\"" + phrase + "\"");
Event testEvent = getEvent(metadata);
assertThat(phrase + " matched", predicate.matches(testEvent), is(equalTo(false)));
}
}
}
}
}
use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.
the class PredicateTest method testTemporal.
@Test
public void testTemporal() throws Exception {
String methodName = "testTemporal";
LOGGER.debug("*************** START: {} *****************", methodName);
MockQuery query = new MockQuery();
DatatypeFactory df = DatatypeFactory.newInstance();
XMLGregorianCalendar start = df.newXMLGregorianCalendarDate(2011, 10, 25, 0);
XMLGregorianCalendar end = df.newXMLGregorianCalendarDate(2011, 10, 27, 0);
query.addTemporalFilter(start, end, Metacard.EFFECTIVE);
SubscriptionFilterVisitor visitor = new SubscriptionFilterVisitor();
Predicate pred = (Predicate) query.getFilter().accept(visitor, null);
LOGGER.debug("Resulting Predicate: {}", pred);
Filter filter = query.getFilter();
FilterTransformer transform = new FilterTransformer();
transform.setIndentation(2);
String filterXml = transform.transform(filter);
LOGGER.debug(filterXml);
// input that passes temporal
LOGGER.debug("\npass temporal.\n");
MetacardImpl metacard = new MetacardImpl();
metacard.setCreatedDate(new Date());
metacard.setExpirationDate(new Date());
metacard.setModifiedDate(new Date());
metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
XMLGregorianCalendar cal = df.newXMLGregorianCalendarDate(2011, 10, 26, 0);
Date effectiveDate = cal.toGregorianCalendar().getTime();
metacard.setEffectiveDate(effectiveDate);
HashMap<String, Object> properties = new HashMap<>();
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
Map<String, Object> contextualMap = constructContextualMap(metacard);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
// Above Pulled from PubSubProviderImpl
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
Event testEvent = new Event("topic", properties);
boolean b = pred.matches(testEvent);
assertTrue(b);
// input that fails temporal
LOGGER.debug("\nfail temporal. fail content type.\n");
// time out of
XMLGregorianCalendar cal1 = df.newXMLGregorianCalendarDate(2012, 10, 30, 0);
// range
Date effectiveDate1 = cal1.toGregorianCalendar().getTime();
metacard.setEffectiveDate(effectiveDate1);
LOGGER.debug("metacard date: {}", metacard.getEffectiveDate());
properties.clear();
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
testEvent = new Event("topic", properties);
assertFalse(pred.matches(testEvent));
LOGGER.debug("*************** END: {} *****************", methodName);
}
use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.
the class PredicateTest method testContextualQuerySpecialMatch.
@Test
public void testContextualQuerySpecialMatch() throws IOException {
for (String term : Arrays.asList(LEADING_TERM, TRAILING_TERM, EMBEDDED_TERM)) {
for (Character specialChar : ContextualTokenizer.SPECIAL_CHARACTERS_SET) {
String phrase = String.format(term, specialChar);
String metadata = String.format(METADATA_FORMAT, StringEscapeUtils.escapeXml(phrase));
Predicate predicate = getPredicate("\"" + phrase + "\"");
Event testEvent = getEvent(metadata);
assertThat(phrase + " not matched", predicate.matches(testEvent), is(equalTo(true)));
}
}
}
use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.
the class PredicateTest method testContextualQuerySurroundedByWildcards.
@Test
public void testContextualQuerySurroundedByWildcards() throws Exception {
Predicate predicate = getPredicate("*test*");
for (String term : Arrays.asList(LEADING_TERM, TRAILING_TERM, EMBEDDED_TERM)) {
for (Character specialChar : ContextualTokenizer.SPECIAL_CHARACTERS_SET) {
String phrase = String.format(term, specialChar);
String metadata = String.format(METADATA_FORMAT, StringEscapeUtils.escapeXml(phrase));
Event testEvent = getEvent(metadata);
assertThat(phrase + " not matched", predicate.matches(testEvent), is(equalTo(true)));
}
}
}
use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.
the class PredicateTest method testCaseSensitiveContextualQuery.
@Test
public void testCaseSensitiveContextualQuery() throws Exception {
String methodName = "testCaseSensitiveContextualQuery";
LOGGER.debug("*************** START: {} *****************", methodName);
String searchPhrase = "laZy BROwn foX";
Predicate predicate = getPredicate(searchPhrase, true);
String metadata = String.format(METADATA_FORMAT, "laZy BROwn foX");
Event testEvent = getEvent(metadata);
assertTrue(predicate.matches(testEvent));
metadata = String.format(METADATA_FORMAT, "lazy brown fox");
testEvent = getEvent(metadata);
assertFalse(predicate.matches(testEvent));
metadata = String.format(METADATA_FORMAT, "laZy bROwn foX");
testEvent = getEvent(metadata);
assertFalse(predicate.matches(testEvent));
metadata = String.format(METADATA_FORMAT, "laZyBROwn foX");
testEvent = getEvent(metadata);
assertFalse(predicate.matches(testEvent));
LOGGER.debug("*************** END: {} *****************", methodName);
}
Aggregations