Search in sources :

Example 96 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class PortletUtilsTest method testUpdateAttachmentsRemoveAndUpdate.

@Test
public void testUpdateAttachmentsRemoveAndUpdate() {
    PortletRequest request = Mockito.mock(PortletRequest.class);
    new TestUserCacheHolder().enable();
    // fill existing data
    Set<Attachment> documentAttachments = createAttachments("1", "2", "3");
    // fill request
    new TestUserCacheHolder().enable(createUser("tid", "test@example.org", "tpd"));
    setAttachmentIds(request, "2");
    setAttachmentFilenames(request, "B");
    setAttachmentTypes(request, AttachmentType.SCREENSHOT);
    setAttachmenCreatedComments(request, "CC2");
    setAttachmentCheckStatus(request, CheckStatus.ACCEPTED);
    setAttachmentCheckComment(request, "CCK2");
    // run tests
    Set<Attachment> updatedAttachments = PortletUtils.updateAttachmentsFromRequest(request, documentAttachments);
    // assertThat(documentAttachments.size(), is(3));
    assertThat(updatedAttachments.size(), is(1));
    Attachment updatedAttachment = updatedAttachments.iterator().next();
    assertThat(updatedAttachment.getAttachmentContentId(), is("2"));
    assertThat(updatedAttachment.getCheckStatus(), is(CheckStatus.ACCEPTED));
    assertThat(updatedAttachment.getCheckedBy(), is("test@example.org"));
    assertThat(updatedAttachment.getCheckedTeam(), is("tpd"));
    assertThat(updatedAttachment.getCheckedComment(), is("CCK2"));
}
Also used : PortletRequest(javax.portlet.PortletRequest) TestUserCacheHolder(org.eclipse.sw360.portal.TestUserCacheHolder) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Example 97 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class PortletUtilsTest method testUpdateAttachmentsFromRequestIdsAreNull.

@Test
public void testUpdateAttachmentsFromRequestIdsAreNull() {
    PortletRequest request = Mockito.mock(PortletRequest.class);
    new TestUserCacheHolder().enable();
    // use immutable set to ensure that set is not changed.
    Set<Attachment> documentAttachments = ImmutableSet.of();
    assertThat(PortletUtils.updateAttachmentsFromRequest(request, documentAttachments), is(empty()));
}
Also used : PortletRequest(javax.portlet.PortletRequest) TestUserCacheHolder(org.eclipse.sw360.portal.TestUserCacheHolder) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Example 98 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class DisplayDownloadApprovedClearingReportTest method testThatImageDependsOnStatus.

@Test
public void testThatImageDependsOnStatus() {
    Attachment attachment = createAttachment("test.file");
    DisplayDownloadApprovedClearingReport displayDownloadAttachment = new DisplayDownloadApprovedClearingReport();
    displayDownloadAttachment.setAttachment(attachment);
    assertEquals(DisplayDownloadAbstract.DOWNLOAD_IMAGE_ENABLED, displayDownloadAttachment.getImage());
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Example 99 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class DisplayDownloadApprovedClearingReportTest method createAttachment.

private Attachment createAttachment(String filename) {
    Attachment attachment = new Attachment();
    attachment.setFilename(filename);
    return attachment;
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment)

Example 100 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class ComponentAttachmentCSVRecord method getAttachment.

public Attachment getAttachment() {
    final Attachment attachment = new Attachment().setAttachmentContentId(attachmentContentId).setFilename(filename);
    if (!isNullOrEmpty(attachmentType)) {
        final AttachmentType attachmentTypeCandidate = ThriftEnumUtils.stringToEnum(attachmentType, AttachmentType.class);
        if (attachmentTypeCandidate != null)
            attachment.setAttachmentType(attachmentTypeCandidate);
    }
    attachment.setCreatedComment(nullToEmpty(comment)).setCreatedOn(nullToEmpty(createdOn)).setCreatedBy(nullToEmpty(createdBy));
    return attachment;
}
Also used : AttachmentType(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentType) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment)

Aggregations

Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)65 Test (org.junit.Test)40 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)38 User (org.eclipse.sw360.datahandler.thrift.users.User)27 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)22 InputStream (java.io.InputStream)19 Release (org.eclipse.sw360.datahandler.thrift.components.Release)15 IOException (java.io.IOException)13 PortletRequest (javax.portlet.PortletRequest)11 TestUserCacheHolder (org.eclipse.sw360.portal.TestUserCacheHolder)9 StringReader (java.io.StringReader)8 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)8 TException (org.apache.thrift.TException)8 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)8 LicenseInfoParsingResult (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult)7 OutputStream (java.io.OutputStream)5 AttachmentInputStream (org.ektorp.AttachmentInputStream)5 ResponseEntity (org.springframework.http.ResponseEntity)5 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)4 Maps (com.google.common.collect.Maps)3