Search in sources :

Example 31 with ProjectName

use of com.google.spanner.admin.instance.v1.ProjectName in project java-dlp by googleapis.

the class DlpServiceClientTest method listStoredInfoTypesExceptionTest4.

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

Example 32 with ProjectName

use of com.google.spanner.admin.instance.v1.ProjectName in project java-dlp by googleapis.

the class DlpServiceClientTest method createDeidentifyTemplateTest4.

@Test
public void createDeidentifyTemplateTest4() 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);
    ProjectName parent = ProjectName.of("[PROJECT]");
    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 : AbstractMessage(com.google.protobuf.AbstractMessage) CreateDeidentifyTemplateRequest(com.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest) ProjectName(com.google.privacy.dlp.v2.ProjectName) DeidentifyTemplate(com.google.privacy.dlp.v2.DeidentifyTemplate) Test(org.junit.Test)

Example 33 with ProjectName

use of com.google.spanner.admin.instance.v1.ProjectName in project java-dlp by googleapis.

the class DlpServiceClientTest method createDlpJobExceptionTest3.

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

Example 34 with ProjectName

use of com.google.spanner.admin.instance.v1.ProjectName in project java-dlp by googleapis.

the class DlpServiceClientTest method listJobTriggersExceptionTest2.

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

Example 35 with ProjectName

use of com.google.spanner.admin.instance.v1.ProjectName in project java-logging by googleapis.

the class ConfigClientTest method listExclusionsTest4.

@Test
public void listExclusionsTest4() throws Exception {
    LogExclusion responsesElement = LogExclusion.newBuilder().build();
    ListExclusionsResponse expectedResponse = ListExclusionsResponse.newBuilder().setNextPageToken("").addAllExclusions(Arrays.asList(responsesElement)).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    ListExclusionsPagedResponse pagedListResponse = client.listExclusions(parent);
    List<LogExclusion> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getExclusionsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListExclusionsRequest actualRequest = ((ListExclusionsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListExclusionsRequest(com.google.logging.v2.ListExclusionsRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ListExclusionsResponse(com.google.logging.v2.ListExclusionsResponse) ProjectName(com.google.logging.v2.ProjectName) LogExclusion(com.google.logging.v2.LogExclusion) ListExclusionsPagedResponse(com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)146 StatusRuntimeException (io.grpc.StatusRuntimeException)73 ProjectName (com.google.monitoring.v3.ProjectName)62 AbstractMessage (com.google.protobuf.AbstractMessage)60 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)58 ProjectName (com.google.pubsub.v1.ProjectName)30 ArrayList (java.util.ArrayList)29 ProjectName (com.google.privacy.dlp.v2.ProjectName)22 ByteString (com.google.protobuf.ByteString)18 DataTransferServiceClient (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient)17 ProjectName (com.google.cloud.bigquery.datatransfer.v1.ProjectName)17 IOException (java.io.IOException)17 CreateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest)16 TransferConfig (com.google.cloud.bigquery.datatransfer.v1.TransferConfig)16 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)16 ProjectName (com.google.containeranalysis.v1beta1.ProjectName)16 ApiException (com.google.api.gax.rpc.ApiException)15 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)15 TimeSeries (com.google.monitoring.v3.TimeSeries)15 ProjectName (com.google.logging.v2.ProjectName)14