Search in sources :

Example 46 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.

the class ComponentDatabaseHandlerTest method testAddComponent.

@Test
public void testAddComponent() throws Exception {
    Component expected = new Component().setName("NEW_CLEARING");
    Release release = new Release().setName("REL").setVersion("VER");
    expected.addToReleases(release);
    String id = handler.addComponent(expected, "new@mail.com").getId();
    assertNotNull(id);
    Component actual = handler.getComponent(id, user1);
    // Check that object was added correctly
    assertEquals(expected.getName(), actual.getName());
    assertEquals("new@mail.com", actual.getCreatedBy());
    // Releases are not included!
    assertEquals(0, actual.getReleasesSize());
}
Also used : TestUtils.assertTestString(org.eclipse.sw360.datahandler.TestUtils.assertTestString)

Example 47 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.

the class ComponentDatabaseHandlerTest method testUpdateInconsistentComponent.

@Test
public void testUpdateInconsistentComponent() throws Exception {
    // Make some changes in the component
    Component expected = components.get(0);
    expected.unsetReleases();
    expected.unsetReleaseIds();
    List<Release> tmpReleases = new ArrayList<>();
    tmpReleases.add(releases.get(0));
    tmpReleases.add(releases.get(1));
    Set<String> tmpReleaseIds = new HashSet<>();
    tmpReleaseIds.add(tmpReleases.get(0).getId());
    tmpReleaseIds.add(tmpReleases.get(1).getId());
    expected.setName("UPDATE");
    expected.setReleaseIds(tmpReleaseIds);
    expected.setReleases(tmpReleases);
    RequestStatus status = handler.updateComponent(expected, user1);
    assertThat(RequestStatus.SUCCESS, is(status));
    Component actual = handler.getComponent("C1", user1);
    // Other asserts have been dealt with in testUpdateComponent
    // Check releases
    assertEquals(2, actual.getReleasesSize());
    assertEquals(0, actual.getReleaseIdsSize());
}
Also used : TestUtils.assertTestString(org.eclipse.sw360.datahandler.TestUtils.assertTestString) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 48 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component 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 49 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.

the class ComponentDatabaseHandlerTest method testDeleteReleaseNotModerator.

@Test
public void testDeleteReleaseNotModerator() throws Exception {
    when(releaseModerator.deleteRelease(any(Release.class), eq(user1))).thenReturn(RequestStatus.SENT_TO_MODERATOR);
    RequestStatus status = handler.deleteRelease("R1B", user1);
    assertEquals(RequestStatus.SENT_TO_MODERATOR, status);
    List<Release> releaseSummary = handler.getReleaseSummary();
    assertEquals(5, releaseSummary.size());
    assertTrue("Component NOT deleted", releasesContain(releaseSummary, "R1B"));
    verify(releaseModerator).deleteRelease(any(Release.class), eq(user1));
}
Also used : RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 50 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.

the class ComponentDatabaseHandlerTest method testAddRelease.

@Test
public void testAddRelease() throws Exception {
    Release expected = new Release().setName("REL").setVersion("VER");
    expected.setComponentId("C1");
    String id = handler.addRelease(expected, "new@mail.com").getId();
    assertNotNull(id);
    Release actual = handler.getRelease(id, user1);
    // Check that object was added correctly
    assertEquals(expected.getName(), actual.getName());
    assertEquals(expected.getVersion(), actual.getVersion());
    // Check that the component was also updated
    Component component = handler.getComponent("C1", user1);
    assertTrue(releasesContain(component.getReleases(), id));
}
Also used : TestUtils.assertTestString(org.eclipse.sw360.datahandler.TestUtils.assertTestString)

Aggregations

Component (org.eclipse.sw360.datahandler.thrift.components.Component)38 User (org.eclipse.sw360.datahandler.thrift.users.User)30 TException (org.apache.thrift.TException)23 Release (org.eclipse.sw360.datahandler.thrift.components.Release)23 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)10 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)8 Before (org.junit.Before)7 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)6 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)5 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)5 IOException (java.io.IOException)4 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)4 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)4 Test (org.junit.Test)4 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)3 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)3 FluentIterable (com.google.common.collect.FluentIterable)2 LiferayPortletURL (com.liferay.portal.kernel.portlet.LiferayPortletURL)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2