Search in sources :

Example 41 with OrganizationName

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

the class DlpServiceClientTest method listInspectTemplatesTest3.

@Test
public void listInspectTemplatesTest3() throws Exception {
    InspectTemplate responsesElement = InspectTemplate.newBuilder().build();
    ListInspectTemplatesResponse expectedResponse = ListInspectTemplatesResponse.newBuilder().setNextPageToken("").addAllInspectTemplates(Arrays.asList(responsesElement)).build();
    mockDlpService.addResponse(expectedResponse);
    OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    ListInspectTemplatesPagedResponse pagedListResponse = client.listInspectTemplates(parent);
    List<InspectTemplate> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getInspectTemplatesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListInspectTemplatesRequest actualRequest = ((ListInspectTemplatesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : OrganizationName(com.google.privacy.dlp.v2.OrganizationName) ListInspectTemplatesResponse(com.google.privacy.dlp.v2.ListInspectTemplatesResponse) AbstractMessage(com.google.protobuf.AbstractMessage) InspectTemplate(com.google.privacy.dlp.v2.InspectTemplate) ListInspectTemplatesRequest(com.google.privacy.dlp.v2.ListInspectTemplatesRequest) ListInspectTemplatesPagedResponse(com.google.cloud.dlp.v2.DlpServiceClient.ListInspectTemplatesPagedResponse) Test(org.junit.Test)

Example 42 with OrganizationName

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

the class DlpServiceClientTest method createStoredInfoTypeTest3.

@Test
public void createStoredInfoTypeTest3() throws Exception {
    StoredInfoType expectedResponse = StoredInfoType.newBuilder().setName(StoredInfoTypeName.ofOrganizationStoredInfoTypeName("[ORGANIZATION]", "[STORED_INFO_TYPE]").toString()).setCurrentVersion(StoredInfoTypeVersion.newBuilder().build()).addAllPendingVersions(new ArrayList<StoredInfoTypeVersion>()).build();
    mockDlpService.addResponse(expectedResponse);
    OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    StoredInfoTypeConfig config = StoredInfoTypeConfig.newBuilder().build();
    StoredInfoType actualResponse = client.createStoredInfoType(parent, config);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateStoredInfoTypeRequest actualRequest = ((CreateStoredInfoTypeRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(config, actualRequest.getConfig());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : OrganizationName(com.google.privacy.dlp.v2.OrganizationName) AbstractMessage(com.google.protobuf.AbstractMessage) CreateStoredInfoTypeRequest(com.google.privacy.dlp.v2.CreateStoredInfoTypeRequest) ArrayList(java.util.ArrayList) StoredInfoType(com.google.privacy.dlp.v2.StoredInfoType) StoredInfoTypeConfig(com.google.privacy.dlp.v2.StoredInfoTypeConfig) Test(org.junit.Test)

Example 43 with OrganizationName

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

the class DlpServiceClientTest method listStoredInfoTypesExceptionTest3.

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

Example 44 with OrganizationName

use of com.google.cloud.securitycenter.v1.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 45 with OrganizationName

use of com.google.cloud.securitycenter.v1.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)

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