use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment 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.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class DisplayDownloadApprovedClearingReportTest method testTitleTextWithMinimalInformation.
@Test
public void testTitleTextWithMinimalInformation() {
Attachment attachment = createAttachment("test.file");
DisplayDownloadApprovedClearingReport displayDownloadAttachment = new DisplayDownloadApprovedClearingReport();
displayDownloadAttachment.setAttachment(attachment);
assertEquals("Filename: test.file
Status: APPROVED by on 
Comment: 
Created: on ", displayDownloadAttachment.getTitleText());
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class DisplayDownloadApprovedClearingReportTest method testThatFieldsAreEscapedForTitle.
@Test
public void testThatFieldsAreEscapedForTitle() {
Attachment attachment = createAttachment("F<>&'\"F");
attachment.setCheckedBy("AB<>&'\"AB");
attachment.setCheckedOn("AO<>&'\"AO");
attachment.setCheckedComment("CC<>&'\"CC");
attachment.setCreatedBy("CB<>&'\"CB");
attachment.setCreatedOn("CO<>&'\"CO");
attachment.setCheckStatus(CheckStatus.ACCEPTED);
DisplayDownloadApprovedClearingReport displayDownloadAttachment = new DisplayDownloadApprovedClearingReport();
displayDownloadAttachment.setAttachment(attachment);
assertEquals("Filename: F<>&'"F
Status: APPROVED by AB<>&'"AB on AO<>&'"AO
Comment: CC<>&'"CC
Created: CB<>&'"CB on CO<>&'"CO", displayDownloadAttachment.getTitleText());
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class ComponentImportUtils method removeAutogeneratedAttachments.
private static HashSet<Attachment> removeAutogeneratedAttachments(AttachmentService.Iface attachmentClient, /*read value*/
Attachment attachment, /*read value*/
Release release) throws /*return value*/
TException {
final HashSet<Attachment> attachmentsToRemove = new HashSet<>();
if (release.isSetAttachments()) {
final AttachmentContent attachmentContent = attachmentClient.getAttachmentContent(attachment.getAttachmentContentId());
final Set<Attachment> attachments = release.getAttachments();
if (attachmentContent.isSetRemoteUrl()) {
for (Attachment existentAttachment : attachments) {
final AttachmentContent existentAttachmentContent = attachmentClient.getAttachmentContent(existentAttachment.getAttachmentContentId());
if (existentAttachmentContent.isSetRemoteUrl()) {
if (existentAttachmentContent.getRemoteUrl().equals(attachmentContent.getRemoteUrl())) {
attachmentsToRemove.add(existentAttachment);
}
}
}
// This changes the release and this is actually used.
attachments.removeAll(attachmentsToRemove);
}
}
return attachmentsToRemove;
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class ComponentImportUtilsTest method assertExpectedComponentsInDb.
private void assertExpectedComponentsInDb() throws TException {
List<Component> importedComponents = componentClient.getComponentSummary(user);
List<Release> importedReleases = componentClient.getReleaseSummary(user);
// see the test file
assertThat(importedComponents, hasSize(7));
// see the test file
assertThat(importedReleases, hasSize(8));
sortByField(importedComponents, Component._Fields.NAME);
sortByField(importedReleases, Release._Fields.VERSION);
sortByField(importedReleases, Release._Fields.NAME);
Component component = importedComponents.get(0);
assertThat(component.getName(), is("7-Zip"));
component = componentClient.getComponentById(component.getId(), user);
assertThat(component.getName(), is("7-Zip"));
assertThat(component.getHomepage(), is("http://commons.apache.org/proper/commons-exec"));
assertThat(component.getVendorNames(), is(emptyOrNullCollectionOf(String.class)));
assertThat(component.getAttachments(), is(emptyOrNullCollectionOf(Attachment.class)));
assertThat(component.getCreatedBy(), equalTo(user.getEmail()));
assertThat(component.getReleases(), is(not(nullValue())));
assertThat(getReleaseIds(component.getReleases()), containsInAnyOrder(importedReleases.get(0).getId(), importedReleases.get(1).getId()));
final Release release = importedReleases.get(4);
assertThat(release.getVersion(), is("1.2.11"));
// This release has an download url so the import creates an attachmen
final Set<Attachment> attachments = release.getAttachments();
assertThat(attachments.size(), is(1));
final Attachment theAttachment = getFirst(attachments);
final String attachmentContentId = theAttachment.getAttachmentContentId();
final AttachmentContent attachmentContent = attachmentClient.getAttachmentContent(attachmentContentId);
assertThat(attachmentContent.isOnlyRemote(), is(true));
assertThat(attachmentContent.getRemoteUrl(), is(REMOTE_URL));
}
Aggregations