Search in sources :

Example 6 with NoteName

use of com.google.containeranalysis.v1beta1.NoteName in project java-containeranalysis by googleapis.

the class GrafeasV1Beta1ClientTest method createOccurrenceTest.

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

Example 7 with NoteName

use of com.google.containeranalysis.v1beta1.NoteName in project java-containeranalysis by googleapis.

the class GrafeasV1Beta1ClientTest method deleteNoteTest.

@Test
@SuppressWarnings("all")
public void deleteNoteTest() {
    Empty expectedResponse = Empty.newBuilder().build();
    mockGrafeasV1Beta1.addResponse(expectedResponse);
    NoteName name = NoteName.of("[PROJECT]", "[NOTE]");
    client.deleteNote(name);
    List<AbstractMessage> actualRequests = mockGrafeasV1Beta1.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteNoteRequest actualRequest = (DeleteNoteRequest) actualRequests.get(0);
    Assert.assertEquals(name, NoteName.parse(actualRequest.getName()));
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) NoteName(com.google.containeranalysis.v1beta1.NoteName) DeleteNoteRequest(io.grafeas.v1beta1.DeleteNoteRequest) Test(org.junit.Test)

Example 8 with NoteName

use of com.google.containeranalysis.v1beta1.NoteName in project java-containeranalysis by googleapis.

the class GrafeasV1Beta1ClientTest method deleteNoteExceptionTest.

@Test
@SuppressWarnings("all")
public void deleteNoteExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockGrafeasV1Beta1.addException(exception);
    try {
        NoteName name = NoteName.of("[PROJECT]", "[NOTE]");
        client.deleteNote(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) NoteName(com.google.containeranalysis.v1beta1.NoteName) Test(org.junit.Test)

Example 9 with NoteName

use of com.google.containeranalysis.v1beta1.NoteName in project java-docs-samples by GoogleCloudPlatform.

the class SamplesTest method testPollDiscoveryOccurrenceFinished.

@Test
public void testPollDiscoveryOccurrenceFinished() throws Exception {
    try {
        // expect fail on first try
        PollDiscoveryOccurrenceFinished.pollDiscoveryOccurrenceFinished(imageUrl, PROJECT_ID, 5);
        Assert.fail("found unexpected discovery occurrence");
    } catch (TimeoutException e) {
    // test passes
    }
    // create discovery note
    Note newNote = Note.newBuilder().setDiscovery(DiscoveryNote.newBuilder().setAnalysisKind(NoteKind.DISCOVERY)).build();
    String discNoteId = "discovery-note-" + (new Date()).getTime();
    NoteName noteName = NoteName.of(PROJECT_ID, discNoteId);
    GrafeasClient client = ContainerAnalysisClient.create().getGrafeasClient();
    client.createNote(ProjectName.format(PROJECT_ID), discNoteId, newNote);
    // create discovery occurrence
    Occurrence newOcc = Occurrence.newBuilder().setNoteName(noteName.toString()).setResourceUri(imageUrl).setDiscovery(DiscoveryOccurrence.newBuilder().setAnalysisStatus(AnalysisStatus.FINISHED_SUCCESS)).build();
    Occurrence result = client.createOccurrence(ProjectName.format(PROJECT_ID), newOcc);
    // poll again
    Occurrence found = PollDiscoveryOccurrenceFinished.pollDiscoveryOccurrenceFinished(imageUrl, PROJECT_ID, 5);
    AnalysisStatus foundStatus = found.getDiscovery().getAnalysisStatus();
    assertEquals(foundStatus, AnalysisStatus.FINISHED_SUCCESS);
    // clean up
    String[] nameArr = found.getName().split("/");
    String occId = nameArr[nameArr.length - 1];
    DeleteOccurrence.deleteOccurrence(occId, PROJECT_ID);
    DeleteNote.deleteNote(discNoteId, PROJECT_ID);
}
Also used : GrafeasClient(io.grafeas.v1.GrafeasClient) VulnerabilityNote(io.grafeas.v1.VulnerabilityNote) DiscoveryNote(io.grafeas.v1.DiscoveryNote) Note(io.grafeas.v1.Note) NoteName(io.grafeas.v1.NoteName) AnalysisStatus(io.grafeas.v1.DiscoveryOccurrence.AnalysisStatus) Occurrence(io.grafeas.v1.Occurrence) VulnerabilityOccurrence(io.grafeas.v1.VulnerabilityOccurrence) DiscoveryOccurrence(io.grafeas.v1.DiscoveryOccurrence) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 10 with NoteName

use of com.google.containeranalysis.v1beta1.NoteName in project java-docs-samples by GoogleCloudPlatform.

the class DeleteNote method deleteNote.

// Deletes an existing Note from the server
public static void deleteNote(String noteId, String projectId) throws IOException, InterruptedException {
    // String noteId = "my-note";
    // String projectId = "my-project-id";
    final NoteName noteName = NoteName.of(projectId, noteId);
    // 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.deleteNote(noteName);
}
Also used : GrafeasClient(io.grafeas.v1.GrafeasClient) NoteName(io.grafeas.v1.NoteName)

Aggregations

Test (org.junit.Test)12 NoteName (com.google.containeranalysis.v1beta1.NoteName)8 AbstractMessage (com.google.protobuf.AbstractMessage)7 GrafeasClient (io.grafeas.v1.GrafeasClient)5 NoteName (io.grafeas.v1.NoteName)5 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)4 Occurrence (io.grafeas.v1beta1.Occurrence)4 StatusRuntimeException (io.grpc.StatusRuntimeException)4 FieldMask (com.google.protobuf.FieldMask)3 Occurrence (io.grafeas.v1.Occurrence)3 Note (io.grafeas.v1beta1.Note)3 OccurrenceName (com.google.containeranalysis.v1beta1.OccurrenceName)2 Note (io.grafeas.v1.Note)2 VulnerabilityOccurrence (io.grafeas.v1.VulnerabilityOccurrence)2 ListNoteOccurrencesPagedResponse (com.google.cloud.devtools.containeranalysis.v1beta1.GrafeasV1Beta1Client.ListNoteOccurrencesPagedResponse)1 ProjectName (com.google.containeranalysis.v1beta1.ProjectName)1 Empty (com.google.protobuf.Empty)1 DiscoveryNote (io.grafeas.v1.DiscoveryNote)1 DiscoveryOccurrence (io.grafeas.v1.DiscoveryOccurrence)1 AnalysisStatus (io.grafeas.v1.DiscoveryOccurrence.AnalysisStatus)1