Search in sources :

Example 1 with UFGroup

use of bio.terra.cli.serialization.userfacing.UFGroup in project terra-cli by DataBiosphere.

the class SpendProfileUser method generateSamGroupForEmail.

/**
 * Create a SAM group, so we can use its generated email. This is a workaround to our current use
 * of hard-coded test users. We don't want to use the CLI test users here because then this test
 * could not be run simultaneously with other tests.
 *
 * @return the generated group's email
 */
private String generateSamGroupForEmail() throws IOException {
    String name = SamGroups.randomGroupName();
    spendProfileOwner.login();
    // `terra group create --name=$name`
    UFGroup groupCreated = TestCommand.runAndParseCommandExpectSuccess(UFGroup.class, "group", "create", "--name=" + name);
    // track the group so we can clean it up in case this test method fails
    trackedGroups.trackGroup(name, spendProfileOwner);
    return groupCreated.email;
}
Also used : UFGroup(bio.terra.cli.serialization.userfacing.UFGroup)

Example 2 with UFGroup

use of bio.terra.cli.serialization.userfacing.UFGroup in project terra-cli by DataBiosphere.

the class Group method listUsersReflectsAddRemove.

@Test
@DisplayName("list-users reflects adding and removing a user")
void listUsersReflectsAddRemove() throws IOException {
    TestUser groupCreator = TestUser.chooseTestUser();
    groupCreator.login();
    // `terra group create --name=$name`
    String name = SamGroups.randomGroupName();
    TestCommand.runCommandExpectSuccess("group", "create", "--name=" + name);
    // track the group so we can clean it up in case this test method fails
    trackedGroups.trackGroup(name, groupCreator);
    // `terra group add-user --name=$name --email=$email --policy=MEMBER`
    TestUser groupMember = TestUser.chooseTestUserWhoIsNot(groupCreator);
    TestCommand.runCommandExpectSuccess("group", "add-user", "--name=" + name, "--email=" + groupMember.email, "--policy=MEMBER");
    // check that group member is included in the list-users output with one policy
    expectListedMemberWithPolicies(name, groupMember.email, GroupPolicy.MEMBER);
    // `terra group add-user --name=$name --email=$email --policy=ADMIN`
    TestCommand.runCommandExpectSuccess("group", "add-user", "--name=" + name, "--email=" + groupMember.email, "--policy=ADMIN");
    // check that group member is included in the list-users output with two policies
    expectListedMemberWithPolicies(name, groupMember.email, GroupPolicy.MEMBER, GroupPolicy.ADMIN);
    // `terra group describe --name=$name`
    UFGroup groupDescribed = TestCommand.runAndParseCommandExpectSuccess(UFGroup.class, "group", "describe", "--name=" + name);
    assertEquals(2, groupDescribed.numMembers, "group describe shows two members");
    // `terra group remove-user --name=$name --email=$email --policy=MEMBER`
    TestCommand.runCommandExpectSuccess("group", "remove-user", "--name=" + name, "--email=" + groupMember.email, "--policy=MEMBER");
    // check that group member is included in the list-users output with one policy
    expectListedMemberWithPolicies(name, groupMember.email, GroupPolicy.ADMIN);
    // `terra group remove-user --name=$name --email=$email --policy=ADMIN`
    TestCommand.runCommandExpectSuccess("group", "remove-user", "--name=" + name, "--email=" + groupMember.email, "--policy=ADMIN");
    // check that group member is no longer included in the list-users output
    Optional<UFGroupMember> listedGroupMember = listMembersWithEmail(name, groupMember.email);
    assertTrue(listedGroupMember.isEmpty(), "test user is no longer included in members list");
    // check that the group creator is included in the list-users output
    expectListedMemberWithPolicies(name, groupCreator.email, GroupPolicy.ADMIN);
    // `terra group delete --name=$name`
    TestCommand.runCommandExpectSuccess("group", "delete", "--name=" + name, "--quiet");
}
Also used : UFGroupMember(bio.terra.cli.serialization.userfacing.UFGroupMember) UFGroup(bio.terra.cli.serialization.userfacing.UFGroup) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with UFGroup

use of bio.terra.cli.serialization.userfacing.UFGroup in project terra-cli by DataBiosphere.

the class Group method listDescribeUsersReflectCreateDelete.

@Test
@DisplayName("list, describe, list-users reflect creating and deleting a group")
void listDescribeUsersReflectCreateDelete() throws IOException {
    TestUser testUser = TestUser.chooseTestUser();
    testUser.login();
    // `terra group create --name=$name`
    String name = SamGroups.randomGroupName();
    UFGroup groupCreated = TestCommand.runAndParseCommandExpectSuccess(UFGroup.class, "group", "create", "--name=" + name);
    // track the group so we can clean it up in case this test method fails
    trackedGroups.trackGroup(name, testUser);
    // check that the name and email match
    assertEquals(name, groupCreated.name, "group name matches after create");
    assertThat("group email contains the name", groupCreated.email, CoreMatchers.containsString(name));
    assertThat("group creator is an admin", groupCreated.currentUserPolicies.contains(GroupPolicy.ADMIN));
    // `terra group list-users --name=$name`
    // check that the group creator is included in the list and is an admin
    expectListedMemberWithPolicies(name, testUser.email, GroupPolicy.ADMIN);
    // `terra group list`
    List<UFGroup> groupList = TestCommand.runAndParseCommandExpectSuccess(new TypeReference<>() {
    }, "group", "list");
    // check that the listed group matches the created one
    Optional<UFGroup> matchedGroup = groupList.stream().filter(listedGroup -> listedGroup.name.equals(name)).findAny();
    assertTrue(matchedGroup.isPresent(), "group appears in list after create");
    assertEquals(name, matchedGroup.get().name, "group name matches list output after create");
    assertEquals(groupCreated.email, matchedGroup.get().email, "group email matches list output after create");
    assertTrue(matchedGroup.get().currentUserPolicies.contains(GroupPolicy.ADMIN), "group policies for current user matches list output after create");
    // `terra group describe --name=$name`
    UFGroup groupDescribed = TestCommand.runAndParseCommandExpectSuccess(UFGroup.class, "group", "describe", "--name=" + name);
    // check that the described group matches the created one
    assertEquals(name, groupDescribed.name, "group name matches describe output after create");
    assertEquals(groupCreated.email, groupDescribed.email, "group email matches describe output after create");
    assertTrue(groupDescribed.currentUserPolicies.contains(GroupPolicy.ADMIN), "group policies for current user matches describe output after create");
    assertEquals(1, groupDescribed.numMembers, "group # members matches describe output after create");
    // `terra group delete --name=$name`
    TestCommand.runCommandExpectSuccess("group", "delete", "--name=" + name, "--quiet");
    // `terra group list`
    groupList = TestCommand.runAndParseCommandExpectSuccess(new TypeReference<>() {
    }, "group", "list");
    // check that the group is not included in the list output
    matchedGroup = groupList.stream().filter(listedGroup -> listedGroup.name.equals(name)).findAny();
    assertTrue(matchedGroup.isEmpty(), "group does not appear in list after delete");
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) UFGroupMember(bio.terra.cli.serialization.userfacing.UFGroupMember) Arrays(java.util.Arrays) UFGroup(bio.terra.cli.serialization.userfacing.UFGroup) TestCommand(harness.TestCommand) SamGroups(harness.utils.SamGroups) TestUser(harness.TestUser) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) DisplayName(org.junit.jupiter.api.DisplayName) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) GroupPolicy(bio.terra.cli.service.SamService.GroupPolicy) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ClearContextUnit(harness.baseclasses.ClearContextUnit) Optional(java.util.Optional) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Tag(org.junit.jupiter.api.Tag) TypeReference(com.fasterxml.jackson.core.type.TypeReference) TypeReference(com.fasterxml.jackson.core.type.TypeReference) UFGroup(bio.terra.cli.serialization.userfacing.UFGroup) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with UFGroup

use of bio.terra.cli.serialization.userfacing.UFGroup in project terra-cli by DataBiosphere.

the class Delete method execute.

/**
 * Delete an existing Terra group.
 */
@Override
protected void execute() {
    Group groupToDelete = Group.get(groupNameOption.name);
    // print details about the group before showing the delete prompt
    new UFGroup(groupToDelete).print();
    deletePromptOption.confirmOrThrow();
    groupToDelete.delete();
    OUT.println("Terra group successfully deleted.");
}
Also used : UFGroup(bio.terra.cli.serialization.userfacing.UFGroup) Group(bio.terra.cli.businessobject.Group) UFGroup(bio.terra.cli.serialization.userfacing.UFGroup)

Example 5 with UFGroup

use of bio.terra.cli.serialization.userfacing.UFGroup in project terra-cli by DataBiosphere.

the class SpendProfileUser method cleanupOnce.

@AfterAll
void cleanupOnce() throws IOException, InterruptedException {
    spendProfileOwner.login();
    // try to disable spend for each group that was created by a method in this class
    for (Map.Entry<String, TestUser> groupNameToCreator : trackedGroups.getTrackedGroups().entrySet()) {
        UFGroup groupInfo = TestCommand.runAndParseCommandExpectSuccess(UFGroup.class, "group", "describe", "--name=" + groupNameToCreator.getKey());
        TestCommand.runCommand("spend", "disable", "--email=" + groupInfo.email, "--policy=USER");
        TestCommand.runCommand("spend", "disable", "--email=" + groupInfo.email, "--policy=OWNER");
    }
    // then try to delete the groups
    trackedGroups.deleteAllTrackedGroups();
}
Also used : UFGroup(bio.terra.cli.serialization.userfacing.UFGroup) Map(java.util.Map) TestUser(harness.TestUser) AfterAll(org.junit.jupiter.api.AfterAll)

Aggregations

UFGroup (bio.terra.cli.serialization.userfacing.UFGroup)8 TestUser (harness.TestUser)4 Group (bio.terra.cli.businessobject.Group)3 AfterAll (org.junit.jupiter.api.AfterAll)3 DisplayName (org.junit.jupiter.api.DisplayName)3 Test (org.junit.jupiter.api.Test)3 UFGroupMember (bio.terra.cli.serialization.userfacing.UFGroupMember)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 TestCommand (harness.TestCommand)2 ClearContextUnit (harness.baseclasses.ClearContextUnit)2 SamGroups (harness.utils.SamGroups)2 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2