Search in sources :

Example 61 with CreateRequest

use of ddf.catalog.operation.CreateRequest in project ddf by codice.

the class CatalogComponentFrameworkTest method testCreateWithListOfMetacards.

@Test
public /**
 * Operation: CREATE Body contains: List<Metacard>
 */
void testCreateWithListOfMetacards() 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);
    metacards.add(metacard2);
    // 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", metacards, "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, 2);
    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 62 with CreateRequest

use of ddf.catalog.operation.CreateRequest 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 63 with CreateRequest

use of ddf.catalog.operation.CreateRequest in project ddf by codice.

the class FrameworkProducer method create.

/**
 * Creates metacard(s) in the catalog using the Catalog Framework.
 *
 * @param exchange The {@link org.apache.camel.Exchange} can contain a {@link
 *     org.apache.camel.Message} with a body of type {@link java.util.List} of Metacard or a
 *     single Metacard.
 * @throws ddf.catalog.source.SourceUnavailableException
 * @throws ddf.catalog.source.IngestException
 * @throws ddf.camel.component.catalog.framework.FrameworkProducerException
 */
private void create(final Exchange exchange) throws SourceUnavailableException, IngestException, FrameworkProducerException {
    CreateResponse createResponse = null;
    // read in data
    final List<Metacard> metacardsToBeCreated = readBodyDataAsMetacards(exchange);
    if (!validateList(metacardsToBeCreated, Metacard.class)) {
        processCatalogResponse(createResponse, exchange);
        throw new FrameworkProducerException("Validation of Metacard list failed");
    }
    LOGGER.debug("Validation of Metacard list passed...");
    final CreateRequest createRequest = new CreateRequestImpl(metacardsToBeCreated);
    int expectedNumberOfCreatedMetacards = metacardsToBeCreated.size();
    if (expectedNumberOfCreatedMetacards < 1) {
        LOGGER.debug("Empty list of Metacards...nothing to process");
        processCatalogResponse(createResponse, exchange);
        return;
    }
    LOGGER.debug("Making CREATE call to Catalog Framework...");
    createResponse = catalogFramework.create(createRequest);
    if (createResponse == null) {
        LOGGER.debug("CreateResponse is null from catalog framework");
        processCatalogResponse(createResponse, exchange);
        return;
    }
    final List<Metacard> createdMetacards = createResponse.getCreatedMetacards();
    if (createdMetacards == null) {
        LOGGER.debug("CreateResponse returned null metacards list");
        processCatalogResponse(createResponse, exchange);
        return;
    }
    final int numberOfCreatedMetacards = createdMetacards.size();
    if (numberOfCreatedMetacards != expectedNumberOfCreatedMetacards) {
        LOGGER.debug("Expected {} metacards created but only {} were successfully created", expectedNumberOfCreatedMetacards, numberOfCreatedMetacards);
        processCatalogResponse(createResponse, exchange);
        return;
    }
    LOGGER.debug("Created {} metacards", numberOfCreatedMetacards);
    processCatalogResponse(createResponse, exchange);
}
Also used : Metacard(ddf.catalog.data.Metacard) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequest(ddf.catalog.operation.CreateRequest) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) Endpoint(org.apache.camel.Endpoint)

Example 64 with CreateRequest

use of ddf.catalog.operation.CreateRequest in project ddf by codice.

the class MetacardGroomerPluginTest method testCreateWithNullRequest.

@Test
public void testCreateWithNullRequest() throws PluginExecutionException, StopProcessingException {
    CreateRequest returnedRequest = plugin.process((CreateRequest) null);
    assertThat(returnedRequest, nullValue());
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) Test(org.junit.Test)

Example 65 with CreateRequest

use of ddf.catalog.operation.CreateRequest in project ddf by codice.

the class CatalogMetricsTest method catalogPostCreateLatencyMetric.

@Test
public void catalogPostCreateLatencyMetric() throws Exception {
    Iterable<Tag> tags = Tags.of("successful", "true");
    CreateRequest request = mock(CreateRequest.class);
    CreateResponse response = mock(CreateResponse.class);
    when(response.getRequest()).thenReturn(request);
    when(request.getPropertyValue("metrics.catalog.operation.start")).thenReturn(System.currentTimeMillis() - 1000);
    catalogMetrics.process(response);
    assertThat(meterRegistry.summary("ddf.catalog.create.latency", tags).count(), is(1L));
    assertThat(meterRegistry.summary("ddf.catalog.create.latency", tags).max(), greaterThanOrEqualTo(1000.0));
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) Tag(io.micrometer.core.instrument.Tag) Test(org.junit.Test)

Aggregations

CreateRequest (ddf.catalog.operation.CreateRequest)80 Test (org.junit.Test)62 Metacard (ddf.catalog.data.Metacard)44 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)39 CreateResponse (ddf.catalog.operation.CreateResponse)29 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)17 Subject (ddf.security.Subject)14 Serializable (java.io.Serializable)12 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)11 CreateResponseImpl (ddf.catalog.operation.impl.CreateResponseImpl)11 IngestException (ddf.catalog.source.IngestException)11 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)9 List (java.util.List)9 HashSet (java.util.HashSet)7 UpdateRequest (ddf.catalog.operation.UpdateRequest)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 Map (java.util.Map)5 CatalogFramework (ddf.catalog.CatalogFramework)4