diff --git a/jkube-kit/jkube-kit-vertx/pom.xml b/jkube-kit/jkube-kit-vertx/pom.xml
index 949bf16646..f6bc6b84cd 100644
--- a/jkube-kit/jkube-kit-vertx/pom.xml
+++ b/jkube-kit/jkube-kit-vertx/pom.xml
@@ -43,8 +43,14 @@
- junit
- junit
+ org.junit.jupiter
+ junit-jupiter-engine
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-params
+ test
org.assertj
diff --git a/jkube-kit/jkube-kit-vertx/src/test/java/org/eclipse/jkube/vertx/enricher/VertxHealthCheckEnricherTest.java b/jkube-kit/jkube-kit-vertx/src/test/java/org/eclipse/jkube/vertx/enricher/VertxHealthCheckEnricherTest.java
index 1913de63ba..e9f3183931 100644
--- a/jkube-kit/jkube-kit-vertx/src/test/java/org/eclipse/jkube/vertx/enricher/VertxHealthCheckEnricherTest.java
+++ b/jkube-kit/jkube-kit-vertx/src/test/java/org/eclipse/jkube/vertx/enricher/VertxHealthCheckEnricherTest.java
@@ -20,7 +20,9 @@
import java.util.Properties;
import java.util.TreeMap;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import io.fabric8.kubernetes.api.model.ExecAction;
import io.fabric8.kubernetes.client.utils.Serialization;
import org.eclipse.jkube.kit.common.JavaProject;
import org.eclipse.jkube.kit.common.KitLogger;
@@ -31,27 +33,31 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import io.fabric8.kubernetes.api.model.HTTPHeader;
import io.fabric8.kubernetes.api.model.Probe;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import static org.junit.jupiter.params.provider.Arguments.arguments;
/**
* @author Clement Escoffier
*/
-public class VertxHealthCheckEnricherTest {
+class VertxHealthCheckEnricherTest {
private JKubeEnricherContext context;
private TreeMap plexusMavenConfig;
private Map jKubePluginConfiguration;
private Properties properties;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
plexusMavenConfig = new TreeMap<>();
jKubePluginConfiguration = new HashMap<>();
properties = new Properties();
@@ -64,493 +70,436 @@ public void setUp() throws Exception {
.build();
}
- @Test
- public void testDefaultConfiguration() {
+ @Nested
+ @DisplayName("with TCP health type")
+ class TCPHealthType {
+ @Test
+ @DisplayName("and port using properties, should enable probes with configured port")
+ void andPortUsingProperties_shouldConfigureProbesWithPort() {
+ properties.put("vertx.health.type", "tcp");
+ properties.put("vertx.health.port", "1234");
+ properties.put("vertx.health.readiness.port", "1235");
+
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNull(probe);
- probe = enricher.getReadinessProbe();
- assertNull(probe);
- }
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertTCPSocket(livenessProbe, 1234);
- @Test
- public void testDefaultConfiguration_Enabled() {
- properties.put("vertx.health.path", "/ping");
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertTCPSocket(readinessProbe, 1235);
+ }
+ @Test
+ @DisplayName("and port using config, should enable probes with configured port")
+ void andPortUsingConfig_shouldConfigureProbesWithPort() throws Exception {
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
+ final String config = "{\"type\":\"tcp\",\"liveness\":{\"port\":\"1234\"},\"readiness\":{\"port\":\"1235\"}}";
+ jKubePluginConfiguration.putAll(createFakeConfig(config));
+ plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
- Probe probe = enricher.getLivenessProbe();
- assertNotNull(probe);
- assertNull(probe.getHttpGet().getHost());
- assertThat(probe.getHttpGet().getScheme()).isEqualTo("HTTP");
- assertThat(probe.getHttpGet().getPort().getIntVal().intValue()).isEqualTo(8080);
- assertThat(probe.getHttpGet().getPath()).isEqualTo( "/ping");
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertTCPSocket(livenessProbe, 1234);
- probe = enricher.getReadinessProbe();
- assertNotNull(probe);
- assertThat(probe.getHttpGet().getScheme()).isEqualTo("HTTP");
- assertNull(probe.getHttpGet().getHost());
- assertThat(probe.getHttpGet().getPort().getIntVal().intValue()).isEqualTo(8080);
- assertThat(probe.getHttpGet().getPath()).isEqualTo( "/ping");
- }
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertTCPSocket(readinessProbe, 1235);
+ }
- @Test
- public void testDifferentPathForLivenessAndReadiness() {
- properties.put("vertx.health.path", "/ping");
- properties.put("vertx.health.readiness.path", "/ready");
+ @Test
+ @DisplayName("and port name using properties, should enable probes with configured port name")
+ void andPortNameUsingProperties_shouldConfigureProbesWithPortName() {
+ properties.put("vertx.health.type", "tcp");
+ properties.put("vertx.health.port-name", "health");
+ properties.put("vertx.health.readiness.port-name", "ready");
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNotNull(probe);
- assertNull(probe.getHttpGet().getHost());
- assertThat(probe.getHttpGet().getScheme()).isEqualTo("HTTP");
- assertThat(probe.getHttpGet().getPort().getIntVal().intValue()).isEqualTo(8080);
- assertThat(probe.getHttpGet().getPath()).isEqualTo( "/ping");
-
- probe = enricher.getReadinessProbe();
- assertNotNull(probe);
- assertThat(probe.getHttpGet().getScheme()).isEqualTo("HTTP");
- assertNull(probe.getHttpGet().getHost());
- assertThat(probe.getHttpGet().getPort().getIntVal().intValue()).isEqualTo(8080);
- assertThat(probe.getHttpGet().getPath()).isEqualTo( "/ready");
- }
-
- @SuppressWarnings("unchecked")
- private TreeMap createFakeConfigLikeMaven(String config) throws Exception {
- Map nestedConfig = Serialization.jsonMapper().readValue(config, Map.class);
- return nestedConfig.entrySet().stream()
- .filter(e -> e.getValue() instanceof String)
- .map(e -> new AbstractMap.SimpleEntry<>(e.getKey(), (String)e.getValue()))
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (old, v) -> v, TreeMap::new));
- }
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNotNull()
+ .hasFieldOrPropertyWithValue("tcpSocket.port.strVal", "health");
- @SuppressWarnings("unchecked")
- private Map createFakeConfig(String config) throws JsonProcessingException {
- Map healthCheckVertxMap = Serialization.jsonMapper().readValue(config, Map.class);
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe).isNotNull()
+ .hasFieldOrPropertyWithValue("tcpSocket.port.strVal", "ready");
+ }
- Map enricherConfigMap = new HashMap<>();
- enricherConfigMap.put("jkube-healthcheck-vertx", healthCheckVertxMap);
+ @Test
+ @DisplayName("and port name using config, should enable probes with configured port name")
+ void andPortNameUsingConfig_shouldConfigureProbesWithPortName() throws Exception {
+ final String config = "{\"type\":\"tcp\",\"liveness\":{\"port-name\":\"health\"},\"readiness\":{\"port-name\":\"ready\"}}";
+ jKubePluginConfiguration.putAll(createFakeConfig(config));
+ plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
- Map enricherMap = new HashMap<>();
- enricherMap.put("config", enricherConfigMap);
+ VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Map pluginConfigurationMap = new HashMap<>();
- pluginConfigurationMap.put("enricher", enricherMap);
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNotNull()
+ .hasFieldOrPropertyWithValue("tcpSocket.port.strVal", "health");
- return pluginConfigurationMap;
- }
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe).isNotNull()
+ .hasFieldOrPropertyWithValue("tcpSocket.port.strVal", "ready");
+ }
- @Test
- public void testWithCustomConfigurationComingFromProcessorConf() throws Exception {
- String configString = "{\"path\":\"health\",\"port\":\"1234\",\"scheme\":\"https\"}";
- plexusMavenConfig.putAll(createFakeConfigLikeMaven(configString));
+ @Test
+ @DisplayName("and without liveness probe using properties, should disable liveness probe")
+ void andWithoutLivenessProbeUsingProperties_shouldDisableLiveness() {
+ properties.put("vertx.health.type", "tcp");
+ properties.put("vertx.health.readiness.port", "1235");
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNotNull(probe);
- assertNull(probe.getHttpGet().getHost());
- assertThat(probe.getHttpGet().getScheme()).isEqualTo("HTTPS");
- assertThat(probe.getHttpGet().getPort().getIntVal().intValue()).isEqualTo(1234);
- assertThat(probe.getHttpGet().getPath()).isEqualTo( "/health");
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNull();
- probe = enricher.getReadinessProbe();
- assertNotNull(probe);
- assertThat(probe.getHttpGet().getScheme()).isEqualTo("HTTPS");
- assertNull(probe.getHttpGet().getHost());
- assertThat(probe.getHttpGet().getPort().getIntVal().intValue()).isEqualTo(1234);
- assertThat(probe.getHttpGet().getPath()).isEqualTo( "/health");
- }
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertTCPSocket(readinessProbe, 1235);
+ }
- @Test
- public void testWithCustomConfigurationForLivenessAndReadinessComingFromConf() throws Exception {
- final String config =
- "{\"path\":\"health\",\"port\":\"1234\",\"scheme\":\"https\",\"readiness\":{\"path\":\"/ready\"}}";
- jKubePluginConfiguration.putAll(createFakeConfig(config));
- plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
+ @Test
+ @DisplayName("and without liveness probe using config, should disable liveness probe")
+ void andWithoutLivenessProbeUsingConfig_shouldDisableLiveness() throws Exception {
+ final String config = "{\"type\":\"tcp\",\"readiness\":{\"port\":\"1235\"}}";
+ jKubePluginConfiguration.putAll(createFakeConfig(config));
+ plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- assertThat(enricher.getLivenessProbe())
- .hasFieldOrPropertyWithValue("httpGet.host", null)
- .hasFieldOrPropertyWithValue("httpGet.scheme", "HTTPS")
- .hasFieldOrPropertyWithValue("httpGet.port.intVal", 1234)
- .hasFieldOrPropertyWithValue("httpGet.path", "/health");
- assertThat(enricher.getReadinessProbe())
- .hasFieldOrPropertyWithValue("httpGet.host", null)
- .hasFieldOrPropertyWithValue("httpGet.scheme", "HTTPS")
- .hasFieldOrPropertyWithValue("httpGet.port.intVal", 1234)
- .hasFieldOrPropertyWithValue("httpGet.path", "/ready");
- }
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNull();
- @Test
- public void testCustomConfiguration() {
- properties.put("vertx.health.path", "/health");
- properties.put("vertx.health.port", " 8081 ");
- properties.put("vertx.health.scheme", " https");
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertTCPSocket(readinessProbe, 1235);
+ }
+
+ @Test
+ @DisplayName("and negative readiness port using properties, should disable readiness probe")
+ void andNegativeReadinessPortUsingProperties_shouldDisableReadiness() {
+ properties.put("vertx.health.type", "tcp");
+ properties.put("vertx.health.port", "1337");
+ properties.put("vertx.health.readiness.port", "-1");
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNotNull(probe);
- assertNull(probe.getHttpGet().getHost());
- assertThat(probe.getHttpGet().getScheme()).isEqualToIgnoringCase("https");
- assertThat(probe.getHttpGet().getPort().getIntVal().intValue()).isEqualTo(8081);
- assertThat(probe.getHttpGet().getPath()).isEqualTo( "/health");
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertTCPSocket(livenessProbe, 1337);
- probe = enricher.getReadinessProbe();
- assertNotNull(probe);
- assertThat(probe.getHttpGet().getScheme()).isEqualToIgnoringCase("https");
- assertNull(probe.getHttpGet().getHost());
- assertThat(probe.getHttpGet().getPort().getIntVal().intValue()).isEqualTo(8081);
- assertThat(probe.getHttpGet().getPath()).isEqualTo( "/health");
- }
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe).isNull();
+ }
- @Test
- public void testWithHttpHeaders() throws Exception {
- final String config = "{\"path\":\"health\",\"headers\":{\"X-Header\":\"X\",\"Y-Header\":\"Y\"}}";
+ @Test
+ @DisplayName("and negative readiness port using config, should disable readiness probe")
+ void andNegativeReadinessPortUsingConfig_shouldDisableReadiness() throws Exception {
+ final String config = "{\"type\":\"tcp\",\"liveness\":{\"port\":\"1235\"},\"readiness\":{\"port\":\"-1\"}}";
jKubePluginConfiguration.putAll(createFakeConfig(config));
plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNotNull(probe);
- assertThat(probe.getHttpGet().getPath()).isEqualTo( "/health");
- assertThat(probe.getHttpGet().getPort().getIntVal()).isEqualTo(8080);
- assertThat(probe.getHttpGet().getHttpHeaders()).hasSize(2)
- .contains(new HTTPHeader("X-Header", "X"), new HTTPHeader("Y-Header", "Y"));
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertTCPSocket(livenessProbe, 1235);
- probe = enricher.getReadinessProbe();
- assertNotNull(probe);
- assertThat(probe.getHttpGet().getPath()).isEqualTo( "/health");
- assertThat(probe.getHttpGet().getPort().getIntVal()).isEqualTo(8080);
- assertThat(probe.getHttpGet().getHttpHeaders()).hasSize(2)
- .contains(new HTTPHeader("X-Header", "X"), new HTTPHeader("Y-Header", "Y"));
- }
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe).isNull();
+ }
- @Test
- public void testDisabledUsingEmptyPath() {
- properties.put("vertx.health.path", "");
+ @Test
+ @DisplayName("port and port name both using properties, should throw exception")
+ void portAndPortNameUsingProperties_shouldThrowException() {
+ properties.put("vertx.health.type", "tcp");
+ properties.put("vertx.health.port", "1235");
+ properties.put("vertx.health.port-name", "health");
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNull(probe);
- probe = enricher.getReadinessProbe();
- assertNull(probe);
- }
-
- @Test
- public void testDisabledUsingNegativePort() {
- properties.put("vertx.health.port", " -1 ");
- properties.put("vertx.health.path", " /ping ");
-
- VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
+ assertThatIllegalArgumentException()
+ .isThrownBy(enricher::getLivenessProbe)
+ .withMessageContaining("Invalid health check configuration");
- Probe probe = enricher.getLivenessProbe();
- assertNull(probe);
- probe = enricher.getReadinessProbe();
- assertNull(probe);
- }
+ assertThatIllegalArgumentException()
+ .isThrownBy(enricher::getReadinessProbe)
+ .withMessageStartingWith("Invalid health check configuration");
+ }
- @Test
- public void testDisabledUsingInvalidPort() {
- properties.put("vertx.health.port", "not an integer");
- properties.put("vertx.health.path", " /ping ");
+ @Test
+ @DisplayName("port and port name both using config, should throw exception")
+ void portAndPortNameUsingConfig_shouldThrowException() throws Exception {
+ final String config = "{\"type\":\"tcp\"," +
+ "\"liveness\":{\"port\":\"1234\",\"port-name\":\"foo\"}," +
+ "\"readiness\":{\"port\":\"1235\",\"port-name\":\"foo\"}}";
+ jKubePluginConfiguration.putAll(createFakeConfig(config));
+ plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- try {
- enricher.getLivenessProbe();
- fail("Illegal configuration not detected");
- } catch (Exception e) {
- // OK.
- }
-
- try {
- enricher.getReadinessProbe();
- fail("Illegal configuration not detected");
- } catch (Exception e) {
- // OK.
- }
- }
-
- @Test
- public void testDisabledUsingPortName() {
- properties.put("vertx.health.port-name", " health ");
- properties.put("vertx.health.path", " /ping ");
+ assertThatIllegalArgumentException()
+ .isThrownBy(enricher::getLivenessProbe)
+ .withMessageStartingWith("Invalid health check configuration");
- VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
+ assertThatIllegalArgumentException()
+ .isThrownBy(enricher::getReadinessProbe)
+ .withMessageStartingWith("Invalid health check configuration");
+ }
- Probe probe = enricher.getLivenessProbe();
- assertThat(probe.getHttpGet().getPort().getStrVal()).isEqualToIgnoringCase("health");
- probe = enricher.getReadinessProbe();
- assertThat(probe.getHttpGet().getPort().getStrVal()).isEqualToIgnoringCase("health");
}
@Test
- public void testDisabledUsingNegativePortUsingConfiguration() throws Exception {
- final String config = "{\"path\":\"/ping\",\"port\":\"-1\"}";
- jKubePluginConfiguration.putAll(createFakeConfig(config));
- plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
-
+ @DisplayName("with empty configuration, should disable probes")
+ void withEmptyConfig_shouldDisableProbes() {
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNull(probe);
- probe = enricher.getReadinessProbe();
- assertNull(probe);
+ assertNoLivenessReadinessProbes(enricher);
}
@Test
- public void testReadinessDisabled() {
- properties.put("vertx.health.readiness.path", "");
+ @DisplayName("default configuration with path, should enable probes with configured path")
+ void defaultConfigurationWithPath_shouldEnableProbes() {
properties.put("vertx.health.path", "/ping");
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNotNull(probe);
- assertThat(probe.getHttpGet().getPath()).isEqualTo("/ping");
- probe = enricher.getReadinessProbe();
- assertNull(probe);
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertHTTPGet(livenessProbe, "HTTP", 8080, "/ping");
+
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertHTTPGet(readinessProbe, "HTTP", 8080, "/ping");
}
@Test
- public void testReadinessDisabledUsingConfig() throws Exception {
- final String config = "{\"readiness\":{\"path\":\"\"},\"path\":\"/ping\"}";
- jKubePluginConfiguration.putAll(createFakeConfig(config));
- plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
+ @DisplayName("with different paths using properties, should enable probes with different paths")
+ void differentPathForLivenessAndReadinessProbes() {
+ properties.put("vertx.health.path", "/ping");
+ properties.put("vertx.health.readiness.path", "/ready");
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNotNull(probe);
- assertThat(probe.getHttpGet().getPath()).isEqualTo("/ping");
- probe = enricher.getReadinessProbe();
- assertNull(probe);
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertHTTPGet(livenessProbe, "HTTP", 8080, "/ping");
+
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertHTTPGet(readinessProbe, "HTTP", 8080, "/ready");
}
@Test
- public void testLivenessDisabledAndReadinessEnabled() {
- properties.put("vertx.health.readiness.path", "/ping");
- properties.put("vertx.health.path", "");
+ @DisplayName("with custom configuration coming from processor, should enable probes with config")
+ void withCustomConfigurationComingFromProcessorConf() throws Exception {
+ String configString = "{\"path\":\"health\",\"port\":\"1234\",\"scheme\":\"https\"}";
+ plexusMavenConfig.putAll(createFakeConfigLikeMaven(configString));
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNull(probe);
- probe = enricher.getReadinessProbe();
- assertNotNull(probe);
- assertThat(probe.getHttpGet().getPath()).isEqualTo("/ping");
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertHTTPGet(livenessProbe, "HTTPS", 1234, "/health");
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertHTTPGet(readinessProbe, "HTTPS", 1234, "/health");
}
@Test
- public void testLivenessDisabledAndReadinessEnabledUsingConfig() throws Exception {
- final String config = "{\"readiness\":{\"path\":\"/ping\"},\"path\":\"\"}";
- jKubePluginConfiguration.putAll(createFakeConfig(config));
- plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
+ @DisplayName("with custom configuration for liveness and readiness probe coming from config, should enable probes with config")
+ void withCustomConfigurationForLivenessAndReadinessComingFromConf() throws Exception {
+ final String config =
+ "{\"path\":\"health\",\"port\":\"1234\",\"scheme\":\"https\",\"readiness\":{\"path\":\"/ready\"}}";
+ jKubePluginConfiguration.putAll(createFakeConfig(config));
+ plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
- VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
+ VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNull(probe);
- probe = enricher.getReadinessProbe();
- assertNotNull(probe);
- assertThat(probe.getHttpGet().getPath()).isEqualTo("/ping");
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertHTTPGet(livenessProbe, "HTTPS", 1234, "/health");
+
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertHTTPGet(readinessProbe, "HTTPS", 1234, "/ready");
}
@Test
- public void testTCPSocketUsingUserProperties() {
- properties.put("vertx.health.type", "tcp");
- properties.put("vertx.health.port", "1234");
- properties.put("vertx.health.readiness.port", "1235");
+ @DisplayName("with custom configuration coming from properties, should enable probes with config")
+ void withCustomConfigurationFromProperties() {
+ properties.put("vertx.health.path", "/health");
+ properties.put("vertx.health.port", " 8081 ");
+ properties.put("vertx.health.scheme", " https");
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNotNull(probe);
- assertThat(probe.getTcpSocket().getPort().getIntVal().intValue()).isEqualTo(1234);
- probe = enricher.getReadinessProbe();
- assertNotNull(probe);
- assertThat(probe.getTcpSocket().getPort().getIntVal().intValue()).isEqualTo(1235);
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertHTTPGet(livenessProbe, "HTTPS", 8081, "/health");
+
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertHTTPGet(readinessProbe, "HTTPS", 8081, "/health");
}
@Test
- public void testTCPSocketUsingConfig() throws Exception {
- VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- final String config = "{\"type\":\"tcp\",\"liveness\":{\"port\":\"1234\"},\"readiness\":{\"port\":\"1235\"}}";
+ @DisplayName("with HTTP headers, should enable probes with headers")
+ void withHttpHeaders() throws Exception {
+ final String config = "{\"path\":\"health\",\"headers\":{\"X-Header\":\"X\",\"Y-Header\":\"Y\"}}";
jKubePluginConfiguration.putAll(createFakeConfig(config));
plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
- Probe probe = enricher.getLivenessProbe();
- assertNotNull(probe);
- assertThat(probe.getTcpSocket().getPort().getIntVal().intValue()).isEqualTo(1234);
- probe = enricher.getReadinessProbe();
- assertNotNull(probe);
- assertThat(probe.getTcpSocket().getPort().getIntVal().intValue()).isEqualTo(1235);
- }
-
- @Test
- public void testTCPSocketUsingUserPropertiesAndPortName() {
- properties.put("vertx.health.type", "tcp");
- properties.put("vertx.health.port-name", "health");
- properties.put("vertx.health.readiness.port-name", "ready");
-
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNotNull(probe);
- assertThat(probe.getTcpSocket().getPort().getStrVal()).isEqualTo( "health");
- probe = enricher.getReadinessProbe();
- assertNotNull(probe);
- assertThat(probe.getTcpSocket().getPort().getStrVal()).isEqualTo( "ready");
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertHTTPGet(livenessProbe, "HTTP", 8080, "/health");
+ assertThat(livenessProbe.getHttpGet().getHttpHeaders()).hasSize(2)
+ .contains(new HTTPHeader("X-Header", "X"), new HTTPHeader("Y-Header", "Y"));
+
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertHTTPGet(readinessProbe, "HTTP", 8080, "/health");
+ assertThat(readinessProbe.getHttpGet().getHttpHeaders()).hasSize(2)
+ .contains(new HTTPHeader("X-Header", "X"), new HTTPHeader("Y-Header", "Y"));
}
@Test
- public void testTCPSocketUsingConfigAndPortName() throws Exception {
- final String config = "{\"type\":\"tcp\",\"liveness\":{\"port-name\":\"health\"},\"readiness\":{\"port-name\":\"ready\"}}";
- jKubePluginConfiguration.putAll(createFakeConfig(config));
- plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
+ @DisplayName("with negative port using property, should disable probes")
+ void withNegativePort_shouldDisableProbes() {
+ properties.put("vertx.health.port", " -1 ");
+ properties.put("vertx.health.path", " /ping ");
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNotNull(probe);
- assertThat(probe.getTcpSocket().getPort().getStrVal()).isEqualTo( "health");
- probe = enricher.getReadinessProbe();
- assertNotNull(probe);
- assertThat(probe.getTcpSocket().getPort().getStrVal()).isEqualTo( "ready");
+ assertNoLivenessReadinessProbes(enricher);
}
@Test
- public void testTCPSocketUsingUserPropertiesLivenessDisabled() {
- properties.put("vertx.health.type", "tcp");
- properties.put("vertx.health.readiness.port", "1235");
+ @DisplayName("with invalid port using property, should throw exception")
+ void withInvalidPort_shouldThrowException() {
+ properties.put("vertx.health.port", "not an integer");
+ properties.put("vertx.health.path", " /ping ");
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNull(probe);
- probe = enricher.getReadinessProbe();
- assertNotNull(probe);
- assertEquals(1235, probe.getTcpSocket().getPort().getIntVal().intValue());
+ assertThatExceptionOfType(NumberFormatException.class)
+ .isThrownBy(enricher::getLivenessProbe)
+ .withMessageContaining("not an integer");
+
+ assertThatExceptionOfType(NumberFormatException.class)
+ .isThrownBy(enricher::getReadinessProbe)
+ .withMessageContaining("not an integer");
}
@Test
- public void testTCPSocketUsingConfigLivenessDisabled() throws Exception {
- final String config = "{\"type\":\"tcp\",\"readiness\":{\"port\":\"1235\"}}";
- jKubePluginConfiguration.putAll(createFakeConfig(config));
- plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
+ @DisplayName("with port name, should disable probes ")
+ void withPortName_shouldDisableProbes() {
+ properties.put("vertx.health.port-name", " health ");
+ properties.put("vertx.health.path", " /ping ");
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNull(probe);
- probe = enricher.getReadinessProbe();
- assertNotNull(probe);
- assertEquals(1235, probe.getTcpSocket().getPort().getIntVal().intValue());
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe.getHttpGet().getPort().getStrVal()).isEqualToIgnoringCase("health");
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe.getHttpGet().getPort().getStrVal()).isEqualToIgnoringCase("health");
}
- @Test
- public void testTCPSocketUsingUserPropertiesReadinessDisabled() {
- properties.put("vertx.health.type", "tcp");
- properties.put("vertx.health.port", "1337");
- properties.put("vertx.health.readiness.port", "0");
-
+ @DisplayName("using invalid properties")
+ @ParameterizedTest(name = "{index}: with ''{0}'' should disable probes")
+ @MethodSource("invalidProperties")
+ void withInvalidProperties_shouldDisableProbes(String description, String property, String propVal) {
+ // Given
+ properties.put(property, propVal);
+ // When
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
+ // Then
+ assertNoLivenessReadinessProbes(enricher);
+ }
- Probe probe = enricher.getLivenessProbe();
- assertEquals(1337, probe.getTcpSocket().getPort().getIntVal().intValue());
- assertNotNull(probe);
- probe = enricher.getReadinessProbe();
- assertNull(probe);
+ static Stream invalidProperties() {
+ return Stream.of(
+ arguments("empty health path", "vertx.health.path", ""),
+ arguments("TCP health type", "vertx.health.type", "tcp"),
+ arguments("exec health type", "vertx.health.type", "exec"));
}
- @Test
- public void testTCPSocketUsingConfigReadinessDisabled() throws Exception {
- final String config = "{\"type\":\"tcp\",\"liveness\":{\"port\":\"1235\"},\"readiness\":{\"port\":\"-1\"}}";
+ @DisplayName("using invalid config")
+ @ParameterizedTest(name = "{index}: with ''{0}'' should disable probes")
+ @MethodSource("invalidConfigs")
+ void withInvalidConfigs_shouldDisableProbes(String description, String config) throws Exception {
+ // Given
jKubePluginConfiguration.putAll(createFakeConfig(config));
plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
+ // When
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertEquals(1235, probe.getTcpSocket().getPort().getIntVal().intValue());
- assertNotNull(probe);
- probe = enricher.getReadinessProbe();
- assertNull(probe);
+ // Then
+ assertNoLivenessReadinessProbes(enricher);
}
- @Test(expected = IllegalArgumentException.class)
- public void testTCPSocketUsingUserPropertiesIllegal() {
- properties.put("vertx.health.type", "tcp");
- properties.put("vertx.health.port", "1235");
- properties.put("vertx.health.port-name", "health");
+ static Stream invalidConfigs() {
+ return Stream.of(
+ arguments("negative port", "{\"path\":\"/ping\",\"port\":\"-1\"}"),
+ arguments("TCP health type", "{\"type\":\"tcp\"}"),
+ arguments("exec health type", "{\"type\":\"exec\"}"));
+ }
+
+ @Test
+ @DisplayName("with empty readiness and non-empty health path using properties, should disable readiness probe")
+ void withEmptyReadinessAndNonEmptyHealthPathUsingProperties_shouldDisableReadiness() {
+ properties.put("vertx.health.readiness.path", "");
+ properties.put("vertx.health.path", "/ping");
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- enricher.getLivenessProbe();
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNotNull()
+ .hasFieldOrPropertyWithValue("httpGet.path", "/ping");
+
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe).isNull();
}
@Test
- public void testTCPSocketUsingConfigIllegal() throws Exception {
- final String config = "{\"type\":\"tcp\"," +
- "\"liveness\":{\"port\":\"1234\",\"port-name\":\"foo\"}," +
- "\"readiness\":{\"port\":\"1235\",\"port-name\":\"foo\"}}";
+ @DisplayName("with empty readiness and non-empty health path using config, should disable readiness probe")
+ void withEmptyReadinessAndNonEmptyHealthPathUsingConfig_shouldDisableReadiness() throws Exception {
+ final String config = "{\"readiness\":{\"path\":\"\"},\"path\":\"/ping\"}";
jKubePluginConfiguration.putAll(createFakeConfig(config));
plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- try {
- enricher.getLivenessProbe();
- fail("Illegal configuration not detected");
- } catch (Exception e) {
- // OK.
- }
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNotNull()
+ .hasFieldOrPropertyWithValue("httpGet.path", "/ping");
- try {
- enricher.getReadinessProbe();
- fail("Illegal configuration not detected");
- } catch (Exception e) {
- // OK.
- }
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe).isNull();
}
-
@Test
- public void testTCPSocketUsingUserPropertiesDisabled() {
- properties.put("vertx.health.type", "tcp");
+ @DisplayName("with empty health path and non-empty readiness path using properties, should disable liveness and enable readiness probe")
+ void withEmptyHealthAndNonEmptyReadinessPathUsingProperties_shouldDisableLivenessAndEnableReadiness() {
+ properties.put("vertx.health.readiness.path", "/ping");
+ properties.put("vertx.health.path", "");
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNull(probe);
- probe = enricher.getReadinessProbe();
- assertNull(probe);
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNull();
+
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe).isNotNull()
+ .hasFieldOrPropertyWithValue("httpGet.path", "/ping");
}
@Test
- public void testTCPSocketUsingConfigDisabled() throws Exception {
- final String config = "{\"type\":\"tcp\"}";
+ @DisplayName("with empty health path and non-empty readiness path using config, should disable liveness and enable readiness probe")
+ void withEmptyHealthAndNonEmptyReadinessPathUsingConfig_shouldDisableLivenessAndEnableReadiness() throws Exception {
+ final String config = "{\"readiness\":{\"path\":\"/ping\"},\"path\":\"\"}";
jKubePluginConfiguration.putAll(createFakeConfig(config));
plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNull(probe);
- probe = enricher.getReadinessProbe();
- assertNull(probe);
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNull();
+
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe).isNotNull()
+ .hasFieldOrPropertyWithValue("httpGet.path", "/ping");
}
@Test
- public void testExecUsingConfig() throws Exception {
+ @DisplayName("with exec type using config, should enable probes with configured exec")
+ void withExecTypeUsingConfig_shouldConfigureProbesWithExec() throws Exception {
final String config = "{\"type\":\"exec\"," +
"\"command\": {\"arg\":[\"/bin/sh\", \"-c\",\"touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600\"]}" +
"}";
@@ -559,16 +508,24 @@ public void testExecUsingConfig() throws Exception {
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNotNull(probe);
- assertThat(probe.getExec().getCommand()).hasSize(3);
- probe = enricher.getReadinessProbe();
- assertNotNull(probe);
- assertThat(probe.getExec().getCommand()).hasSize(3);
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNotNull()
+ .extracting(Probe::getExec)
+ .extracting(ExecAction::getCommand)
+ .asList()
+ .hasSize(3);
+
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe).isNotNull()
+ .extracting(Probe::getExec)
+ .extracting(ExecAction::getCommand)
+ .asList()
+ .hasSize(3);
}
@Test
- public void testExecUsingConfigLivenessDisabled() throws Exception {
+ @DisplayName("with exec type and readiness using config, should disable liveness probe")
+ void withExecTypeReadinessUsingConfig_shouldDisableLiveness() throws Exception {
final String config = "{\"type\":\"exec\"," +
"\"readiness\":{" +
"\"command\": {\"arg\":[\"/bin/sh\", \"-c\",\"touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600\"]}}," +
@@ -579,15 +536,19 @@ public void testExecUsingConfigLivenessDisabled() throws Exception {
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNull(probe);
- probe = enricher.getReadinessProbe();
- assertNotNull(probe);
- assertThat(probe.getExec().getCommand()).hasSize(3);
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNull();
+
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe).isNotNull()
+ .extracting(Probe::getExec)
+ .extracting(ExecAction::getCommand).asList()
+ .hasSize(3);
}
@Test
- public void testExecUsingConfigReadinessDisabled() throws Exception {
+ @DisplayName("with exec type and liveness using config, should disable readiness probe")
+ void withExecTypeLivenessUsingConfig_shouldDisableReadiness() throws Exception {
final String config = "{\"type\":\"exec\"," +
"\"liveness\":{" +
"\"command\": {\"arg\":[\"/bin/sh\", \"-c\",\"touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600\"]}}," +
@@ -598,112 +559,77 @@ public void testExecUsingConfigReadinessDisabled() throws Exception {
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertThat(probe.getExec().getCommand()).hasSize(3);
- assertNotNull(probe);
- probe = enricher.getReadinessProbe();
- assertNull(probe);
- }
-
- @Test
- public void testExecUsingUserPropertiesDisabled() {
- properties.put("vertx.health.type", "exec");
-
- VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
-
- Probe probe = enricher.getLivenessProbe();
- assertNull(probe);
- probe = enricher.getReadinessProbe();
- assertNull(probe);
- }
-
- @Test
- public void testExecUsingConfigDisabled() throws Exception {
- final String config = "{\"type\":\"exec\"}";
- jKubePluginConfiguration.putAll(createFakeConfig(config));
- plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
-
- VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNotNull()
+ .extracting(Probe::getExec)
+ .extracting(ExecAction::getCommand).asList()
+ .hasSize(3);
- Probe probe = enricher.getLivenessProbe();
- assertNull(probe);
- probe = enricher.getReadinessProbe();
- assertNull(probe);
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe).isNull();
}
@Test
- public void testUnknownTypeUsingUserProperties() {
+ @DisplayName("with invalid type using properties, should throw exception")
+ void withInvalidTypeUsingProperties_shouldThrowException() {
properties.put("vertx.health.type", "not a valid type");
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- try {
- enricher.getLivenessProbe();
- fail("Illegal configuration not detected");
- } catch (Exception e) {
- // OK.
- }
+ assertThatIllegalArgumentException()
+ .isThrownBy(enricher::getLivenessProbe)
+ .withMessageContaining("Invalid health check configuration");
- try {
- enricher.getReadinessProbe();
- fail("Illegal configuration not detected");
- } catch (Exception e) {
- // OK.
- }
+ assertThatIllegalArgumentException()
+ .isThrownBy(enricher::getReadinessProbe)
+ .withMessageContaining("Invalid health check configuration");
}
-
@Test
- public void testUnknownTypeUsingConfig() throws Exception {
+ @DisplayName("with invalid type using config, should throw exception")
+ void withInvalidTypeUsingConfig_shouldThrowException() throws Exception {
final String config = "{\"type\":\"not a valid type\"}";
jKubePluginConfiguration.putAll(createFakeConfig(config));
plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- try {
- enricher.getLivenessProbe();
- fail("Illegal configuration not detected");
- } catch (Exception e) {
- // OK.
- }
+ assertThatIllegalArgumentException()
+ .isThrownBy(enricher::getLivenessProbe)
+ .withMessageContaining("Invalid health check configuration");
- try {
- enricher.getReadinessProbe();
- fail("Illegal configuration not detected");
- } catch (Exception e) {
- // OK.
- }
+ assertThatIllegalArgumentException()
+ .isThrownBy(enricher::getReadinessProbe)
+ .withMessageContaining("Invalid health check configuration");
}
@Test
- public void testNotApplicableProject() {
+ @DisplayName("with no project, vertx enricher should not be applicable")
+ void witNoPlugin_enricherShouldNotBeApplicable() {
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
context.getProject().setPlugins(Collections.emptyList());
- Probe probe = enricher.getLivenessProbe();
- assertNull(probe);
- probe = enricher.getReadinessProbe();
- assertNull(probe);
+ assertNoLivenessReadinessProbes(enricher);
}
@Test
- public void testApplicableProjectWithGradle() {
+ @DisplayName("with gradle plugin, vertx enricher should be applicable")
+ void withGradlePlugin_enricherShouldBeApplicable() {
properties.put("vertx.health.path", "/ping");
context = context.toBuilder()
.project(createNewJavaProjectWithVertxPlugin("io.vertx", "io.vertx.vertx-plugin"))
.build();
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
-
- Probe probe = enricher.getLivenessProbe();
- assertThat(probe).isNotNull();
- probe = enricher.getReadinessProbe();
- assertThat(probe).isNotNull();
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNotNull();
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe).isNotNull();
}
@Test
- public void testThatWeCanUSeDifferentTypesForLivenessAndReadiness() throws Exception {
+ @DisplayName("with different types for liveness and readiness probes, should enable probes with configured types")
+ void withDifferentTypesForLivenessAndReadiness_shouldConfigureProbesWithConfiguredTypes() throws Exception {
final String config = "{\"liveness\":{" +
"\"type\":\"exec\",\"command\":{\"arg\":\"ls\"}" +
"},\"readiness\":{\"path\":\"/ping\"}}";
@@ -712,16 +638,20 @@ public void testThatWeCanUSeDifferentTypesForLivenessAndReadiness() throws Excep
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getLivenessProbe();
- assertNotNull(probe);
- assertNotNull(probe.getExec());
- probe = enricher.getReadinessProbe();
- assertNotNull(probe);
- assertNotNull(probe.getHttpGet());
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNotNull()
+ .extracting(Probe::getExec)
+ .isNotNull();
+
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe).isNotNull()
+ .extracting(Probe::getHttpGet)
+ .isNotNull();
}
@Test
- public void testThatSpecificConfigOverrideGenericUserProperties() throws Exception {
+ @DisplayName("with specific config, should override generic user properties")
+ void specificConfigOverrideGenericUserProperties() throws Exception {
final String config = "{\"liveness\":{" +
"\"type\":\"exec\",\"command\":{\"arg\":\"ls\"}" +
"},\"readiness\":{\"port\":\"1337\"}}";
@@ -733,21 +663,22 @@ public void testThatSpecificConfigOverrideGenericUserProperties() throws Excepti
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getReadinessProbe();
- assertThat(probe).isNotNull();
- assertThat(probe.getTcpSocket()).isNotNull();
- assertThat(probe.getHttpGet()).isNull();
- assertThat(probe.getTcpSocket().getPort().getIntVal()).isEqualTo(1337);
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe.getHttpGet()).isNull();
+ assertTCPSocket(readinessProbe, 1337);
- probe = enricher.getLivenessProbe();
- assertThat(probe).isNotNull();
- assertThat(probe.getTcpSocket()).isNull();
- assertThat(probe.getExec()).isNotNull();
- assertThat(probe.getExec().getCommand().iterator().next()).isEqualTo("ls");
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNotNull()
+ .hasFieldOrPropertyWithValue("tcpSocket", null)
+ .extracting(Probe::getExec).isNotNull()
+ .extracting(ExecAction::getCommand).asList()
+ .singleElement()
+ .isEqualTo("ls");
}
@Test
- public void testThatGenericConfigOverrideGenericUserProperties() throws Exception {
+ @DisplayName("with generic config, should override generic user properties")
+ void withGenericConfig_shouldOverrideGenericUserProperties() throws Exception {
final String config = "{\"type\":\"exec\",\"command\":{\"arg\":\"ls\"}}";
jKubePluginConfiguration.putAll(createFakeConfig(config));
plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
@@ -756,21 +687,26 @@ public void testThatGenericConfigOverrideGenericUserProperties() throws Exceptio
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getReadinessProbe();
- assertThat(probe).isNotNull();
- assertThat(probe.getTcpSocket()).isNull();
- assertThat(probe.getExec()).isNotNull();
- assertThat(probe.getExec().getCommand().iterator().next()).isEqualTo("ls");
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe).isNotNull()
+ .hasFieldOrPropertyWithValue("tcpSocket", null)
+ .extracting(Probe::getExec).isNotNull()
+ .extracting(ExecAction::getCommand).asList()
+ .singleElement()
+ .isEqualTo("ls");
- probe = enricher.getLivenessProbe();
- assertThat(probe).isNotNull();
- assertThat(probe.getTcpSocket()).isNull();
- assertThat(probe.getExec()).isNotNull();
- assertThat(probe.getExec().getCommand().iterator().next()).isEqualTo("ls");
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNotNull()
+ .hasFieldOrPropertyWithValue("tcpSocket", null)
+ .extracting(Probe::getExec).isNotNull()
+ .extracting(ExecAction::getCommand).asList()
+ .singleElement()
+ .isEqualTo("ls");
}
@Test
- public void testThatSpecificConfigOverrideSpecificUserProperties() throws Exception {
+ @DisplayName("with specific config, should override specific user properties")
+ void withSpecificConfig_shouldOverrideSpecificUserProperties() throws Exception {
final String config = "{\"liveness\":{\"type\":\"http\",\"path\":\"/ping\"},\"readiness\":{\"port\":\"1337\"}}";
jKubePluginConfiguration.putAll(createFakeConfig(config));
plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
@@ -780,21 +716,21 @@ public void testThatSpecificConfigOverrideSpecificUserProperties() throws Except
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getReadinessProbe();
- assertThat(probe).isNotNull();
- assertThat(probe.getTcpSocket()).isNotNull();
- assertThat(probe.getHttpGet()).isNull();
- assertThat(probe.getTcpSocket().getPort().getIntVal()).isEqualTo(1337);
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe.getHttpGet()).isNull();
+ assertTCPSocket(readinessProbe, 1337);
- probe = enricher.getLivenessProbe();
- assertThat(probe).isNotNull();
- assertThat(probe.getHttpGet()).isNotNull();
- assertThat(probe.getTcpSocket()).isNull();
- assertThat(probe.getHttpGet().getPath()).isEqualTo("/ping");
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNotNull()
+ .hasFieldOrPropertyWithValue("tcpSocket", null)
+ .extracting(Probe::getHttpGet)
+ .isNotNull()
+ .hasFieldOrPropertyWithValue("path", "/ping");
}
@Test
- public void testThatSpecificUserPropertiesOverrideGenericConfig() throws Exception {
+ @DisplayName("with specific user properties, should override generic config")
+ void withSpecificUserProperties_shouldOverrideGenericConfig() throws Exception {
final String config = "{\"path\":\"/ping\",\"type\":\"http\"}";
jKubePluginConfiguration.putAll(createFakeConfig(config));
plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
@@ -804,21 +740,21 @@ public void testThatSpecificUserPropertiesOverrideGenericConfig() throws Excepti
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getReadinessProbe();
- assertThat(probe).isNotNull();
- assertThat(probe.getTcpSocket()).isNotNull();
- assertThat(probe.getHttpGet()).isNull();
- assertThat(probe.getTcpSocket().getPort().getIntVal()).isEqualTo(1234);
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe.getHttpGet()).isNull();
+ assertTCPSocket(readinessProbe, 1234);
- probe = enricher.getLivenessProbe();
- assertThat(probe).isNotNull();
- assertThat(probe.getHttpGet()).isNotNull();
- assertThat(probe.getTcpSocket()).isNull();
- assertThat(probe.getHttpGet().getPort().getIntVal()).isEqualTo(1235);
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNotNull()
+ .hasFieldOrPropertyWithValue("tcpSocket", null)
+ .extracting(Probe::getHttpGet)
+ .isNotNull()
+ .hasFieldOrPropertyWithValue("port.intVal", 1235);
}
@Test
- public void testThatSpecificConfigOverrideGenericConfig() throws Exception {
+ @DisplayName("with specific config, should override generic config")
+ void withSpecificConfig_shouldOverrideGenericConfig() throws Exception {
final String config = "{\"liveness\":{\"path\":\"/live\"}," +
"\"readiness\":{\"path\":\"/ping\",\"port-name\":\"ready\"}," +
"\"path\":\"/health\",\"port-name\":\"health\"}";
@@ -827,21 +763,24 @@ public void testThatSpecificConfigOverrideGenericConfig() throws Exception {
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getReadinessProbe();
- assertThat(probe).isNotNull();
- assertThat(probe.getHttpGet()).isNotNull();
- assertThat(probe.getHttpGet().getPort().getStrVal()).isEqualTo("ready");
- assertThat(probe.getHttpGet().getPath()).isEqualTo("/ping");
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe).isNotNull()
+ .extracting(Probe::getHttpGet)
+ .isNotNull()
+ .hasFieldOrPropertyWithValue("port.strVal", "ready")
+ .hasFieldOrPropertyWithValue("path", "/ping");
- probe = enricher.getLivenessProbe();
- assertThat(probe).isNotNull();
- assertThat(probe.getHttpGet()).isNotNull();
- assertThat(probe.getHttpGet().getPort().getStrVal()).isEqualTo("health");
- assertThat(probe.getHttpGet().getPath()).isEqualTo("/live");
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe).isNotNull()
+ .extracting(Probe::getHttpGet)
+ .isNotNull()
+ .hasFieldOrPropertyWithValue("port.strVal", "health")
+ .hasFieldOrPropertyWithValue("path", "/live");
}
@Test
- public void testThatSpecificUserPropertiesOverrideGenericUserProperties() throws Exception {
+ @DisplayName("with specific user properties, should override generic user properties")
+ void withSpecificUserProperties_shouldOverrideGenericUserProperties() throws Exception {
final String config = "{\"path\":\"/ping\",\"type\":\"http\"}";
jKubePluginConfiguration.putAll(createFakeConfig(config));
plexusMavenConfig.putAll(createFakeConfigLikeMaven(config));
@@ -853,17 +792,13 @@ public void testThatSpecificUserPropertiesOverrideGenericUserProperties() throws
VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
- Probe probe = enricher.getReadinessProbe();
- assertThat(probe).isNotNull();
- assertThat(probe.getTcpSocket()).isNotNull();
- assertThat(probe.getHttpGet()).isNull();
- assertThat(probe.getTcpSocket().getPort().getIntVal()).isEqualTo(1234);
+ Probe readinessProbe = enricher.getReadinessProbe();
+ assertThat(readinessProbe.getHttpGet()).isNull();
+ assertTCPSocket(readinessProbe, 1234);
- probe = enricher.getLivenessProbe();
- assertThat(probe).isNotNull();
- assertThat(probe.getHttpGet()).isNull();
- assertThat(probe.getTcpSocket()).isNotNull();
- assertThat(probe.getTcpSocket().getPort().getIntVal()).isEqualTo(1236);
+ Probe livenessProbe = enricher.getLivenessProbe();
+ assertThat(livenessProbe.getHttpGet()).isNull();
+ assertTCPSocket(livenessProbe, 1236);
}
private JavaProject createNewJavaProjectWithVertxPlugin(String vertxGroup, String vertxArtifact) {
@@ -881,4 +816,51 @@ private JavaProject createNewJavaProjectWithVertxPlugin(String vertxGroup, Strin
.build();
}
+ @SuppressWarnings("unchecked")
+ private TreeMap createFakeConfigLikeMaven(String config) throws Exception {
+ Map nestedConfig = Serialization.jsonMapper().readValue(config, Map.class);
+ return nestedConfig.entrySet().stream()
+ .filter(e -> e.getValue() instanceof String)
+ .map(e -> new AbstractMap.SimpleEntry<>(e.getKey(), (String)e.getValue()))
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (old, v) -> v, TreeMap::new));
+ }
+
+ @SuppressWarnings("unchecked")
+ private Map createFakeConfig(String config) throws JsonProcessingException {
+ Map healthCheckVertxMap = Serialization.jsonMapper().readValue(config, Map.class);
+
+ Map enricherConfigMap = new HashMap<>();
+ enricherConfigMap.put("jkube-healthcheck-vertx", healthCheckVertxMap);
+
+ Map enricherMap = new HashMap<>();
+ enricherMap.put("config", enricherConfigMap);
+
+ Map pluginConfigurationMap = new HashMap<>();
+ pluginConfigurationMap.put("enricher", enricherMap);
+
+ return pluginConfigurationMap;
+ }
+
+ private void assertNoLivenessReadinessProbes(VertxHealthCheckEnricher enricher) {
+ assertThat(enricher)
+ .returns(null, VertxHealthCheckEnricher::getLivenessProbe)
+ .returns(null, VertxHealthCheckEnricher::getReadinessProbe);
+ }
+
+ private void assertHTTPGet(Probe probe, String scheme, int port, String path) {
+ assertThat(probe).isNotNull()
+ .extracting(Probe::getHttpGet)
+ .hasFieldOrPropertyWithValue("host", null)
+ .hasFieldOrPropertyWithValue("scheme", scheme)
+ .hasFieldOrPropertyWithValue("port.intVal", port)
+ .hasFieldOrPropertyWithValue("path", path);
+ }
+
+ private void assertTCPSocket(Probe probe, int port) {
+ assertThat(probe).isNotNull()
+ .extracting(Probe::getTcpSocket)
+ .isNotNull()
+ .hasFieldOrPropertyWithValue("port.intVal", port);
+ }
+
}
diff --git a/jkube-kit/jkube-kit-vertx/src/test/java/org/eclipse/jkube/vertx/generator/VertxGeneratorIsApplicableTest.java b/jkube-kit/jkube-kit-vertx/src/test/java/org/eclipse/jkube/vertx/generator/VertxGeneratorIsApplicableTest.java
index f43fd6ded9..420f7a7466 100644
--- a/jkube-kit/jkube-kit-vertx/src/test/java/org/eclipse/jkube/vertx/generator/VertxGeneratorIsApplicableTest.java
+++ b/jkube-kit/jkube-kit-vertx/src/test/java/org/eclipse/jkube/vertx/generator/VertxGeneratorIsApplicableTest.java
@@ -17,58 +17,44 @@
import org.eclipse.jkube.kit.common.Dependency;
import org.eclipse.jkube.kit.common.JavaProject;
import org.eclipse.jkube.kit.common.Plugin;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mockito;
-import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.params.provider.Arguments.arguments;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-@RunWith(Parameterized.class)
-public class VertxGeneratorIsApplicableTest {
+class VertxGeneratorIsApplicableTest {
private JavaProject project;
private GeneratorContext context;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
project = mock(JavaProject.class, Mockito.RETURNS_DEEP_STUBS);
context = mock(GeneratorContext.class, Mockito.RETURNS_DEEP_STUBS);
when(context.getProject()).thenReturn(project);
}
- @Parameterized.Parameters(name = "{0}")
- public static Collection