use of io.grafeas.v1.GetOccurrenceRequest in project java-docs-samples by GoogleCloudPlatform.
the class VulnerabilityFunctionTest method testAccept.
@Test
public void testAccept() throws IOException {
AtomicInteger occurrenceCallCount = new AtomicInteger();
Mockito.when(grafeasStub.getOccurrenceCallable()).thenReturn(new UnaryCallable<>() {
@Override
public ApiFuture<Occurrence> futureCall(GetOccurrenceRequest request, ApiCallContext context) {
occurrenceCallCount.incrementAndGet();
return ApiFutures.immediateFuture(Occurrence.newBuilder().setKind(NoteKind.VULNERABILITY).setResourceUri("gcr.io/test-project/some-image").setVulnerability(VulnerabilityOccurrence.newBuilder().setSeverity(Severity.CRITICAL).setShortDescription("CVE-CRITICAL").build()).build());
}
});
VulnerabilityFunction function = new VulnerabilityFunction(containerAnalysisClient);
String notificationPayload = "{\"name\":\"projects/test-project/occurrences/some-uuid\",\"kind\":\"VULNERABILITY\"," + "\"notificationTime\":\"2020-09-04T00:38:25.575543Z\"}";
PubSubMessage msg = new PubSubMessage();
msg.setData(Base64.getEncoder().encodeToString(notificationPayload.getBytes(StandardCharsets.UTF_8)));
function.accept(msg, null);
Assert.assertEquals(1, occurrenceCallCount.get());
}
Aggregations