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());
}
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()));
}
Aggregations