Search in sources :

Example 6 with LogSinkName

use of com.google.logging.v2.LogSinkName in project gapic-generator-java by googleapis.

the class SyncGetSinkLogsinkname method syncGetSinkLogsinkname.

public static void syncGetSinkLogsinkname() throws Exception {
    // It may require modifications to work in your environment.
    try (ConfigClient configClient = ConfigClient.create()) {
        LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
        LogSink response = configClient.getSink(sinkName);
    }
}
Also used : LogSinkName(com.google.logging.v2.LogSinkName) LogSink(com.google.logging.v2.LogSink) ConfigClient(com.google.cloud.logging.v2.ConfigClient)

Example 7 with LogSinkName

use of com.google.logging.v2.LogSinkName in project java-logging by googleapis.

the class ConfigClientTest method getSinkTest.

@Test
public void getSinkTest() throws Exception {
    LogSink expectedResponse = LogSink.newBuilder().setName(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString()).setDestination("destination-1429847026").setFilter("filter-1274492040").setDescription("description-1724546052").setDisabled(true).addAllExclusions(new ArrayList<LogExclusion>()).setWriterIdentity("writerIdentity925193809").setIncludeChildren(true).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
    LogSink actualResponse = client.getSink(sinkName);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetSinkRequest actualRequest = ((GetSinkRequest) actualRequests.get(0));
    Assert.assertEquals(sinkName.toString(), actualRequest.getSinkName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : LogSink(com.google.logging.v2.LogSink) LogSinkName(com.google.logging.v2.LogSinkName) AbstractMessage(com.google.protobuf.AbstractMessage) GetSinkRequest(com.google.logging.v2.GetSinkRequest) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with LogSinkName

use of com.google.logging.v2.LogSinkName in project java-logging by googleapis.

the class ConfigClientTest method updateSinkTest.

@Test
public void updateSinkTest() throws Exception {
    LogSink expectedResponse = LogSink.newBuilder().setName(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString()).setDestination("destination-1429847026").setFilter("filter-1274492040").setDescription("description-1724546052").setDisabled(true).addAllExclusions(new ArrayList<LogExclusion>()).setWriterIdentity("writerIdentity925193809").setIncludeChildren(true).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
    LogSink sink = LogSink.newBuilder().build();
    LogSink actualResponse = client.updateSink(sinkName, sink);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateSinkRequest actualRequest = ((UpdateSinkRequest) actualRequests.get(0));
    Assert.assertEquals(sinkName.toString(), actualRequest.getSinkName());
    Assert.assertEquals(sink, actualRequest.getSink());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : LogSink(com.google.logging.v2.LogSink) LogSinkName(com.google.logging.v2.LogSinkName) AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) UpdateSinkRequest(com.google.logging.v2.UpdateSinkRequest) Test(org.junit.Test)

Example 9 with LogSinkName

use of com.google.logging.v2.LogSinkName in project java-logging by googleapis.

the class ConfigClientTest method updateSinkExceptionTest.

@Test
public void updateSinkExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
        LogSink sink = LogSink.newBuilder().build();
        client.updateSink(sinkName, sink);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : LogSinkName(com.google.logging.v2.LogSinkName) LogSink(com.google.logging.v2.LogSink) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 10 with LogSinkName

use of com.google.logging.v2.LogSinkName in project java-logging by googleapis.

the class ConfigClientTest method updateSinkTest3.

@Test
public void updateSinkTest3() throws Exception {
    LogSink expectedResponse = LogSink.newBuilder().setName(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString()).setDestination("destination-1429847026").setFilter("filter-1274492040").setDescription("description-1724546052").setDisabled(true).addAllExclusions(new ArrayList<LogExclusion>()).setWriterIdentity("writerIdentity925193809").setIncludeChildren(true).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
    LogSink sink = LogSink.newBuilder().build();
    FieldMask updateMask = FieldMask.newBuilder().build();
    LogSink actualResponse = client.updateSink(sinkName, sink, updateMask);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateSinkRequest actualRequest = ((UpdateSinkRequest) actualRequests.get(0));
    Assert.assertEquals(sinkName.toString(), actualRequest.getSinkName());
    Assert.assertEquals(sink, actualRequest.getSink());
    Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : LogSink(com.google.logging.v2.LogSink) LogSinkName(com.google.logging.v2.LogSinkName) AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) UpdateSinkRequest(com.google.logging.v2.UpdateSinkRequest) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Aggregations

LogSinkName (com.google.logging.v2.LogSinkName)20 Test (org.junit.Test)16 LogSink (com.google.logging.v2.LogSink)13 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)8 AbstractMessage (com.google.protobuf.AbstractMessage)8 StatusRuntimeException (io.grpc.StatusRuntimeException)8 ArrayList (java.util.ArrayList)6 FieldMask (com.google.protobuf.FieldMask)5 ConfigClient (com.google.cloud.logging.v2.ConfigClient)4 DeleteSinkRequest (com.google.logging.v2.DeleteSinkRequest)4 UpdateSinkRequest (com.google.logging.v2.UpdateSinkRequest)4 GetSinkRequest (com.google.logging.v2.GetSinkRequest)2 Empty (com.google.protobuf.Empty)2