Search in sources :

Example 31 with CswSourceConfiguration

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

the class TestCswFilterDelegate method testRelative.

@Test
public void testRelative() throws JAXBException, SAXException, IOException {
    long duration = 92000000000L;
    CswSourceConfiguration cswSourceConfiguration = initCswSourceConfiguration(CswAxisOrder.LAT_LON, false, CswConstants.CSW_TYPE, effectiveDateMapping, createdDateMapping, modifiedDateMapping, CswConstants.CSW_IDENTIFIER);
    CswFilterDelegate localCswFilterDelegate = createCswFilterDelegate(cswSourceConfiguration);
    Map<String, Object> propMap = new HashMap<>();
    propMap.put("extendedComparisonOp", "relative");
    propMap.put("duration", new Long(duration));
    String xml = getXmlProperty(localCswFilterDelegate, propertyNameModified, BETWEEN, testStartDate.toCalendar(null).getTime(), testEndDate.toCalendar(null).getTime(), propMap);
    String durationCompare = duringXml.replace(REPLACE_START_DATE, "").replace(REPLACE_END_DATE, "").replace(REPLACE_TEMPORAL_PROPERTY, modifiedDateMapping);
    String pattern = "(?i)(<ns.:Literal>)(.+?)(</ns.:Literal>)";
    String compareXml = xml.replaceAll(pattern, "<ogc:Literal xmlns:ogc=\"http://www.opengis.net/ogc\"></ogc:Literal>");
    Diff xmlDiff = new Diff(durationCompare, compareXml);
    xmlDiff.overrideElementQualifier(new ElementNameQualifier() {

        @Override
        protected boolean equalsNamespace(Node control, Node test) {
            return true;
        }
    });
    xmlDiff.overrideDifferenceListener(new DifferenceListener() {

        @Override
        public int differenceFound(Difference diff) {
            if (diff.getId() == DifferenceConstants.NAMESPACE_PREFIX_ID) {
                return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
            }
            return RETURN_ACCEPT_DIFFERENCE;
        }

        @Override
        public void skippedComparison(Node arg0, Node arg1) {
        }
    });
    assertXMLIdentical(xmlDiff, true);
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) HashMap(java.util.HashMap) Diff(org.custommonkey.xmlunit.Diff) Node(org.w3c.dom.Node) Difference(org.custommonkey.xmlunit.Difference) DifferenceListener(org.custommonkey.xmlunit.DifferenceListener) ElementNameQualifier(org.custommonkey.xmlunit.ElementNameQualifier) Test(org.junit.Test)

Example 32 with CswSourceConfiguration

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

the class TestCswFilterDelegate method testDuring.

@Test
public void testDuring() throws JAXBException, SAXException, IOException {
    CswSourceConfiguration cswSourceConfiguration = initCswSourceConfiguration(CswAxisOrder.LAT_LON, false, CswConstants.CSW_TYPE, effectiveDateMapping, createdDateMapping, modifiedDateMapping, CswConstants.CSW_IDENTIFIER);
    CswFilterDelegate localCswFilterDelegate = createCswFilterDelegate(cswSourceConfiguration);
    String xml = getXmlProperty(localCswFilterDelegate, propertyNameModified, 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, modifiedDateMapping);
    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 33 with CswSourceConfiguration

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

the class TestCswCqlFilter method testDuringAlteredCreatedDateMapping.

@Test
public void testDuringAlteredCreatedDateMapping() 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 = "myCreatedDate";
    CswSourceConfiguration cswSourceConfiguration = initCswSourceConfiguration(CswAxisOrder.LAT_LON, CswConstants.CSW_TYPE, effectiveDateMapping, replacedTemporalProperty, modifiedDateMapping, CswConstants.CSW_IDENTIFIER);
    CswFilterDelegate localCswFilterDelegate = initDefaultCswFilterDelegate(cswSourceConfiguration);
    FilterType filterType = localCswFilterDelegate.during(propertyNameCreated, 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));
}
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) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 34 with CswSourceConfiguration

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

the class TestRegistryStore method setup.

@Before
public void setup() throws Exception {
    parser = new XmlParser();
    marshaller = new MetacardMarshaller(new XmlParser());
    context = mock(BundleContext.class);
    provider = mock(Converter.class);
    cswSourceConfiguration = new CswSourceConfiguration();
    factory = mock(SecureCxfClientFactory.class);
    transformer = mock(TransformerManager.class);
    encryptionService = mock(EncryptionService.class);
    configAdmin = mock(ConfigurationAdmin.class);
    configuration = mock(Configuration.class);
    subject = mock(Subject.class);
    queryResults = new ArrayList<>();
    registryStore = spy(new RegistryStoreImpl(context, cswSourceConfiguration, provider, factory, encryptionService) {

        @Override
        protected void validateOperation() {
        }

        @Override
        public boolean isAvailable() {
            return availability;
        }

        @Override
        protected SourceResponse query(QueryRequest queryRequest, ElementSetType elementSetName, List<QName> elementNames, Csw csw) throws UnsupportedQueryException {
            if (queryResults == null) {
                throw new UnsupportedQueryException("Test - Bad Query");
            }
            return new SourceResponseImpl(queryRequest, queryResults);
        }

        @Override
        protected CapabilitiesType getCapabilities() {
            return mock(CapabilitiesType.class);
        }

        @Override
        public void configureCswSource() {
        }

        ;

        @Override
        protected Subject getSystemSubject() {
            return subject;
        }

        @Override
        BundleContext getBundleContext() {
            return context;
        }
    });
    registryStore.setFilterBuilder(filterBuilder);
    registryStore.setFilterAdapter(filterAdapter);
    registryStore.setConfigAdmin(configAdmin);
    registryStore.setMetacardMarshaller(new MetacardMarshaller(parser));
    registryStore.setSchemaTransformerManager(transformer);
    registryStore.setAutoPush(true);
    registryStore.setRegistryUrl("http://test.url:0101/example");
    properties = new Hashtable<>();
    properties.put(RegistryStoreImpl.ID, "registryId");
    registryStore.setMetacardMarshaller(marshaller);
    when(configAdmin.getConfiguration(any())).thenReturn(configuration);
    when(configuration.getProperties()).thenReturn(properties);
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) XmlParser(org.codice.ddf.parser.xml.XmlParser) TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) Configuration(org.osgi.service.cm.Configuration) CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) QueryRequest(ddf.catalog.operation.QueryRequest) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) Subject(ddf.security.Subject) EncryptionService(ddf.security.encryption.EncryptionService) ElementSetType(net.opengis.cat.csw.v_2_0_2.ElementSetType) Converter(com.thoughtworks.xstream.converters.Converter) List(java.util.List) ArrayList(java.util.ArrayList) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

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