Search in sources :

Example 71 with ContentItem

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

the class ChecksumTest 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(Collections.singletonList(mockChecksumProvider));
    checksum.setChecksumAlgorithm(SAMPLE_CHECKSUM_ALGORITHM);
    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 72 with ContentItem

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

the class ChecksumTest method testProcessUpdateDerivedContentDoesNotSetAttribute.

@Test
public void testProcessUpdateDerivedContentDoesNotSetAttribute() throws Exception {
    Metacard metacard = mock(Metacard.class);
    ContentItem mockContentItem = mock(ContentItem.class);
    when(mockContentItem.getQualifier()).thenReturn("some-qualifier");
    when(mockContentItem.getMetacard()).thenReturn(metacard);
    List<ContentItem> mockContentItems = new ArrayList<>();
    mockContentItems.add(mockContentItem);
    UpdateStorageRequest mockUpdateRequest = mock(UpdateStorageRequest.class);
    when(mockUpdateRequest.getContentItems()).thenReturn(mockContentItems);
    checksum.process(mockUpdateRequest);
    verify(metacard, never()).setAttribute(any(Attribute.class));
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ArrayList(java.util.ArrayList) ContentItem(ddf.catalog.content.data.ContentItem) Test(org.junit.Test)

Example 73 with ContentItem

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

the class ChecksumTest method testProcessCreateDerivedContentDoesNotSetAttribute.

@Test
public void testProcessCreateDerivedContentDoesNotSetAttribute() throws Exception {
    Metacard metacard = mock(Metacard.class);
    ContentItem mockContentItem = mock(ContentItem.class);
    when(mockContentItem.getQualifier()).thenReturn("some-qualifier");
    when(mockContentItem.getMetacard()).thenReturn(metacard);
    List<ContentItem> mockContentItems = new ArrayList<>();
    mockContentItems.add(mockContentItem);
    CreateStorageRequest mockCreateRequest = mock(CreateStorageRequest.class);
    when(mockCreateRequest.getContentItems()).thenReturn(mockContentItems);
    checksum.process(mockCreateRequest);
    verify(metacard, never()).setAttribute(any(Attribute.class));
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) ArrayList(java.util.ArrayList) ContentItem(ddf.catalog.content.data.ContentItem) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) Test(org.junit.Test)

Example 74 with ContentItem

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

the class FileSystemStorageProviderTest method assertReadRequest.

private void assertReadRequest(String uriString, String mimeType) throws StorageException, IOException, URISyntaxException {
    final URI uri = new URI(uriString);
    ReadStorageRequest readRequest = new ReadStorageRequestImpl(uri, Collections.emptyMap());
    ReadStorageResponse readResponse = provider.read(readRequest);
    ContentItem item = readResponse.getContentItem();
    LOGGER.debug("Item retrieved: {}", item);
    assertThat(item, notNullValue());
    assertThat(item.getId(), is(uri.getSchemeSpecificPart()));
    if (uri.getFragment() != null) {
        assertThat(item.getQualifier(), is(uri.getFragment()));
    }
    if (mimeType.equals(NITF_MIME_TYPE)) {
        assertThat(item.getMimeTypeRawData(), is(NITF_MIME_TYPE));
    }
    List<String> parts = provider.getContentFilePathParts(uri.getSchemeSpecificPart(), uri.getFragment());
    String expectedFilePath = baseDir + File.separator + FileSystemStorageProvider.DEFAULT_CONTENT_REPOSITORY + File.separator + FileSystemStorageProvider.DEFAULT_CONTENT_STORE + File.separator + parts.get(0) + File.separator + parts.get(1) + File.separator + parts.get(2) + (StringUtils.isNotBlank(item.getQualifier()) ? File.separator + item.getQualifier() : "") + File.separator + item.getFilename();
    assertThat(Files.exists(Paths.get(expectedFilePath)), is(true));
    assertTrue(item.getSize() > 0);
}
Also used : ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) ReadStorageRequestImpl(ddf.catalog.content.operation.impl.ReadStorageRequestImpl) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) URI(java.net.URI) ContentItem(ddf.catalog.content.data.ContentItem)

Example 75 with ContentItem

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

the class FileSystemStorageProviderTest method testRollback.

@Test(expected = StorageException.class)
public void testRollback() throws Exception {
    String id = UUID.randomUUID().toString().replaceAll("-", "");
    ByteSource byteSource = new ByteSource() {

        @Override
        public InputStream openStream() throws IOException {
            return IOUtils.toInputStream(TEST_INPUT_CONTENTS, StandardCharsets.UTF_8);
        }
    };
    Metacard metacard = mock(Metacard.class);
    when(metacard.getId()).thenReturn(id);
    ContentItem contentItem = new ContentItemImpl(id, byteSource, NITF_MIME_TYPE, TEST_INPUT_FILENAME, TEST_INPUT_CONTENTS.getBytes().length, metacard);
    CreateStorageRequest createRequest = new CreateStorageRequestImpl(Collections.singletonList(contentItem), null);
    CreateStorageResponse createStorageResponse = provider.create(createRequest);
    provider.rollback(createRequest);
    ReadStorageRequest readStorageRequest = new ReadStorageRequestImpl(new URI("content:" + id), null);
    ReadStorageResponse read = provider.read(readStorageRequest);
}
Also used : CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) Metacard(ddf.catalog.data.Metacard) ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) ByteSource(com.google.common.io.ByteSource) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) ReadStorageRequestImpl(ddf.catalog.content.operation.impl.ReadStorageRequestImpl) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) URI(java.net.URI) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) Test(org.junit.Test)

Aggregations

ContentItem (ddf.catalog.content.data.ContentItem)92 Test (org.junit.Test)51 Metacard (ddf.catalog.data.Metacard)44 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)31 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)30 ArrayList (java.util.ArrayList)29 IOException (java.io.IOException)21 HashMap (java.util.HashMap)21 ByteSource (com.google.common.io.ByteSource)20 URI (java.net.URI)20 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)17 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)16 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)16 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)15 InputStream (java.io.InputStream)14 StorageException (ddf.catalog.content.StorageException)13 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)13 UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)12 Map (java.util.Map)12 StorageProvider (ddf.catalog.content.StorageProvider)11