use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class TestEventProcessorImpl method testNullOperation.
@Test
public void testNullOperation() {
MetacardImpl metacard = new MetacardImpl();
metacard.setContentTypeName("Nitf");
metacard.setContentTypeVersion("2.0");
metacard.setMetadata("<xml/>");
EventAdmin eventAdmin = new MockEventAdmin();
try {
EventProcessorImpl.processEntry(metacard, null, eventAdmin);
} catch (Exception e) {
LOGGER.error("Unexpected exception.", e);
fail();
}
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class PredicateTest method testGeospatialPredicateNullOperation.
@Test
public void testGeospatialPredicateNullOperation() throws IOException {
String methodName = "testGeospatialPredicateNullOperation";
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)");
metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
HashMap<String, Object> properties = new HashMap<>();
properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "type1,version1");
properties.put(PubSubConstants.HEADER_OPERATION_KEY, null);
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
Map<String, Object> contextualMap = constructContextualMap(metacard);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
Event testEvent = new Event("topic", properties);
assertTrue(predicate.matches(testEvent));
LOGGER.debug("*************** END: {} *****************", methodName);
}
use of ddf.catalog.data.impl.MetacardImpl 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.data.impl.MetacardImpl 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.data.impl.MetacardImpl in project ddf by codice.
the class TestMetacardGroomerPlugin method getStandardMetacard.
private Metacard getStandardMetacard(String id) {
DateTime currentDate = new DateTime();
Date defaultDate = currentDate.minusMinutes(1).toDate();
MetacardImpl metacard = new MetacardImpl(getHybridMetacardType());
if (id != null) {
metacard.setId(id);
}
metacard.setTitle(DEFAULT_TITLE);
metacard.setCreatedDate(defaultDate);
metacard.setAttribute(new AttributeImpl(Core.METACARD_CREATED, defaultDate));
metacard.setEffectiveDate(defaultDate);
metacard.setExpirationDate(defaultDate);
metacard.setModifiedDate(defaultDate);
metacard.setAttribute(new AttributeImpl(Core.METACARD_MODIFIED, defaultDate));
metacard.setMetadata(DEFAULT_METADATA);
metacard.setContentTypeName(DEFAULT_TYPE);
metacard.setContentTypeVersion(DEFAULT_VERSION);
metacard.setLocation(DEFAULT_LOCATION);
byte[] defaultBytes = { -86 };
metacard.setThumbnail(defaultBytes);
return metacard;
}
Aggregations