Search in sources :

Example 6 with CswSourceConfiguration

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.

the class TestCswFilterDelegate method testBefore.

@Test
public void testBefore() throws Exception {
    // Setup
    CswSourceConfiguration cswSourceConfiguration = initCswSourceConfiguration(CswAxisOrder.LAT_LON, false, CswConstants.CSW_TYPE, effectiveDateMapping, createdDateMapping, modifiedDateMapping, CswConstants.CSW_IDENTIFIER);
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    String dateStr = fmt.print(testStartDate);
    String controlFilterAsXml = beforeXml.replace(REPLACE_TEMPORAL_PROPERTY, createdDateMapping).replace(REPLACE_DATE, dateStr);
    CswFilterDelegate localCswFilterDelegate = createCswFilterDelegate(cswSourceConfiguration);
    // Perform Test
    FilterType filterType = localCswFilterDelegate.before(propertyNameCreated, testStartDate.toDate());
    // Verify
    assertXMLEqual(controlFilterAsXml, getXmlFromMarshaller(filterType));
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) FilterType(net.opengis.filter.v_1_1_0.FilterType) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Test(org.junit.Test)

Example 7 with CswSourceConfiguration

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.

the class TestCswFilterDelegate method testDuringAlteredEffectiveDateMapping.

@Test
public void testDuringAlteredEffectiveDateMapping() throws JAXBException, SAXException, IOException {
    String replacedTemporalProperty = "myEffectiveDate";
    CswSourceConfiguration cswSourceConfiguration = initCswSourceConfiguration(CswAxisOrder.LAT_LON, false, CswConstants.CSW_TYPE, replacedTemporalProperty, createdDateMapping, modifiedDateMapping, CswConstants.CSW_IDENTIFIER);
    CswFilterDelegate localCswFilterDelegate = createCswFilterDelegate(cswSourceConfiguration);
    String xml = getXmlProperty(localCswFilterDelegate, propertyNameEffective, BETWEEN, testStartDate.toCalendar(null).getTime(), testEndDate.toCalendar(null).getTime());
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    String startDateStr = fmt.print(testStartDate);
    String endDateStr = fmt.print(testEndDate);
    String testResponse = duringXml.replace(REPLACE_START_DATE, startDateStr).replace(REPLACE_END_DATE, endDateStr).replace(REPLACE_TEMPORAL_PROPERTY, replacedTemporalProperty);
    assertXMLEqual(testResponse, xml);
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Test(org.junit.Test)

Example 8 with CswSourceConfiguration

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.

the class TestCswSource method testRefreshWithRegisterForEvents.

@Test
public void testRefreshWithRegisterForEvents() throws Exception {
    String subscriptionId = "subscriptionid";
    String eventEndpoint = "https://ddf/services/csw/subscriptions";
    CswSourceStub cswSource = (CswSourceStub) getCswSource(mockCsw, mockContext, "contentType");
    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);
    // 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(ack).getRequestId();
}
Also used : Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) CswSubscribe(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType) Test(org.junit.Test)

Example 9 with CswSourceConfiguration

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.

the class TestCswSource method testRefresh.

@Test
public void testRefresh() throws SecurityServiceException {
    AbstractCswSource cswSource = getCswSource(mockCsw, mockContext, "contentType");
    CswSourceConfiguration defaultCswSourceConfiguration = getStandardCswSourceConfiguration("contentType", "qname", "queryprefix", encryptionService);
    // Assert Defaults
    assertDefaultCswSourceConfiguration(cswSource.cswSourceConfiguration, defaultCswSourceConfiguration);
    // Set Configuration Map
    Map<String, Object> configuration = getConfigurationMap(cswSource);
    when(encryptionService.decryptValue(PASSWORD)).thenReturn(PASSWORD);
    // Call Refresh
    cswSource.refresh(configuration);
    // Get Configuration
    CswSourceConfiguration cswSourceConfiguration = cswSource.cswSourceConfiguration;
    // Assert Refresh Changes
    assertConfigurationAfterRefresh(cswSourceConfiguration);
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 10 with CswSourceConfiguration

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.

the class TestCswSource method getStandardCswSourceConfiguration.

private CswSourceConfiguration getStandardCswSourceConfiguration(String contentTypeMapping, String queryTypeQName, String queryTypePrefix, EncryptionService encryptionService) {
    CswSourceConfiguration cswSourceConfiguration = new CswSourceConfiguration(encryptionService);
    if (encryptionService != null) {
        when(encryptionService.decryptValue("pass")).thenReturn("pass");
    }
    if (contentTypeMapping == null) {
        cswSourceConfiguration.putMetacardCswMapping(Metacard.CONTENT_TYPE, CswConstants.CSW_TYPE);
    } else {
        cswSourceConfiguration.putMetacardCswMapping(Metacard.CONTENT_TYPE, contentTypeMapping);
    }
    cswSourceConfiguration.setQueryTypeNamespace(queryTypePrefix);
    cswSourceConfiguration.setQueryTypeName(queryTypeQName);
    cswSourceConfiguration.setId(ID);
    cswSourceConfiguration.setCswUrl(URL);
    cswSourceConfiguration.putMetacardCswMapping(Core.MODIFIED, Core.MODIFIED);
    cswSourceConfiguration.putMetacardCswMapping(Core.ID, CswConstants.CSW_IDENTIFIER);
    cswSourceConfiguration.setCswAxisOrder(CswAxisOrder.LON_LAT);
    cswSourceConfiguration.setUsername("user");
    cswSourceConfiguration.setPassword("pass");
    return cswSourceConfiguration;
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration)

Aggregations

CswSourceConfiguration (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration)34 Test (org.junit.Test)29 FilterType (net.opengis.filter.v_1_1_0.FilterType)12 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)10 ByteArrayInputStream (java.io.ByteArrayInputStream)6 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)6 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)5 Matchers.anyString (org.mockito.Matchers.anyString)5 HashMap (java.util.HashMap)4 DateTime (org.joda.time.DateTime)4 ResourceResponse (ddf.catalog.operation.ResourceResponse)3 SourceResponse (ddf.catalog.operation.SourceResponse)3 Resource (ddf.catalog.resource.Resource)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 MediaType (javax.ws.rs.core.MediaType)3 Response (javax.ws.rs.core.Response)3 AcknowledgementType (net.opengis.cat.csw.v_2_0_2.AcknowledgementType)3 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)3 CswSubscribe (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe)3