Search in sources :

Example 1 with ParentNameOneof

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

the class ConfigClientTest method createSinkTest.

@Test
@SuppressWarnings("all")
public void createSinkTest() {
    String name = "name3373707";
    ResourceName destination = ProjectName.create("[PROJECT]");
    String filter = "filter-1274492040";
    String writerIdentity = "writerIdentity775638794";
    LogSink expectedResponse = LogSink.newBuilder().setName(name).setDestinationWithResourceName(destination).setFilter(filter).setWriterIdentity(writerIdentity).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
    LogSink sink = LogSink.newBuilder().build();
    LogSink actualResponse = client.createSink(parent, sink);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateSinkRequest actualRequest = (CreateSinkRequest) actualRequests.get(0);
    Assert.assertEquals(parent, actualRequest.getParentAsParentNameOneof());
    Assert.assertEquals(sink, actualRequest.getSink());
}
Also used : LogSink(com.google.logging.v2.LogSink) ResourceName(com.google.api.resourcenames.ResourceName) ParentNameOneof(com.google.logging.v2.ParentNameOneof) CreateSinkRequest(com.google.logging.v2.CreateSinkRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 2 with ParentNameOneof

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

the class ConfigClientTest method createSinkExceptionTest.

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

Example 3 with ParentNameOneof

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

the class MetricsClientTest method listLogMetricsExceptionTest.

@Test
@SuppressWarnings("all")
public void listLogMetricsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockMetricsServiceV2.addException(exception);
    try {
        ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
        client.listLogMetrics(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)

Example 4 with ParentNameOneof

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

the class ConfigClientTest method listSinksTest.

@Test
@SuppressWarnings("all")
public void listSinksTest() {
    String nextPageToken = "";
    LogSink sinksElement = LogSink.newBuilder().build();
    List<LogSink> sinks = Arrays.asList(sinksElement);
    ListSinksResponse expectedResponse = ListSinksResponse.newBuilder().setNextPageToken(nextPageToken).addAllSinks(sinks).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
    ListSinksPagedResponse pagedListResponse = client.listSinks(parent);
    List<LogSink> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getSinksList().get(0), resources.get(0));
    List<GeneratedMessageV3> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListSinksRequest actualRequest = (ListSinksRequest) actualRequests.get(0);
    Assert.assertEquals(parent, actualRequest.getParentAsParentNameOneof());
}
Also used : LogSink(com.google.logging.v2.LogSink) ListSinksResponse(com.google.logging.v2.ListSinksResponse) ListSinksPagedResponse(com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListSinksPagedResponse) ParentNameOneof(com.google.logging.v2.ParentNameOneof) ListSinksRequest(com.google.logging.v2.ListSinksRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 5 with ParentNameOneof

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

the class LoggingClientTest method listLogsExceptionTest.

@Test
@SuppressWarnings("all")
public void listLogsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLoggingServiceV2.addException(exception);
    try {
        ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
        client.listLogs(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