use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdate.
/**
* Tests that the framework properly passes an update request to the local provider.
*/
@Test
public void testUpdate() throws Exception {
List<Metacard> metacards = new ArrayList<Metacard>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
metacards.add(newCard);
// create the entry manually in the provider
CreateResponse response = provider.create(new CreateRequestImpl(metacards, null));
Metacard insertedCard = response.getCreatedMetacards().get(0);
Result mockFederationResult = mock(Result.class);
MetacardImpl metacard = new MetacardImpl();
metacard.setId(insertedCard.getId());
when(mockFederationResult.getMetacard()).thenReturn(metacard);
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), Collections.singletonList(mockFederationResult), 1);
when(mockFederationStrategy.federate(anyList(), any())).thenReturn(queryResponse);
List<Entry<Serializable, Metacard>> updatedEntries = new ArrayList<Entry<Serializable, Metacard>>();
updatedEntries.add(new SimpleEntry<Serializable, Metacard>(insertedCard.getId(), insertedCard));
UpdateRequest request = new UpdateRequestImpl(updatedEntries, Metacard.ID, null);
// send update to framework
List<Update> returnedCards = framework.update(request).getUpdatedMetacards();
for (Update curCard : returnedCards) {
assertNotNull(curCard.getNewMetacard().getId());
}
// make sure that the event was posted correctly
assertTrue(eventAdmin.wasEventPosted());
assertEquals(eventAdmin.getLastEvent().getId(), returnedCards.get(returnedCards.size() - 1).getOldMetacard().getId());
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testProviderUnavailableUpdateByIdentifier.
/**
* Tests that the framework properly throws a catalog exception when the local provider is not
* available for update by identifier.
*
* @throws IngestException
* @throws SourceUnavailableException
*/
@Test(expected = SourceUnavailableException.class)
public void testProviderUnavailableUpdateByIdentifier() throws SourceUnavailableException {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), false, null);
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, false);
List<Metacard> metacards = new ArrayList<Metacard>();
List<URI> uris = new ArrayList<URI>();
// expected to throw exception due to catalog provider being unavailable
try {
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
newCard.setResourceURI(new URI("uri:///1234"));
metacards.add(newCard);
uris.add(new URI("uri:////1234"));
UpdateRequest update = new UpdateRequestImpl((URI[]) uris.toArray(new URI[uris.size()]), metacards);
framework.update(update);
} catch (URISyntaxException e) {
fail();
} catch (IngestException e) {
fail();
}
}
Aggregations