use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentSummary method makeExportSummary.
private Component makeExportSummary(Component document, List<Release> releases) {
if (releaseRepository == null) {
throw new IllegalStateException("Cannot make export summary without database connection!");
}
Component copy = new Component();
copyField(document, copy, Component._Fields.ID);
copyField(document, copy, Component._Fields.NAME);
copyField(document, copy, Component._Fields.LANGUAGES);
copyField(document, copy, Component._Fields.OPERATING_SYSTEMS);
copyField(document, copy, Component._Fields.SOFTWARE_PLATFORMS);
copyField(document, copy, Component._Fields.CREATED_BY);
copyField(document, copy, Component._Fields.CREATED_ON);
copyField(document, copy, Component._Fields.VENDOR_NAMES);
for (Release release : releases) {
Release exportRelease = new Release();
copyField(release, exportRelease, Release._Fields.NAME);
copyField(release, exportRelease, Release._Fields.VERSION);
exportRelease.setComponentId("");
copy.addToReleases(exportRelease);
}
return copy;
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentHandlerTest method testGetByUploadId.
@Test
public void testGetByUploadId() throws Exception {
Component originalComponent = new Component("name").setDescription("a desc");
String componentId = componentHandler.addComponent(originalComponent, adminUser).getId();
Release release = new Release("name", "version", componentId).setFossologyId("id");
String releaseId = componentHandler.addRelease(release, adminUser).getId();
Component component = componentHandler.getComponentForReportFromFossologyUploadId("id");
assertThat(component, is(not(nullValue())));
assertThat(component, is(equalTo(originalComponent, restrictedToFields(ID, NAME, DESCRIPTION))));
assertThat(componentHandler.getReleaseById(releaseId, adminUser), is(not(nullValue())));
assertThat(componentHandler.getComponentById(componentId, adminUser), is(not(nullValue())));
assertThat(componentHandler.deleteRelease(releaseId, adminUser), is(RequestStatus.SUCCESS));
assertThat(componentHandler.deleteComponent(componentId, adminUser), is(RequestStatus.SUCCESS));
try {
componentHandler.getReleaseById(releaseId, adminUser);
fail("expected exception not thrown");
} catch (SW360Exception e) {
assertThat(e.getWhy(), containsString("Could not fetch"));
}
try {
componentHandler.getComponentById(componentId, adminUser);
fail("expected exception not thrown");
} catch (SW360Exception e) {
assertThat(e.getWhy(), containsString("Could not fetch"));
}
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentDatabaseHandlerTest method testDeleteComponent.
@Test
public void testDeleteComponent() throws Exception {
RequestStatus status = handler.deleteComponent("C3", user1);
assertEquals(RequestStatus.SUCCESS, status);
List<Component> componentSummary = handler.getComponentSummary(user1);
assertEquals(2, componentSummary.size());
assertFalse("Component deleted", componentsContain(componentSummary, "C3"));
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentDatabaseHandlerTest method testDeleteComponentNotModerator.
@Test
public void testDeleteComponentNotModerator() throws Exception {
when(moderator.deleteComponent(any(Component.class), eq(user2))).thenReturn(RequestStatus.SENT_TO_MODERATOR);
RequestStatus status = handler.deleteComponent("C3", user2);
assertEquals(RequestStatus.SENT_TO_MODERATOR, status);
List<Component> componentSummary = handler.getComponentSummary(user1);
assertEquals(3, componentSummary.size());
assertTrue("Component NOT deleted", componentsContain(componentSummary, "C1"));
verify(moderator).deleteComponent(any(Component.class), eq(user2));
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentDatabaseHandlerTest method testDontDeleteComponentWithReleaseContained.
@Test
public void testDontDeleteComponentWithReleaseContained() throws Exception {
Component component = new Component().setId("Del").setName("delete").setDescription("d1").setCreatedBy(email1);
Release release = new Release().setId("DelR").setComponentId("Del").setName("delete Release").setVersion("1.0").setCreatedBy(email1).setVendorId("V1").setClearingState(ClearingState.NEW_CLEARING);
handler.addComponent(component, email1);
handler.addRelease(release, email1);
{
Component del = handler.getComponent("Del", user1);
assertThat(del.getName(), is("delete"));
Release delR = handler.getRelease("DelR", user1);
assertThat(delR.getName(), is("delete Release"));
}
RequestStatus status = handler.deleteComponent("Del", user1);
assertThat(status, is(RequestStatus.IN_USE));
{
Component del = handler.getComponent("Del", user1);
assertThat(del.getName(), is("delete"));
Release delR = handler.getRelease("DelR", user1);
assertThat(delR.getName(), is("delete Release"));
}
}
Aggregations