Search in sources :

Example 41 with ProjectName

use of com.google.cloud.datalabeling.v1beta1.ProjectName in project gapic-generator-java by googleapis.

the class MetricsClientTest method createLogMetricTest.

@Test
public void createLogMetricTest() throws Exception {
    LogMetric expectedResponse = LogMetric.newBuilder().setName(LogMetricName.of("[PROJECT]", "[METRIC]").toString()).setDescription("description-1724546052").setFilter("filter-1274492040").setMetricDescriptor(MetricDescriptor.newBuilder().build()).setValueExtractor("valueExtractor-1867420749").putAllLabelExtractors(new HashMap<String, String>()).setBucketOptions(Distribution.BucketOptions.newBuilder().build()).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).build();
    mockMetricsServiceV2.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    LogMetric metric = LogMetric.newBuilder().build();
    LogMetric actualResponse = client.createLogMetric(parent, metric);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockMetricsServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateLogMetricRequest actualRequest = ((CreateLogMetricRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(metric, actualRequest.getMetric());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) LogMetric(com.google.logging.v2.LogMetric) CreateLogMetricRequest(com.google.logging.v2.CreateLogMetricRequest) ProjectName(com.google.logging.v2.ProjectName) Test(org.junit.Test)

Example 42 with ProjectName

use of com.google.cloud.datalabeling.v1beta1.ProjectName in project gapic-generator-java by googleapis.

the class ConfigClientTest method createSinkExceptionTest4.

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

Example 43 with ProjectName

use of com.google.cloud.datalabeling.v1beta1.ProjectName in project gapic-generator-java by googleapis.

the class ConfigClientTest method createExclusionTest4.

@Test
public void createExclusionTest4() throws Exception {
    LogExclusion expectedResponse = LogExclusion.newBuilder().setName(LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString()).setDescription("description-1724546052").setFilter("filter-1274492040").setDisabled(true).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    LogExclusion exclusion = LogExclusion.newBuilder().build();
    LogExclusion actualResponse = client.createExclusion(parent, exclusion);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateExclusionRequest actualRequest = ((CreateExclusionRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(exclusion, actualRequest.getExclusion());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : CreateExclusionRequest(com.google.logging.v2.CreateExclusionRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ProjectName(com.google.logging.v2.ProjectName) LogExclusion(com.google.logging.v2.LogExclusion) Test(org.junit.Test)

Example 44 with ProjectName

use of com.google.cloud.datalabeling.v1beta1.ProjectName in project gapic-generator-java by googleapis.

the class LoggingClientTest method listLogsExceptionTest4.

@Test
public void listLogsExceptionTest4() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockLoggingServiceV2.addException(exception);
    try {
        ProjectName parent = ProjectName.of("[PROJECT]");
        client.listLogs(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 45 with ProjectName

use of com.google.cloud.datalabeling.v1beta1.ProjectName in project gapic-generator-java by googleapis.

the class SyncCreateLogMetricProjectnameLogmetric method syncCreateLogMetricProjectnameLogmetric.

public static void syncCreateLogMetricProjectnameLogmetric() throws Exception {
    // It may require modifications to work in your environment.
    try (MetricsClient metricsClient = MetricsClient.create()) {
        ProjectName parent = ProjectName.of("[PROJECT]");
        LogMetric metric = LogMetric.newBuilder().build();
        LogMetric response = metricsClient.createLogMetric(parent, metric);
    }
}
Also used : MetricsClient(com.google.cloud.logging.v2.MetricsClient) LogMetric(com.google.logging.v2.LogMetric) ProjectName(com.google.logging.v2.ProjectName)

Aggregations

Test (org.junit.Test)182 StatusRuntimeException (io.grpc.StatusRuntimeException)89 AbstractMessage (com.google.protobuf.AbstractMessage)80 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