Search in sources :

Example 1 with TextIO

use of org.beryx.textio.TextIO in project mars-sim by mars-sim.

the class CommanderInfo method main.

public static void main(String[] args) {
    TextIO textIO = TextIoFactory.getTextIO();
    new CommanderInfo().accept(textIO, null);
}
Also used : TextIO(org.beryx.textio.TextIO)

Example 2 with TextIO

use of org.beryx.textio.TextIO in project mars-sim by mars-sim.

the class ConsoleApp method main.

public static void main(String... args) {
    UserChannel channel = null;
    if ((args.length > 1) && args[1].equals("--swing")) {
        TextIO term = TextIoFactory.getTextIO();
        channel = new TextIOChannel(term);
    } else {
        channel = new StreamChannel(System.in, System.out);
    }
    Set<ConversationRole> roles = new HashSet<>();
    roles.add(ConversationRole.ADMIN);
    Conversation conversation = new Conversation(channel, new TopLevel(), roles, null);
    conversation.interact();
}
Also used : TopLevel(org.mars.sim.console.chat.simcommand.TopLevel) TextIO(org.beryx.textio.TextIO) HashSet(java.util.HashSet)

Example 3 with TextIO

use of org.beryx.textio.TextIO in project aws-codeguru-cli by aws.

the class ArtifactAdapterTest method test_zipAndUpload_happyCaseGitFilesOnly.

@Test
public void test_zipAndUpload_happyCaseGitFilesOnly() throws Exception {
    val repoDir = Paths.get("./test-data/two-commits").toRealPath();
    val tempDir = Files.createTempDirectory("test_zipAndUpload_happyCaseGitFilesOnly");
    val bucketName = "some-bucket";
    // only include files from the util dir.
    final List<Path> buildDirs = Collections.emptyList();
    val mockTerminal = new MockTextTerminal();
    // answer No to the question if only files under version control should be scanned.
    mockTerminal.getInputs().add("y");
    val config = Configuration.builder().s3Client(s3client).interactiveMode(true).textIO(new TextIO(mockTerminal)).versionedFiles(Arrays.asList(repoDir.resolve("test.txt"))).build();
    Answer<Object> answer = invocationOnMock -> {
        Path filePath = invocationOnMock.getArgument(1);
        Assertions.assertTrue(filePath.toFile().isFile());
        try (val zipFile = new ZipFile(filePath.toFile())) {
            val entries = zipFile.entries();
            int count = 0;
            while (entries.hasMoreElements()) {
                val s = entries.nextElement().getName();
                val original = repoDir.resolve(s).toFile();
                Assertions.assertTrue(original.isFile(), "Not a valid file: " + original);
                Assertions.assertFalse(s.startsWith(".."));
                if (!s.startsWith("git/")) {
                    // count the files that are not in the git folder.
                    count++;
                }
            }
            Assertions.assertEquals(1, count, "Unexpected number of files in zip.");
        }
        return null;
    };
    doAnswer(answer).when(s3client).putObject(any(PutObjectRequest.class), any(Path.class));
    val metaData = ArtifactAdapter.zipAndUpload(config, tempDir, repoDir, Arrays.asList(repoDir), buildDirs, bucketName);
    Assertions.assertNull(metaData.getBuildKey());
    Assertions.assertNotNull(metaData.getSourceKey());
}
Also used : lombok.val(lombok.val) Path(java.nio.file.Path) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockTextTerminal(org.beryx.textio.mock.MockTextTerminal) Arrays(java.util.Arrays) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Files(java.nio.file.Files) TextIO(org.beryx.textio.TextIO) Mock(org.mockito.Mock) S3Client(software.amazon.awssdk.services.s3.S3Client) Configuration(com.amazonaws.gurureviewercli.model.Configuration) lombok.val(lombok.val) Test(org.junit.jupiter.api.Test) Answer(org.mockito.stubbing.Answer) List(java.util.List) Assumptions(org.junit.jupiter.api.Assumptions) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Paths(java.nio.file.Paths) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Assertions(org.junit.jupiter.api.Assertions) PutObjectRequest(software.amazon.awssdk.services.s3.model.PutObjectRequest) ZipFile(java.util.zip.ZipFile) Path(java.nio.file.Path) Collections(java.util.Collections) MockTextTerminal(org.beryx.textio.mock.MockTextTerminal) ZipFile(java.util.zip.ZipFile) TextIO(org.beryx.textio.TextIO) PutObjectRequest(software.amazon.awssdk.services.s3.model.PutObjectRequest) Test(org.junit.jupiter.api.Test)

Example 4 with TextIO

use of org.beryx.textio.TextIO in project aws-codeguru-cli by aws.

the class AssociationAdapterTest method test_getAssociatedGuruRepo_createNewWithCreateBucketInteractive.

@Test
public void test_getAssociatedGuruRepo_createNewWithCreateBucketInteractive() {
    val bucketName = "some-bucket";
    val fakeArn = "123";
    val expected = RepositoryAssociation.builder().associationArn(fakeArn).state(RepositoryAssociationState.ASSOCIATED).build();
    val emptyListResponse = ListRepositoryAssociationsResponse.builder().repositoryAssociationSummaries(Collections.emptyList()).build();
    when(guruFrontendService.listRepositoryAssociations(any(ListRepositoryAssociationsRequest.class))).thenReturn(emptyListResponse);
    when(s3client.headBucket(any(HeadBucketRequest.class))).thenThrow(NoSuchBucketException.class);
    when(guruFrontendService.associateRepository(any(AssociateRepositoryRequest.class))).thenReturn(AssociateRepositoryResponse.builder().repositoryAssociation(expected).build());
    when(guruFrontendService.describeRepositoryAssociation(any(DescribeRepositoryAssociationRequest.class))).thenReturn(DescribeRepositoryAssociationResponse.builder().repositoryAssociation(expected).build());
    val mockTerminal = new MockTextTerminal();
    mockTerminal.getInputs().add("y");
    val config = Configuration.builder().guruFrontendService(guruFrontendService).interactiveMode(true).s3Client(s3client).repoName("some-repo-name").textIO(new TextIO(mockTerminal)).build();
    val association = AssociationAdapter.getAssociatedGuruRepo(config);
    Assertions.assertEquals(expected.associationArn(), association.associationArn());
}
Also used : lombok.val(lombok.val) HeadBucketRequest(software.amazon.awssdk.services.s3.model.HeadBucketRequest) MockTextTerminal(org.beryx.textio.mock.MockTextTerminal) DescribeRepositoryAssociationRequest(software.amazon.awssdk.services.codegurureviewer.model.DescribeRepositoryAssociationRequest) AssociateRepositoryRequest(software.amazon.awssdk.services.codegurureviewer.model.AssociateRepositoryRequest) ListRepositoryAssociationsRequest(software.amazon.awssdk.services.codegurureviewer.model.ListRepositoryAssociationsRequest) TextIO(org.beryx.textio.TextIO) Test(org.junit.jupiter.api.Test)

Example 5 with TextIO

use of org.beryx.textio.TextIO in project aws-codeguru-cli by aws.

the class AssociationAdapterTest method test_getAssociatedGuruRepo_createNewWithCreateBucketInteractiveAbort.

@Test
public void test_getAssociatedGuruRepo_createNewWithCreateBucketInteractiveAbort() {
    val bucketName = "some-bucket";
    val emptyListResponse = ListRepositoryAssociationsResponse.builder().repositoryAssociationSummaries(Collections.emptyList()).build();
    when(guruFrontendService.listRepositoryAssociations(any(ListRepositoryAssociationsRequest.class))).thenReturn(emptyListResponse);
    when(s3client.headBucket(any(HeadBucketRequest.class))).thenThrow(NoSuchBucketException.class);
    val mockTerminal = new MockTextTerminal();
    mockTerminal.getInputs().add("n");
    val config = Configuration.builder().guruFrontendService(guruFrontendService).interactiveMode(true).s3Client(s3client).repoName("some-repo-name").textIO(new TextIO(mockTerminal)).build();
    GuruCliException ret = Assertions.assertThrows(GuruCliException.class, () -> AssociationAdapter.getAssociatedGuruRepo(config));
    Assertions.assertEquals(ErrorCodes.USER_ABORT, ret.getErrorCode());
}
Also used : lombok.val(lombok.val) HeadBucketRequest(software.amazon.awssdk.services.s3.model.HeadBucketRequest) MockTextTerminal(org.beryx.textio.mock.MockTextTerminal) ListRepositoryAssociationsRequest(software.amazon.awssdk.services.codegurureviewer.model.ListRepositoryAssociationsRequest) GuruCliException(com.amazonaws.gurureviewercli.exceptions.GuruCliException) TextIO(org.beryx.textio.TextIO) Test(org.junit.jupiter.api.Test)

Aggregations

TextIO (org.beryx.textio.TextIO)11 lombok.val (lombok.val)7 MockTextTerminal (org.beryx.textio.mock.MockTextTerminal)6 Test (org.junit.jupiter.api.Test)6 GuruCliException (com.amazonaws.gurureviewercli.exceptions.GuruCliException)3 Path (java.nio.file.Path)3 Paths (java.nio.file.Paths)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 List (java.util.List)3 Configuration (com.amazonaws.gurureviewercli.model.Configuration)2 CustomTextIoStringListReader (com.microsoft.azure.maven.utils.CustomTextIoStringListReader)2 AzureExecutionException (com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ListRepositoryAssociationsRequest (software.amazon.awssdk.services.codegurureviewer.model.ListRepositoryAssociationsRequest)2 HeadBucketRequest (software.amazon.awssdk.services.s3.model.HeadBucketRequest)2 ScanMetaData (com.amazonaws.gurureviewercli.model.ScanMetaData)1 ParameterException (com.beust.jcommander.ParameterException)1 AzureAuthFailureException (com.microsoft.azure.maven.auth.AzureAuthFailureException)1