Search in sources :

Example 1 with GetOccurrenceRequest

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());
}
Also used : ApiFuture(com.google.api.core.ApiFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GetOccurrenceRequest(io.grafeas.v1.GetOccurrenceRequest) ApiCallContext(com.google.api.gax.rpc.ApiCallContext) Test(org.junit.Test)

Aggregations

ApiFuture (com.google.api.core.ApiFuture)1 ApiCallContext (com.google.api.gax.rpc.ApiCallContext)1 GetOccurrenceRequest (io.grafeas.v1.GetOccurrenceRequest)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1