Search in sources :

Example 1 with SleepingApplication

use of applications.SleepingApplication in project oracle-bedrock by coherence-community.

the class JacocoProfileTest method shouldEstablishJaCoCoProfileUsingASystemProperty.

/**
 * Ensure we can configure and establish a {@link JacocoProfile} using a System Property
 */
@Test
public void shouldEstablishJaCoCoProfileUsingASystemProperty() throws Exception {
    // define the JaCoCo destination file pattern
    String jacocoDestinationFileName = "jacoco-${bedrock.runtime.id}.exec";
    // create a temp file name for JaCoCo to output the code coverage report to
    File destinationFile = new File(System.getProperty("java.io.tmpdir"), jacocoDestinationFileName);
    // define the JaCoCo profile as a System Property
    System.getProperties().setProperty("bedrock.profile.jacoco", "destfile=" + destinationFile);
    // build and start the SleepingApplication
    LocalPlatform platform = LocalPlatform.get();
    File telemetricsFile;
    try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(SleepingApplication.class), IPv4Preferred.yes())) {
        ExpressionEvaluator evaluator = new ExpressionEvaluator(application.getOptions());
        // create a File representing the JaCoCo telemetrics file
        telemetricsFile = new File(System.getProperty("java.io.tmpdir"), evaluator.evaluate(jacocoDestinationFileName, String.class));
    } finally {
        System.getProperties().remove("bedrock.profile.jacoco");
    }
    // assert that JaCoCo created the telemetrics file (and thus the agent ran)
    assertThat(telemetricsFile.exists(), is(true));
    // assert that the telemetrics file contains something
    assertThat(telemetricsFile.length(), is(greaterThan(0L)));
}
Also used : SleepingApplication(applications.SleepingApplication) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) File(java.io.File) ExpressionEvaluator(com.oracle.bedrock.lang.ExpressionEvaluator) Test(org.junit.Test)

Example 2 with SleepingApplication

use of applications.SleepingApplication in project oracle-bedrock by coherence-community.

the class JacocoProfileTest method shouldEstablishJaCoCoProfileUsingAnOption.

/**
 * Ensure we can configure and establish a {@link JacocoProfile} as an {@link Option}.
 */
@Test
public void shouldEstablishJaCoCoProfileUsingAnOption() throws Exception {
    // define the JaCoCo destination file pattern
    String jacocoDestinationFileName = "jacoco-${bedrock.runtime.id}.exec";
    // create a temp file name for JaCoCo to output the code coverage report to
    File destinationFile = new File(System.getProperty("java.io.tmpdir"), jacocoDestinationFileName);
    // define the JaCoCo profile
    JacocoProfile profile = JacocoProfile.enabled("destfile=" + destinationFile);
    // build and start the SleepingApplication
    LocalPlatform platform = LocalPlatform.get();
    File telemetricsFile;
    try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(SleepingApplication.class), IPv4Preferred.yes(), profile)) {
        ExpressionEvaluator evaluator = new ExpressionEvaluator(application.getOptions());
        // create a File representing the JaCoCo telemetrics file
        telemetricsFile = new File(System.getProperty("java.io.tmpdir"), evaluator.evaluate(jacocoDestinationFileName, String.class));
    }
    // assert that JaCoCo created the telemetrics file (and thus the agent ran)
    assertThat(telemetricsFile.exists(), is(true));
    // assert that the telemetrics file contains something
    assertThat(telemetricsFile.length(), is(greaterThan(0L)));
}
Also used : SleepingApplication(applications.SleepingApplication) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) File(java.io.File) ExpressionEvaluator(com.oracle.bedrock.lang.ExpressionEvaluator) Test(org.junit.Test)

Aggregations

SleepingApplication (applications.SleepingApplication)2 ExpressionEvaluator (com.oracle.bedrock.lang.ExpressionEvaluator)2 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)2 JavaApplication (com.oracle.bedrock.runtime.java.JavaApplication)2 File (java.io.File)2 Test (org.junit.Test)2