Search in sources :

Example 1 with ComponentDatabaseHandler

use of org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler in project sw360portal by sw360.

the class ProjectDatabaseHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    assertTestString(dbName);
    assertTestString(attachmentsDbName);
    vendors = new ArrayList<>();
    vendors.add(new Vendor().setId("V1").setShortname("vendor").setFullname("vendor").setUrl("http://vendor.example.com"));
    releases = new ArrayList<>();
    Release release1a = new Release().setId("R1A").setComponentId("C1").setName("component1").setVersion("releaseA").setVendorId("V1");
    releases.add(release1a);
    Release release1b = new Release().setId("R1B").setComponentId("C1").setName("component1").setVersion("releaseB").setVendorId("V1");
    releases.add(release1b);
    Release release2a = new Release().setId("R2A").setComponentId("C2").setName("component2").setVersion("releaseA").setVendorId("V1");
    releases.add(release2a);
    Release release2b = new Release().setId("R2B").setComponentId("C2").setName("component2").setVersion("releaseB").setVendorId("V1");
    releases.add(release2b);
    components = new ArrayList<>();
    Component component1 = new Component().setId("C1").setName("component1").setDescription("d1").setComponentType(ComponentType.OSS);
    components.add(component1);
    Component component2 = new Component().setId("C2").setName("component2").setDescription("d2").setComponentType(ComponentType.COTS);
    components.add(component2);
    projects = new ArrayList<>();
    Project project1 = new Project().setId("P1").setName("project1").setLinkedProjects(ImmutableMap.of("P2", ProjectRelationship.CONTAINED)).setVisbility(Visibility.EVERYONE);
    projects.add(project1);
    Project project2 = new Project().setId("P2").setName("project2").setLinkedProjects(ImmutableMap.of("P3", ProjectRelationship.REFERRED, "P4", ProjectRelationship.CONTAINED)).setReleaseIdToUsage(ImmutableMap.of("R1A", newDefaultProjectReleaseRelationship(), "R1B", newDefaultProjectReleaseRelationship())).setVisbility(Visibility.EVERYONE);
    projects.add(project2);
    Project project3 = new Project().setId("P3").setName("project3").setLinkedProjects(ImmutableMap.of("P2", ProjectRelationship.UNKNOWN)).setReleaseIdToUsage(ImmutableMap.of("R2A", newDefaultProjectReleaseRelationship(), "R2B", newDefaultProjectReleaseRelationship())).setVisbility(Visibility.EVERYONE);
    projects.add(project3);
    Project project4 = new Project().setId("P4").setName("project4").setLinkedProjects(ImmutableMap.of("P1", ProjectRelationship.UNKNOWN)).setVisbility(Visibility.EVERYONE);
    projects.add(project4);
    Project project5 = new Project().setId("P5").setName("project5").setLinkedProjects(ImmutableMap.of("P6", ProjectRelationship.CONTAINED, "P7", ProjectRelationship.CONTAINED)).setVisbility(Visibility.EVERYONE);
    projects.add(project5);
    Project project6 = new Project().setId("P6").setName("project6").setLinkedProjects(ImmutableMap.of("P7", ProjectRelationship.CONTAINED)).setVisbility(Visibility.EVERYONE);
    projects.add(project6);
    Project project7 = new Project().setId("P7").setName("project7").setVisbility(Visibility.EVERYONE);
    projects.add(project7);
    // Create the database
    TestUtils.createDatabase(DatabaseSettings.getConfiguredHttpClient(), dbName);
    // Prepare the database
    DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), dbName);
    for (Vendor vendor : vendors) {
        databaseConnector.add(vendor);
    }
    for (Release release : releases) {
        databaseConnector.add(release);
    }
    for (Component component : components) {
        databaseConnector.add(component);
    }
    for (Project project : projects) {
        databaseConnector.add(project);
    }
    ComponentDatabaseHandler componentHandler = new ComponentDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentsDbName);
    handler = new ProjectDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentsDbName, moderator, componentHandler);
}
Also used : DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) ComponentDatabaseHandler(org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler) ProjectDatabaseHandler(org.eclipse.sw360.datahandler.db.ProjectDatabaseHandler) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Before(org.junit.Before)

Example 2 with ComponentDatabaseHandler

use of org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler in project sw360portal by sw360.

the class ProjectDatabaseHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    assertTestString(dbName);
    assertTestString(attachmentsDbName);
    List<Project> projects = new ArrayList<>();
    Project p1 = new Project().setId("P1").setName("Project1").setBusinessUnit("AB CD EF").setCreatedBy("user1").setReleaseIdToUsage(ImmutableMap.<String, ProjectReleaseRelationship>builder().put("r1", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r2", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r3", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r4", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r5", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r6", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).build());
    projects.add(p1);
    Project p2 = new Project().setId("P2").setName("Project2").setBusinessUnit("AB CD FE").setCreatedBy("user2").setReleaseIdToUsage(ImmutableMap.<String, ProjectReleaseRelationship>builder().put("r1", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r2", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r3", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).build());
    projects.add(p2);
    projects.get(1).addToContributors("user1");
    projects.add(new Project().setId("P3").setName("Project3").setBusinessUnit("AB CD EF").setCreatedBy("user3"));
    Project p4 = new Project().setId("P4").setName("Project4").setBusinessUnit("AB CD EF").setCreatedBy("user1").setVisbility(Visibility.PRIVATE).setReleaseIdToUsage(ImmutableMap.<String, ProjectReleaseRelationship>builder().put("r1", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r2", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).build()).setLinkedProjects(ImmutableMap.<String, ProjectRelationship>builder().put("P5", ProjectRelationship.CONTAINED).build());
    projects.add(p4);
    projects.add(new Project().setId("P5").setName("Project5").setBusinessUnit("AB CD EF").setCreatedBy("user1"));
    List<Release> releases = new ArrayList<>();
    releases.add(new Release().setId("r1").setComponentId("c1"));
    releases.add(new Release().setId("r2").setComponentId("c1"));
    releases.add(new Release().setId("r3").setComponentId("c1"));
    releases.add(new Release().setId("r4").setComponentId("c1"));
    releases.add(new Release().setId("r5").setComponentId("c1"));
    releases.add(new Release().setId("r6").setComponentId("c1"));
    // Create the database
    TestUtils.createDatabase(DatabaseSettings.getConfiguredHttpClient(), dbName);
    // Prepare the database
    DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), dbName);
    for (Project project : projects) {
        databaseConnector.add(project);
    }
    for (Release r : releases) {
        databaseConnector.add(r);
    }
    databaseConnector.add(new Component("comp1").setId("c1"));
    componentHandler = new ComponentDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentsDbName);
    handler = new ProjectDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentDbName, moderator, componentHandler);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) TestUtils.assertTestString(org.eclipse.sw360.datahandler.TestUtils.assertTestString) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Before(org.junit.Before)

Example 3 with ComponentDatabaseHandler

use of org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler in project sw360portal by sw360.

the class ComponentDatabaseHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    assertTestString(dbName);
    assertTestString(attachmentsDbName);
    // Set up vendors
    vendors = new HashMap<>();
    vendors.put("V1", new Vendor().setId("V1").setShortname("Microsoft").setFullname("Microsoft Corporation").setUrl("http://www.microsoft.com"));
    vendors.put("V2", new Vendor().setId("V2").setShortname("Apache").setFullname("The Apache Software Foundation").setUrl("http://www.apache.org"));
    vendors.put("V3", new Vendor().setId("V3").setShortname("Oracle").setFullname("Oracle Corporation Inc").setUrl("http://www.oracle.com"));
    components = new ArrayList<>();
    Component component1 = new Component().setId("C1").setName("component1").setDescription("d1").setCreatedBy(email1).setMainLicenseIds(new HashSet<>(Arrays.asList("lic1"))).setCreatedOn("2017-07-20");
    component1.addToReleaseIds("R1A");
    component1.addToReleaseIds("R1B");
    components.add(component1);
    Component component2 = new Component().setId("C2").setName("component2").setDescription("d2").setCreatedBy(email2).setMainLicenseIds(new HashSet<>(Arrays.asList("lic2"))).setCreatedOn("2017-07-21");
    component2.addToReleaseIds("R2A");
    component2.addToReleaseIds("R2B");
    component2.addToReleaseIds("R2C");
    components.add(component2);
    Component component3 = new Component().setId("C3").setName("component3").setDescription("d3").setCreatedBy(email1).setMainLicenseIds(new HashSet<>(Arrays.asList("lic3"))).setCreatedOn("2017-07-22");
    component3.addToSubscribers(email1);
    component3.addToLanguages("E");
    components.add(component3);
    releases = new ArrayList<>();
    Release release1a = new Release().setId("R1A").setComponentId("C1").setName("component1").setVersion("releaseA").setCreatedBy(email1).setVendorId("V1");
    releases.add(release1a);
    Release release1b = new Release().setId("R1B").setComponentId("C1").setName("component1").setVersion("releaseB").setCreatedBy(email2).setVendorId("V2");
    release1b.setEccInformation(new EccInformation().setAL("AL"));
    release1b.addToSubscribers(email1);
    releases.add(release1b);
    Release release2a = new Release().setId("R2A").setComponentId("C2").setName("component2").setVersion("releaseA").setCreatedBy(email1).setVendorId("V3");
    releases.add(release2a);
    Release release2b = new Release().setId("R2B").setComponentId("C2").setName("component2").setVersion("releaseB").setCreatedBy(email2).setVendorId("V1");
    releases.add(release2b);
    release2b.addToSubscribers(email2);
    Release release2c = new Release().setId("R2C").setComponentId("C2").setName("component2").setVersion("releaseC").setCreatedBy(email1).setVendorId("V2");
    releases.add(release2c);
    // Create the database
    TestUtils.createDatabase(DatabaseSettings.getConfiguredHttpClient(), dbName);
    // Prepare the database
    DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), dbName);
    for (Vendor vendor : vendors.values()) {
        databaseConnector.add(vendor);
    }
    for (Component component : components) {
        databaseConnector.add(component);
    }
    for (Release release : releases) {
        databaseConnector.add(release);
    }
    componentMap = ThriftUtils.getIdMap(components);
    releaseMap = ThriftUtils.getIdMap(releases);
    // Prepare the handler
    handler = new ComponentDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentsDbName, moderator, releaseModerator);
}
Also used : DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) ComponentDatabaseHandler(org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor)

Example 4 with ComponentDatabaseHandler

use of org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler 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));
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Before(org.junit.Before)

Example 5 with ComponentDatabaseHandler

use of org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler in project sw360portal by sw360.

the class ProjectHandlerTest method testUpdateProject2_1.

@Test
public void testUpdateProject2_1() throws Exception {
    ProjectModerator moderator = Mockito.mock(ProjectModerator.class);
    ProjectDatabaseHandler handler = new ProjectDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentDbName, moderator, new ComponentDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentDbName));
    Project project2 = handler.getProjectById("P2", user1);
    project2.setName("Project2new");
    Mockito.doReturn(RequestStatus.SENT_TO_MODERATOR).when(moderator).updateProject(project2, user1);
    RequestStatus status = handler.updateProject(project2, user1);
    // Now contributors can also change the project
    assertEquals(RequestStatus.SUCCESS, status);
// assertEquals(RequestStatus.SENT_TO_MODERATOR, status);
// assertEquals("Project2", handler.getProjectById("P2", user1).getName());
// Mockito.verify(moderator, times(1)).updateProject(project2, user1.getEmail());
// Mockito.verifyNoMoreInteractions(moderator);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ProjectModerator(org.eclipse.sw360.datahandler.entitlement.ProjectModerator) ProjectDatabaseHandler(org.eclipse.sw360.datahandler.db.ProjectDatabaseHandler) ComponentDatabaseHandler(org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) Test(org.junit.Test)

Aggregations

DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)3 ComponentDatabaseHandler (org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler)3 Release (org.eclipse.sw360.datahandler.thrift.components.Release)3 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)3 Before (org.junit.Before)3 ProjectDatabaseHandler (org.eclipse.sw360.datahandler.db.ProjectDatabaseHandler)2 Component (org.eclipse.sw360.datahandler.thrift.components.Component)2 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)2 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)1 ProjectModerator (org.eclipse.sw360.datahandler.entitlement.ProjectModerator)1 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)1 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)1 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)1 Test (org.junit.Test)1