use of org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult 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.licenseinfo.LicenseInfoParsingResult in project sw360portal by sw360.
the class CLIParserTest method testGetCLIFailsOnMalformedXML.
@Test
public void testGetCLIFailsOnMalformedXML() throws Exception {
Attachment cliAttachment = new Attachment("A1", "a.xml");
when(connector.getAttachmentStream(anyObject(), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader(CLI_TESTFILE.replaceAll("</Content>", "</Broken>"))));
LicenseInfoParsingResult res = parser.getLicenseInfos(cliAttachment, new User(), new Project()).stream().findFirst().orElseThrow(() -> new RuntimeException("Parser returned empty LisenceInfoParsingResult list"));
assertLicenseInfoParsingResult(res, LicenseInfoRequestStatus.FAILURE);
assertThat(res.getStatus(), is(LicenseInfoRequestStatus.FAILURE));
assertThat(res.getLicenseInfo(), notNullValue());
assertThat(res.getLicenseInfo().getFilenames(), contains("a.xml"));
}
Aggregations