Search in sources :

Example 61 with ProjectName

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

the class GrafeasV1Beta1ClientTest method createNoteTest.

@Test
@SuppressWarnings("all")
public void createNoteTest() {
    String name = "name3373707";
    String shortDescription = "shortDescription-235369287";
    String longDescription = "longDescription-1747792199";
    Note expectedResponse = Note.newBuilder().setName(name).setShortDescription(shortDescription).setLongDescription(longDescription).build();
    mockGrafeasV1Beta1.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    String noteId = "noteId2129224840";
    Note note = Note.newBuilder().build();
    Note actualResponse = client.createNote(parent, noteId, note);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockGrafeasV1Beta1.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateNoteRequest actualRequest = (CreateNoteRequest) actualRequests.get(0);
    Assert.assertEquals(parent, ProjectName.parse(actualRequest.getParent()));
    Assert.assertEquals(noteId, actualRequest.getNoteId());
    Assert.assertEquals(note, actualRequest.getNote());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : CreateNoteRequest(io.grafeas.v1beta1.CreateNoteRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ProjectName(com.google.containeranalysis.v1beta1.ProjectName) Note(io.grafeas.v1beta1.Note) Test(org.junit.Test)

Example 62 with ProjectName

use of com.google.containeranalysis.v1beta1.ProjectName 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 63 with ProjectName

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

the class GrafeasV1Beta1ClientTest method batchCreateNotesTest.

@Test
@SuppressWarnings("all")
public void batchCreateNotesTest() {
    BatchCreateNotesResponse expectedResponse = BatchCreateNotesResponse.newBuilder().build();
    mockGrafeasV1Beta1.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    Map<String, Note> notes = new HashMap<>();
    BatchCreateNotesResponse actualResponse = client.batchCreateNotes(parent, notes);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockGrafeasV1Beta1.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    BatchCreateNotesRequest actualRequest = (BatchCreateNotesRequest) actualRequests.get(0);
    Assert.assertEquals(parent, ProjectName.parse(actualRequest.getParent()));
    Assert.assertEquals(notes, actualRequest.getNotesMap());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : BatchCreateNotesRequest(io.grafeas.v1beta1.BatchCreateNotesRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ProjectName(com.google.containeranalysis.v1beta1.ProjectName) HashMap(java.util.HashMap) Note(io.grafeas.v1beta1.Note) BatchCreateNotesResponse(io.grafeas.v1beta1.BatchCreateNotesResponse) Test(org.junit.Test)

Example 64 with ProjectName

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

the class GrafeasV1Beta1ClientTest method listOccurrencesExceptionTest.

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

Example 65 with ProjectName

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

the class GrafeasV1Beta1ClientTest method createNoteExceptionTest.

@Test
@SuppressWarnings("all")
public void createNoteExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockGrafeasV1Beta1.addException(exception);
    try {
        ProjectName parent = ProjectName.of("[PROJECT]");
        String noteId = "noteId2129224840";
        Note note = Note.newBuilder().build();
        client.createNote(parent, noteId, note);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ProjectName(com.google.containeranalysis.v1beta1.ProjectName) Note(io.grafeas.v1beta1.Note) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)146 StatusRuntimeException (io.grpc.StatusRuntimeException)73 ProjectName (com.google.monitoring.v3.ProjectName)62 AbstractMessage (com.google.protobuf.AbstractMessage)60 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)58 ProjectName (com.google.pubsub.v1.ProjectName)30 ArrayList (java.util.ArrayList)29 ProjectName (com.google.privacy.dlp.v2.ProjectName)22 ByteString (com.google.protobuf.ByteString)18 DataTransferServiceClient (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient)17 ProjectName (com.google.cloud.bigquery.datatransfer.v1.ProjectName)17 IOException (java.io.IOException)17 CreateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest)16 TransferConfig (com.google.cloud.bigquery.datatransfer.v1.TransferConfig)16 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)16 ProjectName (com.google.containeranalysis.v1beta1.ProjectName)16 ApiException (com.google.api.gax.rpc.ApiException)15 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)15 TimeSeries (com.google.monitoring.v3.TimeSeries)15 ProjectName (com.google.logging.v2.ProjectName)14