Search in sources :

Example 86 with Release

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

the class ComponentDatabaseHandlerTest method testDontDeleteUsedComponent.

@Test
public void testDontDeleteUsedComponent() throws Exception {
    final Release r1A = handler.getRelease("R1A", user1);
    r1A.setReleaseIdToRelationship(ImmutableMap.of("R2A", ReleaseRelationship.CONTAINED));
    handler.updateRelease(r1A, user1, ThriftUtils.IMMUTABLE_OF_RELEASE);
    RequestStatus status = handler.deleteComponent("C2", user1);
    assertEquals(RequestStatus.IN_USE, status);
    List<Component> componentSummary = handler.getComponentSummary(user1);
    assertEquals(3, componentSummary.size());
    assertTrue("Component not deleted", componentsContain(componentSummary, "C2"));
}
Also used : RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 87 with Release

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

the class ComponentDatabaseHandlerTest method testDuplicateReleaseNotAdded.

@Test
public void testDuplicateReleaseNotAdded() throws Exception {
    String originalReleaseId = "R1A";
    final Release tmp = handler.getRelease(originalReleaseId, user1);
    tmp.unsetId();
    tmp.unsetRevision();
    String newReleaseId = handler.addRelease(tmp, email1).getId();
    final Map<String, List<String>> duplicateReleases = handler.getDuplicateReleases();
    assertThat(newReleaseId, isEmptyOrNullString());
    assertThat(duplicateReleases.size(), is(0));
}
Also used : TestUtils.assertTestString(org.eclipse.sw360.datahandler.TestUtils.assertTestString)

Example 88 with Release

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

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

use of org.eclipse.sw360.datahandler.thrift.components.Release 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)

Aggregations

Release (org.eclipse.sw360.datahandler.thrift.components.Release)93 User (org.eclipse.sw360.datahandler.thrift.users.User)39 TException (org.apache.thrift.TException)34 Test (org.junit.Test)22 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)20 Component (org.eclipse.sw360.datahandler.thrift.components.Component)18 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)15 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)13 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)13 FossologyStatus (org.eclipse.sw360.datahandler.thrift.components.FossologyStatus)11 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)10 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)9 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)9 HalResource (org.eclipse.sw360.rest.resourceserver.core.HalResource)7 Before (org.junit.Before)7 Collectors (java.util.stream.Collectors)6 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)6 FilledAttachment (org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment)6 IOException (java.io.IOException)5 java.util (java.util)5