use of org.eclipse.sw360.portal.TestUserCacheHolder 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"));
}
use of org.eclipse.sw360.portal.TestUserCacheHolder 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"));
}
use of org.eclipse.sw360.portal.TestUserCacheHolder 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());
}
use of org.eclipse.sw360.portal.TestUserCacheHolder in project sw360portal by sw360.
the class PortletUtilsTest method testUpdateAttachmentsFromRequestOneArrayHasDifferentLength.
@Test
public void testUpdateAttachmentsFromRequestOneArrayHasDifferentLength() {
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 data
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");
// run test
Set<Attachment> updatedAttachments = PortletUtils.updateAttachmentsFromRequest(request, documentAttachments);
assertTrue(updatedAttachments.isEmpty());
assertThat(updatedAttachments, is(sameInstance(documentAttachments)));
}
use of org.eclipse.sw360.portal.TestUserCacheHolder in project sw360portal by sw360.
the class PortletUtilsTest method testUpdateAttachmentsFromRequestIdsAreEmpty.
@Test
public void testUpdateAttachmentsFromRequestIdsAreEmpty() {
PortletRequest request = Mockito.mock(PortletRequest.class);
new TestUserCacheHolder().enable();
// existing data
// use immutable set to ensure that set is not changed.
Set<Attachment> documentAttachments = ImmutableSet.of();
// fill request
setAttachmentIds(request);
// run test
assertThat(PortletUtils.updateAttachmentsFromRequest(request, documentAttachments), is(empty()));
}
Aggregations