Search in sources :

Example 1 with DeidentifyTemplateName

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

the class DlpServiceClientTest method deidentifyContentTest.

@Test
public void deidentifyContentTest() throws Exception {
    DeidentifyContentResponse expectedResponse = DeidentifyContentResponse.newBuilder().setItem(ContentItem.newBuilder().build()).setOverview(TransformationOverview.newBuilder().build()).build();
    mockDlpService.addResponse(expectedResponse);
    DeidentifyContentRequest request = DeidentifyContentRequest.newBuilder().setParent(ProjectName.of("[PROJECT]").toString()).setDeidentifyConfig(DeidentifyConfig.newBuilder().build()).setInspectConfig(InspectConfig.newBuilder().build()).setItem(ContentItem.newBuilder().build()).setInspectTemplateName("inspectTemplateName1828857433").setDeidentifyTemplateName("deidentifyTemplateName-1374666414").setLocationId("locationId1541836720").build();
    DeidentifyContentResponse actualResponse = client.deidentifyContent(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeidentifyContentRequest actualRequest = ((DeidentifyContentRequest) actualRequests.get(0));
    Assert.assertEquals(request.getParent(), actualRequest.getParent());
    Assert.assertEquals(request.getDeidentifyConfig(), actualRequest.getDeidentifyConfig());
    Assert.assertEquals(request.getInspectConfig(), actualRequest.getInspectConfig());
    Assert.assertEquals(request.getItem(), actualRequest.getItem());
    Assert.assertEquals(request.getInspectTemplateName(), actualRequest.getInspectTemplateName());
    Assert.assertEquals(request.getDeidentifyTemplateName(), actualRequest.getDeidentifyTemplateName());
    Assert.assertEquals(request.getLocationId(), actualRequest.getLocationId());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : DeidentifyContentRequest(com.google.privacy.dlp.v2.DeidentifyContentRequest) AbstractMessage(com.google.protobuf.AbstractMessage) DeidentifyContentResponse(com.google.privacy.dlp.v2.DeidentifyContentResponse) Test(org.junit.Test)

Example 2 with DeidentifyTemplateName

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

the class DlpServiceClientTest method updateDeidentifyTemplateTest.

@Test
public void updateDeidentifyTemplateTest() throws Exception {
    DeidentifyTemplate expectedResponse = DeidentifyTemplate.newBuilder().setName(DeidentifyTemplateName.ofOrganizationDeidentifyTemplateName("[ORGANIZATION]", "[DEIDENTIFY_TEMPLATE]").toString()).setDisplayName("displayName1714148973").setDescription("description-1724546052").setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).setDeidentifyConfig(DeidentifyConfig.newBuilder().build()).build();
    mockDlpService.addResponse(expectedResponse);
    DeidentifyTemplateName name = DeidentifyTemplateName.ofOrganizationDeidentifyTemplateName("[ORGANIZATION]", "[DEIDENTIFY_TEMPLATE]");
    DeidentifyTemplate deidentifyTemplate = DeidentifyTemplate.newBuilder().build();
    FieldMask updateMask = FieldMask.newBuilder().build();
    DeidentifyTemplate actualResponse = client.updateDeidentifyTemplate(name, deidentifyTemplate, updateMask);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateDeidentifyTemplateRequest actualRequest = ((UpdateDeidentifyTemplateRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(deidentifyTemplate, actualRequest.getDeidentifyTemplate());
    Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : UpdateDeidentifyTemplateRequest(com.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest) AbstractMessage(com.google.protobuf.AbstractMessage) DeidentifyTemplateName(com.google.privacy.dlp.v2.DeidentifyTemplateName) FieldMask(com.google.protobuf.FieldMask) DeidentifyTemplate(com.google.privacy.dlp.v2.DeidentifyTemplate) Test(org.junit.Test)

Example 3 with DeidentifyTemplateName

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

the class DlpServiceClientTest method deleteDeidentifyTemplateTest.

@Test
public void deleteDeidentifyTemplateTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockDlpService.addResponse(expectedResponse);
    DeidentifyTemplateName name = DeidentifyTemplateName.ofOrganizationDeidentifyTemplateName("[ORGANIZATION]", "[DEIDENTIFY_TEMPLATE]");
    client.deleteDeidentifyTemplate(name);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteDeidentifyTemplateRequest actualRequest = ((DeleteDeidentifyTemplateRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) DeleteDeidentifyTemplateRequest(com.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest) AbstractMessage(com.google.protobuf.AbstractMessage) DeidentifyTemplateName(com.google.privacy.dlp.v2.DeidentifyTemplateName) Test(org.junit.Test)

Example 4 with DeidentifyTemplateName

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

the class DlpServiceClientTest method getDeidentifyTemplateExceptionTest.

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

Example 5 with DeidentifyTemplateName

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

the class DlpServiceClient method deleteDeidentifyTemplate.

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

Aggregations

Test (org.junit.Test)8 DeidentifyTemplateName (com.google.privacy.dlp.v2.DeidentifyTemplateName)6 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 StatusRuntimeException (io.grpc.StatusRuntimeException)4 DeidentifyTemplate (com.google.privacy.dlp.v2.DeidentifyTemplate)3 DeidentifyContentRequest (com.google.privacy.dlp.v2.DeidentifyContentRequest)2 DeleteDeidentifyTemplateRequest (com.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest)2 FieldMask (com.google.protobuf.FieldMask)2 DeidentifyContentResponse (com.google.privacy.dlp.v2.DeidentifyContentResponse)1 GetDeidentifyTemplateRequest (com.google.privacy.dlp.v2.GetDeidentifyTemplateRequest)1 UpdateDeidentifyTemplateRequest (com.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest)1 Empty (com.google.protobuf.Empty)1