Search in sources :

Example 1 with ProjectDatabaseHandler

use of org.eclipse.sw360.datahandler.db.ProjectDatabaseHandler 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 ProjectDatabaseHandler

use of org.eclipse.sw360.datahandler.db.ProjectDatabaseHandler 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 ProjectDatabaseHandler

use of org.eclipse.sw360.datahandler.db.ProjectDatabaseHandler 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)2 ComponentDatabaseHandler (org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler)2 ProjectDatabaseHandler (org.eclipse.sw360.datahandler.db.ProjectDatabaseHandler)2 Component (org.eclipse.sw360.datahandler.thrift.components.Component)2 Release (org.eclipse.sw360.datahandler.thrift.components.Release)2 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)2 Before (org.junit.Before)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 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)1 Test (org.junit.Test)1