<commit_before>package unit;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.emptyString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import bio.terra.cli.serialization.userfacing.UFStatus;
import bio.terra.cli.serialization.userfacing.UFWorkspace;
import bio.terra.cli.serialization.userfacing.UFWorkspaceLight;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import harness.TestCommand;
import harness.TestCommand.Result;
import harness.TestUser;
import harness.baseclasses.ClearContextUnit;
import harness.utils.WorkspaceUtils;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

/** Tests for the `terra workspace` commands. */
@Tag("unit")
public class Workspace extends ClearContextUnit {
  @Test
  @DisplayName("status, describe, workspace list reflect workspace create")
  void statusDescribeListReflectCreate() throws IOException {
    // select a test user and login
    TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
    testUser.login();

    UFWorkspace createWorkspace = WorkspaceUtils.createWorkspaceWithCleanup(testUser);

    // check the created workspace has an id and a google project
    assertNotNull(createWorkspace.id, "create workspace returned a workspace id");
    assertNotNull(createWorkspace.googleProjectId, "create workspace created a gcp project");
    assertThat(
        "workspace email matches test user",
        createWorkspace.userEmail,
        equalToIgnoringCase(testUser.email));

    // `terra status --format=json`
    UFStatus status = TestCommand.runAndParseCommandExpectSuccess(UFStatus.class, "status");

    // check the current status reflects the new workspace
    assertThat(
        "workspace server matches current server",
        createWorkspace.serverName,
        equalToIgnoringCase(status.server.name));
    assertEquals(createWorkspace.id, status.workspace.id, "workspace id matches current status");
    assertEquals(
        createWorkspace.googleProjectId,
        status.workspace.googleProjectId,
        "workspace gcp project matches current status");

    // `terra workspace describe --format=json`
    UFWorkspace describeWorkspace =
        TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "describe");

    // check the new workspace is returned by describe
    assertEquals(createWorkspace.id, describeWorkspace.id, "workspace id matches that in describe");
    assertEquals(
        createWorkspace.googleProjectId,
        describeWorkspace.googleProjectId,
        "workspace gcp project matches that in describe");

    // check the new workspace is included in the list
    List<UFWorkspaceLight> matchingWorkspaces = listWorkspacesWithId(createWorkspace.id);
    assertEquals(1, matchingWorkspaces.size(), "new workspace is included exactly once in list");
    assertEquals(
        createWorkspace.id, matchingWorkspaces.get(0).id, "workspace id matches that in list");
    assertEquals(
        createWorkspace.googleProjectId,
        matchingWorkspaces.get(0).googleProjectId,
        "workspace gcp project matches that in list");

    // `terra workspace delete`
    TestCommand.runCommandExpectSuccess("workspace", "delete", "--quiet");
  }

  @Test
  @DisplayName("status, describe, workspace list reflect workspace delete")
  void statusDescribeListReflectDelete() throws IOException {
    // select a test user and login
    TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
    testUser.login();

    UFWorkspace createWorkspace = WorkspaceUtils.createWorkspaceWithCleanup(testUser);

    // `terra workspace delete --format=json`
    TestCommand.runCommandExpectSuccess("workspace", "delete", "--quiet");

    // `terra status --format=json`
    UFStatus status = TestCommand.runAndParseCommandExpectSuccess(UFStatus.class, "status");

    // check the current status reflects the deleted workspace
    assertNull(status.workspace, "status has no workspace after delete");

    // `terra workspace describe --format=json`
    TestCommand.runCommandExpectExitCode(1, "workspace", "describe");

    // check the deleted workspace is not included in the list
    List<UFWorkspaceLight> matchingWorkspaces = listWorkspacesWithId(createWorkspace.id);
    assertEquals(0, matchingWorkspaces.size(), "deleted workspace is not included in list");
  }

  @Test
  @DisplayName("status, describe, workspace list reflect workspace update")
  void statusDescribeListReflectUpdate() throws IOException {
    // select a test user and login
    TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
    testUser.login();

    String name = "statusDescribeListReflectUpdate";
    String description = "status list reflect update";
    UFWorkspace createWorkspace = WorkspaceUtils.createWorkspaceWithCleanup(testUser, name, description);

    // check the created workspace name and description are set
    assertNotNull(createWorkspace.name, "create workspace name is defined");
    assertNotNull(createWorkspace.description, "create workspace description is defined");<commit_msg>spotless<commit_after>package unit;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.emptyString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import bio.terra.cli.serialization.userfacing.UFStatus;
import bio.terra.cli.serialization.userfacing.UFWorkspace;
import bio.terra.cli.serialization.userfacing.UFWorkspaceLight;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import harness.TestCommand;
import harness.TestCommand.Result;
import harness.TestUser;
import harness.baseclasses.ClearContextUnit;
import harness.utils.WorkspaceUtils;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

/** Tests for the `terra workspace` commands. */
@Tag("unit")
public class Workspace extends ClearContextUnit {
  @Test
  @DisplayName("status, describe, workspace list reflect workspace create")
  void statusDescribeListReflectCreate() throws IOException {
    // select a test user and login
    TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
    testUser.login();

    UFWorkspace createWorkspace = WorkspaceUtils.createWorkspaceWithCleanup(testUser);

    // check the created workspace has an id and a google project
    assertNotNull(createWorkspace.id, "create workspace returned a workspace id");
    assertNotNull(createWorkspace.googleProjectId, "create workspace created a gcp project");
    assertThat(
        "workspace email matches test user",
        createWorkspace.userEmail,
        equalToIgnoringCase(testUser.email));

    // `terra status --format=json`
    UFStatus status = TestCommand.runAndParseCommandExpectSuccess(UFStatus.class, "status");

    // check the current status reflects the new workspace
    assertThat(
        "workspace server matches current server",
        createWorkspace.serverName,
        equalToIgnoringCase(status.server.name));
    assertEquals(createWorkspace.id, status.workspace.id, "workspace id matches current status");
    assertEquals(
        createWorkspace.googleProjectId,
        status.workspace.googleProjectId,
        "workspace gcp project matches current status");

    // `terra workspace describe --format=json`
    UFWorkspace describeWorkspace =
        TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "describe");

    // check the new workspace is returned by describe
    assertEquals(createWorkspace.id, describeWorkspace.id, "workspace id matches that in describe");
    assertEquals(
        createWorkspace.googleProjectId,
        describeWorkspace.googleProjectId,
        "workspace gcp project matches that in describe");

    // check the new workspace is included in the list
    List<UFWorkspaceLight> matchingWorkspaces = listWorkspacesWithId(createWorkspace.id);
    assertEquals(1, matchingWorkspaces.size(), "new workspace is included exactly once in list");
    assertEquals(
        createWorkspace.id, matchingWorkspaces.get(0).id, "workspace id matches that in list");
    assertEquals(
        createWorkspace.googleProjectId,
        matchingWorkspaces.get(0).googleProjectId,
        "workspace gcp project matches that in list");

    // `terra workspace delete`
    TestCommand.runCommandExpectSuccess("workspace", "delete", "--quiet");
  }

  @Test
  @DisplayName("status, describe, workspace list reflect workspace delete")
  void statusDescribeListReflectDelete() throws IOException {
    // select a test user and login
    TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
    testUser.login();

    UFWorkspace createWorkspace = WorkspaceUtils.createWorkspaceWithCleanup(testUser);

    // `terra workspace delete --format=json`
    TestCommand.runCommandExpectSuccess("workspace", "delete", "--quiet");

    // `terra status --format=json`
    UFStatus status = TestCommand.runAndParseCommandExpectSuccess(UFStatus.class, "status");

    // check the current status reflects the deleted workspace
    assertNull(status.workspace, "status has no workspace after delete");

    // `terra workspace describe --format=json`
    TestCommand.runCommandExpectExitCode(1, "workspace", "describe");

    // check the deleted workspace is not included in the list
    List<UFWorkspaceLight> matchingWorkspaces = listWorkspacesWithId(createWorkspace.id);
    assertEquals(0, matchingWorkspaces.size(), "deleted workspace is not included in list");
  }

  @Test
  @DisplayName("status, describe, workspace list reflect workspace update")
  void statusDescribeListReflectUpdate() throws IOException {
    // select a test user and login
    TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
    testUser.login();

    String name = "statusDescribeListReflectUpdate";
    String description = "status list reflect update";
    UFWorkspace createWorkspace =
        WorkspaceUtils.createWorkspaceWithCleanup(testUser, name, description);

    // check the created workspace name and description are set
    assertNotNull(createWorkspace.name, "create workspace name is defined");
    assertNotNull(createWorkspace.description, "create workspace description is defined");
{'fraction_non_alphanumeric': 0.08844432745459331, 'fraction_numerical': 0.0008774238834781083, 'mean_word_length': 4.6791230692575985, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1059916', 'n_tokens_mistral': 2980, 'n_tokens_neox': 2987, 'n_words': 791}