use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent in project sw360portal by sw360.
the class SPDXParserTools method getLicenseInfoFromSpdx.
protected static LicenseInfoParsingResult getLicenseInfoFromSpdx(AttachmentContent attachmentContent, SpdxDocument doc) {
LicenseInfo licenseInfo = new LicenseInfo().setFilenames(Arrays.asList(attachmentContent.getFilename()));
licenseInfo.setLicenseNamesWithTexts(new HashSet<>());
licenseInfo.setCopyrights(new HashSet<>());
try {
for (SpdxItem spdxItem : doc.getDocumentDescribes()) {
licenseInfo.getLicenseNamesWithTexts().addAll(getAllLicenseTexts(spdxItem, true).collect(Collectors.toSet()));
licenseInfo.getCopyrights().addAll(getAllCopyrights(spdxItem).collect(Collectors.toSet()));
}
} catch (UncheckedInvalidSPDXAnalysisException e) {
return new LicenseInfoParsingResult().setStatus(LicenseInfoRequestStatus.FAILURE).setMessage(e.getInvalidSPDXAnalysisExceptionCause().getMessage());
} catch (InvalidSPDXAnalysisException e) {
return new LicenseInfoParsingResult().setStatus(LicenseInfoRequestStatus.FAILURE).setMessage(e.getMessage());
}
return new LicenseInfoParsingResult().setLicenseInfo(licenseInfo).setStatus(LicenseInfoRequestStatus.SUCCESS);
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent in project sw360portal by sw360.
the class CombinedCLIParserTest method testIsApplicableToFailsOnIncorrectRootElement.
@Test
public void testIsApplicableToFailsOnIncorrectRootElement() throws Exception {
AttachmentContent content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml");
when(connector.getAttachmentStream(content, new User(), new Project())).thenReturn(new ReaderInputStream(new StringReader("<wrong-root/>")));
assertFalse(parser.isApplicableTo(attachment, new User(), new Project()));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent in project sw360portal by sw360.
the class CombinedCLIParserTest method setUp.
@Before
public void setUp() throws Exception {
cliTestfile = IOUtils.toString(makeAttachmentContentStream(TEST_XML_FILENAME));
attachment = new Attachment("A1", "a.xml").setAttachmentType(AttachmentType.COMPONENT_LICENSE_INFO_COMBINED);
content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml");
parser = spy(new CombinedCLIParser(connector, attachment -> content, componentDatabaseHandler));
doReturn("external-correlation-id").when(parser).getCorrelationKey();
Release r1 = new Release().setId("id1").setName("r1").setVersion("1.0").setVendor(new Vendor().setFullname("VendorA Fullname").setShortname("VendorA")).setExternalIds(ImmutableMap.of(parser.getCorrelationKey(), "1234"));
Release r2 = new Release().setId("id2").setName("r2").setVersion("2.0").setVendor(new Vendor().setFullname("VendorB Fullname").setShortname("VendorB")).setExternalIds(ImmutableMap.of(parser.getCorrelationKey(), "4321"));
Release r3 = new Release().setId("id3").setName("r3").setVersion("3.0").setVendor(new Vendor().setFullname("VendorC Fullname").setShortname("VendorC"));
Release r4 = new Release().setId("id4").setName("r4").setVersion("4.0").setVendor(new Vendor().setFullname("VendorD Fullname").setShortname("VendorD")).setExternalIds(ImmutableMap.of("some_external_id", "1234"));
when(componentDatabaseHandler.getAllReleasesIdMap()).thenReturn(ImmutableMap.of(r1.getId(), r1, r2.getId(), r2, r3.getId(), r3, r4.getId(), r4));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent in project sw360portal by sw360.
the class SPDXParserTest method testAddSPDXContentToCLI.
@Test
@UseDataProvider("dataProviderAdd")
public void testAddSPDXContentToCLI(String exampleFile, List<String> expectedLicenses, int numberOfCoyprights, String exampleCopyright) throws Exception {
AttachmentContent attachmentContent = new AttachmentContent().setFilename(exampleFile);
InputStream input = makeAttachmentContentStream(exampleFile);
SpdxDocument spdxDocument = SPDXDocumentFactory.createSpdxDocument(input, parser.getUriOfAttachment(attachmentContentStore.get(exampleFile)), FILETYPE_SPDX_INTERNAL);
LicenseInfoParsingResult result = SPDXParserTools.getLicenseInfoFromSpdx(attachmentContent, spdxDocument);
assertIsResultOfExample(result.getLicenseInfo(), exampleFile, expectedLicenses, numberOfCoyprights, exampleCopyright);
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent 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));
}
Aggregations