Search in sources :

Example 1 with PipedApplicationConsole

use of com.oracle.bedrock.runtime.console.PipedApplicationConsole in project oracle-bedrock by coherence-community.

the class LocalPlatformApplicationTest method shouldInvokeApplicationListeners.

/**
 * Ensure that we can run an {@link Application} (a JVM in this case) and
 * {@link ApplicationListener}s are notified.
 *
 * @throws Exception
 */
@Test
public void shouldInvokeApplicationListeners() throws Exception {
    Assume.assumeFalse("Skipping test in GitHub", Boolean.getBoolean("github.build"));
    ApplicationListener<Application> listener = Mockito.mock(ApplicationListener.class);
    PipedApplicationConsole console = new PipedApplicationConsole();
    try (Application application = LocalPlatform.get().launch(Application.class, Executable.named("java"), Argument.of("-help"), Diagnostics.enabled(), ErrorStreamRedirection.enabled(), Console.of(console), Decoration.of(listener), DisplayName.of("java"))) {
        Mockito.verify(listener, Mockito.times(1)).onLaunched(Mockito.same(application));
        BufferedReader reader = console.getOutputReader();
        String stdout = reader.readLine();
        while (stdout.contains("JAVA_TOOL_OPTIONS")) {
            stdout = reader.readLine();
        }
        assertThat(stdout, containsString("Usage: java"));
        application.waitFor();
        application.close();
        Mockito.verify(listener, Mockito.times(1)).onClosing(Mockito.same(application), any(OptionsByType.class));
        Mockito.verify(listener, Mockito.times(1)).onClosed(Mockito.same(application), any(OptionsByType.class));
        int exitCode = application.exitValue();
        assertThat(exitCode, is(0));
    }
}
Also used : PipedApplicationConsole(com.oracle.bedrock.runtime.console.PipedApplicationConsole) BufferedReader(java.io.BufferedReader) StringContains.containsString(org.hamcrest.core.StringContains.containsString) OptionsByType(com.oracle.bedrock.OptionsByType) AbstractTest(com.oracle.bedrock.testsupport.junit.AbstractTest) Test(org.junit.Test)

Example 2 with PipedApplicationConsole

use of com.oracle.bedrock.runtime.console.PipedApplicationConsole in project oracle-bedrock by coherence-community.

the class LocalPlatformApplicationTest method shouldLaunchApplication.

/**
 * Ensure that we can run an {@link Application} (a JVM in this case).
 *
 * @throws Exception
 */
@Test
public void shouldLaunchApplication() throws Exception {
    Assume.assumeFalse("Skipping test in GitHub", Boolean.getBoolean("github.build"));
    PipedApplicationConsole console = new PipedApplicationConsole();
    try (Application application = LocalPlatform.get().launch(Application.class, Executable.named("java"), Argument.of("-help"), DisplayName.of("java"), ErrorStreamRedirection.enabled(), Diagnostics.enabled(), Console.of(console))) {
        BufferedReader reader = console.getOutputReader();
        String stdout = reader.readLine();
        while (stdout.contains("JAVA_TOOL_OPTIONS")) {
            stdout = reader.readLine();
        }
        assertThat(stdout, containsString("Usage: java"));
    }
}
Also used : PipedApplicationConsole(com.oracle.bedrock.runtime.console.PipedApplicationConsole) BufferedReader(java.io.BufferedReader) StringContains.containsString(org.hamcrest.core.StringContains.containsString) AbstractTest(com.oracle.bedrock.testsupport.junit.AbstractTest) Test(org.junit.Test)

Example 3 with PipedApplicationConsole

use of com.oracle.bedrock.runtime.console.PipedApplicationConsole in project oracle-bedrock by coherence-community.

the class AbstractJavaApplicationTest method shouldRunApplication.

/**
 * Ensure that we can start and terminate a {@link JavaApplication}.
 *
 * @throws Exception
 */
@Test
public void shouldRunApplication() throws Exception {
    PipedApplicationConsole console = new PipedApplicationConsole();
    try (JavaApplication application = getPlatform().launch(JavaApplication.class, DisplayName.of("java-app"), ClassName.of(DummyApp.class), Arguments.of("arg1", "arg2"), SystemProperty.of("test.prop.1", "value.1"), SystemProperty.of("test.prop.2", "value.2"), IPv4Preferred.yes(), Diagnostics.enabled(), Console.of(console))) {
        String stdout = console.getOutputReader().readLine();
        assertThat(stdout.startsWith("[java-app:"), is(true));
        assertThat(stdout, containsString("arg1,arg2"));
        stdout = console.getOutputReader().readLine();
        assertThat(stdout, containsString("test.prop.1=value.1"));
    }
}
Also used : PipedApplicationConsole(com.oracle.bedrock.runtime.console.PipedApplicationConsole) DummyApp(com.oracle.bedrock.runtime.DummyApp) StringContains.containsString(org.hamcrest.core.StringContains.containsString) AbstractTest(com.oracle.bedrock.testsupport.junit.AbstractTest) Test(org.junit.Test)

Example 4 with PipedApplicationConsole

use of com.oracle.bedrock.runtime.console.PipedApplicationConsole in project oracle-bedrock by coherence-community.

the class VagrantChecker method vagrantExists.

/**
 * Attempt to run the Vagrant --version command and
 * parse the expected output. If this succeeds then
 * Vagrant is present on the system.
 *
 * @return true if Vagrant is installed
 */
public static synchronized boolean vagrantExists() {
    boolean noVagrantProperty = Boolean.getBoolean("no.vagrant");
    if (noVagrantProperty) {
        return false;
    }
    String command = VagrantPlatform.getDefaultVagrantCommand();
    try (PipedApplicationConsole console = new PipedApplicationConsole();
        Application application = LocalPlatform.get().launch(Application.class, Executable.named(command), Argument.of("--version"), DisplayName.of("Vagrant"), Console.of(console))) {
        int exitCode = application.waitFor();
        if (exitCode != 0) {
            return false;
        }
        String line = console.getOutputReader().readLine();
        application.close();
        Pattern pattern = Pattern.compile(VAGRANT_REGEX);
        Matcher matcher = pattern.matcher(line);
        return matcher.matches();
    } catch (Throwable e) {
        System.err.println("Error checking for Vagrant - assume not present. " + e.getMessage());
        return false;
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PipedApplicationConsole(com.oracle.bedrock.runtime.console.PipedApplicationConsole) Application(com.oracle.bedrock.runtime.Application)

Example 5 with PipedApplicationConsole

use of com.oracle.bedrock.runtime.console.PipedApplicationConsole in project oracle-bedrock by coherence-community.

the class LocalPlatformApplicationTest method shouldLaunchExecutable.

/**
 * Ensure that we can run an {@link Application} (a JVM in this case).
 *
 * @throws Exception
 */
@Test
public void shouldLaunchExecutable() throws Exception {
    Assume.assumeFalse("Skipping test in GitHub", Boolean.getBoolean("github.build"));
    PipedApplicationConsole console = new PipedApplicationConsole();
    try (Application application = LocalPlatform.get().launch("java", Argument.of("-help"), DisplayName.of("java"), ErrorStreamRedirection.enabled(), Diagnostics.enabled(), Console.of(console))) {
        BufferedReader reader = console.getOutputReader();
        String stdout = reader.readLine();
        while (stdout.contains("JAVA_TOOL_OPTIONS")) {
            stdout = reader.readLine();
        }
        assertThat(stdout, containsString("Usage: java"));
    }
}
Also used : PipedApplicationConsole(com.oracle.bedrock.runtime.console.PipedApplicationConsole) BufferedReader(java.io.BufferedReader) StringContains.containsString(org.hamcrest.core.StringContains.containsString) AbstractTest(com.oracle.bedrock.testsupport.junit.AbstractTest) Test(org.junit.Test)

Aggregations

PipedApplicationConsole (com.oracle.bedrock.runtime.console.PipedApplicationConsole)12 Test (org.junit.Test)10 BufferedReader (java.io.BufferedReader)6 AbstractTest (com.oracle.bedrock.testsupport.junit.AbstractTest)5 StringContains.containsString (org.hamcrest.core.StringContains.containsString)5 OptionsByType (com.oracle.bedrock.OptionsByType)2 Application (com.oracle.bedrock.runtime.Application)2 DummyApp (com.oracle.bedrock.runtime.DummyApp)1 DummyClassPathApp (com.oracle.bedrock.runtime.DummyClassPathApp)1 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)1 AbstractPipedApplicationConsole (com.oracle.bedrock.runtime.console.AbstractPipedApplicationConsole)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 Properties (java.util.Properties)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Mock (org.mockito.Mock)1