Search in sources :

Example 1 with CreateLogMetricRequest

use of com.google.logging.v2.CreateLogMetricRequest in project google-cloud-java by GoogleCloudPlatform.

the class LoggingImplTest method testCreateMetricAsync.

@Test
public void testCreateMetricAsync() throws ExecutionException, InterruptedException {
    LogMetric metricPb = METRIC_INFO.toPb();
    ApiFuture<LogMetric> response = ApiFutures.immediateFuture(metricPb);
    CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder().setParent(PROJECT_PB).setMetric(metricPb).build();
    EasyMock.expect(loggingRpcMock.create(request)).andReturn(response);
    EasyMock.replay(rpcFactoryMock, loggingRpcMock);
    logging = options.getService();
    Metric metric = logging.createAsync(METRIC_INFO).get();
    assertEquals(new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)), metric);
}
Also used : LogMetric(com.google.logging.v2.LogMetric) CreateLogMetricRequest(com.google.logging.v2.CreateLogMetricRequest) LogMetric(com.google.logging.v2.LogMetric) Test(org.junit.Test)

Example 2 with CreateLogMetricRequest

use of com.google.logging.v2.CreateLogMetricRequest in project google-cloud-java by GoogleCloudPlatform.

the class MetricsClientTest method createLogMetricTest.

@Test
@SuppressWarnings("all")
public void createLogMetricTest() {
    String name = "name3373707";
    String description = "description-1724546052";
    String filter = "filter-1274492040";
    LogMetric expectedResponse = LogMetric.newBuilder().setName(name).setDescription(description).setFilter(filter).build();
    mockMetricsServiceV2.addResponse(expectedResponse);
    ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
    LogMetric metric = LogMetric.newBuilder().build();
    LogMetric actualResponse = client.createLogMetric(parent, metric);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockMetricsServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateLogMetricRequest actualRequest = (CreateLogMetricRequest) actualRequests.get(0);
    Assert.assertEquals(parent, actualRequest.getParentAsParentNameOneof());
    Assert.assertEquals(metric, actualRequest.getMetric());
}
Also used : LogMetric(com.google.logging.v2.LogMetric) CreateLogMetricRequest(com.google.logging.v2.CreateLogMetricRequest) ParentNameOneof(com.google.logging.v2.ParentNameOneof) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 3 with CreateLogMetricRequest

use of com.google.logging.v2.CreateLogMetricRequest in project google-cloud-java by GoogleCloudPlatform.

the class LoggingImplTest method testCreateMetric.

@Test
public void testCreateMetric() {
    LogMetric metricPb = METRIC_INFO.toPb();
    ApiFuture<LogMetric> response = ApiFutures.immediateFuture(metricPb);
    CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder().setParent(PROJECT_PB).setMetric(metricPb).build();
    EasyMock.expect(loggingRpcMock.create(request)).andReturn(response);
    EasyMock.replay(rpcFactoryMock, loggingRpcMock);
    logging = options.getService();
    Metric metric = logging.create(METRIC_INFO);
    assertEquals(new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)), metric);
}
Also used : LogMetric(com.google.logging.v2.LogMetric) CreateLogMetricRequest(com.google.logging.v2.CreateLogMetricRequest) LogMetric(com.google.logging.v2.LogMetric) Test(org.junit.Test)

Aggregations

CreateLogMetricRequest (com.google.logging.v2.CreateLogMetricRequest)3 LogMetric (com.google.logging.v2.LogMetric)3 Test (org.junit.Test)3 ParentNameOneof (com.google.logging.v2.ParentNameOneof)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1