Search in sources :

Example 11 with Predicate

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)));
                }
            }
        }
    }
}
Also used : Event(org.osgi.service.event.Event) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate) Test(org.junit.Test)

Example 12 with Predicate

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);
}
Also used : DatatypeFactory(javax.xml.datatype.DatatypeFactory) SubscriptionFilterVisitor(ddf.catalog.pubsub.internal.SubscriptionFilterVisitor) HashMap(java.util.HashMap) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Date(java.util.Date) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Filter(org.opengis.filter.Filter) Event(org.osgi.service.event.Event) FilterTransformer(org.geotools.filter.FilterTransformer) Test(org.junit.Test)

Example 13 with Predicate

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)));
        }
    }
}
Also used : Event(org.osgi.service.event.Event) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate) Test(org.junit.Test)

Example 14 with Predicate

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)));
        }
    }
}
Also used : Event(org.osgi.service.event.Event) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate) Test(org.junit.Test)

Example 15 with Predicate

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);
}
Also used : Event(org.osgi.service.event.Event) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate) Test(org.junit.Test)

Aggregations

Predicate (ddf.catalog.pubsub.predicate.Predicate)27 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)26 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)26 Test (org.junit.Test)17 Event (org.osgi.service.event.Event)16 SubscriptionFilterVisitor (ddf.catalog.pubsub.internal.SubscriptionFilterVisitor)13 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)10 HashMap (java.util.HashMap)10 Filter (org.opengis.filter.Filter)9 ContextualPredicate (ddf.catalog.pubsub.predicate.ContextualPredicate)8 EntryPredicate (ddf.catalog.pubsub.predicate.EntryPredicate)8 TemporalPredicate (ddf.catalog.pubsub.predicate.TemporalPredicate)8 Date (java.util.Date)6 FilterTransformer (org.geotools.filter.FilterTransformer)6 ArrayList (java.util.ArrayList)5 DatatypeFactory (javax.xml.datatype.DatatypeFactory)5 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)5 IncludeFilter (org.opengis.filter.IncludeFilter)3 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)2 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)2