Search in sources :

Example 1 with LogExclusionName

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

the class ConfigClientTest method deleteExclusionTest.

@Test
public void deleteExclusionTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockConfigServiceV2.addResponse(expectedResponse);
    LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
    client.deleteExclusion(name);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteExclusionRequest actualRequest = ((DeleteExclusionRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) DeleteExclusionRequest(com.google.logging.v2.DeleteExclusionRequest) LogExclusionName(com.google.logging.v2.LogExclusionName) Test(org.junit.Test)

Example 2 with LogExclusionName

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

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

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

the class ConfigClient method deleteExclusion.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes an exclusion in the _Default sink.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * 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>For example:
 *     <p>`"projects/my-project/exclusions/my-exclusion"`
 * @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 5 with LogExclusionName

use of com.google.logging.v2.LogExclusionName in project java-logging 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)6 Test (org.junit.Test)6 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)3 LogExclusion (com.google.logging.v2.LogExclusion)3 AbstractMessage (com.google.protobuf.AbstractMessage)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 DeleteExclusionRequest (com.google.logging.v2.DeleteExclusionRequest)2 FieldMask (com.google.protobuf.FieldMask)2 GetExclusionRequest (com.google.logging.v2.GetExclusionRequest)1 UpdateExclusionRequest (com.google.logging.v2.UpdateExclusionRequest)1 Empty (com.google.protobuf.Empty)1