Search in sources :

Example 46 with Attachment

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

the class PortletUtilsTest method testUpdateAttachmentsUncheckRemovesCheckedFields.

@Test
public void testUpdateAttachmentsUncheckRemovesCheckedFields() {
    PortletRequest request = Mockito.mock(PortletRequest.class);
    // fill existing data
    User user = createUser("tid", "test@example.org", "tpd");
    Attachment attachment = createAttachments(user, "1").iterator().next();
    attachment.setCheckStatus(CheckStatus.ACCEPTED);
    attachment.setCheckedBy("check@example.org");
    attachment.setCheckedComment("check-comment");
    attachment.setCheckedOn("2017-01-31");
    attachment.setCheckedTeam("check-team");
    // fill request
    setAttachmentIds(request, "1");
    setAttachmentFilenames(request, "A");
    setAttachmentTypes(request, AttachmentType.SOURCE);
    setAttachmenCreatedComments(request, "CC1");
    setAttachmentCheckStatus(request, CheckStatus.NOTCHECKED);
    setAttachmentCheckComment(request, "");
    // run test
    Set<Attachment> updatedAttachments = PortletUtils.updateAttachmentsFromRequest(request, Sets.newHashSet(attachment));
    assertThat(updatedAttachments.size(), is(1));
    Attachment updatedAttachment = updatedAttachments.iterator().next();
    assertThat(updatedAttachment.getAttachmentContentId(), is("1"));
    assertThat(updatedAttachment.getCheckStatus(), is(CheckStatus.NOTCHECKED));
    assertNull(updatedAttachment.getCheckedBy());
    assertNull(updatedAttachment.getCheckedTeam());
    assertThat(updatedAttachment.getCheckedComment(), is(""));
}
Also used : PortletRequest(javax.portlet.PortletRequest) User(org.eclipse.sw360.datahandler.thrift.users.User) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Example 47 with Attachment

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

the class PortletUtilsTest method testUpdateAttachmentsFromRequestOnlyAddToEmpty.

@Test
public void testUpdateAttachmentsFromRequestOnlyAddToEmpty() {
    PortletRequest request = Mockito.mock(PortletRequest.class);
    new TestUserCacheHolder().enable();
    // fill existing data
    // use immutable set to ensure that set is not changed.
    Set<Attachment> documentAttachments = ImmutableSet.of();
    // fill request
    setAttachmentIds(request, "1", "2", "3");
    setAttachmentFilenames(request, "A", "B", "C");
    setAttachmentTypes(request, AttachmentType.DOCUMENT, AttachmentType.BINARY, AttachmentType.DECISION_REPORT);
    setAttachmenCreatedComments(request, "CC1", "CC2", "CC3");
    setAttachmentCheckStatus(request, CheckStatus.NOTCHECKED, CheckStatus.ACCEPTED, CheckStatus.REJECTED);
    setAttachmentCheckComment(request, "CCK1", "CCK2", "CCK3");
    // run tests
    Set<Attachment> updatedAttachments = PortletUtils.updateAttachmentsFromRequest(request, documentAttachments);
    assertThat(updatedAttachments.size(), is(3));
    assertThat(updatedAttachments.stream().map(Attachment::getAttachmentContentId).collect(Collectors.toList()), containsInAnyOrder("1", "2", "3"));
}
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 48 with Attachment

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

the class PortletUtilsTest method testUpdateAttachmentsFromRequestAddAndUpdate.

@Test
public void testUpdateAttachmentsFromRequestAddAndUpdate() {
    PortletRequest request = Mockito.mock(PortletRequest.class);
    new TestUserCacheHolder().enable();
    // fill existing data
    Set<Attachment> documentAttachments = createAttachments("9", "8");
    // fill request
    setAttachmentIds(request, "1", "2", "8", "9");
    setAttachmentFilenames(request, "A", "B", "C", "D");
    setAttachmentTypes(request, AttachmentType.DOCUMENT, AttachmentType.BINARY, AttachmentType.DECISION_REPORT, AttachmentType.OTHER);
    setAttachmenCreatedComments(request, "CC1", "CC2", "CC3", "CC4");
    setAttachmentCheckStatus(request, CheckStatus.NOTCHECKED, CheckStatus.ACCEPTED, CheckStatus.REJECTED, CheckStatus.NOTCHECKED);
    setAttachmentCheckComment(request, "CCK1", "CCK2", "CCK3", "CCK4;");
    // run test
    Set<Attachment> updatedAttachments = PortletUtils.updateAttachmentsFromRequest(request, documentAttachments);
    assertThat(updatedAttachments.size(), is(4));
    assertThat(updatedAttachments.stream().map(Attachment::getAttachmentContentId).collect(Collectors.toList()), containsInAnyOrder("1", "2", "8", "9"));
    assertThat(updatedAttachments.stream().map(Attachment::getFilename).collect(Collectors.toList()), containsInAnyOrder("A", "B", "file8", "file9"));
}
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 49 with Attachment

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

the class PortletUtilsTest method setAttachmentTypes.

protected static void setAttachmentTypes(PortletRequest request, AttachmentType... types) {
    List<String> stringTypes = Lists.newArrayList();
    for (AttachmentType type : types) {
        stringTypes.add("" + type.getValue());
    }
    Mockito.when(request.getParameterValues(Release._Fields.ATTACHMENTS.toString() + Attachment._Fields.ATTACHMENT_TYPE.toString())).thenReturn(stringTypes.toArray(new String[] {}));
}
Also used : AttachmentType(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentType)

Example 50 with Attachment

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

the class PortletUtilsTest method testUpdateAttachmentsRemoveAll.

@Test
public void testUpdateAttachmentsRemoveAll() {
    PortletRequest request = Mockito.mock(PortletRequest.class);
    new TestUserCacheHolder().enable();
    // fill existing data
    Set<Attachment> documentAttachments = createAttachments("1", "2", "3");
    // fill request
    setAttachmentIds(request);
    setAttachmentFilenames(request);
    setAttachmentTypes(request);
    setAttachmenCreatedComments(request);
    setAttachmentCheckStatus(request);
    setAttachmentCheckComment(request);
    // run tests
    Set<Attachment> updatedAttachments = PortletUtils.updateAttachmentsFromRequest(request, documentAttachments);
    assertThat(documentAttachments.size(), is(3));
    assertTrue(updatedAttachments.isEmpty());
}
Also used : PortletRequest(javax.portlet.PortletRequest) TestUserCacheHolder(org.eclipse.sw360.portal.TestUserCacheHolder) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

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