Search in sources :

Example 6 with ContentTypePredicate

use of ddf.catalog.pubsub.predicate.ContentTypePredicate in project ddf by codice.

the class PredicateTest method testContentTypeEvaluatorOnlyTypeNoMatch.

@Test
public void testContentTypeEvaluatorOnlyTypeNoMatch() throws Exception {
    LOGGER.debug("**************************  START: testContentTypeEvaluator_OnlyType_NoMatch()  ***********************");
    // Match on "nitf", all versions
    ContentTypePredicate predicate = new ContentTypePredicate("nitf", null);
    String inputContentType = "video,v20";
    ContentTypeEvaluationCriteriaImpl ctec = new ContentTypeEvaluationCriteriaImpl(predicate, inputContentType);
    boolean status = ContentTypeEvaluator.evaluate(ctec);
    assertFalse(status);
    LOGGER.debug("**************************  END: testContentTypeEvaluator_OnlyType_NoMatch()  ***********************");
}
Also used : ContentTypeEvaluationCriteriaImpl(ddf.catalog.pubsub.criteria.contenttype.ContentTypeEvaluationCriteriaImpl) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Test(org.junit.Test)

Example 7 with ContentTypePredicate

use of ddf.catalog.pubsub.predicate.ContentTypePredicate in project ddf by codice.

the class PredicateTest method testContentTypeFilterTypeOnly.

@Test
public void testContentTypeFilterTypeOnly() throws Exception {
    String methodName = "testContentTypeFilterTypeOnly";
    LOGGER.debug("***************  START: {}  *****************", methodName);
    MetacardImpl metacard = new MetacardImpl();
    metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
    String type1 = "type_1";
    List<MockTypeVersionsExtension> extensions = new ArrayList<>();
    MockTypeVersionsExtension ext1 = new MockTypeVersionsExtension();
    ext1.setExtensionTypeName(type1);
    extensions.add(ext1);
    MockQuery query = new MockQuery();
    query.addTypeFilter(extensions);
    SubscriptionFilterVisitor visitor = new SubscriptionFilterVisitor();
    ContentTypePredicate pred = (ContentTypePredicate) query.getFilter().accept(visitor, null);
    assertEquals(type1, pred.getType());
    assertNull(pred.getVersion());
    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
    // handle null case
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, null);
    Event testEvent = new Event("topic", properties);
    assertFalse(pred.matches(testEvent));
    // handle content type
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, type1 + ",");
    testEvent = new Event("topic", properties);
    assertTrue(pred.matches(testEvent));
    // handle content version that matches content type
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "," + type1);
    testEvent = new Event("topic", properties);
    assertFalse(pred.matches(testEvent));
    properties.clear();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, type1 + "," + "random_version");
    testEvent = new Event("topic", properties);
    assertTrue(pred.matches(testEvent));
    properties.clear();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "unmatchingtype" + "," + "random_version");
    testEvent = new Event("topic", properties);
    assertFalse(pred.matches(testEvent));
    properties.clear();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, // Invalid
    "," + "unmatchingversion");
    // input
    testEvent = new Event("topic", properties);
    assertFalse(pred.matches(testEvent));
    LOGGER.debug("***************  END: {}  *****************", methodName);
}
Also used : SubscriptionFilterVisitor(ddf.catalog.pubsub.internal.SubscriptionFilterVisitor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Event(org.osgi.service.event.Event) Test(org.junit.Test)

Example 8 with ContentTypePredicate

use of ddf.catalog.pubsub.predicate.ContentTypePredicate in project ddf by codice.

the class PredicateTest method testContentTypeEvaluatorTypeAndVersionVersionMismatch.

@Test
public void testContentTypeEvaluatorTypeAndVersionVersionMismatch() throws Exception {
    LOGGER.debug("**************************  START: testContentTypeEvaluator_TypeAndVersion_VersionMismatch()  ***********************");
    // Match on "nitf, v20"
    ContentTypePredicate predicate = new ContentTypePredicate("nitf", "v20");
    String inputContentType = "nitf,v20_Army";
    ContentTypeEvaluationCriteriaImpl ctec = new ContentTypeEvaluationCriteriaImpl(predicate, inputContentType);
    boolean status = ContentTypeEvaluator.evaluate(ctec);
    assertFalse(status);
    LOGGER.debug("**************************  END: testContentTypeEvaluator_TypeAndVersion_VersionMismatch()  ***********************");
}
Also used : ContentTypeEvaluationCriteriaImpl(ddf.catalog.pubsub.criteria.contenttype.ContentTypeEvaluationCriteriaImpl) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Test(org.junit.Test)

Example 9 with ContentTypePredicate

use of ddf.catalog.pubsub.predicate.ContentTypePredicate in project ddf by codice.

the class PredicateTest method testContentTypeEvaluationNullMetadata.

@Test
public void testContentTypeEvaluationNullMetadata() throws IOException {
    String methodName = "testContentTypeEvaluationNullMetadata";
    LOGGER.debug("***************  START: {}  *****************", methodName);
    ContentTypePredicate ctp = new ContentTypePredicate("type1", "version1");
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "type1,version1");
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    // No Contextual map added to properties containing indexed metadata
    Event testEvent = new Event("topic", properties);
    assertTrue(ctp.matches(testEvent));
    LOGGER.debug("***************  END: {}  *****************", methodName);
}
Also used : HashMap(java.util.HashMap) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Event(org.osgi.service.event.Event) Test(org.junit.Test)

Example 10 with ContentTypePredicate

use of ddf.catalog.pubsub.predicate.ContentTypePredicate in project ddf by codice.

the class PredicateTest method testContentTypeEvaluatorOnlyTypeMatch.

@Test
public void testContentTypeEvaluatorOnlyTypeMatch() throws Exception {
    LOGGER.debug("**************************  START: testContentTypeEvaluator_OnlyType_Match()  ***********************");
    // Match on "nitf", all versions
    ContentTypePredicate predicate = new ContentTypePredicate("nitf", null);
    String inputContentType = "nitf,v20";
    ContentTypeEvaluationCriteriaImpl ctec = new ContentTypeEvaluationCriteriaImpl(predicate, inputContentType);
    boolean status = ContentTypeEvaluator.evaluate(ctec);
    assertTrue(status);
    LOGGER.debug("**************************  END: testContentTypeEvaluator_OnlyType_Match()  ***********************");
}
Also used : ContentTypeEvaluationCriteriaImpl(ddf.catalog.pubsub.criteria.contenttype.ContentTypeEvaluationCriteriaImpl) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Test(org.junit.Test)

Aggregations

ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)13 Test (org.junit.Test)9 ContentTypeEvaluationCriteriaImpl (ddf.catalog.pubsub.criteria.contenttype.ContentTypeEvaluationCriteriaImpl)5 HashMap (java.util.HashMap)4 Event (org.osgi.service.event.Event)4 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)3 ContextualPredicate (ddf.catalog.pubsub.predicate.ContextualPredicate)3 ArrayList (java.util.ArrayList)3 EntryPredicate (ddf.catalog.pubsub.predicate.EntryPredicate)2 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)2 Predicate (ddf.catalog.pubsub.predicate.Predicate)2 TemporalPredicate (ddf.catalog.pubsub.predicate.TemporalPredicate)2 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)2 FuzzyFunction (ddf.catalog.impl.filter.FuzzyFunction)1 SubscriptionFilterVisitor (ddf.catalog.pubsub.internal.SubscriptionFilterVisitor)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 List (java.util.List)1 LikeFilterImpl (org.geotools.filter.LikeFilterImpl)1 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)1