Skip to content

Commit 72bb089

Browse files
Handle extraction of Jacoco report by test utilities
1 parent 5d67ee3 commit 72bb089

File tree

6 files changed

+47
-107
lines changed

6 files changed

+47
-107
lines changed

src/test/java/org/phoebus/channelfinder/docker/ChannelFinderChannelsIT.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,18 @@
1919
package org.phoebus.channelfinder.docker;
2020

2121
import com.fasterxml.jackson.databind.ObjectMapper;
22-
import com.github.dockerjava.api.DockerClient;
2322

2423
import org.junit.jupiter.api.AfterAll;
2524
import org.junit.jupiter.api.BeforeAll;
2625
import org.junit.jupiter.api.Test;
2726
import org.phoebus.channelfinder.docker.ITUtil.AuthorizationChoice;
2827
import org.phoebus.channelfinder.entity.Channel;
2928
import org.testcontainers.containers.ComposeContainer;
30-
import org.testcontainers.containers.ContainerState;
3129
import org.testcontainers.junit.jupiter.Container;
3230
import org.testcontainers.junit.jupiter.Testcontainers;
3331

3432
import java.io.IOException;
3533
import java.net.HttpURLConnection;
36-
import java.util.Optional;
3734

3835
import static org.junit.jupiter.api.Assertions.assertEquals;
3936
import static org.junit.jupiter.api.Assertions.fail;
@@ -100,7 +97,7 @@ public class ChannelFinderChannelsIT {
10097

10198
static Channel channel_c1_owner_o2;
10299

103-
@Container
100+
@Container
104101
public static final ComposeContainer ENVIRONMENT = ITUtil.defaultComposeContainers();
105102

106103
@BeforeAll
@@ -138,23 +135,8 @@ public static void tearDownObjects() {
138135
@AfterAll
139136
public static void extractJacocoReport() {
140137
// extract jacoco report from container file system
141-
// stop jvm to make data available
142-
143-
if (!Boolean.FALSE.toString().equals(System.getProperty(ITUtil.JACOCO_SKIPITCOVERAGE))) {
144-
return;
145-
}
146-
147-
Optional<ContainerState> container = ENVIRONMENT.getContainerByServiceName(ITUtil.CHANNELFINDER);
148-
if (container.isPresent()) {
149-
ContainerState cs = container.get();
150-
DockerClient dc = cs.getDockerClient();
151-
dc.stopContainerCmd(cs.getContainerId()).exec();
152-
try {
153-
cs.copyFileFromContainer(ITUtil.JACOCO_EXEC_PATH, ITUtil.JACOCO_TARGET_PREFIX + ChannelFinderChannelsIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX);
154-
} catch (Exception e) {
155-
// proceed if file cannot be copied
156-
}
157-
}
138+
ITUtil.extractJacocoReport(ENVIRONMENT,
139+
ITUtil.JACOCO_TARGET_PREFIX + ChannelFinderChannelsIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX);
158140
}
159141

160142
@Test

src/test/java/org/phoebus/channelfinder/docker/ChannelFinderIT.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,11 @@
2121
import org.junit.jupiter.api.AfterAll;
2222
import org.junit.jupiter.api.Test;
2323
import org.testcontainers.containers.ComposeContainer;
24-
import org.testcontainers.containers.ContainerState;
2524
import org.testcontainers.junit.jupiter.Container;
2625
import org.testcontainers.junit.jupiter.Testcontainers;
2726

28-
import com.github.dockerjava.api.DockerClient;
29-
3027
import java.io.IOException;
3128
import java.net.HttpURLConnection;
32-
import java.util.Optional;
3329

3430
import static org.junit.jupiter.api.Assertions.assertEquals;
3531
import static org.junit.jupiter.api.Assertions.fail;
@@ -61,29 +57,14 @@ class ChannelFinderIT {
6157
// https://channelfinder.readthedocs.io/en/latest/api.html
6258
// ------------------------------------------------------------------------------------------------
6359

64-
@Container
60+
@Container
6561
public static final ComposeContainer ENVIRONMENT = ITUtil.defaultComposeContainers();
6662

6763
@AfterAll
6864
public static void extractJacocoReport() {
6965
// extract jacoco report from container file system
70-
// stop jvm to make data available
71-
72-
if (!Boolean.FALSE.toString().equals(System.getProperty(ITUtil.JACOCO_SKIPITCOVERAGE))) {
73-
return;
74-
}
75-
76-
Optional<ContainerState> container = ENVIRONMENT.getContainerByServiceName(ITUtil.CHANNELFINDER);
77-
if (container.isPresent()) {
78-
ContainerState cs = container.get();
79-
DockerClient dc = cs.getDockerClient();
80-
dc.stopContainerCmd(cs.getContainerId()).exec();
81-
try {
82-
cs.copyFileFromContainer(ITUtil.JACOCO_EXEC_PATH, ITUtil.JACOCO_TARGET_PREFIX + ChannelFinderIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX);
83-
} catch (Exception e) {
84-
// proceed if file cannot be copied
85-
}
86-
}
66+
ITUtil.extractJacocoReport(ENVIRONMENT,
67+
ITUtil.JACOCO_TARGET_PREFIX + ChannelFinderIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX);
8768
}
8869

8970
@Test

src/test/java/org/phoebus/channelfinder/docker/ChannelFinderPropertiesIT.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.phoebus.channelfinder.docker;
2020

2121
import com.fasterxml.jackson.databind.ObjectMapper;
22-
import com.github.dockerjava.api.DockerClient;
2322

2423
import org.junit.jupiter.api.AfterAll;
2524
import org.junit.jupiter.api.BeforeAll;
@@ -28,13 +27,11 @@
2827
import org.phoebus.channelfinder.entity.Channel;
2928
import org.phoebus.channelfinder.entity.Property;
3029
import org.testcontainers.containers.ComposeContainer;
31-
import org.testcontainers.containers.ContainerState;
3230
import org.testcontainers.junit.jupiter.Container;
3331
import org.testcontainers.junit.jupiter.Testcontainers;
3432

3533
import java.io.IOException;
3634
import java.net.HttpURLConnection;
37-
import java.util.Optional;
3835

3936
import static org.junit.jupiter.api.Assertions.assertEquals;
4037
import static org.junit.jupiter.api.Assertions.fail;
@@ -100,7 +97,7 @@ class ChannelFinderPropertiesIT {
10097
static Property property_p2_owner_o2;
10198
static Property property_p3_owner_o2;
10299

103-
@Container
100+
@Container
104101
public static final ComposeContainer ENVIRONMENT = ITUtil.defaultComposeContainers();
105102

106103
@BeforeAll
@@ -142,23 +139,8 @@ public static void tearDownObjects() {
142139
@AfterAll
143140
public static void extractJacocoReport() {
144141
// extract jacoco report from container file system
145-
// stop jvm to make data available
146-
147-
if (!Boolean.FALSE.toString().equals(System.getProperty(ITUtil.JACOCO_SKIPITCOVERAGE))) {
148-
return;
149-
}
150-
151-
Optional<ContainerState> container = ENVIRONMENT.getContainerByServiceName(ITUtil.CHANNELFINDER);
152-
if (container.isPresent()) {
153-
ContainerState cs = container.get();
154-
DockerClient dc = cs.getDockerClient();
155-
dc.stopContainerCmd(cs.getContainerId()).exec();
156-
try {
157-
cs.copyFileFromContainer(ITUtil.JACOCO_EXEC_PATH, ITUtil.JACOCO_TARGET_PREFIX + ChannelFinderPropertiesIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX);
158-
} catch (Exception e) {
159-
// proceed if file cannot be copied
160-
}
161-
}
142+
ITUtil.extractJacocoReport(ENVIRONMENT,
143+
ITUtil.JACOCO_TARGET_PREFIX + ChannelFinderPropertiesIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX);
162144
}
163145

164146
@Test

src/test/java/org/phoebus/channelfinder/docker/ChannelFinderScrollIT.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@
2222
import org.junit.jupiter.api.Test;
2323
import org.phoebus.channelfinder.entity.Scroll;
2424
import org.testcontainers.containers.ComposeContainer;
25-
import org.testcontainers.containers.ContainerState;
2625
import org.testcontainers.junit.jupiter.Container;
2726
import org.testcontainers.junit.jupiter.Testcontainers;
2827

29-
import com.github.dockerjava.api.DockerClient;
30-
3128
import java.io.IOException;
3229
import java.net.HttpURLConnection;
33-
import java.util.Optional;
3430

3531
import static org.junit.jupiter.api.Assertions.assertEquals;
3632
import static org.junit.jupiter.api.Assertions.fail;
@@ -65,29 +61,14 @@ class ChannelFinderScrollIT {
6561
// https://channelfinder.readthedocs.io/en/latest/api.html
6662
// ------------------------------------------------------------------------------------------------
6763

68-
@Container
64+
@Container
6965
public static final ComposeContainer ENVIRONMENT = ITUtil.defaultComposeContainers();
7066

7167
@AfterAll
7268
public static void extractJacocoReport() {
7369
// extract jacoco report from container file system
74-
// stop jvm to make data available
75-
76-
if (!Boolean.FALSE.toString().equals(System.getProperty(ITUtil.JACOCO_SKIPITCOVERAGE))) {
77-
return;
78-
}
79-
80-
Optional<ContainerState> container = ENVIRONMENT.getContainerByServiceName(ITUtil.CHANNELFINDER);
81-
if (container.isPresent()) {
82-
ContainerState cs = container.get();
83-
DockerClient dc = cs.getDockerClient();
84-
dc.stopContainerCmd(cs.getContainerId()).exec();
85-
try {
86-
cs.copyFileFromContainer(ITUtil.JACOCO_EXEC_PATH, ITUtil.JACOCO_TARGET_PREFIX + ChannelFinderScrollIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX);
87-
} catch (Exception e) {
88-
// proceed if file cannot be copied
89-
}
90-
}
70+
ITUtil.extractJacocoReport(ENVIRONMENT,
71+
ITUtil.JACOCO_TARGET_PREFIX + ChannelFinderScrollIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX);
9172
}
9273

9374
@Test

src/test/java/org/phoebus/channelfinder/docker/ChannelFinderTagsIT.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.phoebus.channelfinder.docker;
2020

2121
import com.fasterxml.jackson.databind.ObjectMapper;
22-
import com.github.dockerjava.api.DockerClient;
2322

2423
import org.junit.jupiter.api.AfterAll;
2524
import org.junit.jupiter.api.BeforeAll;
@@ -28,13 +27,11 @@
2827
import org.phoebus.channelfinder.entity.Channel;
2928
import org.phoebus.channelfinder.entity.Tag;
3029
import org.testcontainers.containers.ComposeContainer;
31-
import org.testcontainers.containers.ContainerState;
3230
import org.testcontainers.junit.jupiter.Container;
3331
import org.testcontainers.junit.jupiter.Testcontainers;
3432

3533
import java.io.IOException;
3634
import java.net.HttpURLConnection;
37-
import java.util.Optional;
3835

3936
import static org.junit.jupiter.api.Assertions.assertEquals;
4037
import static org.junit.jupiter.api.Assertions.fail;
@@ -98,7 +95,7 @@ class ChannelFinderTagsIT {
9895

9996
static Tag tag_t1_owner_o2;
10097

101-
@Container
98+
@Container
10299
public static final ComposeContainer ENVIRONMENT = ITUtil.defaultComposeContainers();
103100

104101
@BeforeAll
@@ -136,23 +133,8 @@ public static void tearDownObjects() {
136133
@AfterAll
137134
public static void extractJacocoReport() {
138135
// extract jacoco report from container file system
139-
// stop jvm to make data available
140-
141-
if (!Boolean.FALSE.toString().equals(System.getProperty(ITUtil.JACOCO_SKIPITCOVERAGE))) {
142-
return;
143-
}
144-
145-
Optional<ContainerState> container = ENVIRONMENT.getContainerByServiceName(ITUtil.CHANNELFINDER);
146-
if (container.isPresent()) {
147-
ContainerState cs = container.get();
148-
DockerClient dc = cs.getDockerClient();
149-
dc.stopContainerCmd(cs.getContainerId()).exec();
150-
try {
151-
cs.copyFileFromContainer(ITUtil.JACOCO_EXEC_PATH, ITUtil.JACOCO_TARGET_PREFIX + ChannelFinderTagsIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX);
152-
} catch (Exception e) {
153-
// proceed if file cannot be copied
154-
}
155-
}
136+
ITUtil.extractJacocoReport(ENVIRONMENT,
137+
ITUtil.JACOCO_TARGET_PREFIX + ChannelFinderTagsIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX);
156138
}
157139

158140
@Test

src/test/java/org/phoebus/channelfinder/docker/ITUtil.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@
1919
package org.phoebus.channelfinder.docker;
2020

2121
import org.testcontainers.containers.ComposeContainer;
22+
import org.testcontainers.containers.ContainerState;
2223
import org.testcontainers.containers.wait.strategy.Wait;
2324
import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils;
2425

26+
import com.github.dockerjava.api.DockerClient;
27+
2528
import java.io.BufferedReader;
2629
import java.io.File;
2730
import java.io.IOException;
2831
import java.io.InputStreamReader;
2932
import java.net.HttpURLConnection;
3033
import java.net.URL;
34+
import java.util.Optional;
3135
import java.util.concurrent.TimeUnit;
3236
import java.util.stream.Collectors;
3337

@@ -116,6 +120,34 @@ public static ComposeContainer defaultComposeContainers() {
116120
.waitingFor(ITUtil.CHANNELFINDER, Wait.forLogMessage(ITUtil.INTEGRATIONTEST_LOG_MESSAGE, 1));
117121
}
118122

123+
/**
124+
* Extract coverage report from compose container to file system.
125+
*
126+
* @param environment compose container
127+
* @param destinationPath destination path, i.e. where in file system to put coverage report
128+
* that has been extracted from container
129+
*/
130+
public static void extractJacocoReport(ComposeContainer environment, String destinationPath) {
131+
// extract jacoco report from container file system
132+
// stop jvm to make data available
133+
134+
if (!Boolean.FALSE.toString().equals(System.getProperty(ITUtil.JACOCO_SKIPITCOVERAGE))) {
135+
return;
136+
}
137+
138+
Optional<ContainerState> container = environment.getContainerByServiceName(ITUtil.CHANNELFINDER);
139+
if (container.isPresent()) {
140+
ContainerState cs = container.get();
141+
DockerClient dc = cs.getDockerClient();
142+
dc.stopContainerCmd(cs.getContainerId()).exec();
143+
try {
144+
cs.copyFileFromContainer(ITUtil.JACOCO_EXEC_PATH, destinationPath);
145+
} catch (Exception e) {
146+
// proceed if file cannot be copied
147+
}
148+
}
149+
}
150+
119151
/**
120152
* Do GET request with given string as URL and return response code.
121153
*

0 commit comments

Comments
 (0)