use of org.osgi.service.event.Event in project ddf by codice.
the class PredicateTest method testGeospatialPredicateNullMetadata.
@Test
public void testGeospatialPredicateNullMetadata() throws IOException {
String methodName = "testGeospatialPredicateNullMetadata()";
LOGGER.debug("*************** START: {} *****************", methodName);
String geometryWkt = "POLYGON ((40 34, 40 33, 44.5 33, 44.5 34, 40 34))";
String operation = "overlaps";
double distance = 0.0;
GeospatialPredicate predicate = new GeospatialPredicate(geometryWkt, operation, distance);
MetacardImpl metacard = new MetacardImpl();
metacard.setLocation("POINT (41 34)");
HashMap<String, Object> properties = new HashMap<>();
properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "type1,version1");
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
// No Contextual map added to properties containing indexed metadata
Event testEvent = new Event("topic", properties);
assertTrue(predicate.matches(testEvent));
LOGGER.debug("*************** END: {} *****************", methodName);
}
use of org.osgi.service.event.Event in project ddf by codice.
the class PredicateTest method testContentTypeEvaluationNullOperation.
@Test
public void testContentTypeEvaluationNullOperation() throws IOException {
String methodName = "testContentTypeEvaluationNullOperation";
LOGGER.debug("*************** START: {} *****************", methodName);
MetacardImpl metacard = new MetacardImpl();
metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
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, null);
Map<String, Object> contextualMap = constructContextualMap(metacard);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
Event testEvent = new Event("topic", properties);
assertTrue(ctp.matches(testEvent));
LOGGER.debug("*************** END: {} *****************", methodName);
}
use of org.osgi.service.event.Event in project ddf by codice.
the class PredicateTest method testContextualQueryLeadingWildcard.
@Test
public void testContextualQueryLeadingWildcard() throws Exception {
Predicate predicate = getPredicate("*test");
for (String term : Arrays.asList(LEADING_TERM, EMBEDDED_TERM_REVERSED)) {
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)));
}
}
for (String term : Arrays.asList(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 + " matched", predicate.matches(testEvent), is(equalTo(false)));
}
}
}
use of org.osgi.service.event.Event in project ddf by codice.
the class PredicateTest method testContentTypeEvaluation.
@Test
public void testContentTypeEvaluation() throws IOException {
String methodName = "testContentTypeEvaluation";
LOGGER.debug("*************** START: {} *****************", methodName);
// test input that has type1:version1 matches
// test input that has type1:version2 doesn't match
// TODO: tests input that has type2:version1 doesn't match
// TODO: test input that has type1:""
// TODO: test input that has "":""
// TODO: test input that has "":version1
// TODO: test UNKNOWN for entire contentType String
MetacardImpl metacard = new MetacardImpl();
metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
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);
Map<String, Object> contextualMap = constructContextualMap(metacard);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
// Above Pulled from PubSubProviderImpl
Event testEvent = new Event("topic", properties);
assertTrue(ctp.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,version2");
Event testEvent1 = new Event("topic1", properties);
assertFalse(ctp.matches(testEvent1));
properties.clear();
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, ",version2");
testEvent1 = new Event("topic1", properties);
assertFalse(ctp.matches(testEvent1));
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,");
testEvent1 = new Event("topic1", properties);
assertFalse(ctp.matches(testEvent1));
properties.clear();
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, ",");
testEvent1 = new Event("topic1", properties);
assertFalse(ctp.matches(testEvent1));
properties.clear();
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "UNKNOWN");
testEvent1 = new Event("topic1", properties);
assertFalse(ctp.matches(testEvent1));
// TODO: test input type1:version1 matches
// TODO: test input type1:someversion matches
// TODO: test input type2:version1 doesn't match
ContentTypePredicate ctp2 = new ContentTypePredicate("type1", null);
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,version1");
Event testEvent2 = new Event("topic", properties);
assertTrue(ctp2.matches(testEvent2));
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,someversion");
Event testEvent3 = new Event("topic", properties);
assertTrue(ctp2.matches(testEvent3));
properties.clear();
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "type2,someversion");
Event testEvent4 = new Event("topic", properties);
assertFalse(ctp2.matches(testEvent4));
LOGGER.debug("*************** END: {} *****************", methodName);
}
use of org.osgi.service.event.Event in project ddf by codice.
the class PredicateTest method testContextualQuery.
@Test
public void testContextualQuery() throws Exception {
String methodName = "testContextualQuery";
LOGGER.debug("*************** START: {} *****************", methodName);
String searchPhrase = "serengeti event";
MockQuery query = new MockQuery();
query.addContextualFilter(searchPhrase, null);
SubscriptionFilterVisitor visitor = new SubscriptionFilterVisitor();
Predicate predicate = (Predicate) query.getFilter().accept(visitor, null);
MetacardImpl metacard = new MetacardImpl();
metacard.setId("ABC123");
metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
HashMap<String, Object> properties = new HashMap<>();
properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId());
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
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
Event testEvent = new Event("topic", properties);
assertTrue(predicate.matches(testEvent));
contextualMap.clear();
properties.clear();
metacard.setMetadata(TestDataLibrary.getDogEntry());
Directory index1 = ContextualEvaluator.buildIndex(metacard.getMetadata());
contextualMap.put("DEFAULT_INDEX", index1);
contextualMap.put("METADATA", metacard.getMetadata());
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId());
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
testEvent = new Event("topic", properties);
assertFalse(predicate.matches(testEvent));
LOGGER.debug("*************** END: {} *****************", methodName);
}
Aggregations