Search in sources :

Example 6 with Vulnerability

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.

the class VulnerabilityConnectorTest method testaddOrUpdateVulnerabilitiesAndSetIds.

@Test
public void testaddOrUpdateVulnerabilitiesAndSetIds() {
    Vulnerability v1 = new Vulnerability().setLastExternalUpdate("1999-12-31").setId("idv1").setExternalId("eid1");
    Vulnerability v2 = new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv2").setExternalId("eid2");
    Vulnerability v3 = new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv3").setExternalId("eid1");
    Vulnerability v4 = new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv4").setExternalId("eid2");
    Vulnerability v5 = new Vulnerability().setLastExternalUpdate("1999-12-31").setId("idv5").setExternalId("eid5");
    List<Vulnerability> vulnerabilityList = Arrays.asList(v3, v4, v5);
    when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid1")).thenReturn(v1);
    when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid2")).thenReturn(v2);
    when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid5")).thenReturn(null);
    when(vulnerabilityDatabaseHandler.add(v5)).thenReturn(RequestStatus.SUCCESS);
    when(vulnerabilityDatabaseHandler.update(v1)).thenReturn(RequestStatus.SUCCESS);
    Map<UpdateType, List<Vulnerability>> resultMap = vulnerabilityConnector.addOrUpdateVulnerabilitiesAndSetIds(vulnerabilityList);
    assertThat(resultMap.get(UpdateType.UPDATED).get(0).getId(), is("idv1"));
    assertThat(resultMap.get(UpdateType.NEW).get(0).getId(), is("idv5"));
    assertThat(resultMap.get(UpdateType.OLD).get(0).getId(), is("idv2"));
    assertThat(resultMap.get(UpdateType.FAILED), is(Collections.EMPTY_LIST));
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType) Test(org.junit.Test)

Example 7 with Vulnerability

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.

the class VulnerabilityConnectorTest method testIsMoreRecentSecondEmpty.

@Test
public void testIsMoreRecentSecondEmpty() throws Exception {
    Vulnerability v1 = new Vulnerability().setLastExternalUpdate("2016");
    Vulnerability v2 = new Vulnerability().setLastExternalUpdate("");
    assertThat(vulnerabilityConnector.isMoreRecent(v1, v2), is(true));
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) Test(org.junit.Test)

Example 8 with Vulnerability

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.

the class VulnerabilityConnectorTest method testAddOrUpdateVulnerabilityAndSetIdUpdateVulnerability.

@Test
public void testAddOrUpdateVulnerabilityAndSetIdUpdateVulnerability() 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.SUCCESS);
    Map<UpdateType, List<Vulnerability>> resultMap = vulnerabilityConnector.addOrUpdateVulnerabilityAndSetId(v2, statusToVulnerabilityMap);
    assertThat(resultMap.get(UpdateType.UPDATED).get(0).getId(), is("idv1"));
    assertThat(resultMap.get(UpdateType.UPDATED).get(0).getLastExternalUpdate(), is("2000-01-01"));
    assertThat(resultMap.get(UpdateType.NEW), is(Collections.EMPTY_LIST));
    assertThat(resultMap.get(UpdateType.OLD), is(Collections.EMPTY_LIST));
    assertThat(resultMap.get(UpdateType.FAILED), is(Collections.EMPTY_LIST));
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType) Test(org.junit.Test)

Example 9 with Vulnerability

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.

the class VulnerabilityConnectorTest method testIsMoreRecentEmpty.

@Test
public void testIsMoreRecentEmpty() throws Exception {
    Vulnerability v1 = new Vulnerability();
    Vulnerability v2 = new Vulnerability();
    assertThat(vulnerabilityConnector.isMoreRecent(v1, v2), is(true));
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) Test(org.junit.Test)

Example 10 with Vulnerability

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.

the class VulnerabilityConnectorTest method testIsMoreRecentFirstEmpty.

@Test
public void testIsMoreRecentFirstEmpty() throws Exception {
    Vulnerability v1 = new Vulnerability().setLastExternalUpdate("");
    Vulnerability v2 = new Vulnerability().setLastExternalUpdate("2016");
    assertThat(vulnerabilityConnector.isMoreRecent(v1, v2), is(true));
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) Test(org.junit.Test)

Aggregations

Vulnerability (org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability)28 Test (org.junit.Test)15 UpdateType (org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType)10 User (org.eclipse.sw360.datahandler.thrift.users.User)8 TException (org.apache.thrift.TException)6 VulnerabilityService (org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityService)5 ReleaseVulnerabilityRelation (org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation)4 JSONObject (com.liferay.portal.kernel.json.JSONObject)3 PrintWriter (java.io.PrintWriter)3 VulnerabilityUpdateStatus (org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus)3 Before (org.junit.Before)3 IOException (java.io.IOException)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)2 PortletUtils.getVerificationState (org.eclipse.sw360.portal.common.PortletUtils.getVerificationState)2 ResponseEntity (org.springframework.http.ResponseEntity)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1