Search in sources :

Example 11 with LogExclusionName

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

the class ConfigClient method deleteExclusion.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes an exclusion.
 *
 * <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()) {
 *   LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
 *   configClient.deleteExclusion(name);
 * }
 * }</pre>
 *
 * @param name Required. The resource name of an existing exclusion to delete:
 *     <p>"projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]"
 *     "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]"
 *     "billingAccounts/[BILLING_ACCOUNT_ID]/exclusions/[EXCLUSION_ID]"
 *     "folders/[FOLDER_ID]/exclusions/[EXCLUSION_ID]"
 *     <p>Example: `"projects/my-project-id/exclusions/my-exclusion-id"`.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteExclusion(LogExclusionName name) {
    DeleteExclusionRequest request = DeleteExclusionRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteExclusion(request);
}
Also used : DeleteExclusionRequest(com.google.logging.v2.DeleteExclusionRequest)

Example 12 with LogExclusionName

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

the class ConfigClientTest method getExclusionExceptionTest.

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

Example 13 with LogExclusionName

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

the class ConfigClientTest method updateExclusionTest.

@Test
public void updateExclusionTest() throws Exception {
    LogExclusion expectedResponse = LogExclusion.newBuilder().setName(LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString()).setDescription("description-1724546052").setFilter("filter-1274492040").setDisabled(true).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
    LogExclusion exclusion = LogExclusion.newBuilder().build();
    FieldMask updateMask = FieldMask.newBuilder().build();
    LogExclusion actualResponse = client.updateExclusion(name, exclusion, updateMask);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateExclusionRequest actualRequest = ((UpdateExclusionRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(exclusion, actualRequest.getExclusion());
    Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) UpdateExclusionRequest(com.google.logging.v2.UpdateExclusionRequest) LogExclusion(com.google.logging.v2.LogExclusion) LogExclusionName(com.google.logging.v2.LogExclusionName) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 14 with LogExclusionName

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

the class ConfigClientTest method getExclusionTest.

@Test
public void getExclusionTest() throws Exception {
    LogExclusion expectedResponse = LogExclusion.newBuilder().setName(LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString()).setDescription("description-1724546052").setFilter("filter-1274492040").setDisabled(true).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
    LogExclusion actualResponse = client.getExclusion(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetExclusionRequest actualRequest = ((GetExclusionRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) LogExclusion(com.google.logging.v2.LogExclusion) GetExclusionRequest(com.google.logging.v2.GetExclusionRequest) LogExclusionName(com.google.logging.v2.LogExclusionName) Test(org.junit.Test)

Example 15 with LogExclusionName

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

the class ConfigClientTest method updateExclusionExceptionTest.

@Test
public void updateExclusionExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
        LogExclusion exclusion = LogExclusion.newBuilder().build();
        FieldMask updateMask = FieldMask.newBuilder().build();
        client.updateExclusion(name, exclusion, updateMask);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) LogExclusion(com.google.logging.v2.LogExclusion) StatusRuntimeException(io.grpc.StatusRuntimeException) LogExclusionName(com.google.logging.v2.LogExclusionName) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Aggregations

LogExclusionName (com.google.logging.v2.LogExclusionName)15 Test (org.junit.Test)12 LogExclusion (com.google.logging.v2.LogExclusion)8 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)6 AbstractMessage (com.google.protobuf.AbstractMessage)6 StatusRuntimeException (io.grpc.StatusRuntimeException)6 FieldMask (com.google.protobuf.FieldMask)5 DeleteExclusionRequest (com.google.logging.v2.DeleteExclusionRequest)4 ConfigClient (com.google.cloud.logging.v2.ConfigClient)3 GetExclusionRequest (com.google.logging.v2.GetExclusionRequest)2 UpdateExclusionRequest (com.google.logging.v2.UpdateExclusionRequest)2 Empty (com.google.protobuf.Empty)2