Search in sources :

Example 1 with GetOccurrenceRequest

use of io.grafeas.v1beta1.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)

Example 2 with GetOccurrenceRequest

use of io.grafeas.v1beta1.GetOccurrenceRequest in project java-containeranalysis by googleapis.

the class GrafeasV1Beta1ClientTest method getOccurrenceTest.

@Test
@SuppressWarnings("all")
public void getOccurrenceTest() {
    String name2 = "name2-1052831874";
    String noteName = "noteName1780787896";
    String remediation = "remediation779381797";
    Occurrence expectedResponse = Occurrence.newBuilder().setName(name2).setNoteName(noteName).setRemediation(remediation).build();
    mockGrafeasV1Beta1.addResponse(expectedResponse);
    OccurrenceName name = OccurrenceName.of("[PROJECT]", "[OCCURRENCE]");
    Occurrence actualResponse = client.getOccurrence(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockGrafeasV1Beta1.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetOccurrenceRequest actualRequest = (GetOccurrenceRequest) actualRequests.get(0);
    Assert.assertEquals(name, OccurrenceName.parse(actualRequest.getName()));
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) OccurrenceName(com.google.containeranalysis.v1beta1.OccurrenceName) GetOccurrenceRequest(io.grafeas.v1beta1.GetOccurrenceRequest) Occurrence(io.grafeas.v1beta1.Occurrence) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 ApiFuture (com.google.api.core.ApiFuture)1 ApiCallContext (com.google.api.gax.rpc.ApiCallContext)1 OccurrenceName (com.google.containeranalysis.v1beta1.OccurrenceName)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 GetOccurrenceRequest (io.grafeas.v1.GetOccurrenceRequest)1 GetOccurrenceRequest (io.grafeas.v1beta1.GetOccurrenceRequest)1 Occurrence (io.grafeas.v1beta1.Occurrence)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1