Search in sources :

Example 1 with OccurrenceName

use of io.grafeas.v1.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);
}
Also used : GrafeasClient(io.grafeas.v1.GrafeasClient) OccurrenceName(io.grafeas.v1.OccurrenceName)

Example 2 with OccurrenceName

use of io.grafeas.v1.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;
}
Also used : GrafeasClient(io.grafeas.v1.GrafeasClient) OccurrenceName(io.grafeas.v1.OccurrenceName) Occurrence(io.grafeas.v1.Occurrence)

Example 3 with OccurrenceName

use of io.grafeas.v1.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()));
}
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)

Example 4 with OccurrenceName

use of io.grafeas.v1.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
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) OccurrenceName(com.google.containeranalysis.v1beta1.OccurrenceName) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 5 with OccurrenceName

use of io.grafeas.v1.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
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) OccurrenceName(com.google.containeranalysis.v1beta1.OccurrenceName) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Aggregations

OccurrenceName (com.google.containeranalysis.v1beta1.OccurrenceName)8 Test (org.junit.Test)8 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 StatusRuntimeException (io.grpc.StatusRuntimeException)4 Occurrence (io.grafeas.v1beta1.Occurrence)3 FieldMask (com.google.protobuf.FieldMask)2 GrafeasClient (io.grafeas.v1.GrafeasClient)2 OccurrenceName (io.grafeas.v1.OccurrenceName)2 Empty (com.google.protobuf.Empty)1 Occurrence (io.grafeas.v1.Occurrence)1 DeleteOccurrenceRequest (io.grafeas.v1beta1.DeleteOccurrenceRequest)1 GetOccurrenceNoteRequest (io.grafeas.v1beta1.GetOccurrenceNoteRequest)1 GetOccurrenceRequest (io.grafeas.v1beta1.GetOccurrenceRequest)1 Note (io.grafeas.v1beta1.Note)1 UpdateOccurrenceRequest (io.grafeas.v1beta1.UpdateOccurrenceRequest)1