Search in sources :

Example 11 with DeidentifyTemplate

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

the class DlpServiceClientTest method listDeidentifyTemplatesTest.

@Test
public void listDeidentifyTemplatesTest() throws Exception {
    DeidentifyTemplate responsesElement = DeidentifyTemplate.newBuilder().build();
    ListDeidentifyTemplatesResponse expectedResponse = ListDeidentifyTemplatesResponse.newBuilder().setNextPageToken("").addAllDeidentifyTemplates(Arrays.asList(responsesElement)).build();
    mockDlpService.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    ListDeidentifyTemplatesPagedResponse pagedListResponse = client.listDeidentifyTemplates(parent);
    List<DeidentifyTemplate> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getDeidentifyTemplatesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListDeidentifyTemplatesRequest actualRequest = ((ListDeidentifyTemplatesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListDeidentifyTemplatesRequest(com.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ListDeidentifyTemplatesResponse(com.google.privacy.dlp.v2.ListDeidentifyTemplatesResponse) ListDeidentifyTemplatesPagedResponse(com.google.cloud.dlp.v2.DlpServiceClient.ListDeidentifyTemplatesPagedResponse) DeidentifyTemplate(com.google.privacy.dlp.v2.DeidentifyTemplate) OrganizationLocationName(com.google.privacy.dlp.v2.OrganizationLocationName) LocationName(com.google.privacy.dlp.v2.LocationName) Test(org.junit.Test)

Example 12 with DeidentifyTemplate

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

the class DlpServiceClientTest method createDeidentifyTemplateTest2.

@Test
public void createDeidentifyTemplateTest2() 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);
    OrganizationLocationName parent = OrganizationLocationName.of("[ORGANIZATION]", "[LOCATION]");
    DeidentifyTemplate deidentifyTemplate = DeidentifyTemplate.newBuilder().build();
    DeidentifyTemplate actualResponse = client.createDeidentifyTemplate(parent, deidentifyTemplate);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateDeidentifyTemplateRequest actualRequest = ((CreateDeidentifyTemplateRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(deidentifyTemplate, actualRequest.getDeidentifyTemplate());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : OrganizationLocationName(com.google.privacy.dlp.v2.OrganizationLocationName) AbstractMessage(com.google.protobuf.AbstractMessage) CreateDeidentifyTemplateRequest(com.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest) DeidentifyTemplate(com.google.privacy.dlp.v2.DeidentifyTemplate) Test(org.junit.Test)

Example 13 with DeidentifyTemplate

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

the class DlpServiceClientTest method createDeidentifyTemplateExceptionTest.

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

Example 14 with DeidentifyTemplate

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

the class DlpServiceClientTest method listDeidentifyTemplatesTest5.

@Test
public void listDeidentifyTemplatesTest5() throws Exception {
    DeidentifyTemplate responsesElement = DeidentifyTemplate.newBuilder().build();
    ListDeidentifyTemplatesResponse expectedResponse = ListDeidentifyTemplatesResponse.newBuilder().setNextPageToken("").addAllDeidentifyTemplates(Arrays.asList(responsesElement)).build();
    mockDlpService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListDeidentifyTemplatesPagedResponse pagedListResponse = client.listDeidentifyTemplates(parent);
    List<DeidentifyTemplate> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getDeidentifyTemplatesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListDeidentifyTemplatesRequest actualRequest = ((ListDeidentifyTemplatesRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListDeidentifyTemplatesRequest(com.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ListDeidentifyTemplatesResponse(com.google.privacy.dlp.v2.ListDeidentifyTemplatesResponse) ByteString(com.google.protobuf.ByteString) ListDeidentifyTemplatesPagedResponse(com.google.cloud.dlp.v2.DlpServiceClient.ListDeidentifyTemplatesPagedResponse) DeidentifyTemplate(com.google.privacy.dlp.v2.DeidentifyTemplate) Test(org.junit.Test)

Example 15 with DeidentifyTemplate

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

the class DlpServiceClientTest method createDeidentifyTemplateTest5.

@Test
public void createDeidentifyTemplateTest5() 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 parent = "parent-995424086";
    DeidentifyTemplate deidentifyTemplate = DeidentifyTemplate.newBuilder().build();
    DeidentifyTemplate actualResponse = client.createDeidentifyTemplate(parent, deidentifyTemplate);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateDeidentifyTemplateRequest actualRequest = ((CreateDeidentifyTemplateRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(deidentifyTemplate, actualRequest.getDeidentifyTemplate());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) CreateDeidentifyTemplateRequest(com.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest) ByteString(com.google.protobuf.ByteString) 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