From d20fb3e36d6a4f2af0f8189a156db2feaba80dd7 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Thu, 20 Dec 2018 16:24:10 +0200 Subject: [PATCH] Add an integration test for the discovery client (#291) * Add an integration test for the discovery client Fixes: #288 * Add missing licenses --- .../discovery/discovery-client/pom.xml | 31 +++++ .../src/main/fabric8/deployment.yml | 10 ++ .../discovery-client/src/main/fabric8/svc.yml | 15 +++ .../it/DiscoveryClientApplication.java | 44 +++++++ .../discovery/discovery-service-a/pom.xml | 29 +++++ .../it/SimpleSpringBootApplication.java | 50 ++++++++ .../discovery/discovery-service-b/pom.xml | 28 +++++ .../it/SimpleSpringBootApplication.java | 50 ++++++++ .../discovery/pom.xml | 26 ++++ .../discovery/tests/pom.xml | 115 ++++++++++++++++++ .../cloud/kubernetes/it/ServicesIT.java | 50 ++++++++ .../tests/src/test/resources/arquillian.xml | 9 ++ .../pom.xml | 1 + 13 files changed, 458 insertions(+) create mode 100644 spring-cloud-kubernetes-integration-tests/discovery/discovery-client/pom.xml create mode 100644 spring-cloud-kubernetes-integration-tests/discovery/discovery-client/src/main/fabric8/deployment.yml create mode 100644 spring-cloud-kubernetes-integration-tests/discovery/discovery-client/src/main/fabric8/svc.yml create mode 100644 spring-cloud-kubernetes-integration-tests/discovery/discovery-client/src/main/java/org/springframework/cloud/kubernetes/it/DiscoveryClientApplication.java create mode 100644 spring-cloud-kubernetes-integration-tests/discovery/discovery-service-a/pom.xml create mode 100644 spring-cloud-kubernetes-integration-tests/discovery/discovery-service-a/src/main/java/org/springframework/cloud/kubernetes/it/SimpleSpringBootApplication.java create mode 100644 spring-cloud-kubernetes-integration-tests/discovery/discovery-service-b/pom.xml create mode 100644 spring-cloud-kubernetes-integration-tests/discovery/discovery-service-b/src/main/java/org/springframework/cloud/kubernetes/it/SimpleSpringBootApplication.java create mode 100644 spring-cloud-kubernetes-integration-tests/discovery/pom.xml create mode 100644 spring-cloud-kubernetes-integration-tests/discovery/tests/pom.xml create mode 100644 spring-cloud-kubernetes-integration-tests/discovery/tests/src/test/java/org/springframework/cloud/kubernetes/it/ServicesIT.java create mode 100644 spring-cloud-kubernetes-integration-tests/discovery/tests/src/test/resources/arquillian.xml diff --git a/spring-cloud-kubernetes-integration-tests/discovery/discovery-client/pom.xml b/spring-cloud-kubernetes-integration-tests/discovery/discovery-client/pom.xml new file mode 100644 index 00000000..b139042d --- /dev/null +++ b/spring-cloud-kubernetes-integration-tests/discovery/discovery-client/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + + org.springframework.cloud + discovery-parent + 1.0.0.BUILD-SNAPSHOT + + + discovery-client + Spring Cloud Kubernetes :: Integration Tests :: Discovery Client + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.cloud + spring-cloud-kubernetes-discovery + + + + \ No newline at end of file diff --git a/spring-cloud-kubernetes-integration-tests/discovery/discovery-client/src/main/fabric8/deployment.yml b/spring-cloud-kubernetes-integration-tests/discovery/discovery-client/src/main/fabric8/deployment.yml new file mode 100644 index 00000000..3c8b53a3 --- /dev/null +++ b/spring-cloud-kubernetes-integration-tests/discovery/discovery-client/src/main/fabric8/deployment.yml @@ -0,0 +1,10 @@ +# We need this fragment in order for the kubernetes client to talk to +# the Kubernetes API without caring about proper certificates +spec: + template: + spec: + containers: + - env: + - name: KUBERNETES_TRUST_CERTIFICATES + value: true + diff --git a/spring-cloud-kubernetes-integration-tests/discovery/discovery-client/src/main/fabric8/svc.yml b/spring-cloud-kubernetes-integration-tests/discovery/discovery-client/src/main/fabric8/svc.yml new file mode 100644 index 00000000..945f430d --- /dev/null +++ b/spring-cloud-kubernetes-integration-tests/discovery/discovery-client/src/main/fabric8/svc.yml @@ -0,0 +1,15 @@ +# we are using an FMP fragment to ensure that NodePort is used correctly +kind: Service +apiVersion: v1 +metadata: + name: ${project.artifactId} + labels: + app: ${project.artifactId} +spec: + selector: + app: ${project.artifactId} + ports: + - protocol: TCP + port: 8080 + nodePort: ${nodeport.value} + type: NodePort diff --git a/spring-cloud-kubernetes-integration-tests/discovery/discovery-client/src/main/java/org/springframework/cloud/kubernetes/it/DiscoveryClientApplication.java b/spring-cloud-kubernetes-integration-tests/discovery/discovery-client/src/main/java/org/springframework/cloud/kubernetes/it/DiscoveryClientApplication.java new file mode 100644 index 00000000..d7ce6f62 --- /dev/null +++ b/spring-cloud-kubernetes-integration-tests/discovery/discovery-client/src/main/java/org/springframework/cloud/kubernetes/it/DiscoveryClientApplication.java @@ -0,0 +1,44 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.springframework.cloud.kubernetes.it; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.DiscoveryClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@SpringBootApplication +@RestController +public class DiscoveryClientApplication { + + @Autowired + private DiscoveryClient discoveryClient; + + @GetMapping("/services") + public List services() { + return discoveryClient.getServices(); + } + + public static void main(String[] args) { + SpringApplication.run(DiscoveryClientApplication.class, args); + } +} diff --git a/spring-cloud-kubernetes-integration-tests/discovery/discovery-service-a/pom.xml b/spring-cloud-kubernetes-integration-tests/discovery/discovery-service-a/pom.xml new file mode 100644 index 00000000..e6b9f60e --- /dev/null +++ b/spring-cloud-kubernetes-integration-tests/discovery/discovery-service-a/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + + org.springframework.cloud + discovery-parent + 1.0.0.BUILD-SNAPSHOT + + + discovery-service-a + Spring Cloud Kubernetes :: Integration Tests :: Discovery Service A + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + \ No newline at end of file diff --git a/spring-cloud-kubernetes-integration-tests/discovery/discovery-service-a/src/main/java/org/springframework/cloud/kubernetes/it/SimpleSpringBootApplication.java b/spring-cloud-kubernetes-integration-tests/discovery/discovery-service-a/src/main/java/org/springframework/cloud/kubernetes/it/SimpleSpringBootApplication.java new file mode 100644 index 00000000..526ff32e --- /dev/null +++ b/spring-cloud-kubernetes-integration-tests/discovery/discovery-service-a/src/main/java/org/springframework/cloud/kubernetes/it/SimpleSpringBootApplication.java @@ -0,0 +1,50 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.springframework.cloud.kubernetes.it; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@SpringBootApplication +@RestController +public class SimpleSpringBootApplication { + + @GetMapping("/greeting") + public Greeting home() { + return new Greeting("Hello from Service A"); + } + + public static void main(String[] args) { + SpringApplication.run(SimpleSpringBootApplication.class, args); + } + + public static class Greeting { + + private final String message; + + public Greeting(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + } +} diff --git a/spring-cloud-kubernetes-integration-tests/discovery/discovery-service-b/pom.xml b/spring-cloud-kubernetes-integration-tests/discovery/discovery-service-b/pom.xml new file mode 100644 index 00000000..9aa9bf11 --- /dev/null +++ b/spring-cloud-kubernetes-integration-tests/discovery/discovery-service-b/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + + org.springframework.cloud + discovery-parent + 1.0.0.BUILD-SNAPSHOT + + + discovery-service-b + Spring Cloud Kubernetes :: Integration Tests :: Discovery Service B + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + + + \ No newline at end of file diff --git a/spring-cloud-kubernetes-integration-tests/discovery/discovery-service-b/src/main/java/org/springframework/cloud/kubernetes/it/SimpleSpringBootApplication.java b/spring-cloud-kubernetes-integration-tests/discovery/discovery-service-b/src/main/java/org/springframework/cloud/kubernetes/it/SimpleSpringBootApplication.java new file mode 100644 index 00000000..e09bcaa7 --- /dev/null +++ b/spring-cloud-kubernetes-integration-tests/discovery/discovery-service-b/src/main/java/org/springframework/cloud/kubernetes/it/SimpleSpringBootApplication.java @@ -0,0 +1,50 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.springframework.cloud.kubernetes.it; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@SpringBootApplication +@RestController +public class SimpleSpringBootApplication { + + @GetMapping("/greeting") + public Greeting home() { + return new Greeting("Hello from Service B"); + } + + public static void main(String[] args) { + SpringApplication.run(SimpleSpringBootApplication.class, args); + } + + public static class Greeting { + + private final String message; + + public Greeting(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + } +} diff --git a/spring-cloud-kubernetes-integration-tests/discovery/pom.xml b/spring-cloud-kubernetes-integration-tests/discovery/pom.xml new file mode 100644 index 00000000..d9dfd4ab --- /dev/null +++ b/spring-cloud-kubernetes-integration-tests/discovery/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + + org.springframework.cloud + spring-cloud-kubernetes-integration-tests + 1.0.0.BUILD-SNAPSHOT + + + Spring Cloud Kubernetes :: Integration Tests :: Discovery Parent + discovery-parent + pom + + + discovery-service-a + discovery-service-b + discovery-client + tests + + + + + \ No newline at end of file diff --git a/spring-cloud-kubernetes-integration-tests/discovery/tests/pom.xml b/spring-cloud-kubernetes-integration-tests/discovery/tests/pom.xml new file mode 100644 index 00000000..6247d320 --- /dev/null +++ b/spring-cloud-kubernetes-integration-tests/discovery/tests/pom.xml @@ -0,0 +1,115 @@ + + + 4.0.0 + + + org.springframework.cloud + discovery-parent + 1.0.0.BUILD-SNAPSHOT + + + tests + Spring Cloud Kubernetes :: Integration Tests :: Discovery Tests + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.arquillian.cube + arquillian-cube-kubernetes + ${arquillian-cube.version} + test + + + undertow-core + io.undertow + + + + + org.jboss.arquillian.junit + arquillian-junit-standalone + test + + + io.rest-assured + rest-assured + test + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + io.fabric8 + fabric8-maven-plugin + + true + + + + + + + + it + + + + io.fabric8 + fabric8-maven-plugin + + false + aggregate + + + + + org.springframework.cloud + discovery-client + ${project.version} + + + org.springframework.cloud + discovery-service-a + ${project.version} + + + org.springframework.cloud + discovery-service-b + ${project.version} + + + + javax.validation + validation-api + 2.0.1.Final + + + + + + + + + \ No newline at end of file diff --git a/spring-cloud-kubernetes-integration-tests/discovery/tests/src/test/java/org/springframework/cloud/kubernetes/it/ServicesIT.java b/spring-cloud-kubernetes-integration-tests/discovery/tests/src/test/java/org/springframework/cloud/kubernetes/it/ServicesIT.java new file mode 100644 index 00000000..2f897e56 --- /dev/null +++ b/spring-cloud-kubernetes-integration-tests/discovery/tests/src/test/java/org/springframework/cloud/kubernetes/it/ServicesIT.java @@ -0,0 +1,50 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.springframework.cloud.kubernetes.it; + +import org.arquillian.cube.kubernetes.impl.requirement.RequiresKubernetes; +import org.hamcrest.core.StringContains; +import org.jboss.arquillian.junit.Arquillian; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static io.restassured.RestAssured.given; + +@RequiresKubernetes +@RunWith(Arquillian.class) +public class ServicesIT { + + private static final String HOST = System.getProperty("service.host"); + private static final Integer PORT = Integer.valueOf(System.getProperty("service.port")); + + @Test + public void testServicesEndpoint() { + given() + .baseUri(String.format("http://%s:%d", HOST, PORT)) + .get("services") + .then() + .statusCode(200) + .body(new StringContains("service-a") { + @Override + protected boolean evalSubstringOf(String s) { + return s.contains("service-a") && s.contains("service-b"); + } + }); + } + +} diff --git a/spring-cloud-kubernetes-integration-tests/discovery/tests/src/test/resources/arquillian.xml b/spring-cloud-kubernetes-integration-tests/discovery/tests/src/test/resources/arquillian.xml new file mode 100644 index 00000000..0eb7aad1 --- /dev/null +++ b/spring-cloud-kubernetes-integration-tests/discovery/tests/src/test/resources/arquillian.xml @@ -0,0 +1,9 @@ + + + + default + + + diff --git a/spring-cloud-kubernetes-integration-tests/pom.xml b/spring-cloud-kubernetes-integration-tests/pom.xml index e688cfc2..427aab48 100644 --- a/spring-cloud-kubernetes-integration-tests/pom.xml +++ b/spring-cloud-kubernetes-integration-tests/pom.xml @@ -128,6 +128,7 @@ simple-core simple-configmap + discovery