Search in sources :

Example 6 with Csw

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

the class TestCswSource method testAddingContentTypesOnQueries.

@Test
public void testAddingContentTypesOnQueries() throws CswException, UnsupportedQueryException, SecurityServiceException {
    Csw mockCsw = createMockCsw();
    List<String> expectedNames = new LinkedList<>(Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"));
    ServiceRegistration<?> mockRegisteredMetacardType = (ServiceRegistration<?>) mock(ServiceRegistration.class);
    LOGGER.info("mockRegisteredMetacardType: {}", mockRegisteredMetacardType);
    doReturn(mockRegisteredMetacardType).when(mockContext).registerService(eq(MetacardType.class.getName()), any(MetacardType.class), Matchers.any());
    ServiceReference<?> mockServiceReference = (ServiceReference<?>) mock(ServiceReference.class);
    doReturn(mockServiceReference).when(mockRegisteredMetacardType).getReference();
    when(mockServiceReference.getProperty(eq(Metacard.CONTENT_TYPE))).thenReturn(expectedNames);
    AbstractCswSource source = getCswSource(mockCsw, mockContext);
    assertThat(source.getContentTypes(), hasSize(10));
    Set<ContentType> expected = generateContentType(expectedNames);
    assertThat(source.getContentTypes(), is(expected));
    CswRecordCollection collection = generateCswCollection("/getRecordsResponse.xml");
    when(mockCsw.getRecords(any(GetRecordsType.class))).thenReturn(collection);
    QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text("*"));
    expectedNames.add("dataset");
    expectedNames.add("dataset 2");
    expectedNames.add("dataset 3");
    expected = generateContentType(expectedNames);
    source.query(new QueryRequestImpl(propertyIsLikeQuery));
    assertThat(source.getContentTypes(), hasSize(13));
    assertThat(source.getContentTypes(), is(expected));
}
Also used : ContentType(ddf.catalog.data.ContentType) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) LinkedList(java.util.LinkedList) MetacardType(ddf.catalog.data.MetacardType) ServiceReference(org.osgi.framework.ServiceReference) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Example 7 with Csw

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

the class TestCswSource method testRetrieveResourceUsingGetRecordById.

@Test
public void testRetrieveResourceUsingGetRecordById() throws CswException, ResourceNotFoundException, IOException, ResourceNotSupportedException, URISyntaxException {
    Csw csw = createMockCsw();
    CswRecordCollection collection = mock(CswRecordCollection.class);
    Resource resource = mock(Resource.class);
    when(collection.getResource()).thenReturn(resource);
    when(csw.getRecordById(any(GetRecordByIdRequest.class), anyString())).thenReturn(collection);
    AbstractCswSource cswSource = getCswSource(csw, mockContext, null, null, null, null);
    ResourceReader reader = mock(ResourceReader.class);
    when(reader.retrieveResource(any(URI.class), any(Map.class))).thenReturn(mock(ResourceResponse.class));
    cswSource.setResourceReader(reader);
    Map<String, Serializable> props = new HashMap<>();
    props.put(Core.ID, "ID");
    cswSource.retrieveResource(new URI("http://example.com/resource"), props);
    // Verify
    verify(csw, times(1)).getRecordById(any(GetRecordByIdRequest.class), any(String.class));
}
Also used : ResourceReader(ddf.catalog.resource.ResourceReader) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) Resource(ddf.catalog.resource.Resource) Matchers.anyString(org.mockito.Matchers.anyString) GetRecordByIdRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest) URI(java.net.URI) ResourceResponse(ddf.catalog.operation.ResourceResponse) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with Csw

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

the class TestCswSource method testRetrieveResourceUsingGetRecordByIdWithNoId.

@Test(expected = ResourceNotFoundException.class)
public void testRetrieveResourceUsingGetRecordByIdWithNoId() throws CswException, ResourceNotFoundException, IOException, ResourceNotSupportedException, URISyntaxException {
    Csw csw = createMockCsw();
    CswRecordCollection collection = mock(CswRecordCollection.class);
    Resource resource = mock(Resource.class);
    when(collection.getResource()).thenReturn(resource);
    when(csw.getRecordById(any(GetRecordByIdRequest.class), anyString())).thenReturn(collection);
    AbstractCswSource cswSource = getCswSource(csw, mockContext, null, null, null, null);
    ResourceReader reader = mock(ResourceReader.class);
    when(reader.retrieveResource(any(URI.class), any(Map.class))).thenReturn(mock(ResourceResponse.class));
    cswSource.setResourceReader(reader);
    Map<String, Serializable> props = new HashMap<>();
    cswSource.retrieveResource(new URI("http://example.com/resource"), props);
}
Also used : ResourceReader(ddf.catalog.resource.ResourceReader) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) Resource(ddf.catalog.resource.Resource) Matchers.anyString(org.mockito.Matchers.anyString) GetRecordByIdRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest) URI(java.net.URI) ResourceResponse(ddf.catalog.operation.ResourceResponse) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 9 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 10 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)

Aggregations

Csw (org.codice.ddf.spatial.ogc.csw.catalog.common.Csw)15 Subject (ddf.security.Subject)7 Test (org.junit.Test)7 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)6 Serializable (java.io.Serializable)6 TransactionResponseType (net.opengis.cat.csw.v_2_0_2.TransactionResponseType)6 HashMap (java.util.HashMap)5 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)5 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)5 Metacard (ddf.catalog.data.Metacard)4 ResultImpl (ddf.catalog.data.impl.ResultImpl)3 Resource (ddf.catalog.resource.Resource)3 IngestException (ddf.catalog.source.IngestException)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 Filter (org.opengis.filter.Filter)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 OperationTransaction (ddf.catalog.operation.OperationTransaction)2 ProcessingDetails (ddf.catalog.operation.ProcessingDetails)2