Search in sources :

Example 11 with OrganizationName

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

the class MetricServiceClientTest method listMetricDescriptorsTest2.

@Test
public void listMetricDescriptorsTest2() throws Exception {
    MetricDescriptor responsesElement = MetricDescriptor.newBuilder().build();
    ListMetricDescriptorsResponse expectedResponse = ListMetricDescriptorsResponse.newBuilder().setNextPageToken("").addAllMetricDescriptors(Arrays.asList(responsesElement)).build();
    mockMetricService.addResponse(expectedResponse);
    OrganizationName name = OrganizationName.of("[ORGANIZATION]");
    ListMetricDescriptorsPagedResponse pagedListResponse = client.listMetricDescriptors(name);
    List<MetricDescriptor> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getMetricDescriptorsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockMetricService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListMetricDescriptorsRequest actualRequest = ((ListMetricDescriptorsRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : OrganizationName(com.google.monitoring.v3.OrganizationName) MetricDescriptor(com.google.api.MetricDescriptor) AbstractMessage(com.google.protobuf.AbstractMessage) ListMetricDescriptorsRequest(com.google.monitoring.v3.ListMetricDescriptorsRequest) ListMetricDescriptorsResponse(com.google.monitoring.v3.ListMetricDescriptorsResponse) ListMetricDescriptorsPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListMetricDescriptorsPagedResponse) Test(org.junit.Test)

Example 12 with OrganizationName

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

the class MetricServiceClientTest method listMonitoredResourceDescriptorsExceptionTest2.

@Test
public void listMonitoredResourceDescriptorsExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockMetricService.addException(exception);
    try {
        OrganizationName name = OrganizationName.of("[ORGANIZATION]");
        client.listMonitoredResourceDescriptors(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : OrganizationName(com.google.monitoring.v3.OrganizationName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 13 with OrganizationName

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

the class UptimeCheckServiceClientTest method createUptimeCheckConfigTest2.

@Test
public void createUptimeCheckConfigTest2() throws Exception {
    UptimeCheckConfig expectedResponse = UptimeCheckConfig.newBuilder().setName(UptimeCheckConfigName.ofProjectUptimeCheckConfigName("[PROJECT]", "[UPTIME_CHECK_CONFIG]").toString()).setDisplayName("displayName1714148973").setPeriod(Duration.newBuilder().build()).setTimeout(Duration.newBuilder().build()).addAllContentMatchers(new ArrayList<UptimeCheckConfig.ContentMatcher>()).addAllSelectedRegions(new ArrayList<UptimeCheckRegion>()).setIsInternal(true).addAllInternalCheckers(new ArrayList<InternalChecker>()).build();
    mockUptimeCheckService.addResponse(expectedResponse);
    OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    UptimeCheckConfig uptimeCheckConfig = UptimeCheckConfig.newBuilder().build();
    UptimeCheckConfig actualResponse = client.createUptimeCheckConfig(parent, uptimeCheckConfig);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockUptimeCheckService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateUptimeCheckConfigRequest actualRequest = ((CreateUptimeCheckConfigRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(uptimeCheckConfig, actualRequest.getUptimeCheckConfig());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : OrganizationName(com.google.monitoring.v3.OrganizationName) AbstractMessage(com.google.protobuf.AbstractMessage) CreateUptimeCheckConfigRequest(com.google.monitoring.v3.CreateUptimeCheckConfigRequest) ArrayList(java.util.ArrayList) UptimeCheckConfig(com.google.monitoring.v3.UptimeCheckConfig) Test(org.junit.Test)

Example 14 with OrganizationName

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

the class UptimeCheckServiceClientTest method listUptimeCheckConfigsTest2.

@Test
public void listUptimeCheckConfigsTest2() throws Exception {
    UptimeCheckConfig responsesElement = UptimeCheckConfig.newBuilder().build();
    ListUptimeCheckConfigsResponse expectedResponse = ListUptimeCheckConfigsResponse.newBuilder().setNextPageToken("").addAllUptimeCheckConfigs(Arrays.asList(responsesElement)).build();
    mockUptimeCheckService.addResponse(expectedResponse);
    OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    ListUptimeCheckConfigsPagedResponse pagedListResponse = client.listUptimeCheckConfigs(parent);
    List<UptimeCheckConfig> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getUptimeCheckConfigsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockUptimeCheckService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListUptimeCheckConfigsRequest actualRequest = ((ListUptimeCheckConfigsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : OrganizationName(com.google.monitoring.v3.OrganizationName) ListUptimeCheckConfigsRequest(com.google.monitoring.v3.ListUptimeCheckConfigsRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ListUptimeCheckConfigsResponse(com.google.monitoring.v3.ListUptimeCheckConfigsResponse) ListUptimeCheckConfigsPagedResponse(com.google.cloud.monitoring.v3.UptimeCheckServiceClient.ListUptimeCheckConfigsPagedResponse) UptimeCheckConfig(com.google.monitoring.v3.UptimeCheckConfig) Test(org.junit.Test)

Example 15 with OrganizationName

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

the class UptimeCheckServiceClientTest method createUptimeCheckConfigExceptionTest2.

@Test
public void createUptimeCheckConfigExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockUptimeCheckService.addException(exception);
    try {
        OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
        UptimeCheckConfig uptimeCheckConfig = UptimeCheckConfig.newBuilder().build();
        client.createUptimeCheckConfig(parent, uptimeCheckConfig);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : OrganizationName(com.google.monitoring.v3.OrganizationName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) UptimeCheckConfig(com.google.monitoring.v3.UptimeCheckConfig) 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