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() ***********************");
}
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);
}
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() ***********************");
}
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);
}
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() ***********************");
}
Aggregations