Search in sources :

Example 11 with OrganizationName

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

the class ConfigClientTest method listExclusionsTest3.

@Test
public void listExclusionsTest3() throws Exception {
    LogExclusion responsesElement = LogExclusion.newBuilder().build();
    ListExclusionsResponse expectedResponse = ListExclusionsResponse.newBuilder().setNextPageToken("").addAllExclusions(Arrays.asList(responsesElement)).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    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 : OrganizationName(com.google.logging.v2.OrganizationName) ListExclusionsRequest(com.google.logging.v2.ListExclusionsRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ListExclusionsResponse(com.google.logging.v2.ListExclusionsResponse) LogExclusion(com.google.logging.v2.LogExclusion) ListExclusionsPagedResponse(com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse) Test(org.junit.Test)

Example 12 with OrganizationName

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

the class LoggingClientTest method listLogsTest3.

@Test
public void listLogsTest3() throws Exception {
    String responsesElement = "responsesElement-318365110";
    ListLogsResponse expectedResponse = ListLogsResponse.newBuilder().setNextPageToken("").addAllLogNames(Arrays.asList(responsesElement)).build();
    mockLoggingServiceV2.addResponse(expectedResponse);
    OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    ListLogsPagedResponse pagedListResponse = client.listLogs(parent);
    List<String> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getLogNamesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockLoggingServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListLogsRequest actualRequest = ((ListLogsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : OrganizationName(com.google.logging.v2.OrganizationName) ListLogsResponse(com.google.logging.v2.ListLogsResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListLogsRequest(com.google.logging.v2.ListLogsRequest) ListLogsPagedResponse(com.google.cloud.logging.v2.LoggingClient.ListLogsPagedResponse) Test(org.junit.Test)

Example 13 with OrganizationName

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

the class ConfigClientTest method createExclusionExceptionTest3.

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

Example 14 with OrganizationName

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

the class ListNotificationConfigSnippets method listNotificationConfigs.

// [START securitycenter_list_notification_configs]
public static ImmutableList<NotificationConfig> listNotificationConfigs(String organizationId) throws IOException {
    // String organizationId = "{your-org-id}";
    OrganizationName orgName = OrganizationName.newBuilder().setOrganization(organizationId).build();
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        ListNotificationConfigsPagedResponse response = client.listNotificationConfigs(orgName);
        ImmutableList<NotificationConfig> notificationConfigs = ImmutableList.copyOf(response.iterateAll());
        System.out.println(String.format("List notifications response: %s", response.getPage().getValues()));
        return notificationConfigs;
    }
}
Also used : OrganizationName(com.google.cloud.securitycenter.v1.OrganizationName) ListNotificationConfigsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.ListNotificationConfigsPagedResponse) NotificationConfig(com.google.cloud.securitycenter.v1.NotificationConfig) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 15 with OrganizationName

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

the class DlpServiceClientTest method listInspectTemplatesExceptionTest3.

@Test
public void listInspectTemplatesExceptionTest3() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDlpService.addException(exception);
    try {
        OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
        client.listInspectTemplates(parent);
        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) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)22 OrganizationName (com.google.privacy.dlp.v2.OrganizationName)12 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)11 AbstractMessage (com.google.protobuf.AbstractMessage)11 StatusRuntimeException (io.grpc.StatusRuntimeException)11 OrganizationName (com.google.logging.v2.OrganizationName)10 LogExclusion (com.google.logging.v2.LogExclusion)3 LogSink (com.google.logging.v2.LogSink)3 DeidentifyTemplate (com.google.privacy.dlp.v2.DeidentifyTemplate)3 InspectTemplate (com.google.privacy.dlp.v2.InspectTemplate)3 StoredInfoType (com.google.privacy.dlp.v2.StoredInfoType)2 StoredInfoTypeConfig (com.google.privacy.dlp.v2.StoredInfoTypeConfig)2 ArrayList (java.util.ArrayList)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 ListExclusionsPagedResponse (com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse)1 ListSinksPagedResponse (com.google.cloud.logging.v2.ConfigClient.ListSinksPagedResponse)1 ListLogsPagedResponse (com.google.cloud.logging.v2.LoggingClient.ListLogsPagedResponse)1 NotificationConfig (com.google.cloud.securitycenter.v1.NotificationConfig)1