Search in sources :

Example 56 with UpdateRequestImpl

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());
}
Also used : Serializable(java.io.Serializable) QueryRequest(ddf.catalog.operation.QueryRequest) UpdateRequest(ddf.catalog.operation.UpdateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Example 57 with UpdateRequestImpl

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();
    }
}
Also used : ContentType(ddf.catalog.data.ContentType) UpdateRequest(ddf.catalog.operation.UpdateRequest) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) CatalogFramework(ddf.catalog.CatalogFramework) IngestException(ddf.catalog.source.IngestException) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Aggregations

UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)57 Metacard (ddf.catalog.data.Metacard)42 ArrayList (java.util.ArrayList)35 Test (org.junit.Test)34 UpdateRequest (ddf.catalog.operation.UpdateRequest)28 HashMap (java.util.HashMap)28 Serializable (java.io.Serializable)26 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)21 UpdateResponse (ddf.catalog.operation.UpdateResponse)19 IngestException (ddf.catalog.source.IngestException)13 AbstractMap (java.util.AbstractMap)13 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 CatalogFramework (ddf.catalog.CatalogFramework)11 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)10 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)10 List (java.util.List)10 Result (ddf.catalog.data.Result)9 URI (java.net.URI)9 Entry (java.util.Map.Entry)9