CveSearchDataTranslator implements EntityTranslator<CveSearchData, CveSearchDataTranslator.VulnerabilityWithRelation> { @Override public VulnerabilityWithRelation apply(CveSearchData cveSearchData) { Vulnerability vulnerability = new CveSearchDataToVulnerabilityTranslator().apply(cveSearchData); ReleaseVulnerabilityRelation relation = new CveSearchDataToReleaseVulnerabilityRelationTranslator().apply(cveSearchData); return new VulnerabilityWithRelation(vulnerability,relation); }  @Override VulnerabilityWithRelation apply(CveSearchData cveSearchData);  }
@Test public void testIdTranslation() { Vulnerability v = cveSearchDataTranslator.apply(cveSearchData).vulnerability; Set<CVEReference> cveReferences = v.getCveReferences(); assert(cveReferences.size() == 1); CVEReference cveReference = cveReferences.stream() .findAny() .get(); assert(CVEYEAR.equals(cveReference.getYear())); assert((CVENUMBER+ID).equals(cveReference.getNumber())); }
@Test public void testSummaryTranslation() { Vulnerability v = cveSearchDataTranslator.apply(cveSearchData).vulnerability; assert(v.getDescription().equals(cveSearchData.getSummary())); }
@Test public void testWithRealData() throws IOException { List<CveSearchData> cveSearchDatas = new CveSearchApiImpl(host).search("zyxel","zywall"); List<CveSearchDataTranslator.VulnerabilityWithRelation> vms = cveSearchDatas.stream() .map(cveSearchData -> cveSearchDataTranslator.apply(cveSearchData)) .collect(Collectors.toList()); assert(vms != null); }
@Test public void testWithApacheData() throws IOException { List<CveSearchData> cveSearchDatas = new CveSearchApiImpl(host).search("apache",".*"); List<CveSearchDataTranslator.VulnerabilityWithRelation> vms = cveSearchDatas.stream() .map(cveSearchData -> cveSearchDataTranslator.apply(cveSearchData)) .collect(Collectors.toList()); assert(vms != null); List<Vulnerability> vs = vms.stream() .map(vm -> vm.vulnerability) .collect(Collectors.toList()); assert(vs.size() > 700); }