use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class CatalogFrameworkImplTest method testInjectsAttributesOnUpdate.
@Test
public void testInjectsAttributesOnUpdate() throws Exception {
final String injectAttributeName = "new attribute";
final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl(injectAttributeName, true, true, false, false, BasicTypes.DOUBLE_TYPE);
stubMetacardInjection(injectAttribute);
final String id = framework.create(new CreateRequestImpl(Collections.singletonList(new MetacardImpl()), null)).getCreatedMetacards().get(0).getId();
final String title = "Update";
final double injectAttributeValue = -1;
final MetacardImpl metacard = new MetacardImpl();
metacard.setId(id);
metacard.setTitle(title);
metacard.setAttribute(injectAttributeName, injectAttributeValue);
final UpdateRequest request = new UpdateRequestImpl(id, metacard);
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);
final UpdateResponse response = framework.update(request);
final Metacard updatedMetacard = response.getUpdatedMetacards().get(0).getNewMetacard();
final MetacardType originalMetacardType = metacard.getMetacardType();
final MetacardType updatedMetacardType = updatedMetacard.getMetacardType();
assertThat(updatedMetacardType.getName(), is(originalMetacardType.getName()));
final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
expectedAttributeDescriptors.add(injectAttribute);
assertThat(updatedMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
assertThat(updatedMetacard.getTitle(), is(title));
assertThat(updatedMetacard.getAttribute(injectAttributeName).getValue(), is(injectAttributeValue));
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class HistorianTest method testNullContentItemStorageReadRequest.
@Test
public void testNullContentItemStorageReadRequest() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException, URISyntaxException {
List<Metacard> metacards = getMetacardUpdatePair();
// Parameters for historian
UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
UpdateResponse updateResponse = mock(UpdateResponse.class);
// Make content item null
storageProvider.storageMap.put(METACARD_ID, null);
mockQuery(metacards.get(1));
historian.version(storageRequest, storageResponse, updateResponse);
// Verify that the content item DIDN't updated
ReadStorageRequest request = mock(ReadStorageRequest.class);
when(request.getResourceUri()).thenReturn(new URI(RESOURCE_URI));
ContentItem item = storageProvider.read(request).getContentItem();
assertThat(item, nullValue());
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class HistorianTest method testBadContentItemSize.
@Test
public void testBadContentItemSize() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException, URISyntaxException, IOException {
// The metacard and updated metacard
List<Metacard> metacards = getMetacardUpdatePair();
// Parameters for historian
UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
UpdateResponse updateResponse = mock(UpdateResponse.class);
storeMetacard(metacards.get(0));
// send a request to update the metacard
updateMetacard(storageRequest, storageResponse, metacards.get(1));
storageProvider.update(storageRequest);
when(storageProvider.storageMap.get(RESOURCE_URI).getSize()).thenThrow(IOException.class);
mockQuery(metacards.get(1));
historian.version(storageRequest, storageResponse, updateResponse);
// Verify that the metacard updated
Metacard update = readMetacard();
assertThat(update, equalTo(metacards.get(1)));
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class CatalogBackupPluginTest method testUpdatingOneMissingMetacard.
@Test
public void testUpdatingOneMissingMetacard() throws PluginExecutionException {
assertThat("The list of metacard IDs has changed sized", METACARD_IDS, arrayWithSize(2));
// Setup
CatalogBackupPlugin plugin = getPlugin();
plugin.process(getCreateResponse(new String[] { METACARD_IDS[0] }));
UpdateResponse mockUpdateResponse = getUpdateResponse(Arrays.asList(METACARD_IDS));
// Perform Test
plugin.process(mockUpdateResponse);
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class HistorianTest method testUpdateResponse.
@Test
public void testUpdateResponse() throws Exception {
UpdateResponse updateResponse = createUpdateResponse(null);
List<Update> updateList = createUpdatedMetacardList();
when(updateResponse.getUpdatedMetacards()).thenReturn(updateList);
historian.version(updateResponse);
ArgumentCaptor<CreateRequest> createRequest = ArgumentCaptor.forClass(CreateRequest.class);
verify(catalogProvider).create(createRequest.capture());
Metacard versionedMetacard = createRequest.getValue().getMetacards().get(0);
assertThat(versionedMetacard.getAttribute(MetacardVersion.VERSION_OF_ID).getValue(), equalTo(METACARD_ID));
}
Aggregations