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