Search in sources :

Example 1 with OrganizationLocationName

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

the class DlpServiceClientTest method listStoredInfoTypesExceptionTest2.

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

Example 2 with OrganizationLocationName

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

the class DlpServiceClientTest method createInspectTemplateTest2.

@Test
public void createInspectTemplateTest2() throws Exception {
    InspectTemplate expectedResponse = InspectTemplate.newBuilder().setName(InspectTemplateName.ofOrganizationInspectTemplateName("[ORGANIZATION]", "[INSPECT_TEMPLATE]").toString()).setDisplayName("displayName1714148973").setDescription("description-1724546052").setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).setInspectConfig(InspectConfig.newBuilder().build()).build();
    mockDlpService.addResponse(expectedResponse);
    OrganizationLocationName parent = OrganizationLocationName.of("[ORGANIZATION]", "[LOCATION]");
    InspectTemplate inspectTemplate = InspectTemplate.newBuilder().build();
    InspectTemplate actualResponse = client.createInspectTemplate(parent, inspectTemplate);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateInspectTemplateRequest actualRequest = ((CreateInspectTemplateRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(inspectTemplate, actualRequest.getInspectTemplate());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : OrganizationLocationName(com.google.privacy.dlp.v2.OrganizationLocationName) AbstractMessage(com.google.protobuf.AbstractMessage) InspectTemplate(com.google.privacy.dlp.v2.InspectTemplate) CreateInspectTemplateRequest(com.google.privacy.dlp.v2.CreateInspectTemplateRequest) Test(org.junit.Test)

Example 3 with OrganizationLocationName

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

the class DlpServiceClientTest method createDeidentifyTemplateExceptionTest2.

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

Example 4 with OrganizationLocationName

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

the class DlpServiceClientTest method listDeidentifyTemplatesTest2.

@Test
public void listDeidentifyTemplatesTest2() throws Exception {
    DeidentifyTemplate responsesElement = DeidentifyTemplate.newBuilder().build();
    ListDeidentifyTemplatesResponse expectedResponse = ListDeidentifyTemplatesResponse.newBuilder().setNextPageToken("").addAllDeidentifyTemplates(Arrays.asList(responsesElement)).build();
    mockDlpService.addResponse(expectedResponse);
    OrganizationLocationName parent = OrganizationLocationName.of("[ORGANIZATION]", "[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) OrganizationLocationName(com.google.privacy.dlp.v2.OrganizationLocationName) 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) Test(org.junit.Test)

Example 5 with OrganizationLocationName

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

the class DlpServiceClientTest method createInspectTemplateExceptionTest2.

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

Aggregations

Test (org.junit.Test)14 OrganizationLocationName (com.google.privacy.dlp.v2.OrganizationLocationName)12 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)7 AbstractMessage (com.google.protobuf.AbstractMessage)7 StatusRuntimeException (io.grpc.StatusRuntimeException)7 DeidentifyTemplate (com.google.privacy.dlp.v2.DeidentifyTemplate)3 InspectTemplate (com.google.privacy.dlp.v2.InspectTemplate)3 OrganizationLocationName (com.google.logging.v2.OrganizationLocationName)2 StoredInfoType (com.google.privacy.dlp.v2.StoredInfoType)2 StoredInfoTypeConfig (com.google.privacy.dlp.v2.StoredInfoTypeConfig)2 ListDeidentifyTemplatesPagedResponse (com.google.cloud.dlp.v2.DlpServiceClient.ListDeidentifyTemplatesPagedResponse)1 ListInspectTemplatesPagedResponse (com.google.cloud.dlp.v2.DlpServiceClient.ListInspectTemplatesPagedResponse)1 ListStoredInfoTypesPagedResponse (com.google.cloud.dlp.v2.DlpServiceClient.ListStoredInfoTypesPagedResponse)1 ListBucketsPagedResponse (com.google.cloud.logging.v2.ConfigClient.ListBucketsPagedResponse)1 ListBucketsRequest (com.google.logging.v2.ListBucketsRequest)1 ListBucketsResponse (com.google.logging.v2.ListBucketsResponse)1 LogBucket (com.google.logging.v2.LogBucket)1 CreateDeidentifyTemplateRequest (com.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest)1 CreateInspectTemplateRequest (com.google.privacy.dlp.v2.CreateInspectTemplateRequest)1 CreateStoredInfoTypeRequest (com.google.privacy.dlp.v2.CreateStoredInfoTypeRequest)1