Search in sources :

Example 51 with Attachment

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)));
}
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 52 with Attachment

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&#010;Status: APPROVED by  on &#010;Comment: &#010;Created:  on ", displayDownloadAttachment.getTitleText());
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Example 53 with Attachment

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&lt;&gt;&amp;&#39;&quot;F&#010;Status: APPROVED by AB&lt;&gt;&amp;&#39;&quot;AB on AO&lt;&gt;&amp;&#39;&quot;AO&#010;Comment: CC&lt;&gt;&amp;&#39;&quot;CC&#010;Created: CB&lt;&gt;&amp;&#39;&quot;CB on CO&lt;&gt;&amp;&#39;&quot;CO", displayDownloadAttachment.getTitleText());
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Example 54 with Attachment

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;
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment)

Example 55 with Attachment

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));
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

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