Search in sources :

Example 76 with OrganizationName

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

the class AlertPolicyServiceClientTest method createAlertPolicyTest2.

@Test
public void createAlertPolicyTest2() throws Exception {
    AlertPolicy expectedResponse = AlertPolicy.newBuilder().setName(AlertPolicyName.ofProjectAlertPolicyName("[PROJECT]", "[ALERT_POLICY]").toString()).setDisplayName("displayName1714148973").setDocumentation(AlertPolicy.Documentation.newBuilder().build()).putAllUserLabels(new HashMap<String, String>()).addAllConditions(new ArrayList<AlertPolicy.Condition>()).setEnabled(BoolValue.newBuilder().build()).setValidity(Status.newBuilder().build()).addAllNotificationChannels(new ArrayList<String>()).setCreationRecord(MutationRecord.newBuilder().build()).setMutationRecord(MutationRecord.newBuilder().build()).setAlertStrategy(AlertPolicy.AlertStrategy.newBuilder().build()).build();
    mockAlertPolicyService.addResponse(expectedResponse);
    OrganizationName name = OrganizationName.of("[ORGANIZATION]");
    AlertPolicy alertPolicy = AlertPolicy.newBuilder().build();
    AlertPolicy actualResponse = client.createAlertPolicy(name, alertPolicy);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockAlertPolicyService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateAlertPolicyRequest actualRequest = ((CreateAlertPolicyRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(alertPolicy, actualRequest.getAlertPolicy());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : OrganizationName(com.google.monitoring.v3.OrganizationName) AbstractMessage(com.google.protobuf.AbstractMessage) CreateAlertPolicyRequest(com.google.monitoring.v3.CreateAlertPolicyRequest) AlertPolicy(com.google.monitoring.v3.AlertPolicy) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 77 with OrganizationName

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

the class AlertPolicyServiceClientTest method createAlertPolicyExceptionTest2.

@Test
public void createAlertPolicyExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockAlertPolicyService.addException(exception);
    try {
        OrganizationName name = OrganizationName.of("[ORGANIZATION]");
        AlertPolicy alertPolicy = AlertPolicy.newBuilder().build();
        client.createAlertPolicy(name, alertPolicy);
        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) AlertPolicy(com.google.monitoring.v3.AlertPolicy) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 78 with OrganizationName

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

the class GroupServiceClientTest method listGroupsExceptionTest2.

@Test
public void listGroupsExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockGroupService.addException(exception);
    try {
        OrganizationName name = OrganizationName.of("[ORGANIZATION]");
        client.listGroups(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 79 with OrganizationName

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

the class ServiceMonitoringServiceClientTest method listServicesExceptionTest2.

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

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

the class UptimeCheckServiceClientTest method listUptimeCheckConfigsExceptionTest2.

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

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