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(""));
}
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"));
}
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"));
}
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[] {}));
}
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());
}
Aggregations