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);
}
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));
}
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));
}
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);
}
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);
}
Aggregations