use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.
the class TestCswCqlFilter method testRelative.
@Test
public void testRelative() throws UnsupportedQueryException {
long duration = 92000000000L;
CswSourceConfiguration cswSourceConfiguration = initCswSourceConfiguration(CswAxisOrder.LAT_LON, CswConstants.CSW_TYPE, effectiveDateMapping, createdDateMapping, modifiedDateMapping, CswConstants.CSW_IDENTIFIER);
CswFilterDelegate localCswFilterDelegate = initDefaultCswFilterDelegate(cswSourceConfiguration);
FilterType filterType = localCswFilterDelegate.relative(propertyNameModified, duration);
String cqlText = CswCqlTextFilter.getInstance().getCqlText(filterType);
String durationCompare = during.replace(REPLACE_START_DATE, "").replace(REPLACE_END_DATE, "").replace(REPLACE_TEMPORAL_PROPERTY, modifiedDateMapping);
String pattern = "(?i)(')(.+?)(')";
String compareXml = cqlText.replaceAll(pattern, "''");
assertThat(durationCompare, is(compareXml));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.
the class TestCswCqlFilter method testDuringAlteredModifiedDateMapping.
@Test
public void testDuringAlteredModifiedDateMapping() throws UnsupportedQueryException {
DateTime startDate = new DateTime(2013, 5, 1, 0, 0, 0, 0);
DateTime endDate = new DateTime(2013, 12, 31, 0, 0, 0, 0);
String replacedTemporalProperty = "myModifiedDate";
CswSourceConfiguration cswSourceConfiguration = initCswSourceConfiguration(CswAxisOrder.LAT_LON, CswConstants.CSW_TYPE, effectiveDateMapping, createdDateMapping, replacedTemporalProperty, CswConstants.CSW_IDENTIFIER);
CswFilterDelegate localCswFilterDelegate = initDefaultCswFilterDelegate(cswSourceConfiguration);
FilterType filterType = localCswFilterDelegate.during(propertyNameModified, startDate.toCalendar(null).getTime(), endDate.toCalendar(null).getTime());
String cqlText = CswCqlTextFilter.getInstance().getCqlText(filterType);
DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
String startDateStr = fmt.print(startDate);
String endDateStr = fmt.print(endDate);
String testResponse = during.replace(REPLACE_START_DATE, startDateStr).replace(REPLACE_END_DATE, endDateStr).replace(REPLACE_TEMPORAL_PROPERTY, replacedTemporalProperty);
assertThat(testResponse, is(cqlText));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.
the class TestCswSource method getCswSource.
private AbstractCswSource getCswSource(Csw csw, BundleContext context, String contentMapping, String queryTypeQName, String queryTypePrefix, EncryptionService encryptionService) {
CswSourceConfiguration cswSourceConfiguration = getStandardCswSourceConfiguration(contentMapping, queryTypeQName, queryTypePrefix, encryptionService);
cswSourceConfiguration.putMetacardCswMapping(Metacard.CONTENT_TYPE, contentMapping);
SecureCxfClientFactory mockFactory = mock(SecureCxfClientFactory.class);
doReturn(csw).when(mockFactory).getClient();
doReturn(csw).when(mockFactory).getClientForSubject(any(Subject.class));
CswSourceStub cswSource = new CswSourceStub(mockContext, cswSourceConfiguration, mockProvider, mockFactory, encryptionService);
setMetacardType(cswSource);
cswSource.setFilterAdapter(new GeotoolsFilterAdapterImpl());
cswSource.setFilterBuilder(builder);
cswSource.setContext(context);
cswSource.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
cswSource.setAvailabilityTask(mockAvailabilityTask);
cswSource.setMetacardTypes(mockRegistry);
cswSource.configureCswSource();
return cswSource;
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.
the class TestCswSource method testRefreshWithUpdateRegisterForEvents.
@Test
public void testRefreshWithUpdateRegisterForEvents() throws Exception {
String subscriptionId = "subscriptionid";
String eventEndpoint = "https://ddf/services/csw/subscriptions";
CswSourceStub cswSource = (CswSourceStub) getCswSource(mockCsw, mockContext, "contentType");
cswSource.filterlessSubscriptionId = subscriptionId;
CswSubscribe client = mock(CswSubscribe.class);
Response response = mock(Response.class);
AcknowledgementType ack = mock(AcknowledgementType.class);
when(client.createRecordsSubscription(any(GetRecordsType.class))).thenReturn(response);
when(response.getStatus()).thenReturn(200);
when(response.readEntity(any(Class.class))).thenReturn(ack);
when(ack.getRequestId()).thenReturn(subscriptionId);
when(cswSource.getSubscriberClientFactory().getClientForSubject(cswSource.getSubject())).thenReturn(client);
cswSource.cswSourceConfiguration.setRegisterForEvents(true);
cswSource.cswSourceConfiguration.setEventServiceAddress(eventEndpoint + "/original");
// Set Configuration Map
Map<String, Object> configuration = getConfigurationMap(cswSource);
configuration.put(cswSource.REGISTER_FOR_EVENTS, true);
configuration.put(cswSource.EVENT_SERVICE_ADDRESS, eventEndpoint);
// Call Refresh
cswSource.refresh(configuration);
// Get Configuration
CswSourceConfiguration cswSourceConfiguration = cswSource.cswSourceConfiguration;
// Assert Refresh Changes
Assert.assertTrue(cswSourceConfiguration.isRegisterForEvents());
Assert.assertEquals(cswSourceConfiguration.getEventServiceAddress(), eventEndpoint);
verify(client).deleteRecordsSubscription(subscriptionId);
verify(ack).getRequestId();
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.
the class TestGetRecordsMessageBodyReader method testConfigurationArguments.
@Test
public void testConfigurationArguments() throws Exception {
CswSourceConfiguration config = new CswSourceConfiguration(encryptionService);
config.setMetacardCswMappings(DefaultCswRecordMap.getCswToMetacardAttributeNames());
config.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
config.setCswAxisOrder(CswAxisOrder.LAT_LON);
config.putMetacardCswMapping(Core.THUMBNAIL, CswConstants.CSW_REFERENCES);
config.putMetacardCswMapping(Core.RESOURCE_URI, CswConstants.CSW_SOURCE);
GetRecordsMessageBodyReader reader = new GetRecordsMessageBodyReader(mockProvider, config);
InputStream is = TestGetRecordsMessageBodyReader.class.getResourceAsStream("/getRecordsResponse.xml");
MultivaluedMap<String, String> httpHeaders = new MultivaluedHashMap<>();
ArgumentCaptor<UnmarshallingContext> captor = ArgumentCaptor.forClass(UnmarshallingContext.class);
reader.readFrom(CswRecordCollection.class, null, null, null, httpHeaders, is);
// Verify the context arguments were set correctly
verify(mockProvider, times(1)).unmarshal(any(HierarchicalStreamReader.class), captor.capture());
UnmarshallingContext context = captor.getValue();
// Assert the properties needed for CswRecordConverter
assertThat(context.get(CswConstants.CSW_MAPPING), notNullValue());
Object cswMapping = context.get(CswConstants.CSW_MAPPING);
assertThat(cswMapping, instanceOf(Map.class));
assertThat(context.get(Core.RESOURCE_URI), instanceOf(String.class));
assertThat(context.get(Core.RESOURCE_URI), is(CswConstants.CSW_SOURCE));
assertThat(context.get(Core.THUMBNAIL), instanceOf(String.class));
assertThat(context.get(Core.THUMBNAIL), is(CswConstants.CSW_REFERENCES));
assertThat(context.get(CswConstants.AXIS_ORDER_PROPERTY), instanceOf(CswAxisOrder.class));
assertThat(context.get(CswConstants.AXIS_ORDER_PROPERTY), is(CswAxisOrder.LAT_LON));
// Assert the output Schema is set.
assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), instanceOf(String.class));
assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
assertThat(context.get(CswConstants.TRANSFORMER_LOOKUP_KEY), instanceOf(String.class));
assertThat(context.get(CswConstants.TRANSFORMER_LOOKUP_KEY), is(TransformerManager.SCHEMA));
assertThat(context.get(CswConstants.TRANSFORMER_LOOKUP_VALUE), instanceOf(String.class));
assertThat(context.get(CswConstants.TRANSFORMER_LOOKUP_VALUE), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
Aggregations