use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdateStorage.
/**
* Tests that the framework properly passes an update request to the local provider.
*/
@Test
public void testUpdateStorage() throws Exception {
List<ContentItem> contentItems = new ArrayList<>();
MetacardImpl metacard = new MetacardImpl();
metacard.setId(null);
ByteSource byteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return new ByteArrayInputStream("blah".getBytes());
}
};
ContentItemImpl contentItem = new ContentItemImpl(uuidGenerator.generateUuid(), byteSource, "application/octet-stream", "blah", 0L, metacard);
contentItems.add(contentItem);
CreateResponse response = framework.create(new CreateStorageRequestImpl(contentItems, null));
Metacard insertedCard = response.getCreatedMetacards().get(0);
List<ContentItem> updatedContentItems = new ArrayList<>();
updatedContentItems.add(new ContentItemImpl(insertedCard.getId(), byteSource, "application/octet-stream", insertedCard));
UpdateStorageRequest request = new UpdateStorageRequestImpl(updatedContentItems, null);
List<Result> mockFederationResults = Stream.of(insertedCard).map(m -> {
Result mockResult = mock(Result.class);
when(mockResult.getMetacard()).thenReturn(m);
return mockResult;
}).collect(Collectors.toList());
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), mockFederationResults, 1);
when(mockFederationStrategy.federate(anyList(), anyObject())).thenReturn(queryResponse);
// send update to framework
List<Update> returnedCards = framework.update(request).getUpdatedMetacards();
assertThat(returnedCards, hasSize(1));
final Metacard newMetacard = returnedCards.get(0).getNewMetacard();
assertThat(newMetacard.getId(), notNullValue());
assertThat(newMetacard.getResourceURI().toString(), is(contentItem.getUri()));
assertThat(newMetacard.getResourceSize(), is(Long.toString(byteSource.size())));
assertThat(response.getCreatedMetacards(), hasSize(storageProvider.size()));
// make sure that the event was posted correctly
assertThat(eventAdmin.wasEventPosted(), is(true));
}
use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testInjectsAttributesOnDelete.
@Test
public void testInjectsAttributesOnDelete() throws Exception {
final String title = "Delete this";
final String injectAttributeName = "new attribute";
final double injectAttributeValue = 11.1;
final MetacardImpl metacard = new MetacardImpl();
metacard.setTitle(title);
metacard.setAttribute(injectAttributeName, injectAttributeValue);
final String id = framework.create(new CreateRequestImpl(Collections.singletonList(metacard), null)).getCreatedMetacards().get(0).getId();
final DeleteRequest request = new DeleteRequestImpl(id);
final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl(injectAttributeName, true, true, false, false, BasicTypes.DOUBLE_TYPE);
stubMetacardInjection(injectAttribute);
List<Result> mockFederationResults = Stream.of(metacard).map(m -> {
Result mockResult = mock(Result.class);
when(mockResult.getMetacard()).thenReturn(m);
return mockResult;
}).collect(Collectors.toList());
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), mockFederationResults, 1);
when(mockFederationStrategy.federate(anyList(), anyObject())).thenReturn(queryResponse);
when(mockRemoteDeleteOperations.performRemoteDelete(any(), any())).then(returnsSecondArg());
deleteOperations.setRemoteDeleteOperations(mockRemoteDeleteOperations);
final DeleteResponse response = framework.delete(request);
final Metacard deletedMetacard = response.getDeletedMetacards().get(0);
final MetacardType originalMetacardType = metacard.getMetacardType();
final MetacardType deletedMetacardType = deletedMetacard.getMetacardType();
assertThat(deletedMetacardType.getName(), is(originalMetacardType.getName()));
final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
expectedAttributeDescriptors.add(injectAttribute);
assertThat(deletedMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
assertThat(deletedMetacard.getTitle(), is(title));
assertThat(deletedMetacard.getAttribute(injectAttributeName).getValue(), is(injectAttributeValue));
}
use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.
the class Jpeg2000ThumbnailConverterTest method testEmptyThumbnail.
@Test
public void testEmptyThumbnail() throws Exception {
Metacard metacard = new MetacardImpl();
metacard.setAttribute(new AttributeImpl(Metacard.THUMBNAIL, new byte[0]));
List<Result> resultList = new ArrayList<>();
resultList.add(new ResultImpl(metacard));
QueryResponseImpl queryResponse = new QueryResponseImpl(null, resultList, 1);
jpeg2000ThumbnailConverter.process(queryResponse);
}
use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.
the class TestCswEndpoint method getQueryResponse.
private QueryResponse getQueryResponse() {
List<Result> results = new LinkedList<>();
for (int i = 0; i < RESULT_COUNT; i++) {
Result result = new ResultImpl();
results.add(result);
}
return new QueryResponseImpl(null, results, TOTAL_COUNT);
}
use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.
the class SearchControllerTest method createFramework.
private CatalogFramework createFramework() {
final long COUNT = 2;
CatalogFramework framework = mock(CatalogFramework.class);
List<Result> results = new ArrayList<Result>();
for (int i = 0; i < COUNT; i++) {
Result result = mock(Result.class);
MetacardImpl metacard = new MetacardImpl();
metacard.setId("Metacard_" + i);
metacard.setTitle("Metacard " + i);
metacard.setLocation("POINT(" + i + " " + i + ")");
metacard.setType(BasicTypes.BASIC_METACARD);
metacard.setCreatedDate(TIMESTAMP);
metacard.setEffectiveDate(TIMESTAMP);
metacard.setExpirationDate(TIMESTAMP);
metacard.setModifiedDate(TIMESTAMP);
metacard.setContentTypeName("TEST");
metacard.setContentTypeVersion("1.0");
metacard.setTargetNamespace(URI.create(getClass().getPackage().getName()));
when(result.getDistanceInMeters()).thenReturn(100.0 * i);
when(result.getRelevanceScore()).thenReturn(100.0 * (COUNT - i) / COUNT);
when(result.getMetacard()).thenReturn(metacard);
results.add(result);
}
QueryResponse response = new QueryResponseImpl(mock(QueryRequest.class), new ArrayList<Result>(), COUNT);
response.getResults().addAll(results);
try {
when(framework.query(any(QueryRequest.class))).thenReturn(response);
} catch (UnsupportedQueryException e) {
LOGGER.debug("Error querying framework", e);
} catch (SourceUnavailableException e) {
LOGGER.debug("Error querying framework", e);
} catch (FederationException e) {
LOGGER.debug("Error querying framework", e);
}
return framework;
}
Aggregations