Search in sources :

Example 31 with CreateResponseImpl

use of ddf.catalog.operation.impl.CreateResponseImpl in project ddf by codice.

the class CatalogComponentFrameworkTest method testCreateWithSingleMetacard.

@Test
public /**
 * Operation: CREATE Body contains: Metacard
 */
void testCreateWithSingleMetacard() 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);
    // Mock catalog framework
    final CreateRequest createRequest = new CreateRequestImpl(metacards);
    final CreateResponse createResponse = new CreateResponseImpl(createRequest, new HashMap(), metacards);
    when(catalogFramework.create(any(CreateRequest.class))).thenReturn(createResponse);
    // Exercise the route with a CREATE operation
    template.sendBodyAndHeader("direct:sampleInput", metacard1, "Operation", "CREATE");
    // 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<Metacard> cardsCreated = (List<Metacard>) exchange.getIn().getBody();
    assertListSize(cardsCreated, 1);
    mockVerifierEndpoint.assertIsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Metacard(ddf.catalog.data.Metacard) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) ArrayList(java.util.ArrayList) List(java.util.List) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Test(org.junit.Test)

Example 32 with CreateResponseImpl

use of ddf.catalog.operation.impl.CreateResponseImpl in project ddf by codice.

the class RESTEndpointTest method givenCatalogFramework.

private CatalogFramework givenCatalogFramework() throws IngestException, SourceUnavailableException {
    CatalogFramework framework = mock(CatalogFramework.class);
    Metacard returnMetacard = mock(Metacard.class);
    when(returnMetacard.getId()).thenReturn(RESTEndpointTest.SAMPLE_ID);
    when(framework.create(isA(CreateRequest.class))).thenReturn(new CreateResponseImpl(null, null, Collections.singletonList(returnMetacard)));
    when(framework.create(isA(CreateStorageRequest.class))).thenReturn(new CreateResponseImpl(null, null, Collections.singletonList(returnMetacard)));
    return framework;
}
Also used : Metacard(ddf.catalog.data.Metacard) CreateRequest(ddf.catalog.operation.CreateRequest) CatalogFramework(ddf.catalog.CatalogFramework) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest)

Example 33 with CreateResponseImpl

use of ddf.catalog.operation.impl.CreateResponseImpl in project ddf by codice.

the class PluginTest method testCreateBadTransform.

@Test(expected = PluginExecutionException.class)
public void testCreateBadTransform() throws PluginExecutionException, CatalogTransformerException, IOException, IngestException, SourceUnavailableException {
    // given
    when(transformer.transform(isA(Metacard.class), isA(Map.class))).thenThrow(CatalogTransformerException.class);
    CreateResponse createResponse = new CreateResponseImpl(new CreateRequestImpl(metacard), null, Arrays.asList(metacard));
    // when
    plugin.process(createResponse);
}
Also used : Metacard(ddf.catalog.data.Metacard) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) Map(java.util.Map) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Test(org.junit.Test)

Example 34 with CreateResponseImpl

use of ddf.catalog.operation.impl.CreateResponseImpl in project ddf by codice.

the class PluginTest method testCreate.

@Test
@Ignore
public void testCreate() throws PluginExecutionException, CatalogTransformerException, IOException, IngestException, SourceUnavailableException {
    // given
    CreateResponse createResponse = new CreateResponseImpl(new CreateRequestImpl(metacard), null, Arrays.asList(metacard));
    // when
    CreateResponse response = plugin.process(createResponse);
    // then
    verify(endpoint).addDocument(isA(HttpHeaders.class), isA(UriInfo.class), isA(InputStream.class));
    assertThat(response, sameInstance(createResponse));
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) CreateResponse(ddf.catalog.operation.CreateResponse) InputStream(java.io.InputStream) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) UriInfo(javax.ws.rs.core.UriInfo) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 35 with CreateResponseImpl

use of ddf.catalog.operation.impl.CreateResponseImpl in project ddf by codice.

the class PluginTest method testCreateNullParent.

@Test
@Ignore
public void testCreateNullParent() throws PluginExecutionException, IngestException, SourceUnavailableException {
    // given
    CreateResponse createResponse = new CreateResponseImpl(new CreateRequestImpl(metacard), null, Arrays.asList(metacard));
    // when
    plugin.process(createResponse);
    // then
    verify(endpoint, never()).addDocument(isA(HttpHeaders.class), isA(UriInfo.class), isA(InputStream.class));
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) CreateResponse(ddf.catalog.operation.CreateResponse) InputStream(java.io.InputStream) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) UriInfo(javax.ws.rs.core.UriInfo) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

CreateResponseImpl (ddf.catalog.operation.impl.CreateResponseImpl)36 CreateResponse (ddf.catalog.operation.CreateResponse)27 Test (org.junit.Test)24 Metacard (ddf.catalog.data.Metacard)20 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)19 CreateRequest (ddf.catalog.operation.CreateRequest)16 HashMap (java.util.HashMap)14 ArrayList (java.util.ArrayList)11 Serializable (java.io.Serializable)9 InputStream (java.io.InputStream)8 HttpHeaders (javax.ws.rs.core.HttpHeaders)7 Subject (ddf.security.Subject)6 List (java.util.List)6 UriInfo (javax.ws.rs.core.UriInfo)6 Ignore (org.junit.Ignore)6 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)5 IngestException (ddf.catalog.source.IngestException)5 Exchange (org.apache.camel.Exchange)5 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)5 CatalogFramework (ddf.catalog.CatalogFramework)4