Search in sources :

Example 6 with ParentNameOneof

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

the class LoggingClientTest method listLogsTest.

@Test
@SuppressWarnings("all")
public void listLogsTest() {
    String nextPageToken = "";
    String logNamesElement = "logNamesElement-1079688374";
    List<String> logNames = Arrays.asList(logNamesElement);
    ListLogsResponse expectedResponse = ListLogsResponse.newBuilder().setNextPageToken(nextPageToken).addAllLogNames(logNames).build();
    mockLoggingServiceV2.addResponse(expectedResponse);
    ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
    ListLogsPagedResponse pagedListResponse = client.listLogs(parent);
    List<String> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getLogNamesList().get(0), resources.get(0));
    List<GeneratedMessageV3> actualRequests = mockLoggingServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListLogsRequest actualRequest = (ListLogsRequest) actualRequests.get(0);
    Assert.assertEquals(parent, actualRequest.getParentAsParentNameOneof());
}
Also used : ListLogsResponse(com.google.logging.v2.ListLogsResponse) ParentNameOneof(com.google.logging.v2.ParentNameOneof) ListLogsRequest(com.google.logging.v2.ListLogsRequest) ListLogsPagedResponse(com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogsPagedResponse) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 7 with ParentNameOneof

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

the class MetricsClientTest method listLogMetricsTest.

@Test
@SuppressWarnings("all")
public void listLogMetricsTest() {
    String nextPageToken = "";
    LogMetric metricsElement = LogMetric.newBuilder().build();
    List<LogMetric> metrics = Arrays.asList(metricsElement);
    ListLogMetricsResponse expectedResponse = ListLogMetricsResponse.newBuilder().setNextPageToken(nextPageToken).addAllMetrics(metrics).build();
    mockMetricsServiceV2.addResponse(expectedResponse);
    ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[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<GeneratedMessageV3> actualRequests = mockMetricsServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListLogMetricsRequest actualRequest = (ListLogMetricsRequest) actualRequests.get(0);
    Assert.assertEquals(parent, actualRequest.getParentAsParentNameOneof());
}
Also used : LogMetric(com.google.logging.v2.LogMetric) ListLogMetricsResponse(com.google.logging.v2.ListLogMetricsResponse) ListLogMetricsPagedResponse(com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogMetricsPagedResponse) ParentNameOneof(com.google.logging.v2.ParentNameOneof) ListLogMetricsRequest(com.google.logging.v2.ListLogMetricsRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 8 with ParentNameOneof

use of com.google.logging.v2.ParentNameOneof 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 9 with ParentNameOneof

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

the class MetricsClientTest method createLogMetricExceptionTest.

@Test
@SuppressWarnings("all")
public void createLogMetricExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockMetricsServiceV2.addException(exception);
    try {
        ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
        LogMetric metric = LogMetric.newBuilder().build();
        client.createLogMetric(parent, metric);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : LogMetric(com.google.logging.v2.LogMetric) ParentNameOneof(com.google.logging.v2.ParentNameOneof) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 10 with ParentNameOneof

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

the class ConfigClientTest method listSinksExceptionTest.

@Test
@SuppressWarnings("all")
public void listSinksExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
        client.listSinks(parent);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : ParentNameOneof(com.google.logging.v2.ParentNameOneof) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

ParentNameOneof (com.google.logging.v2.ParentNameOneof)10 Test (org.junit.Test)10 ApiException (com.google.api.gax.grpc.ApiException)5 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)5 StatusRuntimeException (io.grpc.StatusRuntimeException)5 LogMetric (com.google.logging.v2.LogMetric)3 LogSink (com.google.logging.v2.LogSink)3 ResourceName (com.google.api.resourcenames.ResourceName)1 ListLogMetricsPagedResponse (com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogMetricsPagedResponse)1 ListLogsPagedResponse (com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogsPagedResponse)1 ListSinksPagedResponse (com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListSinksPagedResponse)1 CreateLogMetricRequest (com.google.logging.v2.CreateLogMetricRequest)1 CreateSinkRequest (com.google.logging.v2.CreateSinkRequest)1 ListLogMetricsRequest (com.google.logging.v2.ListLogMetricsRequest)1 ListLogMetricsResponse (com.google.logging.v2.ListLogMetricsResponse)1 ListLogsRequest (com.google.logging.v2.ListLogsRequest)1 ListLogsResponse (com.google.logging.v2.ListLogsResponse)1 ListSinksRequest (com.google.logging.v2.ListSinksRequest)1 ListSinksResponse (com.google.logging.v2.ListSinksResponse)1