Search in sources :

Example 26 with ContentItemImpl

use of ddf.catalog.content.data.impl.ContentItemImpl in project ddf by codice.

the class CatalogFrameworkImplTest method testCreateStorage.

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

        @Override
        public InputStream openStream() throws IOException {
            return new ByteArrayInputStream("blah".getBytes());
        }
    };
    ContentItemImpl newItem = new ContentItemImpl(uuidGenerator.generateUuid(), byteSource, "application/octet-stream", "blah", 0L, newCard);
    contentItems.add(newItem);
    CreateResponse response = framework.create(new CreateStorageRequestImpl(contentItems, null));
    assertEquals(response.getCreatedMetacards().size(), provider.size());
    assertEquals(response.getCreatedMetacards().size(), storageProvider.size());
    for (Metacard curCard : response.getCreatedMetacards()) {
        assertNotNull(curCard.getId());
    }
    // make sure that the event was posted correctly
    assertTrue(eventAdmin.wasEventPosted());
    Metacard[] array = {};
    array = response.getCreatedMetacards().toArray(array);
    assertTrue(eventAdmin.wasEventPosted());
    assertEquals(eventAdmin.getLastEvent(), array[array.length - 1]);
}
Also used : Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) CreateResponse(ddf.catalog.operation.CreateResponse) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) ArrayList(java.util.ArrayList) ByteSource(com.google.common.io.ByteSource) ContentItem(ddf.catalog.content.data.ContentItem) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) Test(org.junit.Test)

Example 27 with ContentItemImpl

use of ddf.catalog.content.data.impl.ContentItemImpl in project ddf by codice.

the class CatalogFrameworkImplTest method testCreateStorageWithAttributeOverridesInvalidType.

/**
     * Tests that the framework properly passes a create request to the local provider with attribute overrides.
     */
@Test
public void testCreateStorageWithAttributeOverridesInvalidType() throws Exception {
    List<ContentItem> contentItems = new ArrayList<>();
    Map<String, Serializable> propertiesMap = new HashMap<>();
    HashMap<String, Object> attributeMap = new HashMap<>();
    attributeMap.put(Metacard.CREATED, "bad date");
    propertiesMap.put(Constants.ATTRIBUTE_OVERRIDES_KEY, attributeMap);
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    MetacardType metacardType = mock(MetacardType.class);
    AttributeDescriptor dateAttributeDescriptor = new AttributeDescriptorImpl(Metacard.CREATED, true, true, true, true, new AttributeType<Date>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Class<Date> getBinding() {
            return Date.class;
        }

        @Override
        public AttributeFormat getAttributeFormat() {
            return AttributeFormat.DATE;
        }
    });
    when(metacardType.getAttributeDescriptor(Metacard.TITLE)).thenReturn(dateAttributeDescriptor);
    newCard.setType(metacardType);
    ByteSource byteSource = new ByteSource() {

        @Override
        public InputStream openStream() throws IOException {
            return new ByteArrayInputStream("blah".getBytes());
        }
    };
    ContentItemImpl newItem = new ContentItemImpl(uuidGenerator.generateUuid(), byteSource, "application/octet-stream", "blah", 0L, newCard);
    contentItems.add(newItem);
    CreateResponse response = framework.create(new CreateStorageRequestImpl(contentItems, propertiesMap));
    assertEquals(response.getCreatedMetacards().size(), provider.size());
    assertEquals(response.getCreatedMetacards().size(), storageProvider.size());
    for (Metacard curCard : response.getCreatedMetacards()) {
        assertNotNull(curCard.getId());
        // Assert value is not set for invalid format
        assertThat(curCard.getCreatedDate(), nullValue());
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Matchers.anyString(org.mockito.Matchers.anyString) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) MetacardType(ddf.catalog.data.MetacardType) Date(java.util.Date) Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteSource(com.google.common.io.ByteSource) Matchers.anyObject(org.mockito.Matchers.anyObject) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) Test(org.junit.Test)

Example 28 with ContentItemImpl

use of ddf.catalog.content.data.impl.ContentItemImpl in project ddf by codice.

the class FanoutCatalogFrameworkTest method testBlacklistedTagUpdateStorageRequestFails.

@Test(expected = IngestException.class)
public void testBlacklistedTagUpdateStorageRequestFails() throws Exception {
    Metacard metacard = new MetacardImpl();
    metacard.setAttribute(new AttributeImpl(Metacard.ID, "metacardId"));
    metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
    ContentItem item = new ContentItemImpl(uuidGenerator.generateUuid(), ByteSource.empty(), "text/xml", "filename.xml", 0L, metacard);
    UpdateStorageRequest request = new UpdateStorageRequestImpl(Collections.singletonList(item), new HashMap<>());
    framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
    framework.update(request);
}
Also used : Metacard(ddf.catalog.data.Metacard) UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) Test(org.junit.Test)

Example 29 with ContentItemImpl

use of ddf.catalog.content.data.impl.ContentItemImpl in project ddf by codice.

the class FanoutCatalogFrameworkTest method testBlacklistedTagCreateStorageRequestFails.

@Test(expected = IngestException.class)
public void testBlacklistedTagCreateStorageRequestFails() throws Exception {
    Metacard metacard = new MetacardImpl();
    metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
    CatalogProvider catalogProvider = mock(CatalogProvider.class);
    doReturn(true).when(catalogProvider).isAvailable();
    StorageProvider storageProvider = new MockMemoryStorageProvider();
    MimeTypeMapper mimeTypeMapper = mock(MimeTypeMapper.class);
    doReturn("extension").when(mimeTypeMapper).getFileExtensionForMimeType(anyString());
    InputTransformer transformer = mock(InputTransformer.class);
    doReturn(metacard).when(transformer).transform(any(InputStream.class));
    MimeTypeToTransformerMapper mimeTypeToTransformerMapper = mock(MimeTypeToTransformerMapper.class);
    doReturn(Collections.singletonList(transformer)).when(mimeTypeToTransformerMapper).findMatches(any(Class.class), any(MimeType.class));
    frameworkProperties.setCatalogProviders(Collections.singletonList(catalogProvider));
    frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
    frameworkProperties.setMimeTypeMapper(mimeTypeMapper);
    frameworkProperties.setMimeTypeToTransformerMapper(mimeTypeToTransformerMapper);
    OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
    MetacardFactory metacardFactory = new MetacardFactory(frameworkProperties.getMimeTypeToTransformerMapper(), uuidGenerator);
    OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(frameworkProperties, metacardFactory);
    SourceOperations sourceOperations = new SourceOperations(frameworkProperties);
    sourceOperations.bind(catalogProvider);
    sourceOperations.bind(storageProvider);
    TransformOperations transformOperations = new TransformOperations(frameworkProperties);
    QueryOperations queryOperations = new QueryOperations(frameworkProperties, sourceOperations, opsSecurity, opsMetacard);
    OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(frameworkProperties, sourceOperations);
    OperationsStorageSupport opsStorage = new OperationsStorageSupport(sourceOperations, queryOperations);
    ResourceOperations resourceOperations = new ResourceOperations(frameworkProperties, queryOperations, opsSecurity);
    OperationsMetacardSupport opsMetacardSupport = new OperationsMetacardSupport(frameworkProperties, metacardFactory);
    // Need to set these for InputValidation to work
    System.setProperty("bad.files", "none");
    System.setProperty("bad.file.extensions", "none");
    System.setProperty("bad.mime.types", "none");
    CreateOperations createOperations = new CreateOperations(frameworkProperties, queryOperations, sourceOperations, opsSecurity, opsMetacardSupport, opsCatStore, opsStorage);
    framework = new CatalogFrameworkImpl(createOperations, null, null, queryOperations, resourceOperations, sourceOperations, transformOperations);
    framework.setId(NEW_SOURCE_ID);
    framework.setFanoutEnabled(true);
    framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
    ContentItem item = new ContentItemImpl(uuidGenerator.generateUuid(), ByteSource.empty(), "text/xml", "filename.xml", 0L, metacard);
    CreateStorageRequest request = new CreateStorageRequestImpl(Collections.singletonList(item), new HashMap<>());
    framework.create(request);
}
Also used : MimeTypeToTransformerMapper(ddf.mime.MimeTypeToTransformerMapper) OperationsCatalogStoreSupport(ddf.catalog.impl.operations.OperationsCatalogStoreSupport) MimeTypeMapper(ddf.mime.MimeTypeMapper) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) InputTransformer(ddf.catalog.transform.InputTransformer) MimeType(javax.activation.MimeType) MetacardFactory(ddf.catalog.impl.operations.MetacardFactory) OperationsStorageSupport(ddf.catalog.impl.operations.OperationsStorageSupport) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) SourceOperations(ddf.catalog.impl.operations.SourceOperations) InputStream(java.io.InputStream) ResourceOperations(ddf.catalog.impl.operations.ResourceOperations) StorageProvider(ddf.catalog.content.StorageProvider) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) TransformOperations(ddf.catalog.impl.operations.TransformOperations) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryOperations(ddf.catalog.impl.operations.QueryOperations) OperationsSecuritySupport(ddf.catalog.impl.operations.OperationsSecuritySupport) CreateOperations(ddf.catalog.impl.operations.CreateOperations) OperationsMetacardSupport(ddf.catalog.impl.operations.OperationsMetacardSupport) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) Test(org.junit.Test)

Aggregations

ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)29 ContentItem (ddf.catalog.content.data.ContentItem)25 Metacard (ddf.catalog.data.Metacard)24 Test (org.junit.Test)17 ByteSource (com.google.common.io.ByteSource)14 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)14 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)10 IOException (java.io.IOException)8 InputStream (java.io.InputStream)8 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)8 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)7 CreateResponse (ddf.catalog.operation.CreateResponse)7 UpdateStorageRequestImpl (ddf.catalog.content.operation.impl.UpdateStorageRequestImpl)6 Serializable (java.io.Serializable)6 URI (java.net.URI)6 CreateStorageRequest (ddf.catalog.content.operation.CreateStorageRequest)5 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)5 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)5