Search in sources :

Example 36 with OrganizationName

use of com.google.cloud.securitycenter.v1.OrganizationName in project java-securitycenter by googleapis.

the class SecurityCenterClientTest method listNotificationConfigsTest.

@Test
public void listNotificationConfigsTest() throws Exception {
    NotificationConfig responsesElement = NotificationConfig.newBuilder().build();
    ListNotificationConfigsResponse expectedResponse = ListNotificationConfigsResponse.newBuilder().setNextPageToken("").addAllNotificationConfigs(Arrays.asList(responsesElement)).build();
    mockSecurityCenter.addResponse(expectedResponse);
    OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    ListNotificationConfigsPagedResponse pagedListResponse = client.listNotificationConfigs(parent);
    List<NotificationConfig> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getNotificationConfigsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockSecurityCenter.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListNotificationConfigsRequest actualRequest = ((ListNotificationConfigsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListNotificationConfigsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.ListNotificationConfigsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 37 with OrganizationName

use of com.google.cloud.securitycenter.v1.OrganizationName in project java-dlp by googleapis.

the class DlpServiceClientTest method createInspectTemplateExceptionTest3.

@Test
public void createInspectTemplateExceptionTest3() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDlpService.addException(exception);
    try {
        OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
        InspectTemplate inspectTemplate = InspectTemplate.newBuilder().build();
        client.createInspectTemplate(parent, inspectTemplate);
        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) InspectTemplate(com.google.privacy.dlp.v2.InspectTemplate) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 38 with OrganizationName

use of com.google.cloud.securitycenter.v1.OrganizationName in project java-dlp by googleapis.

the class DlpServiceClientTest method createDeidentifyTemplateTest3.

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

Example 39 with OrganizationName

use of com.google.cloud.securitycenter.v1.OrganizationName in project java-dlp by googleapis.

the class DlpServiceClientTest method createInspectTemplateTest3.

@Test
public void createInspectTemplateTest3() 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);
    OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    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 : OrganizationName(com.google.privacy.dlp.v2.OrganizationName) AbstractMessage(com.google.protobuf.AbstractMessage) InspectTemplate(com.google.privacy.dlp.v2.InspectTemplate) CreateInspectTemplateRequest(com.google.privacy.dlp.v2.CreateInspectTemplateRequest) Test(org.junit.Test)

Example 40 with OrganizationName

use of com.google.cloud.securitycenter.v1.OrganizationName in project java-dlp by googleapis.

the class DlpServiceClientTest method createStoredInfoTypeExceptionTest3.

@Test
public void createStoredInfoTypeExceptionTest3() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDlpService.addException(exception);
    try {
        OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
        StoredInfoTypeConfig config = StoredInfoTypeConfig.newBuilder().build();
        client.createStoredInfoType(parent, config);
        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) StoredInfoTypeConfig(com.google.privacy.dlp.v2.StoredInfoTypeConfig) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)66 AbstractMessage (com.google.protobuf.AbstractMessage)35 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)31 SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)31 StatusRuntimeException (io.grpc.StatusRuntimeException)31 OrganizationName (com.google.monitoring.v3.OrganizationName)30 IOException (java.io.IOException)30 OrganizationName (com.google.logging.v2.OrganizationName)22 OrganizationName (com.google.privacy.dlp.v2.OrganizationName)12 ListAssetsRequest (com.google.cloud.securitycenter.v1.ListAssetsRequest)10 ListAssetsResult (com.google.cloud.securitycenter.v1.ListAssetsResponse.ListAssetsResult)10 ListAssetsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.ListAssetsPagedResponse)10 GroupResult (com.google.cloud.securitycenter.v1.GroupResult)8 LogExclusion (com.google.logging.v2.LogExclusion)7 LogSink (com.google.logging.v2.LogSink)7 ArrayList (java.util.ArrayList)7 GroupAssetsRequest (com.google.cloud.securitycenter.v1.GroupAssetsRequest)6 GroupAssetsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupAssetsPagedResponse)6 MetricDescriptor (com.google.api.MetricDescriptor)3 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)3