Search in sources :

Example 16 with Csw

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

the class TestCswSourceBase method createMockCsw.

protected Csw createMockCsw() throws CswException {
    Csw mockCsw = mock(Csw.class);
    InputStream stream = getClass().getResourceAsStream("/getCapabilities.xml");
    CapabilitiesType capabilities = parseXml(stream);
    when(mockCsw.getCapabilities(any(GetCapabilitiesRequest.class))).thenReturn(capabilities);
    CswRecordCollection collection = generateCswCollection("/getBriefRecordsResponse.xml");
    when(mockCsw.getRecords(any(GetRecordsType.class))).thenReturn(collection);
    return mockCsw;
}
Also used : GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetCapabilitiesRequest) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) InputStream(java.io.InputStream) ScalarCapabilitiesType(net.opengis.filter.v_1_1_0.ScalarCapabilitiesType) CapabilitiesType(net.opengis.cat.csw.v_2_0_2.CapabilitiesType) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType)

Example 17 with Csw

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

the class TestRegistryStore method testDelete.

@Test
public void testDelete() throws Exception {
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    Csw csw = mock(Csw.class);
    TransactionResponseType transResponse = mock(TransactionResponseType.class);
    TransactionSummaryType transSummary = mock(TransactionSummaryType.class);
    when(transResponse.getTransactionSummary()).thenReturn(transSummary);
    when(transSummary.getTotalDeleted()).thenReturn(new BigInteger("1"));
    when(csw.transaction(any(CswTransactionRequest.class))).thenReturn(transResponse);
    when(factory.getClientForSubject(any())).thenReturn(csw);
    when(transformer.getTransformerIdForSchema(any())).thenReturn(null);
    FilterAdapter mockAdaptor = mock(FilterAdapter.class);
    CswFilterFactory filterFactory = new CswFilterFactory(CswAxisOrder.LAT_LON, false);
    FilterType filterType = filterFactory.buildPropertyIsLikeFilter(Metacard.ID, "testId", false);
    when(mockAdaptor.adapt(any(Filter.class), any(FilterDelegate.class))).thenReturn(filterType);
    registryStore.setFilterAdapter(mockAdaptor);
    DeleteRequestImpl request = new DeleteRequestImpl(Collections.singletonList(RegistryObjectMetacardType.REGISTRY_ID), "registryId", new HashMap<>());
    OperationTransactionImpl opTrans = new OperationTransactionImpl(OperationTransaction.OperationType.DELETE, Collections.singletonList(getDefaultMetacard()));
    request.getProperties().put(Constants.OPERATION_TRANSACTION_KEY, opTrans);
    registryStore.delete(request);
    verify(filterBuilder).attribute(captor.capture());
    assertThat(captor.getValue(), is("id"));
}
Also used : OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) FilterDelegate(ddf.catalog.filter.FilterDelegate) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) FilterAdapter(ddf.catalog.filter.FilterAdapter) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) FilterType(net.opengis.filter.v_1_1_0.FilterType) Filter(org.opengis.filter.Filter) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) CswFilterFactory(org.codice.ddf.spatial.ogc.csw.catalog.common.source.CswFilterFactory) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 18 with Csw

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

the class TestRegistryStore method testUpdate.

@Test
public void testUpdate() throws Exception {
    Csw csw = mock(Csw.class);
    TransactionResponseType responseType = mock(TransactionResponseType.class);
    TransactionSummaryType tst = new TransactionSummaryType();
    tst.setTotalUpdated(new BigInteger("1"));
    when(responseType.getTransactionSummary()).thenReturn(tst);
    when(factory.getClientForSubject(any())).thenReturn(csw);
    when(csw.transaction(any())).thenReturn(responseType);
    when(transformer.getTransformerIdForSchema(any())).thenReturn(null);
    UpdateRequestImpl request = new UpdateRequestImpl("testId", getDefaultMetacard());
    MetacardImpl updatedMcard = getDefaultMetacard();
    updatedMcard.setId("newTestId");
    OperationTransactionImpl opTrans = new OperationTransactionImpl(OperationTransaction.OperationType.UPDATE, Collections.singletonList(updatedMcard));
    request.getProperties().put(Constants.OPERATION_TRANSACTION_KEY, opTrans);
    queryResults.add(new ResultImpl(getDefaultMetacard()));
    registryStore.update(request);
    assertThat(request.getUpdates().get(0).getValue().getMetadata().contains("value=\"newTestId\""), is(true));
}
Also used : OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) BigInteger(java.math.BigInteger) ResultImpl(ddf.catalog.data.impl.ResultImpl) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) Test(org.junit.Test)

Example 19 with Csw

use of org.codice.ddf.spatial.ogc.csw.catalog.common.Csw 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

Csw (org.codice.ddf.spatial.ogc.csw.catalog.common.Csw)19 Test (org.junit.Test)10 Subject (ddf.security.Subject)8 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)8 Serializable (java.io.Serializable)7 HashMap (java.util.HashMap)7 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)6 TransactionResponseType (net.opengis.cat.csw.v_2_0_2.TransactionResponseType)6 Map (java.util.Map)5 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)5 Metacard (ddf.catalog.data.Metacard)4 ResourceResponse (ddf.catalog.operation.ResourceResponse)4 Resource (ddf.catalog.resource.Resource)4 GetRecordByIdRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest)4 ResultImpl (ddf.catalog.data.impl.ResultImpl)3 ResourceReader (ddf.catalog.resource.ResourceReader)3 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 CswTransactionRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest)3 Matchers.anyString (org.mockito.Matchers.anyString)3