use of com.google.containeranalysis.v1beta1.OccurrenceName in project java-docs-samples by GoogleCloudPlatform.
the class DeleteOccurrence method deleteOccurrence.
// Deletes an existing Occurrence from the server
public static void deleteOccurrence(String occurrenceId, String projectId) throws IOException, InterruptedException {
// String occurrenceId = "123-456-789";
// String projectId = "my-project-id";
final OccurrenceName occurrenceName = OccurrenceName.of(projectId, occurrenceId);
// Initialize client that will be used to send requests. After completing all of your requests,
// call the "close" method on the client to safely clean up any remaining background resources.
GrafeasClient client = ContainerAnalysisClient.create().getGrafeasClient();
client.deleteOccurrence(occurrenceName);
}
use of com.google.containeranalysis.v1beta1.OccurrenceName in project java-docs-samples by GoogleCloudPlatform.
the class GetOccurrence method getOccurrence.
// Retrieves and prints a specified Occurrence from the server
public static Occurrence getOccurrence(String occurrenceId, String projectId) throws IOException, InterruptedException {
// String occurrenceId = "123-456-789";
// String projectId = "my-project-id";
final OccurrenceName occurrenceName = OccurrenceName.of(projectId, occurrenceId);
// Initialize client that will be used to send requests. After completing all of your requests,
// call the "close" method on the client to safely clean up any remaining background resources.
GrafeasClient client = ContainerAnalysisClient.create().getGrafeasClient();
Occurrence occ = client.getOccurrence(occurrenceName);
System.out.println(occ);
return occ;
}
use of com.google.containeranalysis.v1beta1.OccurrenceName 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()));
}
use of com.google.containeranalysis.v1beta1.OccurrenceName in project java-containeranalysis by googleapis.
the class GrafeasV1Beta1ClientTest method getOccurrenceNoteExceptionTest.
@Test
@SuppressWarnings("all")
public void getOccurrenceNoteExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockGrafeasV1Beta1.addException(exception);
try {
OccurrenceName name = OccurrenceName.of("[PROJECT]", "[OCCURRENCE]");
client.getOccurrenceNote(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}
use of com.google.containeranalysis.v1beta1.OccurrenceName in project java-containeranalysis by googleapis.
the class GrafeasV1Beta1ClientTest method getOccurrenceExceptionTest.
@Test
@SuppressWarnings("all")
public void getOccurrenceExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockGrafeasV1Beta1.addException(exception);
try {
OccurrenceName name = OccurrenceName.of("[PROJECT]", "[OCCURRENCE]");
client.getOccurrence(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}
Aggregations