Search in sources :

Example 6 with LogSink

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

the class LoggingImplTest method testCreateSink.

@Test
public void testCreateSink() {
    LogSink sinkPb = SINK_INFO.toPb(PROJECT);
    ApiFuture<LogSink> response = ApiFutures.immediateFuture(sinkPb);
    CreateSinkRequest request = CreateSinkRequest.newBuilder().setParent(PROJECT_PB).setSink(sinkPb).build();
    EasyMock.expect(loggingRpcMock.create(request)).andReturn(response);
    EasyMock.replay(rpcFactoryMock, loggingRpcMock);
    logging = options.getService();
    Sink sink = logging.create(SINK_INFO);
    assertEquals(new Sink(logging, new SinkInfo.BuilderImpl(SINK_INFO)), sink);
}
Also used : LogSink(com.google.logging.v2.LogSink) LogSink(com.google.logging.v2.LogSink) CreateSinkRequest(com.google.logging.v2.CreateSinkRequest) Test(org.junit.Test)

Example 7 with LogSink

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

the class LoggingImplTest method testCreateSinkAsync.

@Test
public void testCreateSinkAsync() throws ExecutionException, InterruptedException {
    LogSink sinkPb = SINK_INFO.toPb(PROJECT);
    ApiFuture<LogSink> response = ApiFutures.immediateFuture(sinkPb);
    CreateSinkRequest request = CreateSinkRequest.newBuilder().setParent(PROJECT_PB).setSink(sinkPb).build();
    EasyMock.expect(loggingRpcMock.create(request)).andReturn(response);
    EasyMock.replay(rpcFactoryMock, loggingRpcMock);
    logging = options.getService();
    Sink sink = logging.createAsync(SINK_INFO).get();
    assertEquals(new Sink(logging, new SinkInfo.BuilderImpl(SINK_INFO)), sink);
}
Also used : LogSink(com.google.logging.v2.LogSink) LogSink(com.google.logging.v2.LogSink) CreateSinkRequest(com.google.logging.v2.CreateSinkRequest) Test(org.junit.Test)

Example 8 with LogSink

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

the class LoggingImplTest method testUpdateSink.

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

Example 9 with LogSink

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

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

the class LoggingImplTest method testGetSinkAsync_Null.

@Test
public void testGetSinkAsync_Null() throws ExecutionException, InterruptedException {
    ApiFuture<LogSink> response = ApiFutures.immediateFuture(null);
    GetSinkRequest request = GetSinkRequest.newBuilder().setSinkName(SINK_NAME_PB).build();
    EasyMock.expect(loggingRpcMock.get(request)).andReturn(response);
    EasyMock.replay(rpcFactoryMock, loggingRpcMock);
    logging = options.getService();
    assertNull(logging.getSinkAsync(SINK_NAME).get());
}
Also used : LogSink(com.google.logging.v2.LogSink) GetSinkRequest(com.google.logging.v2.GetSinkRequest) 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