Search in sources :

Example 51 with ContentItem

use of ddf.catalog.content.data.ContentItem 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 52 with ContentItem

use of ddf.catalog.content.data.ContentItem in project ddf by codice.

the class HistorianTest method testRollbackFailed.

@Test(expected = IngestException.class)
public void testRollbackFailed() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException {
    List<Metacard> metacards = getMetacardUpdatePair();
    // Mock out a bad storage provider
    StorageProvider exceptionStorageProvider = mock(StorageProvider.class);
    doThrow(StorageException.class).when(exceptionStorageProvider).commit(any());
    doThrow(StorageException.class).when(exceptionStorageProvider).rollback(any());
    ContentItem item = mock(ContentItem.class);
    when(item.getId()).thenReturn(METACARD_ID);
    when(item.getUri()).thenReturn(RESOURCE_URI);
    when(item.getMetacard()).thenReturn(metacards.get(0));
    ReadStorageResponse readStorageResponse = mock(ReadStorageResponse.class);
    when(readStorageResponse.getContentItem()).thenReturn(item);
    when(exceptionStorageProvider.read(any())).thenReturn(readStorageResponse);
    when(exceptionStorageProvider.create(any())).thenReturn(mock(CreateStorageResponse.class));
    historian.setStorageProviders(Collections.singletonList(exceptionStorageProvider));
    // Parameters for historian
    UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
    UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
    UpdateResponse updateResponse = mock(UpdateResponse.class);
    // send a request to update the metacard
    updateMetacard(storageRequest, storageResponse, metacards.get(1));
    mockQuery(metacards.get(1));
    historian.version(storageRequest, storageResponse, updateResponse);
    verify(exceptionStorageProvider).rollback(any(StorageRequest.class));
}
Also used : CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) UpdateResponse(ddf.catalog.operation.UpdateResponse) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) StorageRequest(ddf.catalog.content.operation.StorageRequest) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) StorageProvider(ddf.catalog.content.StorageProvider) ContentItem(ddf.catalog.content.data.ContentItem) Test(org.junit.Test)

Example 53 with ContentItem

use of ddf.catalog.content.data.ContentItem in project ddf by codice.

the class HistorianTest method storeMetacard.

private void storeMetacard(Metacard metacard) {
    ContentItem item = mock(ContentItem.class);
    when(item.getId()).thenReturn(METACARD_ID);
    when(item.getUri()).thenReturn(RESOURCE_URI);
    when(item.getMetacard()).thenReturn(metacard);
    storageProvider.storageMap.put(item.getUri(), item);
}
Also used : ContentItem(ddf.catalog.content.data.ContentItem)

Example 54 with ContentItem

use of ddf.catalog.content.data.ContentItem in project ddf by codice.

the class TestChecksum method initialize.

@Before
public void initialize() throws IOException, NoSuchAlgorithmException {
    mockChecksumProvider = mock(ChecksumProvider.class);
    InputStream inputStream = mock(InputStream.class);
    when(mockChecksumProvider.getChecksumAlgorithm()).thenReturn(SAMPLE_CHECKSUM_ALGORITHM);
    when(mockChecksumProvider.calculateChecksum(inputStream)).thenReturn(SAMPLE_CHECKSUM_VALUE);
    checksum = new Checksum(mockChecksumProvider);
    List<ContentItem> mockContentItems = new ArrayList<>();
    ContentItem mockContentItem = mock(ContentItem.class);
    when(mockContentItem.getInputStream()).thenReturn(inputStream);
    when(mockContentItem.getMetacard()).thenReturn(new MetacardImpl());
    mockContentItems.add(mockContentItem);
    mockCreateRequest = mock(CreateStorageRequest.class);
    when(mockCreateRequest.getContentItems()).thenReturn(mockContentItems);
    mockUpdateRequest = mock(UpdateStorageRequest.class);
    when(mockUpdateRequest.getContentItems()).thenReturn(mockContentItems);
}
Also used : InputStream(java.io.InputStream) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ArrayList(java.util.ArrayList) ContentItem(ddf.catalog.content.data.ContentItem) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ChecksumProvider(org.codice.ddf.checksum.ChecksumProvider) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) Before(org.junit.Before)

Example 55 with ContentItem

use of ddf.catalog.content.data.ContentItem in project ddf by codice.

the class PreviewStoragePlugin method createPreviewItem.

private ContentItem createPreviewItem(Metacard metacard) {
    ContentItem preview = new ContentItemImpl(metacard.getId(), "preview", ByteSource.wrap(metacard.getThumbnail()), "image/jpg", metacard.getTitle(), metacard.getThumbnail().length, metacard);
    metacard.setAttribute(new AttributeImpl(Metacard.DERIVED_RESOURCE_URI, preview.getUri()));
    return preview;
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl)

Aggregations

ContentItem (ddf.catalog.content.data.ContentItem)65 Metacard (ddf.catalog.data.Metacard)37 Test (org.junit.Test)36 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)27 ArrayList (java.util.ArrayList)22 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)20 HashMap (java.util.HashMap)19 URI (java.net.URI)17 ByteSource (com.google.common.io.ByteSource)16 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)16 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)15 IOException (java.io.IOException)14 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)13 StorageException (ddf.catalog.content.StorageException)12 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)12 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)11 InputStream (java.io.InputStream)11 Map (java.util.Map)11 StorageProvider (ddf.catalog.content.StorageProvider)10 UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)10