Skip to content

Commit bb02fb8

Browse files
committed
Update example to use Dekorate 2.7
1 parent fa94e75 commit bb02fb8

File tree

7 files changed

+17
-44
lines changed

7 files changed

+17
-44
lines changed

.openshiftio/application.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ objects:
247247
app.kubernetes.io/vcs-uri: [email protected]:snowdrop/configmap-example.git
248248
name: configmap
249249
spec:
250+
path: /
250251
port:
251252
targetPort: 8080
252253
to:

pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@
9999
<groupId>io.dekorate</groupId>
100100
<artifactId>kubernetes-junit</artifactId>
101101
<scope>test</scope>
102-
<!--
103-
Workaround: We need to exclude annotations, otherwise Openshift always uses the Docker build in tests.
104-
Reported by https://github.com/dekorateio/dekorate/issues/821.
105-
The same happens with Dekorate 2.7.0.
106-
-->
107102
<exclusions>
108103
<exclusion>
109104
<groupId>io.dekorate</groupId>

run_tests_with_s2i.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
SOURCE_REPOSITORY_URL=${1:-https://github.com/snowdrop/configmap-example}
3-
SOURCE_REPOSITORY_REF=${2:-sb-2.4.x}
3+
SOURCE_REPOSITORY_REF=${2:-sb-2.5.x}
44

55
source scripts/waitFor.sh
66

scripts/waitFor.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ waitFor() {
1616
return 1
1717
fi
1818
sleep $LOOP
19-
echo "Waiting for pod to be created..."
20-
idx=$((idx+1))
19+
let "idx+=1"
2120
done
2221
# Wait for pod to be ready
2322
if [[ $(oc wait --for=condition=ready --timeout=$READY_TIMEOUT pod -l $POD_LABEL=$NAME | grep "condition met" | wc -l) -eq 0 ]] ; then

src/test/java/dev/snowdrop/example/LocalTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
import static io.restassured.RestAssured.given;
2020
import static org.hamcrest.core.Is.is;
2121

22-
import dev.snowdrop.example.service.GreetingProperties;
23-
2422
import org.junit.jupiter.api.Test;
2523
import org.junit.jupiter.api.extension.ExtendWith;
2624
import org.springframework.beans.factory.annotation.Autowired;
2725
import org.springframework.beans.factory.annotation.Value;
2826
import org.springframework.boot.test.context.SpringBootTest;
29-
import org.springframework.boot.web.server.LocalServerPort;
3027
import org.springframework.test.context.junit.jupiter.SpringExtension;
3128

29+
import dev.snowdrop.example.service.GreetingProperties;
30+
3231
@ExtendWith(SpringExtension.class)
33-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
32+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
33+
properties = "spring.cloud.kubernetes.config.enabled=false")
3434
public class LocalTest {
3535

3636
private static final String GREETING_PATH = "api/greeting";

src/test/java/dev/snowdrop/example/ManagedOpenShiftIT.java

+5-16
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,28 @@
1616

1717
package dev.snowdrop.example;
1818

19-
import java.net.MalformedURLException;
2019
import java.net.URL;
2120

22-
import org.junit.jupiter.api.BeforeEach;
2321
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
2422

2523
import io.dekorate.testing.annotation.Inject;
24+
import io.dekorate.testing.annotation.Named;
2625
import io.dekorate.testing.openshift.annotation.OpenshiftIntegrationTest;
2726
import io.fabric8.kubernetes.client.KubernetesClient;
28-
import io.fabric8.openshift.api.model.Route;
29-
import io.fabric8.openshift.client.OpenShiftClient;
3027

3128
@DisabledIfSystemProperty(named = "unmanaged-test", matches = "true")
3229
@OpenshiftIntegrationTest
3330
public class ManagedOpenShiftIT extends AbstractOpenShiftIT {
3431
@Inject
3532
KubernetesClient kubernetesClient;
3633

37-
String baseUrl;
38-
39-
@BeforeEach
40-
public void setup() throws MalformedURLException {
41-
// TODO: In Dekorate 1.7, we can inject Routes directly, so we won't need to do this:
42-
Route route = kubernetesClient.adapt(OpenShiftClient.class).routes().withName("configmap").get();
43-
String protocol = route.getSpec().getTls() == null ? "http" : "https";
44-
int port = "http".equals(protocol) ? 80 : 443;
45-
URL url = new URL(protocol, route.getSpec().getHost(), port, route.getSpec().getPath());
46-
baseUrl = url.toString();
47-
}
34+
@Inject
35+
@Named("configmap")
36+
URL baseUrl;
4837

4938
@Override
5039
protected String baseURL() {
51-
return baseUrl;
40+
return baseUrl.toString();
5241
}
5342

5443
@Override

src/test/java/dev/snowdrop/example/UnmanagedOpenShiftIT.java

+5-16
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,28 @@
1616

1717
package dev.snowdrop.example;
1818

19-
import java.net.MalformedURLException;
2019
import java.net.URL;
2120

22-
import org.junit.jupiter.api.BeforeEach;
2321
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
2422

2523
import io.dekorate.testing.annotation.Inject;
24+
import io.dekorate.testing.annotation.Named;
2625
import io.dekorate.testing.openshift.annotation.OpenshiftIntegrationTest;
2726
import io.fabric8.kubernetes.client.KubernetesClient;
28-
import io.fabric8.openshift.api.model.Route;
29-
import io.fabric8.openshift.client.OpenShiftClient;
3027

3128
@EnabledIfSystemProperty(named = "unmanaged-test", matches = "true")
3229
@OpenshiftIntegrationTest(deployEnabled = false, buildEnabled = false, pushEnabled = false)
3330
public class UnmanagedOpenShiftIT extends AbstractOpenShiftIT {
3431
@Inject
3532
KubernetesClient kubernetesClient;
3633

37-
String baseUrl;
38-
39-
@BeforeEach
40-
public void setup() throws MalformedURLException {
41-
// TODO: In Dekorate 1.7, we can inject Routes directly, so we won't need to do this:
42-
Route route = kubernetesClient.adapt(OpenShiftClient.class).routes().withName("configmap").get();
43-
String protocol = route.getSpec().getTls() == null ? "http" : "https";
44-
int port = "http".equals(protocol) ? 80 : 443;
45-
URL url = new URL(protocol, route.getSpec().getHost(), port, "/");
46-
baseUrl = url.toString();
47-
}
34+
@Inject
35+
@Named("configmap")
36+
URL baseUrl;
4837

4938
@Override
5039
protected String baseURL() {
51-
return baseUrl;
40+
return baseUrl.toString();
5241
}
5342

5443
@Override

0 commit comments

Comments
 (0)