Search in sources :

Example 1 with LogSink

use of com.google.logging.v2.LogSink 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 LogSink

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

the class ConfigClientTest method updateSinkExceptionTest.

@Test
@SuppressWarnings("all")
public void updateSinkExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        SinkNameOneof sinkName = SinkNameOneof.from(SinkName.create("[PROJECT]", "[SINK]"));
        LogSink sink = LogSink.newBuilder().build();
        client.updateSink(sinkName, 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) SinkNameOneof(com.google.logging.v2.SinkNameOneof) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 3 with LogSink

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

the class ConfigClientTest method updateSinkTest.

@Test
@SuppressWarnings("all")
public void updateSinkTest() {
    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);
    SinkNameOneof sinkName = SinkNameOneof.from(SinkName.create("[PROJECT]", "[SINK]"));
    LogSink sink = LogSink.newBuilder().build();
    LogSink actualResponse = client.updateSink(sinkName, sink);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateSinkRequest actualRequest = (UpdateSinkRequest) actualRequests.get(0);
    Assert.assertEquals(sinkName, actualRequest.getSinkNameAsSinkNameOneof());
    Assert.assertEquals(sink, actualRequest.getSink());
}
Also used : LogSink(com.google.logging.v2.LogSink) ResourceName(com.google.api.resourcenames.ResourceName) SinkNameOneof(com.google.logging.v2.SinkNameOneof) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) UpdateSinkRequest(com.google.logging.v2.UpdateSinkRequest) Test(org.junit.Test)

Example 4 with LogSink

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

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

the class LoggingImplTest method testGetSink.

@Test
public void testGetSink() {
    LogSink sinkPb = SINK_INFO.toPb(PROJECT);
    ApiFuture<LogSink> response = ApiFutures.immediateFuture(sinkPb);
    GetSinkRequest request = GetSinkRequest.newBuilder().setSinkName(SINK_NAME_PB).build();
    EasyMock.expect(loggingRpcMock.get(request)).andReturn(response);
    EasyMock.replay(rpcFactoryMock, loggingRpcMock);
    logging = options.getService();
    Sink sink = logging.getSink(SINK_NAME);
    assertEquals(new Sink(logging, new SinkInfo.BuilderImpl(SINK_INFO)), sink);
}
Also used : LogSink(com.google.logging.v2.LogSink) GetSinkRequest(com.google.logging.v2.GetSinkRequest) LogSink(com.google.logging.v2.LogSink) Test(org.junit.Test)

Aggregations

LogSink (com.google.logging.v2.LogSink)14 Test (org.junit.Test)14 GetSinkRequest (com.google.logging.v2.GetSinkRequest)5 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)4 ResourceName (com.google.api.resourcenames.ResourceName)3 CreateSinkRequest (com.google.logging.v2.CreateSinkRequest)3 ParentNameOneof (com.google.logging.v2.ParentNameOneof)3 SinkNameOneof (com.google.logging.v2.SinkNameOneof)3 UpdateSinkRequest (com.google.logging.v2.UpdateSinkRequest)3 ApiException (com.google.api.gax.grpc.ApiException)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 ListSinksPagedResponse (com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListSinksPagedResponse)1 ListSinksRequest (com.google.logging.v2.ListSinksRequest)1 ListSinksResponse (com.google.logging.v2.ListSinksResponse)1