Search in sources :

Example 11 with ProjectName

use of com.google.monitoring.v3.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class ReportErrorsServiceClientTest method reportErrorEventExceptionTest.

@Test
@SuppressWarnings("all")
public void reportErrorEventExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockReportErrorsService.addException(exception);
    try {
        ProjectName projectName = ProjectName.create("[PROJECT]");
        ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build();
        client.reportErrorEvent(projectName, event);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ReportedErrorEvent(com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 12 with ProjectName

use of com.google.monitoring.v3.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClient method createTimeSeries.

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
   * Creates or adds data to one or more time series. The response is empty if all time series in
   * the request were written. If any time series could not be written, a corresponding failure
   * message is included in the error response.
   *
   * <p>Sample code:
   *
   * <pre><code>
   * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
   *   ProjectName name = ProjectName.create("[PROJECT]");
   *   List&lt;TimeSeries&gt; timeSeries = new ArrayList&lt;&gt;();
   *   metricServiceClient.createTimeSeries(name, timeSeries);
   * }
   * </code></pre>
   *
   * @param name The project on which to execute the request. The format is
   *     `"projects/{project_id_or_number}"`.
   * @param timeSeries The new data to be added to a list of time series. Adds at most one data
   *     point to each of several time series. The new data point must be more recent than any other
   *     point in its time series. Each `TimeSeries` value must fully specify a unique time series
   *     by supplying all label values for the metric and the monitored resource.
   * @throws com.google.api.gax.grpc.ApiException if the remote call fails
   */
public final void createTimeSeries(ProjectName name, List<TimeSeries> timeSeries) {
    CreateTimeSeriesRequest request = CreateTimeSeriesRequest.newBuilder().setNameWithProjectName(name).addAllTimeSeries(timeSeries).build();
    createTimeSeries(request);
}
Also used : CreateTimeSeriesRequest(com.google.monitoring.v3.CreateTimeSeriesRequest)

Example 13 with ProjectName

use of com.google.monitoring.v3.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class GroupServiceClientTest method createGroupTest.

@Test
@SuppressWarnings("all")
public void createGroupTest() {
    GroupName name2 = GroupName.create("[PROJECT]", "[GROUP]");
    String displayName = "displayName1615086568";
    GroupName parentName = GroupName.create("[PROJECT]", "[GROUP]");
    String filter = "filter-1274492040";
    boolean isCluster = false;
    Group expectedResponse = Group.newBuilder().setNameWithGroupName(name2).setDisplayName(displayName).setParentNameWithGroupName(parentName).setFilter(filter).setIsCluster(isCluster).build();
    mockGroupService.addResponse(expectedResponse);
    ProjectName name = ProjectName.create("[PROJECT]");
    Group group = Group.newBuilder().build();
    Group actualResponse = client.createGroup(name, group);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockGroupService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateGroupRequest actualRequest = (CreateGroupRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsProjectName());
    Assert.assertEquals(group, actualRequest.getGroup());
}
Also used : GroupName(com.google.monitoring.v3.GroupName) Group(com.google.monitoring.v3.Group) ProjectName(com.google.monitoring.v3.ProjectName) CreateGroupRequest(com.google.monitoring.v3.CreateGroupRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 14 with ProjectName

use of com.google.monitoring.v3.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class GroupServiceClientTest method createGroupExceptionTest.

@Test
@SuppressWarnings("all")
public void createGroupExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockGroupService.addException(exception);
    try {
        ProjectName name = ProjectName.create("[PROJECT]");
        Group group = Group.newBuilder().build();
        client.createGroup(name, group);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : Group(com.google.monitoring.v3.Group) ProjectName(com.google.monitoring.v3.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 15 with ProjectName

use of com.google.monitoring.v3.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method listSnapshotsExceptionTest.

@Test
@SuppressWarnings("all")
public void listSnapshotsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockSubscriber.addException(exception);
    try {
        ProjectName project = ProjectName.create("[PROJECT]");
        client.listSnapshots(project);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : ProjectName(com.google.pubsub.v1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)26 ApiException (com.google.api.gax.grpc.ApiException)13 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)13 StatusRuntimeException (io.grpc.StatusRuntimeException)13 ProjectName (com.google.monitoring.v3.ProjectName)12 ProjectName (com.google.devtools.clouderrorreporting.v1beta1.ProjectName)8 ProjectName (com.google.pubsub.v1.ProjectName)6 MetricDescriptor (com.google.api.MetricDescriptor)3 TimeSeries (com.google.monitoring.v3.TimeSeries)3 ByteString (com.google.protobuf.ByteString)3 QueryTimeRange (com.google.devtools.clouderrorreporting.v1beta1.QueryTimeRange)2 ReportedErrorEvent (com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent)2 CreateTimeSeriesRequest (com.google.monitoring.v3.CreateTimeSeriesRequest)2 Group (com.google.monitoring.v3.Group)2 ListTimeSeriesRequest (com.google.monitoring.v3.ListTimeSeriesRequest)2 TimeSeriesView (com.google.monitoring.v3.ListTimeSeriesRequest.TimeSeriesView)2 TimeInterval (com.google.monitoring.v3.TimeInterval)2 ArrayList (java.util.ArrayList)2 MonitoredResourceDescriptor (com.google.api.MonitoredResourceDescriptor)1 ListEventsPagedResponse (com.google.cloud.errorreporting.spi.v1beta1.PagedResponseWrappers.ListEventsPagedResponse)1