Search in sources :

Example 6 with TestUserCacheHolder

use of org.eclipse.sw360.portal.TestUserCacheHolder in project sw360portal by sw360.

the class PortletUtilsTest method testUpdateAttachmentsFromRequestOneArrayIsNull.

@Test
public void testUpdateAttachmentsFromRequestOneArrayIsNull() {
    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");
    // run test
    Set<Attachment> updatedAttachments = PortletUtils.updateAttachmentsFromRequest(request, documentAttachments);
    assertTrue(updatedAttachments.isEmpty());
    assertThat(updatedAttachments, is(sameInstance(documentAttachments)));
}
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 7 with TestUserCacheHolder

use of org.eclipse.sw360.portal.TestUserCacheHolder in project sw360portal by sw360.

the class PortletUtilsTest method testUpdateAttachmentsFromRequestUpdateOnly.

@Test
public void testUpdateAttachmentsFromRequestUpdateOnly() {
    PortletRequest request = Mockito.mock(PortletRequest.class);
    // fill existing data
    User user = createUser("tid", "test@example.org", "tpd");
    new TestUserCacheHolder().enable(user);
    Set<Attachment> documentAttachments = createAttachments(user, "1", "2", "3");
    // fill request
    new TestUserCacheHolder().enable(createUser("cid", "check@example.org", "cpd"));
    setAttachmentIds(request, "1", "2", "3");
    setAttachmentFilenames(request, "A", "B", "C");
    setAttachmentTypes(request, AttachmentType.DOCUMENT, AttachmentType.SOURCE, AttachmentType.DESIGN);
    setAttachmenCreatedComments(request, "CC1", "CC2", "CC3");
    setAttachmentCheckStatus(request, CheckStatus.NOTCHECKED, CheckStatus.ACCEPTED, CheckStatus.ACCEPTED);
    setAttachmentCheckComment(request, "", "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"));
    assertThat(updatedAttachments.stream().map(Attachment::getFilename).collect(Collectors.toList()), containsInAnyOrder("file1", "file2", "file3"));
    assertThat(updatedAttachments.stream().map(Attachment::getAttachmentType).collect(Collectors.toList()), containsInAnyOrder(AttachmentType.DOCUMENT, AttachmentType.SOURCE, AttachmentType.DESIGN));
    assertThat(updatedAttachments.stream().map(Attachment::getCreatedBy).collect(Collectors.toList()), containsInAnyOrder("test@example.org", "test@example.org", "test@example.org"));
    assertThat(updatedAttachments.stream().map(Attachment::getCreatedTeam).collect(Collectors.toList()), containsInAnyOrder("tpd", "tpd", "tpd"));
    assertThat(updatedAttachments.stream().map(Attachment::getCreatedComment).collect(Collectors.toList()), containsInAnyOrder("CC1", "CC2", "CC3"));
    assertThat(updatedAttachments.stream().map(Attachment::getCheckStatus).collect(Collectors.toList()), containsInAnyOrder(CheckStatus.NOTCHECKED, CheckStatus.ACCEPTED, CheckStatus.ACCEPTED));
    assertThat(updatedAttachments.stream().map(Attachment::getCheckedBy).collect(Collectors.toList()), containsInAnyOrder(null, "check@example.org", "check@example.org"));
    assertThat(updatedAttachments.stream().map(Attachment::getCheckedTeam).collect(Collectors.toList()), containsInAnyOrder(null, "cpd", "cpd"));
    assertThat(updatedAttachments.stream().map(Attachment::getCheckedComment).collect(Collectors.toList()), containsInAnyOrder("", "CCK2", "CCK3"));
}
Also used : PortletRequest(javax.portlet.PortletRequest) User(org.eclipse.sw360.datahandler.thrift.users.User) TestUserCacheHolder(org.eclipse.sw360.portal.TestUserCacheHolder) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Example 8 with TestUserCacheHolder

use of org.eclipse.sw360.portal.TestUserCacheHolder 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 9 with TestUserCacheHolder

use of org.eclipse.sw360.portal.TestUserCacheHolder 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)

Aggregations

PortletRequest (javax.portlet.PortletRequest)9 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)9 TestUserCacheHolder (org.eclipse.sw360.portal.TestUserCacheHolder)9 Test (org.junit.Test)9 User (org.eclipse.sw360.datahandler.thrift.users.User)1