Search in sources :

Example 6 with GroupName

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

the class GroupServiceClientTest method listGroupMembersExceptionTest.

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

Example 7 with GroupName

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

the class GroupServiceClientTest method getGroupTest.

@Test
@SuppressWarnings("all")
public void getGroupTest() {
    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);
    GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
    Group actualResponse = client.getGroup(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockGroupService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetGroupRequest actualRequest = (GetGroupRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsGroupName());
}
Also used : GroupName(com.google.monitoring.v3.GroupName) Group(com.google.monitoring.v3.Group) GetGroupRequest(com.google.monitoring.v3.GetGroupRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 8 with GroupName

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

the class GroupServiceClient method deleteGroup.

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
   * Deletes an existing group.
   *
   * <p>Sample code:
   *
   * <pre><code>
   * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
   *   GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
   *   groupServiceClient.deleteGroup(name);
   * }
   * </code></pre>
   *
   * @param name The group to delete. The format is
   *     `"projects/{project_id_or_number}/groups/{group_id}"`.
   * @throws com.google.api.gax.grpc.ApiException if the remote call fails
   */
public final void deleteGroup(GroupName name) {
    DeleteGroupRequest request = DeleteGroupRequest.newBuilder().setNameWithGroupName(name).build();
    deleteGroup(request);
}
Also used : DeleteGroupRequest(com.google.monitoring.v3.DeleteGroupRequest)

Example 9 with GroupName

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

the class GroupServiceClientTest method listGroupMembersTest.

@Test
@SuppressWarnings("all")
public void listGroupMembersTest() {
    String nextPageToken = "";
    int totalSize = -705419236;
    MonitoredResource membersElement = MonitoredResource.newBuilder().build();
    List<MonitoredResource> members = Arrays.asList(membersElement);
    ListGroupMembersResponse expectedResponse = ListGroupMembersResponse.newBuilder().setNextPageToken(nextPageToken).setTotalSize(totalSize).addAllMembers(members).build();
    mockGroupService.addResponse(expectedResponse);
    GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
    ListGroupMembersPagedResponse pagedListResponse = client.listGroupMembers(name);
    List<MonitoredResource> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getMembersList().get(0), resources.get(0));
    List<GeneratedMessageV3> actualRequests = mockGroupService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListGroupMembersRequest actualRequest = (ListGroupMembersRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsGroupName());
}
Also used : GroupName(com.google.monitoring.v3.GroupName) ListGroupMembersResponse(com.google.monitoring.v3.ListGroupMembersResponse) ListGroupMembersRequest(com.google.monitoring.v3.ListGroupMembersRequest) MonitoredResource(com.google.api.MonitoredResource) ListGroupMembersPagedResponse(com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListGroupMembersPagedResponse) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 10 with GroupName

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

the class GroupServiceClientTest method deleteGroupTest.

@Test
@SuppressWarnings("all")
public void deleteGroupTest() {
    Empty expectedResponse = Empty.newBuilder().build();
    mockGroupService.addResponse(expectedResponse);
    GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
    client.deleteGroup(name);
    List<GeneratedMessageV3> actualRequests = mockGroupService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteGroupRequest actualRequest = (DeleteGroupRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsGroupName());
}
Also used : GroupName(com.google.monitoring.v3.GroupName) Empty(com.google.protobuf.Empty) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) DeleteGroupRequest(com.google.monitoring.v3.DeleteGroupRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 GroupName (com.google.monitoring.v3.GroupName)8 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)7 ApiException (com.google.api.gax.grpc.ApiException)4 StatusRuntimeException (io.grpc.StatusRuntimeException)4 GroupName (com.google.devtools.clouderrorreporting.v1beta1.GroupName)3 Group (com.google.monitoring.v3.Group)3 ErrorGroup (com.google.devtools.clouderrorreporting.v1beta1.ErrorGroup)2 DeleteGroupRequest (com.google.monitoring.v3.DeleteGroupRequest)2 MonitoredResource (com.google.api.MonitoredResource)1 ListGroupMembersPagedResponse (com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListGroupMembersPagedResponse)1 GetGroupRequest (com.google.devtools.clouderrorreporting.v1beta1.GetGroupRequest)1 UpdateGroupRequest (com.google.devtools.clouderrorreporting.v1beta1.UpdateGroupRequest)1 CreateGroupRequest (com.google.monitoring.v3.CreateGroupRequest)1 GetGroupRequest (com.google.monitoring.v3.GetGroupRequest)1 ListGroupMembersRequest (com.google.monitoring.v3.ListGroupMembersRequest)1 ListGroupMembersResponse (com.google.monitoring.v3.ListGroupMembersResponse)1 ProjectName (com.google.monitoring.v3.ProjectName)1 UpdateGroupRequest (com.google.monitoring.v3.UpdateGroupRequest)1 Empty (com.google.protobuf.Empty)1