use of com.google.common.io.ByteSource in project ddf by codice.
the class TestTemporaryFileBackedOutputStream method testWriteByteArrayOffLen.
@Test
public void testWriteByteArrayOffLen() throws IOException {
temporaryFileBackedOutputStream.write(TEST_BYTE_ARRAY, 0, 1);
ByteSource byteSource = temporaryFileBackedOutputStream.asByteSource();
assertThat(byteSource.read(), is(TEST_BYTE_ARRAY));
}
use of com.google.common.io.ByteSource in project ddf by codice.
the class TestTemporaryFileBackedOutputStream method testWriteByteArray.
@Test
public void testWriteByteArray() throws IOException {
temporaryFileBackedOutputStream.write(TEST_BYTE_ARRAY);
ByteSource byteSource = temporaryFileBackedOutputStream.asByteSource();
assertThat(byteSource.read(), is(TEST_BYTE_ARRAY));
}
use of com.google.common.io.ByteSource 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);
}
};
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);
}
use of com.google.common.io.ByteSource in project ddf by codice.
the class FileSystemStorageProviderTest method assertContentItemWithQualifier.
public CreateStorageResponse assertContentItemWithQualifier(String data, String mimeTypeRawData, String filename, String id, String qualifier, Map<String, Serializable> properties) throws Exception {
// Simulates what ContentFrameworkImpl would do
String uuid = StringUtils.defaultIfBlank(id, UUID.randomUUID().toString().replaceAll("-", ""));
ByteSource byteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return IOUtils.toInputStream(data);
}
};
ContentItem contentItem = new ContentItemImpl(uuid, qualifier, byteSource, mimeTypeRawData, filename, byteSource.size(), mock(Metacard.class));
CreateStorageRequest createRequest = new CreateStorageRequestImpl(Collections.singletonList(contentItem), properties);
CreateStorageResponse createResponse = provider.create(createRequest);
List<ContentItem> createdContentItems = createResponse.getCreatedContentItems();
ContentItem createdContentItem = createdContentItems.isEmpty() ? null : createdContentItems.get(0);
assertNotNull(createdContentItem);
String createdId = createdContentItem.getId();
assertNotNull(createdId);
assertThat(createdId, equalTo(uuid));
String contentUri = createdContentItem.getUri();
LOGGER.debug("contentUri = {}", contentUri);
assertNotNull(contentUri);
String expectedContentUri = ContentItem.CONTENT_SCHEME + ":" + uuid + ((StringUtils.isNotBlank(qualifier)) ? "#" + qualifier : "");
assertThat(contentUri, equalTo(expectedContentUri));
assertTrue(createdContentItem.getSize() > 0);
String createdMimeType = createdContentItem.getMimeTypeRawData().replace(";", "");
List<String> createdMimeTypeArr = new ArrayList<>(Arrays.asList(createdMimeType.split(" ")));
List<String> givenMimeTypeArr = new ArrayList<>(Arrays.asList(mimeTypeRawData.replace(";", "").split(" ")));
assertEquals(createdMimeTypeArr.size(), givenMimeTypeArr.size());
givenMimeTypeArr.removeAll(createdMimeTypeArr);
assertThat(givenMimeTypeArr.size(), is(0));
provider.commit(createRequest);
return createResponse;
}
use of com.google.common.io.ByteSource in project ddf by codice.
the class FileSystemStorageProviderTest method testUpdateMultipleQualifiedItemsInTheSameRequest.
@Test
public void testUpdateMultipleQualifiedItemsInTheSameRequest() throws Exception {
// store unqualified content item
final CreateStorageResponse createResponse = assertContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME);
final ContentItem createdContentItem = createResponse.getCreatedContentItems().get(0);
final String id = createdContentItem.getId();
final Metacard metacard = createdContentItem.getMetacard();
// add 2 new qualified content items with the same id
final ByteSource q1ByteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return IOUtils.toInputStream("q1 content");
}
};
final ContentItem q1ContentItem = new ContentItemImpl(id, "q1", q1ByteSource, "image/png", "q1.png", q1ByteSource.size(), metacard);
final ByteSource q2ByteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return IOUtils.toInputStream("q2 content");
}
};
final ContentItem q2ContentItem = new ContentItemImpl(id, "q2", q2ByteSource, "image/png", "q2.png", q2ByteSource.size(), metacard);
submitAndVerifySuccessfulUpdateStorageRequest(q1ContentItem, q2ContentItem);
}
Aggregations