Search in sources :

Example 21 with CreateResponse

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

the class FederationAdminServiceImplTest method testAddRegistryEntryWithNullDestinations.

@Test
public void testAddRegistryEntryWithNullDestinations() throws Exception {
    String registryId = RegistryObjectMetacardType.REGISTRY_ID;
    Metacard metacard = testMetacard;
    Metacard createdMetacard = testMetacard;
    Set<String> destinations = null;
    Subject systemSubject = security.getSystemSubject();
    Map<String, Serializable> properties = new HashMap<>();
    properties.put(SecurityConstants.SECURITY_SUBJECT, systemSubject);
    CreateRequest request = new CreateRequestImpl(Collections.singletonList(metacard), properties, destinations);
    CreateResponse response = new CreateResponseImpl(request, null, Collections.singletonList(createdMetacard));
    when(catalogFramework.create(any(CreateRequest.class))).thenReturn(response);
    String createdMetacardId = federationAdminServiceImpl.addRegistryEntry(metacard, destinations);
    assertThat(createdMetacardId, is(equalTo(registryId)));
    verify(catalogFramework).create(any(CreateRequest.class));
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) Subject(ddf.security.Subject) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Test(org.junit.Test)

Example 22 with CreateResponse

use of ddf.catalog.operation.CreateResponse 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 23 with CreateResponse

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

the class CatalogFrameworkImplTest method testCreateWithStores.

@Test
public void testCreateWithStores() throws Exception {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
    List<CatalogStore> stores = new ArrayList<>();
    MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true);
    stores.add(store);
    CatalogFramework framework = createDummyCatalogFramework(provider, stores, null, eventAdmin);
    List<Metacard> metacards = new ArrayList<>();
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    metacards.add(newCard);
    Map<String, Serializable> reqProps = new HashMap<>();
    HashSet<String> destinations = new HashSet<>();
    // ==== test writing to store and not local ====
    destinations.add("catalogStoreId-1");
    CreateResponse response = framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
    assertEquals(0, provider.size());
    assertEquals(response.getCreatedMetacards().size(), store.size());
    assertEquals(1, store.size());
    assertFalse(eventAdmin.wasEventPosted());
    // ==== test writing to store and local ====
    destinations.add("mockMemoryProvider");
    newCard.setId(null);
    reqProps = new HashMap<>();
    response = framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
    assertEquals(1, provider.size());
    assertEquals(response.getCreatedMetacards().size(), provider.size());
    assertEquals(2, store.size());
    assertTrue(eventAdmin.wasEventPosted());
    // ==== test writing to local when no destination ====
    destinations.clear();
    newCard.setId(null);
    reqProps = new HashMap<>();
    response = framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
    assertEquals(2, provider.size());
    assertEquals(response.getCreatedMetacards().size(), 1);
    assertEquals(2, store.size());
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) CatalogStore(ddf.catalog.source.CatalogStore) Metacard(ddf.catalog.data.Metacard) CatalogFramework(ddf.catalog.CatalogFramework) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with CreateResponse

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

the class CatalogFrameworkImplTest method testUpdateStorage.

/**
 * Tests that the framework properly passes an update request to the local provider.
 */
@Test
public void testUpdateStorage() throws Exception {
    List<ContentItem> contentItems = new ArrayList<>();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setId(null);
    ByteSource byteSource = new ByteSource() {

        @Override
        public InputStream openStream() throws IOException {
            return new ByteArrayInputStream("blah".getBytes());
        }
    };
    ContentItemImpl contentItem = new ContentItemImpl(uuidGenerator.generateUuid(), byteSource, "application/octet-stream", "blah", 0L, metacard);
    contentItems.add(contentItem);
    CreateResponse response = framework.create(new CreateStorageRequestImpl(contentItems, null));
    Metacard insertedCard = response.getCreatedMetacards().get(0);
    List<ContentItem> updatedContentItems = new ArrayList<>();
    updatedContentItems.add(new ContentItemImpl(insertedCard.getId(), byteSource, "application/octet-stream", insertedCard));
    UpdateStorageRequest request = new UpdateStorageRequestImpl(updatedContentItems, null);
    List<Result> mockFederationResults = Stream.of(insertedCard).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
    List<Update> returnedCards = framework.update(request).getUpdatedMetacards();
    assertThat(returnedCards, hasSize(1));
    final Metacard newMetacard = returnedCards.get(0).getNewMetacard();
    assertThat(newMetacard.getId(), notNullValue());
    assertThat(newMetacard.getResourceURI().toString(), is(contentItem.getUri()));
    assertThat(newMetacard.getResourceSize(), is(Long.toString(byteSource.size())));
    assertThat(response.getCreatedMetacards(), hasSize(storageProvider.size()));
    // make sure that the event was posted correctly
    assertThat(eventAdmin.wasEventPosted(), is(true));
}
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) UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) QueryRequest(ddf.catalog.operation.QueryRequest) 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) ByteArrayInputStream(java.io.ByteArrayInputStream) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ByteSource(com.google.common.io.ByteSource) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) Test(org.junit.Test)

Example 25 with CreateResponse

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

the class CatalogFrameworkImplTest method testUpdateWithDefaults.

@Test
public void testUpdateWithDefaults() throws Exception {
    final String title = "some title";
    final Date expiration = new Date();
    List<Metacard> metacards = getMetacards(title, expiration);
    CreateRequest createRequest = new CreateRequestImpl(metacards);
    CreateResponse createResponse = framework.create(createRequest);
    verifyDefaults(createResponse.getCreatedMetacards(), title, expiration, null, null, null, null);
    registerDefaults();
    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);
    UpdateRequest updateRequest = new UpdateRequestImpl(new String[] { "1", "2", "3", "4", "5" }, createResponse.getCreatedMetacards());
    UpdateResponse updateResponse = framework.update(updateRequest);
    List<Metacard> updatedMetacards = updateResponse.getUpdatedMetacards().stream().map(Update::getNewMetacard).collect(Collectors.toList());
    verifyDefaults(updatedMetacards, title, expiration, DEFAULT_TITLE, DEFAULT_EXPIRATION, DEFAULT_TITLE_CUSTOM, DEFAULT_EXPIRATION_CUSTOM);
}
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) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) 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)

Aggregations

CreateResponse (ddf.catalog.operation.CreateResponse)111 Test (org.junit.Test)82 Metacard (ddf.catalog.data.Metacard)76 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)44 ArrayList (java.util.ArrayList)42 CreateRequest (ddf.catalog.operation.CreateRequest)36 QueryImpl (ddf.catalog.operation.impl.QueryImpl)29 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)29 CreateResponseImpl (ddf.catalog.operation.impl.CreateResponseImpl)27 HashMap (java.util.HashMap)25 Serializable (java.io.Serializable)23 List (java.util.List)23 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)22 DeleteResponse (ddf.catalog.operation.DeleteResponse)22 UpdateResponse (ddf.catalog.operation.UpdateResponse)21 Filter (org.opengis.filter.Filter)21 IngestException (ddf.catalog.source.IngestException)20 SourceResponse (ddf.catalog.operation.SourceResponse)18 QueryRequest (ddf.catalog.operation.QueryRequest)17 MetacardType (ddf.catalog.data.MetacardType)16