Search in sources :

Example 36 with ProjectName

use of com.google.cloud.talent.v4beta1.ProjectName in project gapic-generator-java by googleapis.

the class ConfigClientTest method listSinksExceptionTest4.

@Test
public void listSinksExceptionTest4() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        ProjectName parent = ProjectName.of("[PROJECT]");
        client.listSinks(parent);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ProjectName(com.google.logging.v2.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 37 with ProjectName

use of com.google.cloud.talent.v4beta1.ProjectName in project gapic-generator-java by googleapis.

the class ConfigClientTest method listExclusionsTest4.

@Test
public void listExclusionsTest4() throws Exception {
    LogExclusion responsesElement = LogExclusion.newBuilder().build();
    ListExclusionsResponse expectedResponse = ListExclusionsResponse.newBuilder().setNextPageToken("").addAllExclusions(Arrays.asList(responsesElement)).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    ListExclusionsPagedResponse pagedListResponse = client.listExclusions(parent);
    List<LogExclusion> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getExclusionsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListExclusionsRequest actualRequest = ((ListExclusionsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListExclusionsRequest(com.google.logging.v2.ListExclusionsRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ListExclusionsResponse(com.google.logging.v2.ListExclusionsResponse) ProjectName(com.google.logging.v2.ProjectName) LogExclusion(com.google.logging.v2.LogExclusion) ListExclusionsPagedResponse(com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse) Test(org.junit.Test)

Example 38 with ProjectName

use of com.google.cloud.talent.v4beta1.ProjectName in project gapic-generator-java by googleapis.

the class MetricsClientTest method listLogMetricsExceptionTest.

@Test
public void listLogMetricsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockMetricsServiceV2.addException(exception);
    try {
        ProjectName parent = ProjectName.of("[PROJECT]");
        client.listLogMetrics(parent);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ProjectName(com.google.logging.v2.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 39 with ProjectName

use of com.google.cloud.talent.v4beta1.ProjectName in project gapic-generator-java by googleapis.

the class MetricsClientTest method listLogMetricsTest.

@Test
public void listLogMetricsTest() throws Exception {
    LogMetric responsesElement = LogMetric.newBuilder().build();
    ListLogMetricsResponse expectedResponse = ListLogMetricsResponse.newBuilder().setNextPageToken("").addAllMetrics(Arrays.asList(responsesElement)).build();
    mockMetricsServiceV2.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    ListLogMetricsPagedResponse pagedListResponse = client.listLogMetrics(parent);
    List<LogMetric> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getMetricsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockMetricsServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListLogMetricsRequest actualRequest = ((ListLogMetricsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) LogMetric(com.google.logging.v2.LogMetric) ListLogMetricsResponse(com.google.logging.v2.ListLogMetricsResponse) ProjectName(com.google.logging.v2.ProjectName) ListLogMetricsPagedResponse(com.google.cloud.logging.v2.MetricsClient.ListLogMetricsPagedResponse) ListLogMetricsRequest(com.google.logging.v2.ListLogMetricsRequest) Test(org.junit.Test)

Example 40 with ProjectName

use of com.google.cloud.talent.v4beta1.ProjectName in project gapic-generator-java by googleapis.

the class MetricsClientTest method createLogMetricExceptionTest.

@Test
public void createLogMetricExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockMetricsServiceV2.addException(exception);
    try {
        ProjectName parent = ProjectName.of("[PROJECT]");
        LogMetric metric = LogMetric.newBuilder().build();
        client.createLogMetric(parent, metric);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) LogMetric(com.google.logging.v2.LogMetric) ProjectName(com.google.logging.v2.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)181 StatusRuntimeException (io.grpc.StatusRuntimeException)89 AbstractMessage (com.google.protobuf.AbstractMessage)79 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)74 ProjectName (com.google.monitoring.v3.ProjectName)62 ProjectName (com.google.pubsub.v1.ProjectName)44 ProjectName (com.google.logging.v2.ProjectName)31 ArrayList (java.util.ArrayList)31 ProjectName (com.google.privacy.dlp.v2.ProjectName)22 ByteString (com.google.protobuf.ByteString)20 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