Search in sources :

Example 21 with DeidentifyTemplate

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

the class DlpServiceClientTest method updateDeidentifyTemplateExceptionTest.

@Test
public void updateDeidentifyTemplateExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDlpService.addException(exception);
    try {
        DeidentifyTemplateName name = DeidentifyTemplateName.ofOrganizationDeidentifyTemplateName("[ORGANIZATION]", "[DEIDENTIFY_TEMPLATE]");
        DeidentifyTemplate deidentifyTemplate = DeidentifyTemplate.newBuilder().build();
        FieldMask updateMask = FieldMask.newBuilder().build();
        client.updateDeidentifyTemplate(name, deidentifyTemplate, updateMask);
        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) FieldMask(com.google.protobuf.FieldMask) DeidentifyTemplate(com.google.privacy.dlp.v2.DeidentifyTemplate) Test(org.junit.Test)

Example 22 with DeidentifyTemplate

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

the class DlpServiceClientTest method getDeidentifyTemplateTest2.

@Test
public void getDeidentifyTemplateTest2() 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);
    String name = "name3373707";
    DeidentifyTemplate actualResponse = client.getDeidentifyTemplate(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetDeidentifyTemplateRequest actualRequest = ((GetDeidentifyTemplateRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : GetDeidentifyTemplateRequest(com.google.privacy.dlp.v2.GetDeidentifyTemplateRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) DeidentifyTemplate(com.google.privacy.dlp.v2.DeidentifyTemplate) Test(org.junit.Test)

Example 23 with DeidentifyTemplate

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

the class DlpServiceClientTest method createDeidentifyTemplateExceptionTest3.

@Test
public void createDeidentifyTemplateExceptionTest3() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDlpService.addException(exception);
    try {
        OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
        DeidentifyTemplate deidentifyTemplate = DeidentifyTemplate.newBuilder().build();
        client.createDeidentifyTemplate(parent, deidentifyTemplate);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : OrganizationName(com.google.privacy.dlp.v2.OrganizationName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) DeidentifyTemplate(com.google.privacy.dlp.v2.DeidentifyTemplate) Test(org.junit.Test)

Aggregations

DeidentifyTemplate (com.google.privacy.dlp.v2.DeidentifyTemplate)21 Test (org.junit.Test)21 AbstractMessage (com.google.protobuf.AbstractMessage)14 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)7 StatusRuntimeException (io.grpc.StatusRuntimeException)7 OrganizationLocationName (com.google.privacy.dlp.v2.OrganizationLocationName)6 ByteString (com.google.protobuf.ByteString)6 ListDeidentifyTemplatesPagedResponse (com.google.cloud.dlp.v2.DlpServiceClient.ListDeidentifyTemplatesPagedResponse)5 CreateDeidentifyTemplateRequest (com.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest)5 ListDeidentifyTemplatesRequest (com.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest)5 ListDeidentifyTemplatesResponse (com.google.privacy.dlp.v2.ListDeidentifyTemplatesResponse)5 FieldMask (com.google.protobuf.FieldMask)4 DeidentifyTemplateName (com.google.privacy.dlp.v2.DeidentifyTemplateName)3 LocationName (com.google.privacy.dlp.v2.LocationName)3 OrganizationName (com.google.privacy.dlp.v2.OrganizationName)3 ProjectName (com.google.privacy.dlp.v2.ProjectName)3 DeleteDeidentifyTemplateRequest (com.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest)2 GetDeidentifyTemplateRequest (com.google.privacy.dlp.v2.GetDeidentifyTemplateRequest)2 UpdateDeidentifyTemplateRequest (com.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest)2