use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class SPDXParserTest method testGetLicenseInfo.
@Test
@UseDataProvider("dataProviderAdd")
public void testGetLicenseInfo(String exampleFile, List<String> expectedLicenses, int numberOfCoyprights, String exampleCopyright) throws Exception {
Attachment attachment = makeAttachment(exampleFile, Arrays.stream(AttachmentType.values()).filter(SW360Constants.LICENSE_INFO_ATTACHMENT_TYPES::contains).findAny().get());
LicenseInfoParsingResult result = parser.getLicenseInfos(attachment, dummyUser, new Project().setVisbility(Visibility.ME_AND_MODERATORS).setCreatedBy(dummyUser.getEmail()).setAttachments(Collections.singleton(new Attachment().setAttachmentContentId(attachment.getAttachmentContentId())))).stream().findFirst().orElseThrow(() -> new RuntimeException("Parser returned empty LisenceInfoParsingResult list"));
assertLicenseInfoParsingResult(result);
assertIsResultOfExample(result.getLicenseInfo(), exampleFile, expectedLicenses, numberOfCoyprights, exampleCopyright);
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project 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.projects.Project 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()));
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project 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"));
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class DatabaseTestSetup method main.
public static void main(String[] args) throws MalformedURLException {
DatabaseConnector db = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), DatabaseSettings.COUCH_DB_DATABASE);
Project project = new Project().setName("Test Project");
project.addToModerators("user1");
db.add(project);
ModerationRequest moderationRequest = new ModerationRequest();
moderationRequest.setDocumentId(project.id).setDocumentType(DocumentType.PROJECT);
moderationRequest.setRequestingUser("cedric.bodet@tngtech.com");
moderationRequest.addToModerators("cedric.bodet@tngtech.com");
db.add(moderationRequest);
}
Aggregations