Search in sources :

Example 11 with LogSinkName

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

the class ConfigClientTest method deleteSinkTest.

@Test
public void deleteSinkTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockConfigServiceV2.addResponse(expectedResponse);
    LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
    client.deleteSink(sinkName);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteSinkRequest actualRequest = ((DeleteSinkRequest) actualRequests.get(0));
    Assert.assertEquals(sinkName.toString(), actualRequest.getSinkName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : LogSinkName(com.google.logging.v2.LogSinkName) Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) DeleteSinkRequest(com.google.logging.v2.DeleteSinkRequest) Test(org.junit.Test)

Example 12 with LogSinkName

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

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

the class ConfigClientTest method updateSinkExceptionTest3.

@Test
public void updateSinkExceptionTest3() 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();
        FieldMask updateMask = FieldMask.newBuilder().build();
        client.updateSink(sinkName, sink, updateMask);
        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) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 14 with LogSinkName

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

Example 15 with LogSinkName

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

the class ConfigClient method deleteSink.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes a sink. If the sink has a unique `writer_identity`, then that service account is also
 * deleted.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * // This snippet has been automatically generated for illustrative purposes only.
 * // It may require modifications to work in your environment.
 * try (ConfigClient configClient = ConfigClient.create()) {
 *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
 *   configClient.deleteSink(sinkName);
 * }
 * }</pre>
 *
 * @param sinkName Required. The full resource name of the sink to delete, including the parent
 *     resource and the sink identifier:
 *     <p>"projects/[PROJECT_ID]/sinks/[SINK_ID]"
 *     "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]"
 *     "billingAccounts/[BILLING_ACCOUNT_ID]/sinks/[SINK_ID]"
 *     "folders/[FOLDER_ID]/sinks/[SINK_ID]"
 *     <p>For example:
 *     <p>`"projects/my-project/sinks/my-sink"`
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteSink(LogSinkName sinkName) {
    DeleteSinkRequest request = DeleteSinkRequest.newBuilder().setSinkName(sinkName == null ? null : sinkName.toString()).build();
    deleteSink(request);
}
Also used : DeleteSinkRequest(com.google.logging.v2.DeleteSinkRequest)

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