use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.
the class VulnerabilityConnectorTest method testIsMoreRecentSecondNull.
@Test
public void testIsMoreRecentSecondNull() throws Exception {
Vulnerability v1 = new Vulnerability().setLastExternalUpdate("2016");
Vulnerability v2 = new Vulnerability();
assertThat(vulnerabilityConnector.isMoreRecent(v1, v2), is(true));
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.
the class VulnerabilityConnectorTest method testIsMoreRecentSecondOlder.
@Test
public void testIsMoreRecentSecondOlder() throws Exception {
Vulnerability v1 = new Vulnerability().setLastExternalUpdate("2016");
Vulnerability v2 = new Vulnerability().setLastExternalUpdate("2015");
assertThat(vulnerabilityConnector.isMoreRecent(v1, v2), is(true));
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.
the class VulnerabilityConnectorTest method testAddOrUpdateVulnerabilityAndSetIdOldVulnerability.
@Test
public void testAddOrUpdateVulnerabilityAndSetIdOldVulnerability() throws Exception {
Vulnerability v1 = new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv1").setExternalId("eid");
Vulnerability v2 = new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv2").setExternalId("eid");
when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid")).thenReturn(v1);
Map<UpdateType, List<Vulnerability>> resultMap = vulnerabilityConnector.addOrUpdateVulnerabilityAndSetId(v2, statusToVulnerabilityMap);
assertThat(resultMap.get(UpdateType.OLD).get(0).getId(), is("idv1"));
assertThat(resultMap.get(UpdateType.NEW), is(Collections.EMPTY_LIST));
assertThat(resultMap.get(UpdateType.UPDATED), is(Collections.EMPTY_LIST));
assertThat(resultMap.get(UpdateType.FAILED), is(Collections.EMPTY_LIST));
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.
the class VulnerabilityConnectorTest method testAddOrUpdateVulnerabilityAndSetIdFailAdd.
@Test
public void testAddOrUpdateVulnerabilityAndSetIdFailAdd() throws Exception {
Vulnerability v1 = new Vulnerability().setLastExternalUpdate("1999-12-31").setId("idv1").setExternalId("eid");
Vulnerability v2 = new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv2").setExternalId("eid");
when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid")).thenReturn(v1);
when(vulnerabilityDatabaseHandler.update(v1)).thenReturn(RequestStatus.FAILURE);
Map<UpdateType, List<Vulnerability>> resultMap = vulnerabilityConnector.addOrUpdateVulnerabilityAndSetId(v2, statusToVulnerabilityMap);
assertThat(resultMap.get(UpdateType.FAILED).get(0).getId(), is("idv2"));
assertThat(resultMap.get(UpdateType.NEW), is(Collections.EMPTY_LIST));
assertThat(resultMap.get(UpdateType.OLD), is(Collections.EMPTY_LIST));
assertThat(resultMap.get(UpdateType.UPDATED), is(Collections.EMPTY_LIST));
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.
the class VulnerabilityUtils method getUpdateStatusFromUpdateMap.
public static VulnerabilityUpdateStatus getUpdateStatusFromUpdateMap(Map<UpdateType, List<Vulnerability>> statusToVulnerabilities) {
VulnerabilityUpdateStatus status = getEmptyVulnerabilityUpdateStatus();
status.requestStatus = nullToEmptyList(statusToVulnerabilities.get(UpdateType.FAILED)).size() > 0 ? RequestStatus.FAILURE : RequestStatus.SUCCESS;
for (UpdateType updateType : UpdateType.values()) {
List<String> idList = nullToEmptyList(statusToVulnerabilities.get(updateType)).stream().map(Vulnerability::getExternalId).collect(Collectors.toList());
status.statusToVulnerabilityIds.get(updateType).addAll(idList);
}
return status;
}
Aggregations