use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentDatabaseHandlerTest method testAddReleaseUpdatesMainLicenseIds.
@Test
public void testAddReleaseUpdatesMainLicenseIds() throws Exception {
String componentId = "C4";
{
Component component = new Component().setId(componentId).setName("component4").setDescription("d4").setCreatedBy(email1);
handler.addComponent(component, email1);
}
{
Component component = handler.getComponent(componentId, user1);
assertThat(component.getMainLicenseIds(), is(empty()));
}
String id = addRelease(componentId, ImmutableSet.of("14", "15"));
String id1 = addRelease(componentId, ImmutableSet.of("14", "13"));
{
Component component = handler.getComponent(componentId, user1);
assertThat(component.getMainLicenseIds(), containsInAnyOrder("13", "14", "15"));
}
assertThat(handler.deleteRelease(id, user1), is(RequestStatus.SUCCESS));
{
Component component = handler.getComponent(componentId, user1);
assertThat(component.getMainLicenseIds(), containsInAnyOrder("13", "14"));
}
assertThat(handler.deleteRelease(id1, user1), is(RequestStatus.SUCCESS));
{
Component component = handler.getComponent(componentId, user1);
assertThat(component.getMainLicenseIds(), is(empty()));
}
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentDatabaseHandlerTest method testAddReleaseUpdatesProgrammingLanguagesOperatingSystemsAndVendorNames.
@Test
public void testAddReleaseUpdatesProgrammingLanguagesOperatingSystemsAndVendorNames() throws Exception {
String componentId = "C4";
{
Component component = new Component().setId(componentId).setName("component4").setDescription("d4").setCreatedBy(email1);
handler.addComponent(component, email1);
}
{
Component component = handler.getComponent(componentId, user1);
assertTrue("Check that languages are not initialized", component.languages == null);
assertTrue("Check that operating systems are not initialized", component.operatingSystems == null);
assertTrue("Check that vendor names are not initialized", component.vendorNames == null);
}
Set<String> os = new HashSet<>();
os.add("Linux Ubuntu");
os.add("Linux Mint");
Set<String> lang = new HashSet<>();
lang.add("C");
lang.add("C++");
Release release = new Release().setName("REL").setVersion("VER").setOperatingSystems(os).setLanguages(lang).setVendorId("V1");
release.setComponentId(componentId);
String id = handler.addRelease(release, user1.getEmail()).getId();
assertNotNull(id);
{
Component component = handler.getComponent(componentId, user1);
assertThat(component.languages, containsInAnyOrder("C", "C++"));
assertThat(component.operatingSystems, containsInAnyOrder("Linux Ubuntu", "Linux Mint"));
assertThat(component.vendorNames, containsInAnyOrder(vendors.get("V1").getShortname()));
}
Set<String> os2 = new HashSet<>();
os2.add("Linux Debian");
os2.add("Linux Mint");
Set<String> lang2 = new HashSet<>();
lang2.add("C#");
lang2.add("C++");
Release release2 = new Release().setName("REL2").setVersion("VER2").setOperatingSystems(os2).setLanguages(lang2).setVendorId("V2");
release2.setComponentId(componentId);
String id2 = handler.addRelease(release2, user1.getEmail()).getId();
{
Component component = handler.getComponent(componentId, user1);
assertThat(component.languages, containsInAnyOrder("C", "C++", "C#"));
assertThat(component.operatingSystems, containsInAnyOrder("Linux Ubuntu", "Linux Mint", "Linux Debian"));
assertThat(component.vendorNames, containsInAnyOrder(vendors.get("V1").getShortname(), vendors.get("V2").getShortname()));
}
handler.deleteRelease(id, user1);
{
Component component = handler.getComponent(componentId, user1);
assertThat(component.languages, containsInAnyOrder("C++", "C#"));
assertThat(component.operatingSystems, containsInAnyOrder("Linux Mint", "Linux Debian"));
assertThat(component.vendorNames, containsInAnyOrder(vendors.get("V2").getShortname()));
}
handler.deleteRelease(id2, user1);
{
Component component = handler.getComponent(componentId, user1);
assertThat(component.languages, is(empty()));
assertThat(component.operatingSystems, is(empty()));
assertThat(component.vendorNames, is(empty()));
}
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentDatabaseHandlerTest method testUpdateComponent.
@Test
public void testUpdateComponent() throws Exception {
// Make some changes in the component
Component expected = components.get(0);
expected.unsetReleases();
expected.setName("UPDATE");
RequestStatus status = handler.updateComponent(expected, user1);
Component actual = handler.getComponent("C1", user1);
assertEquals(RequestStatus.SUCCESS, status);
assertEquals(expected.getId(), actual.getId());
assertEquals(expected.getName(), actual.getName());
assertEquals(expected.getDescription(), actual.getDescription());
assertEquals(email1, actual.getCreatedBy());
// Check releases
assertEquals(2, actual.getReleasesSize());
assertEquals(0, actual.getReleaseIdsSize());
assertTrue(releasesContain(actual.getReleases(), "R1A"));
assertTrue(releasesContain(actual.getReleases(), "R1B"));
assertFalse(releasesContain(actual.getReleases(), "R2A"));
assertFalse(releasesContain(actual.getReleases(), "R2B"));
assertFalse(releasesContain(actual.getReleases(), "R2C"));
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentDatabaseHandlerTest method testDeleteRelease.
@Test
public void testDeleteRelease() throws Exception {
RequestStatus status = handler.deleteRelease("R1B", user2);
assertEquals(RequestStatus.SUCCESS, status);
List<Release> releaseSummary = handler.getReleaseSummary();
assertEquals(4, releaseSummary.size());
assertFalse("Component deleted", releasesContain(releaseSummary, "R1B"));
// Check deletion in component
Component component = handler.getComponent("C1", user1);
assertEquals(1, component.getReleasesSize());
assertFalse("Release deleted", releasesContain(component.getReleases(), "R1B"));
}
use of org.eclipse.sw360.datahandler.thrift.components.Component 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);
}
Aggregations