use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class CatalogMetricsTest method catalogUpdateMetric.
@Test
public void catalogUpdateMetric() throws Exception {
UpdateRequest request = mock(UpdateRequest.class);
UpdateResponse response = mock(UpdateResponse.class);
List<Update> updatedList = mock(List.class);
when(updatedList.size()).thenReturn(100);
when(response.getRequest()).thenReturn(request);
when(response.getUpdatedMetacards()).thenReturn(updatedList);
catalogMetrics.process(response);
assertThat(meterRegistry.counter("ddf.catalog.update").count(), is(100.0));
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class ResponseMetacardActionSplitter method split.
public List<Metacard> split(Response response) {
List<Metacard> metacards = new ArrayList<>();
if (response instanceof CreateResponse) {
CreateResponse createResponse = (CreateResponse) response;
metacards.addAll(createResponse.getCreatedMetacards());
} else if (response instanceof UpdateResponse) {
UpdateResponse updateResponse = (UpdateResponse) response;
List<Update> updates = updateResponse.getUpdatedMetacards();
for (Update update : updates) {
metacards.add(update.getNewMetacard());
}
} else if (response instanceof DeleteResponse) {
DeleteResponse deleteResponse = (DeleteResponse) response;
metacards.addAll(deleteResponse.getDeletedMetacards());
}
return metacards;
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class ResponseSplitterTest method testSplitUpdate.
@Test
public void testSplitUpdate() {
MetacardImpl metacard = new MetacardImpl();
metacard.setId("test");
UpdateResponse mockResponse = mock(UpdateResponse.class);
List<Update> updates = new ArrayList<>();
Update update = new UpdateImpl(null, metacard);
updates.add(update);
when(mockResponse.getUpdatedMetacards()).thenReturn(updates);
ResponseMetacardActionSplitter splitter = new ResponseMetacardActionSplitter();
List<Metacard> splitCards = splitter.split(mockResponse);
assertThat(splitCards, hasSize(1));
}
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(), any())).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 testRollbackFailed.
@Test(expected = IngestException.class)
public void testRollbackFailed() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException {
List<Metacard> metacards = getMetacardUpdatePair();
// Mock out a bad storage provider
StorageProvider exceptionStorageProvider = mock(StorageProvider.class);
doThrow(StorageException.class).when(exceptionStorageProvider).commit(any());
doThrow(StorageException.class).when(exceptionStorageProvider).rollback(any());
ContentItem item = mock(ContentItem.class);
when(item.getId()).thenReturn(METACARD_ID);
when(item.getUri()).thenReturn(RESOURCE_URI);
when(item.getMetacard()).thenReturn(metacards.get(0));
ReadStorageResponse readStorageResponse = mock(ReadStorageResponse.class);
when(readStorageResponse.getContentItem()).thenReturn(item);
when(exceptionStorageProvider.read(any())).thenReturn(readStorageResponse);
when(exceptionStorageProvider.create(any())).thenReturn(mock(CreateStorageResponse.class));
historian.setStorageProviders(Collections.singletonList(exceptionStorageProvider));
// Parameters for historian
UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
UpdateResponse updateResponse = mock(UpdateResponse.class);
Update update1 = mock(Update.class);
when(update1.getOldMetacard()).thenReturn(metacards.get(0));
when(updateResponse.getUpdatedMetacards()).thenReturn(ImmutableList.of(update1));
// send a request to update the metacard
updateMetacard(storageRequest, storageResponse, metacards.get(1));
mockQuery(metacards.get(1));
historian.version(storageRequest, storageResponse, updateResponse);
verify(exceptionStorageProvider).rollback(any(StorageRequest.class));
}
Aggregations