Search in sources :

Example 56 with AttachmentContent

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));
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) TException(org.apache.thrift.TException) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) Test(org.junit.Test)

Example 57 with AttachmentContent

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;
}
Also used : ConcatClosingInputStream(org.eclipse.sw360.datahandler.common.ConcatClosingInputStream) PipedInputStream(java.io.PipedInputStream) AttachmentInputStream(org.ektorp.AttachmentInputStream) InputStream(java.io.InputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) IOException(java.io.IOException) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Example 58 with 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"));
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Test(org.junit.Test)

Aggregations

AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)52 InputStream (java.io.InputStream)24 Test (org.junit.Test)20 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)13 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)11 IOException (java.io.IOException)10 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)10 User (org.eclipse.sw360.datahandler.thrift.users.User)10 Release (org.eclipse.sw360.datahandler.thrift.components.Release)8 TException (org.apache.thrift.TException)7 LicenseInfoParsingResult (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult)6 AttachmentInputStream (org.ektorp.AttachmentInputStream)6 OutputStream (java.io.OutputStream)5 FilledAttachment (org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment)5 StringReader (java.io.StringReader)4 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)4 RequestSummary (org.eclipse.sw360.datahandler.thrift.RequestSummary)4 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)3 LicenseInfo (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo)3 PipedInputStream (java.io.PipedInputStream)2