Search in sources :

Example 1 with StoredInfoTypeName

use of com.google.privacy.dlp.v2.StoredInfoTypeName in project java-dlp by googleapis.

the class DlpServiceClient method deleteStoredInfoType.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes a stored infoType. See https://cloud.google.com/dlp/docs/creating-stored-infotypes to
 * learn more.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
 *   StoredInfoTypeName name =
 *       StoredInfoTypeName.ofOrganizationStoredInfoTypeName(
 *           "[ORGANIZATION]", "[STORED_INFO_TYPE]");
 *   dlpServiceClient.deleteStoredInfoType(name);
 * }
 * }</pre>
 *
 * @param name Required. Resource name of the organization and storedInfoType to be deleted, for
 *     example `organizations/433245324/storedInfoTypes/432452342` or
 *     projects/project-id/storedInfoTypes/432452342.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteStoredInfoType(StoredInfoTypeName name) {
    DeleteStoredInfoTypeRequest request = DeleteStoredInfoTypeRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteStoredInfoType(request);
}
Also used : DeleteStoredInfoTypeRequest(com.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest)

Example 2 with StoredInfoTypeName

use of com.google.privacy.dlp.v2.StoredInfoTypeName in project java-dlp by googleapis.

the class DlpServiceClientTest method getStoredInfoTypeTest.

@Test
public void getStoredInfoTypeTest() throws Exception {
    StoredInfoType expectedResponse = StoredInfoType.newBuilder().setName(StoredInfoTypeName.ofOrganizationStoredInfoTypeName("[ORGANIZATION]", "[STORED_INFO_TYPE]").toString()).setCurrentVersion(StoredInfoTypeVersion.newBuilder().build()).addAllPendingVersions(new ArrayList<StoredInfoTypeVersion>()).build();
    mockDlpService.addResponse(expectedResponse);
    StoredInfoTypeName name = StoredInfoTypeName.ofOrganizationStoredInfoTypeName("[ORGANIZATION]", "[STORED_INFO_TYPE]");
    StoredInfoType actualResponse = client.getStoredInfoType(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetStoredInfoTypeRequest actualRequest = ((GetStoredInfoTypeRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) StoredInfoTypeName(com.google.privacy.dlp.v2.StoredInfoTypeName) GetStoredInfoTypeRequest(com.google.privacy.dlp.v2.GetStoredInfoTypeRequest) StoredInfoType(com.google.privacy.dlp.v2.StoredInfoType) Test(org.junit.Test)

Example 3 with StoredInfoTypeName

use of com.google.privacy.dlp.v2.StoredInfoTypeName in project java-dlp by googleapis.

the class DlpServiceClientTest method updateStoredInfoTypeExceptionTest.

@Test
public void updateStoredInfoTypeExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDlpService.addException(exception);
    try {
        StoredInfoTypeName name = StoredInfoTypeName.ofOrganizationStoredInfoTypeName("[ORGANIZATION]", "[STORED_INFO_TYPE]");
        StoredInfoTypeConfig config = StoredInfoTypeConfig.newBuilder().build();
        FieldMask updateMask = FieldMask.newBuilder().build();
        client.updateStoredInfoType(name, config, updateMask);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) StoredInfoTypeName(com.google.privacy.dlp.v2.StoredInfoTypeName) StoredInfoTypeConfig(com.google.privacy.dlp.v2.StoredInfoTypeConfig) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 4 with StoredInfoTypeName

use of com.google.privacy.dlp.v2.StoredInfoTypeName in project java-dlp by googleapis.

the class DlpServiceClientTest method updateStoredInfoTypeTest.

@Test
public void updateStoredInfoTypeTest() throws Exception {
    StoredInfoType expectedResponse = StoredInfoType.newBuilder().setName(StoredInfoTypeName.ofOrganizationStoredInfoTypeName("[ORGANIZATION]", "[STORED_INFO_TYPE]").toString()).setCurrentVersion(StoredInfoTypeVersion.newBuilder().build()).addAllPendingVersions(new ArrayList<StoredInfoTypeVersion>()).build();
    mockDlpService.addResponse(expectedResponse);
    StoredInfoTypeName name = StoredInfoTypeName.ofOrganizationStoredInfoTypeName("[ORGANIZATION]", "[STORED_INFO_TYPE]");
    StoredInfoTypeConfig config = StoredInfoTypeConfig.newBuilder().build();
    FieldMask updateMask = FieldMask.newBuilder().build();
    StoredInfoType actualResponse = client.updateStoredInfoType(name, config, updateMask);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateStoredInfoTypeRequest actualRequest = ((UpdateStoredInfoTypeRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(config, actualRequest.getConfig());
    Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) UpdateStoredInfoTypeRequest(com.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest) ArrayList(java.util.ArrayList) StoredInfoTypeName(com.google.privacy.dlp.v2.StoredInfoTypeName) StoredInfoType(com.google.privacy.dlp.v2.StoredInfoType) StoredInfoTypeConfig(com.google.privacy.dlp.v2.StoredInfoTypeConfig) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 5 with StoredInfoTypeName

use of com.google.privacy.dlp.v2.StoredInfoTypeName in project java-dlp by googleapis.

the class DlpServiceClientTest method getStoredInfoTypeExceptionTest.

@Test
public void getStoredInfoTypeExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDlpService.addException(exception);
    try {
        StoredInfoTypeName name = StoredInfoTypeName.ofOrganizationStoredInfoTypeName("[ORGANIZATION]", "[STORED_INFO_TYPE]");
        client.getStoredInfoType(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) StoredInfoTypeName(com.google.privacy.dlp.v2.StoredInfoTypeName) Test(org.junit.Test)

Aggregations

StoredInfoTypeName (com.google.privacy.dlp.v2.StoredInfoTypeName)6 Test (org.junit.Test)6 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)3 AbstractMessage (com.google.protobuf.AbstractMessage)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 DeleteStoredInfoTypeRequest (com.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest)2 StoredInfoType (com.google.privacy.dlp.v2.StoredInfoType)2 StoredInfoTypeConfig (com.google.privacy.dlp.v2.StoredInfoTypeConfig)2 FieldMask (com.google.protobuf.FieldMask)2 ArrayList (java.util.ArrayList)2 GetStoredInfoTypeRequest (com.google.privacy.dlp.v2.GetStoredInfoTypeRequest)1 UpdateStoredInfoTypeRequest (com.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest)1 Empty (com.google.protobuf.Empty)1