use of org.codice.ddf.spatial.ogc.csw.catalog.common.Csw in project ddf by codice.
the class TestRegistryStore method testCreateNoExistingMetacard.
@Test
public void testCreateNoExistingMetacard() throws Exception {
Metacard mcard = getDefaultMetacard();
Csw csw = mock(Csw.class);
TransactionResponseType responseType = mock(TransactionResponseType.class);
InsertResultType insertResultType = mock(InsertResultType.class);
BriefRecordType briefRecord = mock(BriefRecordType.class);
JAXBElement identifier = mock(JAXBElement.class);
SimpleLiteral literal = mock(SimpleLiteral.class);
when(literal.getContent()).thenReturn(Collections.singletonList(mcard.getId()));
when(identifier.getValue()).thenReturn(literal);
when(briefRecord.getIdentifier()).thenReturn(Collections.singletonList(identifier));
when(insertResultType.getBriefRecord()).thenReturn(Collections.singletonList(briefRecord));
when(responseType.getInsertResult()).thenReturn(Collections.singletonList(insertResultType));
when(factory.getClientForSubject(any())).thenReturn(csw);
when(csw.transaction(any())).thenReturn(responseType);
when(transformer.getTransformerIdForSchema(any())).thenReturn("myInsertType");
queryResults.add(new ResultImpl(mcard));
CreateRequest request = new CreateRequestImpl(mcard);
CreateResponse response = registryStore.create(request);
assertThat(response.getCreatedMetacards().get(0), is(mcard));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.Csw in project ddf by codice.
the class TestRegistryStore method testInit.
@Test
public void testInit() throws Exception {
RegistryStoreImpl 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
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
return new SourceResponseImpl(request, Collections.singletonList(new Result() {
@Override
public Metacard getMetacard() {
MetacardImpl metacard = new MetacardImpl();
metacard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "registryId");
metacard.setAttribute(Metacard.TITLE, "title");
return metacard;
}
@Override
public Double getRelevanceScore() {
return null;
}
@Override
public Double getDistanceInMeters() {
return null;
}
}));
}
@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);
Csw csw = mock(Csw.class);
when(factory.getClientForSubject(any())).thenReturn(csw);
cswSourceConfiguration.setCswUrl("https://localhost");
cswSourceConfiguration.setPollIntervalMinutes(1);
queryResults.add(new ResultImpl(getDefaultMetacard()));
registryStore.init();
assertThat(registryStore.getRegistryId(), is("registryId"));
}
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));
}
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));
}
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);
}
Aggregations