Search in sources :

Example 1 with LogSinkName

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

the class ConfigClientTest method getSinkExceptionTest.

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

Example 2 with LogSinkName

use of com.google.logging.v2.LogSinkName in project gapic-generator-java 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 3 with LogSinkName

use of com.google.logging.v2.LogSinkName in project gapic-generator-java 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 4 with LogSinkName

use of com.google.logging.v2.LogSinkName in project gapic-generator-java 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)

Example 5 with LogSinkName

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

the class ConfigClientTest method deleteSinkExceptionTest.

@Test
public void deleteSinkExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
        client.deleteSink(sinkName);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : LogSinkName(com.google.logging.v2.LogSinkName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) 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