use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class CatalogBackupPluginTest method testUpdatingAllMissingMetacards.
@Test
public void testUpdatingAllMissingMetacards() {
// Setup
UpdateResponse mockUpdateResponse = getUpdateResponse(Arrays.asList(METACARD_IDS));
// Perform Test
getPlugin().process(mockUpdateResponse);
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class CatalogBackupPluginTest method testUpdateResponseUpdateSuccessful.
@Test
public void testUpdateResponseUpdateSuccessful() throws Exception {
// Setup
int subDirLevels = 3;
CatalogBackupPlugin plugin = getPlugin(3);
plugin.process(getCreateResponse(METACARD_IDS));
UpdateResponse mockUpdateResponse = getUpdateResponse(Arrays.asList(METACARD_IDS));
// Perform Test
UpdateResponse postPluginUpdateResponse = plugin.process(mockUpdateResponse);
// Verify
assertThat(postPluginUpdateResponse, is(notNullValue()));
IntStream.range(0, METACARD_IDS.length).forEach(index -> {
String oldId = METACARD_IDS[index];
File updatedFile = getFileFor(oldId, subDirLevels);
Metacard updatedCard = readMetacard(updatedFile);
assertThat(updatedFile.exists(), is(Boolean.TRUE));
assertThat(updatedCard.getId(), is(oldId));
assertThat(updatedCard.getAttribute(Metacard.TITLE).getValue(), is(BASE_NEW_TITLE + index));
});
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class ContentProducerDataAccessObjectTest method testCreateContentItem.
@Test
public void testCreateContentItem() throws Exception {
File testFile = temporaryFolder.newFile("testCreateContentItem.txt");
//make sample list of metacard and set of keys
List<MetacardImpl> metacardList = ImmutableList.of(new MetacardImpl());
Set<String> keys = ImmutableSet.of(String.valueOf(testFile.getAbsolutePath().hashCode()));
//mock out responses for create, delete, update
CreateResponse mockCreateResponse = mock(CreateResponse.class);
doReturn(metacardList).when(mockCreateResponse).getCreatedMetacards();
DeleteResponse mockDeleteResponse = mock(DeleteResponse.class);
doReturn(metacardList).when(mockDeleteResponse).getDeletedMetacards();
UpdateResponse mockUpdateResponse = mock(UpdateResponse.class);
doReturn(metacardList).when(mockUpdateResponse).getUpdatedMetacards();
//setup mockFileSystemPersistenceProvider
FileSystemPersistenceProvider mockFileSystemPersistenceProvider = mock(FileSystemPersistenceProvider.class);
doReturn(keys).when(mockFileSystemPersistenceProvider).loadAllKeys();
doReturn("sample").when(mockFileSystemPersistenceProvider).loadFromPersistence(any(String.class));
//setup mockCatalogFramework
CatalogFramework mockCatalogFramework = mock(CatalogFramework.class);
doReturn(mockCreateResponse).when(mockCatalogFramework).create(any(CreateStorageRequest.class));
doReturn(mockDeleteResponse).when(mockCatalogFramework).delete(any(DeleteRequest.class));
//setup mockComponent
ContentComponent mockComponent = mock(ContentComponent.class);
doReturn(mockCatalogFramework).when(mockComponent).getCatalogFramework();
//setup mockEndpoint
ContentEndpoint mockEndpoint = mock(ContentEndpoint.class);
doReturn(mockComponent).when(mockEndpoint).getComponent();
WatchEvent.Kind<Path> kind;
String mimeType = "txt";
Map<String, Object> headers = new HashedMap();
Map<String, Serializable> attributeOverrides = new HashMap<>();
attributeOverrides.put("example", ImmutableList.of("something", "something1"));
attributeOverrides.put("example2", ImmutableList.of("something2"));
headers.put(Constants.ATTRIBUTE_OVERRIDES_KEY, attributeOverrides);
kind = StandardWatchEventKinds.ENTRY_CREATE;
contentProducerDataAccessObject.createContentItem(mockFileSystemPersistenceProvider, mockEndpoint, testFile, kind, mimeType, headers);
kind = StandardWatchEventKinds.ENTRY_DELETE;
contentProducerDataAccessObject.createContentItem(mockFileSystemPersistenceProvider, mockEndpoint, testFile, kind, mimeType, headers);
kind = StandardWatchEventKinds.ENTRY_MODIFY;
contentProducerDataAccessObject.createContentItem(mockFileSystemPersistenceProvider, mockEndpoint, testFile, kind, mimeType, headers);
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class ContentProducerDataAccessObject method createContentItem.
public void createContentItem(FileSystemPersistenceProvider fileIdMap, ContentEndpoint endpoint, File ingestedFile, WatchEvent.Kind<Path> eventType, String mimeType, Map<String, Object> headers) throws SourceUnavailableException, IngestException {
LOGGER.debug("Creating content item.");
String key = String.valueOf(ingestedFile.getAbsolutePath().hashCode());
String id = fileIdMap.loadAllKeys().contains(key) ? String.valueOf(fileIdMap.loadFromPersistence(key)) : null;
if (StandardWatchEventKinds.ENTRY_CREATE.equals(eventType)) {
CreateStorageRequest createRequest = new CreateStorageRequestImpl(Collections.singletonList(new ContentItemImpl(uuidGenerator.generateUuid(), Files.asByteSource(ingestedFile), mimeType, ingestedFile.getName(), 0L, null)), null);
processHeaders(headers, createRequest, ingestedFile);
CreateResponse createResponse = endpoint.getComponent().getCatalogFramework().create(createRequest);
if (createResponse != null) {
List<Metacard> createdMetacards = createResponse.getCreatedMetacards();
for (Metacard metacard : createdMetacards) {
fileIdMap.store(key, metacard.getId());
LOGGER.debug("content item created with id = {}", metacard.getId());
}
}
} else if (StandardWatchEventKinds.ENTRY_MODIFY.equals(eventType)) {
UpdateStorageRequest updateRequest = new UpdateStorageRequestImpl(Collections.singletonList(new ContentItemImpl(id, Files.asByteSource(ingestedFile), mimeType, ingestedFile.getName(), 0, null)), null);
processHeaders(headers, updateRequest, ingestedFile);
UpdateResponse updateResponse = endpoint.getComponent().getCatalogFramework().update(updateRequest);
if (updateResponse != null) {
List<Update> updatedMetacards = updateResponse.getUpdatedMetacards();
for (Update update : updatedMetacards) {
LOGGER.debug("content item updated with id = {}", update.getNewMetacard().getId());
}
}
} else if (StandardWatchEventKinds.ENTRY_DELETE.equals(eventType)) {
DeleteRequest deleteRequest = new DeleteRequestImpl(id);
DeleteResponse deleteResponse = endpoint.getComponent().getCatalogFramework().delete(deleteRequest);
if (deleteResponse != null) {
List<Metacard> deletedMetacards = deleteResponse.getDeletedMetacards();
for (Metacard delete : deletedMetacards) {
fileIdMap.delete(ingestedFile.getAbsolutePath());
LOGGER.debug("content item deleted with id = {}", delete.getId());
}
}
}
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class CatalogComponentFrameworkTest method testUpdateWithIngestException.
@Test
public /**
* Operation: UPDATE
* Body contains: Metacard
*/
void testUpdateWithIngestException() throws Exception {
resetMocks();
// Setup expectations to verify
final MockEndpoint mockVerifierEndpoint = getMockEndpoint("mock:result");
mockVerifierEndpoint.expectedMessageCount(1);
final List<Metacard> metacards = new ArrayList<Metacard>();
metacards.add(metacard1);
// setup mock catalog framework
final Update update = new UpdateImpl(metacard1, metacard2);
List<Update> updates = new ArrayList<Update>();
updates.add(update);
final String[] metacardIds = new String[metacards.size()];
for (int i = 0; i < metacards.size(); i++) {
metacardIds[i] = metacards.get(i).getId();
}
UpdateRequest updateRequest = new UpdateRequestImpl(metacardIds, metacards);
UpdateResponse updateResponse = new UpdateResponseImpl(updateRequest, new HashMap(), updates);
when(catalogFramework.update(any(UpdateRequest.class))).thenThrow(new IngestException());
// Exercise the route with a UPDATE operation
template.sendBodyAndHeader("direct:sampleInput", metacards, "Operation", "UPDATE");
// Verify that the number of metacards in the exchange after the records
// is identical to the input
assertListSize(mockVerifierEndpoint.getExchanges(), 1);
final Exchange exchange = mockVerifierEndpoint.getExchanges().get(0);
final List<Update> cardsUpdated = (List<Update>) exchange.getIn().getBody();
assertListSize(cardsUpdated, 0);
mockVerifierEndpoint.assertIsSatisfied();
}
Aggregations