diff --git a/src/test/java/org/phoebus/olog/docker/ITUtil.java b/src/test/java/org/phoebus/olog/docker/ITUtil.java index 2b9cefa..91f5bc4 100644 --- a/src/test/java/org/phoebus/olog/docker/ITUtil.java +++ b/src/test/java/org/phoebus/olog/docker/ITUtil.java @@ -18,20 +18,25 @@ package org.phoebus.olog.docker; +import org.junit.jupiter.api.AfterAll; import org.phoebus.olog.entity.Log; import org.phoebus.olog.entity.Logbook; import org.phoebus.olog.entity.Property; import org.phoebus.olog.entity.Tag; import org.testcontainers.containers.ComposeContainer; +import org.testcontainers.containers.ContainerState; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils; +import com.github.dockerjava.api.DockerClient; + import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -123,6 +128,34 @@ public static ComposeContainer defaultComposeContainers() { .waitingFor(ITUtil.OLOG, Wait.forLogMessage(ITUtil.INTEGRATIONTEST_LOG_MESSAGE, 1)); } + /** + * Extract coverage report from compose container to file system. + * + * @param environment compose container + * @param destinationPath destination path, i.e. where in file system to put coverage report + * that has been extracted from container + */ + public static void extractJacocoReport(ComposeContainer environment, String destinationPath) { + // extract jacoco report from container file system + // stop jvm to make data available + + if (!Boolean.FALSE.toString().equals(System.getProperty(ITUtil.JACOCO_SKIPITCOVERAGE))) { + return; + } + + Optional container = environment.getContainerByServiceName(ITUtil.OLOG); + if (container.isPresent()) { + ContainerState cs = container.get(); + DockerClient dc = cs.getDockerClient(); + dc.stopContainerCmd(cs.getContainerId()).exec(); + try { + cs.copyFileFromContainer(ITUtil.JACOCO_EXEC_PATH, destinationPath); + } catch (Exception e) { + // proceed if file cannot be copied + } + } + } + /** * Refresh Elastic indices and return response code and string. * diff --git a/src/test/java/org/phoebus/olog/docker/OlogIT.java b/src/test/java/org/phoebus/olog/docker/OlogIT.java index db199c9..92c7177 100644 --- a/src/test/java/org/phoebus/olog/docker/OlogIT.java +++ b/src/test/java/org/phoebus/olog/docker/OlogIT.java @@ -21,15 +21,11 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Test; import org.testcontainers.containers.ComposeContainer; -import org.testcontainers.containers.ContainerState; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import com.github.dockerjava.api.DockerClient; - import java.io.IOException; import java.net.HttpURLConnection; -import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -68,23 +64,8 @@ class OlogIT { @AfterAll public static void extractJacocoReport() { // extract jacoco report from container file system - // stop jvm to make data available - - if (!Boolean.FALSE.toString().equals(System.getProperty(ITUtil.JACOCO_SKIPITCOVERAGE))) { - return; - } - - Optional container = ENVIRONMENT.getContainerByServiceName(ITUtil.OLOG); - if (container.isPresent()) { - ContainerState cs = container.get(); - DockerClient dc = cs.getDockerClient(); - dc.stopContainerCmd(cs.getContainerId()).exec(); - try { - cs.copyFileFromContainer(ITUtil.JACOCO_EXEC_PATH, ITUtil.JACOCO_TARGET_PREFIX + OlogIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX); - } catch (Exception e) { - // proceed if file cannot be copied - } - } + ITUtil.extractJacocoReport(ENVIRONMENT, + ITUtil.JACOCO_TARGET_PREFIX + OlogIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX); } @Test diff --git a/src/test/java/org/phoebus/olog/docker/OlogLogbooksIT.java b/src/test/java/org/phoebus/olog/docker/OlogLogbooksIT.java index 9d24396..c9e3524 100644 --- a/src/test/java/org/phoebus/olog/docker/OlogLogbooksIT.java +++ b/src/test/java/org/phoebus/olog/docker/OlogLogbooksIT.java @@ -25,15 +25,11 @@ import org.phoebus.olog.entity.Logbook; import org.phoebus.olog.entity.State; import org.testcontainers.containers.ComposeContainer; -import org.testcontainers.containers.ContainerState; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import com.github.dockerjava.api.DockerClient; - import java.io.IOException; import java.net.HttpURLConnection; -import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -147,23 +143,8 @@ public static void tearDownObjects() { @AfterAll public static void extractJacocoReport() { // extract jacoco report from container file system - // stop jvm to make data available - - if (!Boolean.FALSE.toString().equals(System.getProperty(ITUtil.JACOCO_SKIPITCOVERAGE))) { - return; - } - - Optional container = ENVIRONMENT.getContainerByServiceName(ITUtil.OLOG); - if (container.isPresent()) { - ContainerState cs = container.get(); - DockerClient dc = cs.getDockerClient(); - dc.stopContainerCmd(cs.getContainerId()).exec(); - try { - cs.copyFileFromContainer(ITUtil.JACOCO_EXEC_PATH, ITUtil.JACOCO_TARGET_PREFIX + OlogLogbooksIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX); - } catch (Exception e) { - // proceed if file cannot be copied - } - } + ITUtil.extractJacocoReport(ENVIRONMENT, + ITUtil.JACOCO_TARGET_PREFIX + OlogLogbooksIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX); } @Test diff --git a/src/test/java/org/phoebus/olog/docker/OlogLogsIT.java b/src/test/java/org/phoebus/olog/docker/OlogLogsIT.java index 295c3d1..3111ab8 100644 --- a/src/test/java/org/phoebus/olog/docker/OlogLogsIT.java +++ b/src/test/java/org/phoebus/olog/docker/OlogLogsIT.java @@ -23,15 +23,11 @@ import org.phoebus.olog.docker.ITUtil.AuthorizationChoice; import org.phoebus.olog.entity.Log; import org.testcontainers.containers.ComposeContainer; -import org.testcontainers.containers.ContainerState; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import com.github.dockerjava.api.DockerClient; - import java.io.IOException; import java.net.HttpURLConnection; -import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -89,23 +85,8 @@ class OlogLogsIT { @AfterAll public static void extractJacocoReport() { // extract jacoco report from container file system - // stop jvm to make data available - - if (!Boolean.FALSE.toString().equals(System.getProperty(ITUtil.JACOCO_SKIPITCOVERAGE))) { - return; - } - - Optional container = ENVIRONMENT.getContainerByServiceName(ITUtil.OLOG); - if (container.isPresent()) { - ContainerState cs = container.get(); - DockerClient dc = cs.getDockerClient(); - dc.stopContainerCmd(cs.getContainerId()).exec(); - try { - cs.copyFileFromContainer(ITUtil.JACOCO_EXEC_PATH, ITUtil.JACOCO_TARGET_PREFIX + OlogLogsIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX); - } catch (Exception e) { - // proceed if file cannot be copied - } - } + ITUtil.extractJacocoReport(ENVIRONMENT, + ITUtil.JACOCO_TARGET_PREFIX + OlogLogsIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX); } @Test diff --git a/src/test/java/org/phoebus/olog/docker/OlogLogsQueryIT.java b/src/test/java/org/phoebus/olog/docker/OlogLogsQueryIT.java index e46612d..846baf9 100644 --- a/src/test/java/org/phoebus/olog/docker/OlogLogsQueryIT.java +++ b/src/test/java/org/phoebus/olog/docker/OlogLogsQueryIT.java @@ -22,17 +22,13 @@ import org.junit.jupiter.api.Test; import org.phoebus.olog.entity.SearchResult; import org.testcontainers.containers.ComposeContainer; -import org.testcontainers.containers.ContainerState; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import com.github.dockerjava.api.DockerClient; - import java.io.IOException; import java.net.HttpURLConnection; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; -import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -91,23 +87,8 @@ class OlogLogsQueryIT { @AfterAll public static void extractJacocoReport() { // extract jacoco report from container file system - // stop jvm to make data available - - if (!Boolean.FALSE.toString().equals(System.getProperty(ITUtil.JACOCO_SKIPITCOVERAGE))) { - return; - } - - Optional container = ENVIRONMENT.getContainerByServiceName(ITUtil.OLOG); - if (container.isPresent()) { - ContainerState cs = container.get(); - DockerClient dc = cs.getDockerClient(); - dc.stopContainerCmd(cs.getContainerId()).exec(); - try { - cs.copyFileFromContainer(ITUtil.JACOCO_EXEC_PATH, ITUtil.JACOCO_TARGET_PREFIX + OlogLogsQueryIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX); - } catch (Exception e) { - // proceed if file cannot be copied - } - } + ITUtil.extractJacocoReport(ENVIRONMENT, + ITUtil.JACOCO_TARGET_PREFIX + OlogLogsQueryIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX); } @Test diff --git a/src/test/java/org/phoebus/olog/docker/OlogPropertiesIT.java b/src/test/java/org/phoebus/olog/docker/OlogPropertiesIT.java index d55701d..0e6bc7b 100644 --- a/src/test/java/org/phoebus/olog/docker/OlogPropertiesIT.java +++ b/src/test/java/org/phoebus/olog/docker/OlogPropertiesIT.java @@ -26,16 +26,12 @@ import org.phoebus.olog.entity.Property; import org.phoebus.olog.entity.State; import org.testcontainers.containers.ComposeContainer; -import org.testcontainers.containers.ContainerState; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import com.github.dockerjava.api.DockerClient; - import java.io.IOException; import java.net.HttpURLConnection; import java.util.HashSet; -import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -221,23 +217,8 @@ public static void tearDownObjects() { @AfterAll public static void extractJacocoReport() { // extract jacoco report from container file system - // stop jvm to make data available - - if (!Boolean.FALSE.toString().equals(System.getProperty(ITUtil.JACOCO_SKIPITCOVERAGE))) { - return; - } - - Optional container = ENVIRONMENT.getContainerByServiceName(ITUtil.OLOG); - if (container.isPresent()) { - ContainerState cs = container.get(); - DockerClient dc = cs.getDockerClient(); - dc.stopContainerCmd(cs.getContainerId()).exec(); - try { - cs.copyFileFromContainer(ITUtil.JACOCO_EXEC_PATH, ITUtil.JACOCO_TARGET_PREFIX + OlogPropertiesIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX); - } catch (Exception e) { - // proceed if file cannot be copied - } - } + ITUtil.extractJacocoReport(ENVIRONMENT, + ITUtil.JACOCO_TARGET_PREFIX + OlogPropertiesIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX); } @Test diff --git a/src/test/java/org/phoebus/olog/docker/OlogTagsIT.java b/src/test/java/org/phoebus/olog/docker/OlogTagsIT.java index 0a74141..aabafc6 100644 --- a/src/test/java/org/phoebus/olog/docker/OlogTagsIT.java +++ b/src/test/java/org/phoebus/olog/docker/OlogTagsIT.java @@ -25,15 +25,11 @@ import org.phoebus.olog.entity.State; import org.phoebus.olog.entity.Tag; import org.testcontainers.containers.ComposeContainer; -import org.testcontainers.containers.ContainerState; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import com.github.dockerjava.api.DockerClient; - import java.io.IOException; import java.net.HttpURLConnection; -import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -145,23 +141,8 @@ public static void tearDownObjects() { @AfterAll public static void extractJacocoReport() { // extract jacoco report from container file system - // stop jvm to make data available - - if (!Boolean.FALSE.toString().equals(System.getProperty(ITUtil.JACOCO_SKIPITCOVERAGE))) { - return; - } - - Optional container = ENVIRONMENT.getContainerByServiceName(ITUtil.OLOG); - if (container.isPresent()) { - ContainerState cs = container.get(); - DockerClient dc = cs.getDockerClient(); - dc.stopContainerCmd(cs.getContainerId()).exec(); - try { - cs.copyFileFromContainer(ITUtil.JACOCO_EXEC_PATH, ITUtil.JACOCO_TARGET_PREFIX + OlogTagsIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX); - } catch (Exception e) { - // proceed if file cannot be copied - } - } + ITUtil.extractJacocoReport(ENVIRONMENT, + ITUtil.JACOCO_TARGET_PREFIX + OlogTagsIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX); } @Test