Search in sources :

Example 16 with CreateRequestImpl

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

the class FederationStrategyTest method testQueryTimeout.

/**
     * Tests that the framework properly times out using the default federation strategy.
     */
@Test
public void testQueryTimeout() throws Exception {
    long queryDelay = 100;
    UuidGenerator uuidGenerator = mock(UuidGenerator.class);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    MockDelayProvider provider = new MockDelayProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
    provider.setQueryDelayMillis(queryDelay);
    // Mock register the provider in the container
    SourcePollerRunner runner = new SourcePollerRunner();
    SourcePoller poller = new SourcePoller(runner);
    runner.bind(provider);
    // Must have more than one thread or sleeps will block the monitor
    SortedFederationStrategy fedStrategy = new SortedFederationStrategy(executor, new ArrayList<>(), new ArrayList<>());
    FrameworkProperties props = new FrameworkProperties();
    props.setCatalogProviders(Collections.singletonList(provider));
    props.setFederationStrategy(fedStrategy);
    props.setSourcePoller(poller);
    props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
    props.setFilterBuilder(new GeotoolsFilterBuilder());
    props.setDefaultAttributeValueRegistry(new DefaultAttributeValueRegistryImpl());
    OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
    MetacardFactory metacardFactory = new MetacardFactory(props.getMimeTypeToTransformerMapper(), uuidGenerator);
    OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(props, metacardFactory);
    Historian historian = new Historian();
    historian.setHistoryEnabled(false);
    SourceOperations sourceOperations = new SourceOperations(props);
    QueryOperations queryOperations = new QueryOperations(props, sourceOperations, opsSecurity, opsMetacard);
    OperationsStorageSupport opsStorage = new OperationsStorageSupport(sourceOperations, queryOperations);
    OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(props, sourceOperations);
    CreateOperations createOperations = new CreateOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard, opsCatStore, opsStorage);
    UpdateOperations updateOperations = new UpdateOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard, opsCatStore, opsStorage);
    DeleteOperations deleteOperations = new DeleteOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard);
    opsStorage.setHistorian(historian);
    updateOperations.setHistorian(historian);
    deleteOperations.setHistorian(historian);
    deleteOperations.setOpsCatStoreSupport(opsCatStore);
    CatalogFrameworkImpl framework = new CatalogFrameworkImpl(createOperations, updateOperations, deleteOperations, queryOperations, null, null, null);
    sourceOperations.bind(provider);
    List<Metacard> metacards = new ArrayList<Metacard>();
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    metacards.add(newCard);
    CreateResponse createResponse = null;
    try {
        try {
            createResponse = framework.create(new CreateRequestImpl(metacards, null));
        } catch (SourceUnavailableException e) {
            long timeout = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10);
            //this is a hack because the unit test is flaky and should be removed once a better test is possible
            while (System.currentTimeMillis() < timeout) {
                Thread.sleep(1000);
                try {
                    createResponse = framework.create(new CreateRequestImpl(metacards, null));
                    break;
                } catch (SourceUnavailableException e1) {
                //ignore
                }
            }
        }
        if (createResponse == null) {
            fail();
        }
    } catch (IngestException e) {
        fail();
    }
    assertEquals(createResponse.getCreatedMetacards().size(), provider.size());
    for (Metacard curCard : createResponse.getCreatedMetacards()) {
        assertNotNull(curCard.getId());
    }
    QueryImpl query = new QueryImpl(filterFactory.equals(filterFactory.property(Metacard.ID), filterFactory.literal(createResponse.getCreatedMetacards().get(0).getId())));
    query.setTimeoutMillis(SHORT_TIMEOUT);
    query.setSortBy(new FilterFactoryImpl().sort(Result.RELEVANCE, SortOrder.ASCENDING));
    QueryRequest fedQueryRequest = new QueryRequestImpl(query);
    try {
        QueryResponse response = framework.query(fedQueryRequest);
        assertEquals("Timeout should happen before results return", 0, response.getHits());
    } catch (UnsupportedQueryException e) {
        fail();
    } catch (FederationException e) {
        LOGGER.error("Unexpected federation exception during test", e);
        fail();
    }
}
Also used : OperationsCatalogStoreSupport(ddf.catalog.impl.operations.OperationsCatalogStoreSupport) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) ContentType(ddf.catalog.data.ContentType) CreateResponse(ddf.catalog.operation.CreateResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) DeleteOperations(ddf.catalog.impl.operations.DeleteOperations) QueryResponsePostProcessor(ddf.catalog.impl.QueryResponsePostProcessor) SourcePoller(ddf.catalog.util.impl.SourcePoller) MetacardFactory(ddf.catalog.impl.operations.MetacardFactory) QueryImpl(ddf.catalog.operation.impl.QueryImpl) OperationsStorageSupport(ddf.catalog.impl.operations.OperationsStorageSupport) SourcePollerRunner(ddf.catalog.util.impl.SourcePollerRunner) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) IngestException(ddf.catalog.source.IngestException) Historian(ddf.catalog.history.Historian) FrameworkProperties(ddf.catalog.impl.FrameworkProperties) DefaultAttributeValueRegistryImpl(ddf.catalog.data.defaultvalues.DefaultAttributeValueRegistryImpl) MockDelayProvider(ddf.catalog.impl.MockDelayProvider) SourceOperations(ddf.catalog.impl.operations.SourceOperations) QueryRequest(ddf.catalog.operation.QueryRequest) FederationException(ddf.catalog.federation.FederationException) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) CatalogFrameworkImpl(ddf.catalog.impl.CatalogFrameworkImpl) Metacard(ddf.catalog.data.Metacard) QueryOperations(ddf.catalog.impl.operations.QueryOperations) UpdateOperations(ddf.catalog.impl.operations.UpdateOperations) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) OperationsSecuritySupport(ddf.catalog.impl.operations.OperationsSecuritySupport) CreateOperations(ddf.catalog.impl.operations.CreateOperations) OperationsMetacardSupport(ddf.catalog.impl.operations.OperationsMetacardSupport) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with CreateRequestImpl

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

the class MetacardApplication method revertMetacard.

private void revertMetacard(Metacard versionMetacard, String id, boolean alreadyCreated) throws SourceUnavailableException, IngestException, FederationException, UnsupportedQueryException {
    LOGGER.trace("Reverting metacard [{}] to version [{}]", id, versionMetacard.getId());
    Metacard revertMetacard = MetacardVersionImpl.toMetacard(versionMetacard, types);
    Action action = Action.fromKey((String) versionMetacard.getAttribute(MetacardVersion.ACTION).getValue());
    if (DELETE_ACTIONS.contains(action)) {
        attemptDeleteDeletedMetacard(id);
        if (!alreadyCreated) {
            catalogFramework.create(new CreateRequestImpl(revertMetacard));
        }
    } else {
        tryUpdate(4, () -> {
            catalogFramework.update(new UpdateRequestImpl(id, revertMetacard));
            return true;
        });
    }
}
Also used : DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) Action(ddf.catalog.core.versioning.MetacardVersion.Action) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl)

Example 18 with CreateRequestImpl

use of ddf.catalog.operation.impl.CreateRequestImpl in project alliance by codice.

the class ParentMetacardStreamCreationPlugin method doOnCreate.

@Override
protected void doOnCreate(Context context) throws StreamCreationException {
    MetacardImpl metacard;
    try {
        metacard = createInitialMetacard();
    } catch (MetacardCreationException e) {
        throw new StreamCreationException("unable to create initial parent metacard", e);
    }
    setParentResourceUri(context, metacard);
    setParentTitle(context, metacard);
    setParentContentType(metacard);
    CreateRequest createRequest = new CreateRequestImpl(metacard);
    try {
        submitParentCreateRequest(context, createRequest);
    } catch (IngestException | SourceUnavailableException e) {
        throw new StreamCreationException("unable to submit parent metacard to catalog framework", e);
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) MetacardCreationException(ddf.catalog.data.MetacardCreationException) CreateRequest(ddf.catalog.operation.CreateRequest) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) IngestException(ddf.catalog.source.IngestException) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 19 with CreateRequestImpl

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

the class CatalogFrameworkImplTest method testUpdateByIdentifier.

/**
 * Tests that the framework properly passes an update by identifier request to the local provider.
 */
@Test
public void testUpdateByIdentifier() throws Exception {
    List<Metacard> metacards = new ArrayList<Metacard>();
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    newCard.setResourceURI(new URI("DDF:///12345"));
    metacards.add(newCard);
    // create the entry manually in the provider
    List<Metacard> insertedCards = provider.create(new CreateRequestImpl(metacards)).getCreatedMetacards();
    ArrayList<URI> list = new ArrayList<URI>();
    list.add(new URI("DDF:///12345"));
    UpdateRequest request = new UpdateRequestImpl((URI[]) list.toArray(new URI[list.size()]), insertedCards);
    List<Result> mockFederationResults = metacards.stream().map(m -> {
        Result mockResult = mock(Result.class);
        when(mockResult.getMetacard()).thenReturn(m);
        return mockResult;
    }).collect(Collectors.toList());
    QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), mockFederationResults, 1);
    when(mockFederationStrategy.federate(anyList(), any())).thenReturn(queryResponse);
    // send update to framework
    UpdateResponse updateResponse = framework.update(request);
    List<Update> returnedCards = updateResponse.getUpdatedMetacards();
    assertNotNull(returnedCards);
    assertEquals(list.size(), returnedCards.size());
    assertTrue(provider.hasReceivedUpdateByIdentifier());
    // make sure that the event was posted correctly
    assertTrue(eventAdmin.wasEventPosted());
    assertEquals(eventAdmin.getLastEvent().getId(), returnedCards.get(returnedCards.size() - 1).getOldMetacard().getId());
}
Also used : AttributeRegistryImpl(ddf.catalog.data.impl.AttributeRegistryImpl) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) CreateRequest(ddf.catalog.operation.CreateRequest) CoreAttributes(ddf.catalog.data.impl.types.CoreAttributes) BinaryContent(ddf.catalog.data.BinaryContent) UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) AttributeType(ddf.catalog.data.AttributeType) FilterFactory(org.opengis.filter.FilterFactory) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) UpdateOperations(ddf.catalog.impl.operations.UpdateOperations) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) CreateOperations(ddf.catalog.impl.operations.CreateOperations) RemoteDeleteOperations(ddf.catalog.impl.operations.RemoteDeleteOperations) InputTransformer(ddf.catalog.transform.InputTransformer) ServiceReference(org.osgi.framework.ServiceReference) PostResourcePlugin(ddf.catalog.plugin.PostResourcePlugin) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Set(java.util.Set) SourceOperations(ddf.catalog.impl.operations.SourceOperations) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) MimeTypeResolver(ddf.mime.MimeTypeResolver) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) Serializable(java.io.Serializable) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) Stream(java.util.stream.Stream) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) Assert.assertFalse(org.junit.Assert.assertFalse) QueryResponseTransformer(ddf.catalog.transform.QueryResponseTransformer) Matchers.is(org.hamcrest.Matchers.is) UpdateResponse(ddf.catalog.operation.UpdateResponse) BasicTypes(ddf.catalog.data.impl.BasicTypes) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) Mockito.mock(org.mockito.Mockito.mock) ResourceResponse(ddf.catalog.operation.ResourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) PostQueryPlugin(ddf.catalog.plugin.PostQueryPlugin) AdditionalAnswers.returnsSecondArg(org.mockito.AdditionalAnswers.returnsSecondArg) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) CatalogFramework(ddf.catalog.CatalogFramework) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) DeleteResponse(ddf.catalog.operation.DeleteResponse) Mockito.spy(org.mockito.Mockito.spy) DefaultAttributeValueRegistryImpl(ddf.catalog.data.defaultvalues.DefaultAttributeValueRegistryImpl) Resource(ddf.catalog.resource.Resource) ArrayList(java.util.ArrayList) PostIngestPlugin(ddf.catalog.plugin.PostIngestPlugin) Source(ddf.catalog.source.Source) TestWatchman(org.junit.rules.TestWatchman) ContentItem(ddf.catalog.content.data.ContentItem) OperationsStorageSupport(ddf.catalog.impl.operations.OperationsStorageSupport) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ResourceRequest(ddf.catalog.operation.ResourceRequest) QueryRequest(ddf.catalog.operation.QueryRequest) SourceInfoRequestSources(ddf.catalog.operation.impl.SourceInfoRequestSources) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ByteSource(com.google.common.io.ByteSource) Result(ddf.catalog.data.Result) TransformOperations(ddf.catalog.impl.operations.TransformOperations) Core(ddf.catalog.data.types.Core) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) Before(org.junit.Before) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) ContentType(ddf.catalog.data.ContentType) ResourceOperations(ddf.catalog.impl.operations.ResourceOperations) SourcePoller(org.codice.ddf.catalog.sourcepoller.SourcePoller) Historian(ddf.catalog.history.Historian) SecurityLogger(ddf.security.audit.SecurityLogger) IngestException(ddf.catalog.source.IngestException) Assert.assertTrue(org.junit.Assert.assertTrue) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Subject(ddf.security.Subject) IOException(java.io.IOException) Test(org.junit.Test) AttributeInjector(ddf.catalog.data.AttributeInjector) FederationException(ddf.catalog.federation.FederationException) AttributeInjectorImpl(ddf.catalog.data.inject.AttributeInjectorImpl) DAYS(java.time.temporal.ChronoUnit.DAYS) Query(ddf.catalog.operation.Query) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) PreQueryPlugin(ddf.catalog.plugin.PreQueryPlugin) CatalogStore(ddf.catalog.source.CatalogStore) DeleteOperations(ddf.catalog.impl.operations.DeleteOperations) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Date(java.util.Date) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) URISyntaxException(java.net.URISyntaxException) MethodRule(org.junit.rules.MethodRule) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) LoggerFactory(org.slf4j.LoggerFactory) ResourceCacheImpl(ddf.catalog.cache.impl.ResourceCacheImpl) SourceDescriptor(ddf.catalog.source.SourceDescriptor) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) Assert.fail(org.junit.Assert.fail) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) URI(java.net.URI) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardFactory(ddf.catalog.impl.operations.MetacardFactory) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) FederatedSource(ddf.catalog.source.FederatedSource) MimeTypeToTransformerMapper(ddf.mime.MimeTypeToTransformerMapper) ResultImpl(ddf.catalog.data.impl.ResultImpl) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) ResourceReader(ddf.catalog.resource.ResourceReader) SourceMonitor(ddf.catalog.source.SourceMonitor) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) MetacardType(ddf.catalog.data.MetacardType) BundleContext(org.osgi.framework.BundleContext) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) DeleteRequest(ddf.catalog.operation.DeleteRequest) QueryResponse(ddf.catalog.operation.QueryResponse) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) MimeTypeMapperImpl(ddf.mime.mapper.MimeTypeMapperImpl) List(java.util.List) PermissionsImpl(ddf.security.permission.impl.PermissionsImpl) Entry(java.util.Map.Entry) Optional(java.util.Optional) ActionRegistry(ddf.action.ActionRegistry) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) FederationStrategy(ddf.catalog.federation.FederationStrategy) FilterBuilder(ddf.catalog.filter.FilterBuilder) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceStatus(org.codice.ddf.catalog.sourcepoller.SourceStatus) HashMap(java.util.HashMap) Update(ddf.catalog.operation.Update) DefaultAttributeValueRegistry(ddf.catalog.data.DefaultAttributeValueRegistry) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) CreateResponse(ddf.catalog.operation.CreateResponse) Constants(ddf.catalog.Constants) Metacard(ddf.catalog.data.Metacard) CollectionUtils(org.apache.commons.collections.CollectionUtils) SecurityConstants(ddf.security.SecurityConstants) MimeType(javax.activation.MimeType) StorageProvider(ddf.catalog.content.StorageProvider) OperationsCatalogStoreSupport(ddf.catalog.impl.operations.OperationsCatalogStoreSupport) UpdateRequest(ddf.catalog.operation.UpdateRequest) SimpleEntry(java.util.AbstractMap.SimpleEntry) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) QueryImpl(ddf.catalog.operation.impl.QueryImpl) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) OperationsMetacardSupport(ddf.catalog.impl.operations.OperationsMetacardSupport) Mockito.when(org.mockito.Mockito.when) OperationsSecuritySupport(ddf.catalog.impl.operations.OperationsSecuritySupport) Mockito.verify(org.mockito.Mockito.verify) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) SourceResponse(ddf.catalog.operation.SourceResponse) Rule(org.junit.Rule) CatalogProvider(ddf.catalog.source.CatalogProvider) Ignore(org.junit.Ignore) ThreadContext(org.apache.shiro.util.ThreadContext) QueryOperations(ddf.catalog.impl.operations.QueryOperations) Filter(org.opengis.filter.Filter) Collections(java.util.Collections) InputStream(java.io.InputStream) QueryRequest(ddf.catalog.operation.QueryRequest) UpdateRequest(ddf.catalog.operation.UpdateRequest) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update) URI(java.net.URI) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Example 20 with CreateRequestImpl

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

the class CatalogFrameworkImplTest method testUpdateWithStores.

// TODO (DDF-2436) -
@Ignore
@Test
public void testUpdateWithStores() throws Exception {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
    List<CatalogStore> storeList = new ArrayList<>();
    List<FederatedSource> sourceList = new ArrayList<>();
    MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true);
    storeList.add(store);
    sourceList.add(store);
    CatalogFramework framework = createDummyCatalogFramework(provider, storeList, sourceList, eventAdmin);
    FilterFactory filterFactory = new FilterFactoryImpl();
    Filter filter = filterFactory.like(filterFactory.property(Metacard.METADATA), "*", "*", "?", "/", false);
    List<Metacard> metacards = new ArrayList<>();
    String id = UUID.randomUUID().toString();
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(id);
    newCard.setAttribute("myKey", "myValue1");
    metacards.add(newCard);
    Map<String, Serializable> reqProps = new HashMap<>();
    HashSet<String> destinations = new HashSet<>();
    destinations.add("mockMemoryProvider");
    destinations.add("catalogStoreId-1");
    framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
    MetacardImpl updateCard = new MetacardImpl();
    updateCard.setId(id);
    updateCard.setAttribute("myKey", "myValue2");
    List<Entry<Serializable, Metacard>> updates = new ArrayList<>();
    updates.add(new SimpleEntry<>(id, updateCard));
    destinations.remove("mockMemoryProvider");
    framework.update(new UpdateRequestImpl(updates, Metacard.ID, new HashMap<>(), destinations));
    assertThat(provider.hasReceivedUpdateByIdentifier(), is(false));
    assertThat(store.hasReceivedUpdateByIdentifier(), is(true));
    QueryResponse storeResponse = framework.query(new QueryRequestImpl(new QueryImpl(filter), destinations));
    assertThat(storeResponse.getResults().size(), is(1));
    assertThat(storeResponse.getResults().get(0).getMetacard().getAttribute("myKey").getValue(), equalTo("myValue2"));
    destinations.clear();
    QueryResponse providerResponse = framework.query(new QueryRequestImpl(new QueryImpl(filter), destinations));
    assertThat(providerResponse.getResults().size(), is(1));
    assertThat(providerResponse.getResults().get(0).getMetacard().getAttribute("myKey").getValue(), equalTo("myValue1"));
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FilterFactory(org.opengis.filter.FilterFactory) CatalogStore(ddf.catalog.source.CatalogStore) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) QueryImpl(ddf.catalog.operation.impl.QueryImpl) CatalogFramework(ddf.catalog.CatalogFramework) HashSet(java.util.HashSet) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FederatedSource(ddf.catalog.source.FederatedSource) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) QueryResponse(ddf.catalog.operation.QueryResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)80 Test (org.junit.Test)60 Metacard (ddf.catalog.data.Metacard)53 CreateResponse (ddf.catalog.operation.CreateResponse)44 CreateRequest (ddf.catalog.operation.CreateRequest)42 ArrayList (java.util.ArrayList)30 HashMap (java.util.HashMap)29 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)26 Serializable (java.io.Serializable)22 CreateResponseImpl (ddf.catalog.operation.impl.CreateResponseImpl)19 IngestException (ddf.catalog.source.IngestException)19 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)17 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)17 InputStream (java.io.InputStream)17 HashSet (java.util.HashSet)16 QueryImpl (ddf.catalog.operation.impl.QueryImpl)15 Subject (ddf.security.Subject)15 QueryRequest (ddf.catalog.operation.QueryRequest)13 QueryResponse (ddf.catalog.operation.QueryResponse)13 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)12