Search in sources :

Example 46 with OrganizationName

use of com.google.monitoring.v3.OrganizationName in project java-monitoring by googleapis.

the class MetricServiceClientTest method createMetricDescriptorExceptionTest2.

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

Example 47 with OrganizationName

use of com.google.monitoring.v3.OrganizationName in project java-monitoring by googleapis.

the class MetricServiceClientTest method createMetricDescriptorTest2.

@Test
public void createMetricDescriptorTest2() throws Exception {
    MetricDescriptor expectedResponse = MetricDescriptor.newBuilder().setName("name3373707").setType("type3575610").addAllLabels(new ArrayList<LabelDescriptor>()).setUnit("unit3594628").setDescription("description-1724546052").setDisplayName("displayName1714148973").setMetadata(MetricDescriptor.MetricDescriptorMetadata.newBuilder().build()).setLaunchStage(LaunchStage.forNumber(0)).addAllMonitoredResourceTypes(new ArrayList<String>()).build();
    mockMetricService.addResponse(expectedResponse);
    OrganizationName name = OrganizationName.of("[ORGANIZATION]");
    MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build();
    MetricDescriptor actualResponse = client.createMetricDescriptor(name, metricDescriptor);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockMetricService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateMetricDescriptorRequest actualRequest = ((CreateMetricDescriptorRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(metricDescriptor, actualRequest.getMetricDescriptor());
    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) CreateMetricDescriptorRequest(com.google.monitoring.v3.CreateMetricDescriptorRequest) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 48 with OrganizationName

use of com.google.monitoring.v3.OrganizationName in project java-monitoring by googleapis.

the class AlertPolicyServiceClientTest method listAlertPoliciesExceptionTest2.

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

use of com.google.monitoring.v3.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 50 with OrganizationName

use of com.google.monitoring.v3.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)

Aggregations

Test (org.junit.Test)62 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)31 AbstractMessage (com.google.protobuf.AbstractMessage)31 StatusRuntimeException (io.grpc.StatusRuntimeException)31 OrganizationName (com.google.monitoring.v3.OrganizationName)30 OrganizationName (com.google.logging.v2.OrganizationName)22 OrganizationName (com.google.privacy.dlp.v2.OrganizationName)12 LogExclusion (com.google.logging.v2.LogExclusion)7 LogSink (com.google.logging.v2.LogSink)7 ArrayList (java.util.ArrayList)7 MetricDescriptor (com.google.api.MetricDescriptor)3 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)3 AlertPolicy (com.google.monitoring.v3.AlertPolicy)3 UptimeCheckConfig (com.google.monitoring.v3.UptimeCheckConfig)3 InspectTemplate (com.google.privacy.dlp.v2.InspectTemplate)3 ConfigClient (com.google.cloud.logging.v2.ConfigClient)2 ListExclusionsPagedResponse (com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse)2 ListSinksPagedResponse (com.google.cloud.logging.v2.ConfigClient.ListSinksPagedResponse)2 ListLogsPagedResponse (com.google.cloud.logging.v2.LoggingClient.ListLogsPagedResponse)2 CreateExclusionRequest (com.google.logging.v2.CreateExclusionRequest)2