Search in sources :

Example 76 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class FossologyUploaderTest method testUploadToFossologyWithNonIntReturn.

@Test
public void testUploadToFossologyWithNonIntReturn() throws Exception {
    AttachmentContent attachment = mock(AttachmentContent.class);
    when(attachment.getId()).thenReturn("id");
    when(attachment.getFilename()).thenReturn("fileName");
    String clearingTeam = "cl";
    final InputStream inputStream = mock(InputStream.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            OutputStream outputStream = (OutputStream) invocation.getArguments()[2];
            outputStream.write("uploadId=60000000000000000".getBytes());
            return 0;
        }
    }).when(sshConnector).runInFossologyViaSsh(anyString(), eq(inputStream), any(OutputStream.class));
    final long uploadId = fossologyUploader.uploadToFossology(inputStream, attachment, clearingTeam);
    verify(sshConnector).runInFossologyViaSsh(anyString(), eq(inputStream), any(OutputStream.class));
    assertThat(uploadId, is((long) -1));
}
Also used : Answer(org.mockito.stubbing.Answer) InputStream(java.io.InputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) OutputStream(java.io.OutputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Test(org.junit.Test)

Example 77 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class FossologyUploaderTest method testUploadToFossology.

@Test
public void testUploadToFossology() throws Exception {
    AttachmentContent attachment = mock(AttachmentContent.class);
    when(attachment.getId()).thenReturn("id");
    when(attachment.getFilename()).thenReturn("fileName");
    String clearingTeam = "cl";
    final InputStream inputStream = mock(InputStream.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            final Object[] arguments = invocation.getArguments();
            String command = (String) arguments[0];
            InputStream input = (InputStream) arguments[1];
            OutputStream outputStream = (OutputStream) arguments[2];
            assertThat(input, sameInstance(inputStream));
            assertThat(command, is("./uploadFromSW360 -i 'id' -g 'cl' -f 'fileName'"));
            outputStream.write("uploadId=60".getBytes());
            return 0;
        }
    }).when(sshConnector).runInFossologyViaSsh(anyString(), eq(inputStream), any(OutputStream.class));
    final long uploadId = fossologyUploader.uploadToFossology(inputStream, attachment, clearingTeam);
    verify(sshConnector).runInFossologyViaSsh(anyString(), eq(inputStream), any(OutputStream.class));
    assertThat(uploadId, is((long) 60));
}
Also used : Answer(org.mockito.stubbing.Answer) InputStream(java.io.InputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) OutputStream(java.io.OutputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Test(org.junit.Test)

Example 78 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class FossologyFileHandlerTest method getMockFilledAttachment.

private static FilledAttachment getMockFilledAttachment(String attachmentContentId) {
    final FilledAttachment filledAttachment = mock(FilledAttachment.class);
    final Attachment attachment = mock(Attachment.class);
    when(filledAttachment.getAttachment()).thenReturn(attachment);
    final AttachmentContent attachmentContent = mock(AttachmentContent.class);
    when(filledAttachment.getAttachmentContent()).thenReturn(attachmentContent);
    when(attachment.getAttachmentContentId()).thenReturn(attachmentContentId);
    when(attachmentContent.getId()).thenReturn(attachmentContentId);
    return filledAttachment;
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment)

Example 79 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class CLIParserTest method testGetCLI.

@Test
public void testGetCLI() throws Exception {
    Attachment cliAttachment = new Attachment("A1", "a.xml");
    when(connector.getAttachmentStream(anyObject(), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader(CLI_TESTFILE)));
    LicenseInfoParsingResult res = parser.getLicenseInfos(cliAttachment, new User(), new Project()).stream().findFirst().orElseThrow(() -> new RuntimeException("Parser returned empty LisenceInfoParsingResult list"));
    assertLicenseInfoParsingResult(res);
    assertThat(res.getStatus(), is(LicenseInfoRequestStatus.SUCCESS));
    assertThat(res.getLicenseInfo(), notNullValue());
    assertThat(res.getLicenseInfo().getFilenames(), contains("a.xml"));
    assertThat(res.getLicenseInfo().getLicenseNamesWithTexts().size(), is(1));
    assertThat(res.getLicenseInfo().getLicenseNamesWithTexts().stream().map(LicenseNameWithText::getLicenseText).collect(Collectors.toSet()), containsInAnyOrder("jQuery projects are released under the terms of the MIT license."));
    assertThat(res.getLicenseInfo().getCopyrights().size(), is(2));
    assertThat(res.getLicenseInfo().getCopyrights(), containsInAnyOrder("Copyrights", "(c) jQuery Foundation, Inc. | jquery.org"));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) User(org.eclipse.sw360.datahandler.thrift.users.User) LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText) StringReader(java.io.StringReader) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) LicenseInfoParsingResult(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult) TestHelper.assertLicenseInfoParsingResult(org.eclipse.sw360.licenseinfo.TestHelper.assertLicenseInfoParsingResult) Test(org.junit.Test)

Example 80 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class CLIParserTest method testIsApplicableToFailsOnIncorrectRootElement.

@Test
public void testIsApplicableToFailsOnIncorrectRootElement() throws Exception {
    AttachmentContent content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml");
    when(connector.getAttachmentStream(eq(content), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader("<wrong-root/>")));
    assertFalse(parser.isApplicableTo(attachment, new User(), new Project()));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) User(org.eclipse.sw360.datahandler.thrift.users.User) StringReader(java.io.StringReader) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Test(org.junit.Test)

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