use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent in project sw360portal by sw360.
the class ComponentImportUtilsTest method testImportOnEmptyDb.
@Test
public void testImportOnEmptyDb() throws Exception {
FluentIterable<ComponentCSVRecord> compCSVRecords = getCompCSVRecordsFromTestFile(fileName);
assertThat(componentClient.getComponentSummary(user), is(empty()));
assertThat(componentClient.getReleaseSummary(user), is(empty()));
ComponentImportUtils.writeToDatabase(compCSVRecords, componentClient, vendorClient, attachmentClient, user);
assertExpectedComponentsInDb();
final String attachmentContentId = getCreatedAttachmentContentId();
final AttachmentContent overwriter = new AttachmentContent().setId(OVERRIDING_ID).setOnlyRemote(true).setRemoteUrl(REMOTE_URL).setType(TYPE_ATTACHMENT);
final AttachmentContent addition = new AttachmentContent().setId(ADDITIONAL_ID).setOnlyRemote(true).setRemoteUrl(REMOTE_URL).setType(TYPE_ATTACHMENT);
attachmentRepository.add(overwriter);
attachmentRepository.add(addition);
assertThat(attachmentRepository.getAll(), Matchers.hasSize(3));
FluentIterable<ComponentAttachmentCSVRecord> compAttachmentCSVRecords = getCompAttachmentCSVRecordsFromTestFile(attachmentsFilename);
ComponentImportUtils.writeAttachmentsToDatabase(compAttachmentCSVRecords, user, componentClient, attachmentClient);
try {
attachmentClient.getAttachmentContent(attachmentContentId);
fail("Expected exception not thrown");
} catch (Exception e) {
assertThat(e, is(instanceOf(SW360Exception.class)));
assertThat(((SW360Exception) e).getWhy(), is("Cannot find " + attachmentContentId + " in database."));
}
assertThat(attachmentRepository.getAll(), Matchers.hasSize(2));
final AttachmentContent attachmentContent = attachmentClient.getAttachmentContent(getCreatedAttachmentContentId());
assertThat(attachmentContent, is(overwriter));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent in project sw360portal by sw360.
the class AttachmentStreamConnector method downloadRemoteAttachmentAndUpdate.
private AttachmentContent downloadRemoteAttachmentAndUpdate(AttachmentContent attachmentContent) throws SW360Exception {
final InputStream downloadStream;
try {
downloadStream = attachmentContentDownloader.download(attachmentContent, downloadTimeout);
} catch (IOException e) {
String msg = "Cannot download attachment " + attachmentContent.getId() + " from URL";
log.error(msg, e);
throw new SW360Exception(msg);
}
uploadAttachment(attachmentContent, downloadStream);
attachmentContent = connector.get(AttachmentContent.class, attachmentContent.getId());
attachmentContent.setOnlyRemote(false);
connector.update(attachmentContent);
return attachmentContent;
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent in project sw360portal by sw360.
the class AttachmentContentDownloaderTest method testTheCouchDbUrl.
@Test
public void testTheCouchDbUrl() throws Exception {
AttachmentContent attachmentContent = mock(AttachmentContent.class);
when(attachmentContent.getRemoteUrl()).thenReturn(DatabaseTestProperties.COUCH_DB_URL);
try (InputStream download = attachmentContentDownloader.download(attachmentContent, downloadTimeout)) {
String read = CharStreams.toString(new InputStreamReader(download));
assertThat(read, is(not(nullOrEmpty())));
assertThat(read, containsString("couchdb"));
}
}
Aggregations