From 11f3ab2c8fd72c23245cfb40b614a1c95fab4f5b Mon Sep 17 00:00:00 2001 From: Ihor Banadiga Date: Thu, 13 Jul 2017 18:35:33 +0300 Subject: [PATCH 01/10] Integration test inited --- api-gateway-service/pom.xml | 50 +++++++- .../src/main/docker/Dockerfile | 6 + .../src/main/docker/wrapper.sh | 26 ++++ .../src/main/resources/application.properties | 10 +- config-server/pom.xml | 59 +++++++-- config-server/src/main/docker/Dockerfile | 6 + config-server/src/main/docker/wrapper.sh | 14 +++ .../src/main/resources/application.properties | 8 ++ discovery-server/pom.xml | 31 ++++- discovery-server/src/main/docker/Dockerfile | 6 + discovery-server/src/main/docker/wrapper.sh | 3 + .../src/main/resources/application.properties | 6 + hackster-service-client/pom.xml | 14 +-- hackster-service/pom.xml | 35 ++++-- hackster-service/src/main/docker/Dockerfile | 6 + hackster-service/src/main/docker/wrapper.sh | 20 +++ .../src/main/resources/application.properties | 10 +- integration-test/pom.xml | 32 +++++ .../integration/EntToEndIntegrationTest.java | 82 +++++++++++++ .../src/test/resources/docker-compose.yml | 114 ++++++++++++++++++ pom.xml | 8 +- rating-service/pom.xml | 32 ++++- rating-service/src/main/docker/Dockerfile | 6 + rating-service/src/main/docker/wrapper.sh | 20 +++ .../src/main/resources/application.properties | 8 ++ realtor-service/pom.xml | 77 ++++++++++-- realtor-service/src/main/docker/Dockerfile | 6 + realtor-service/src/main/docker/wrapper.sh | 20 +++ .../src/main/resources/application.properties | 10 +- storage-service-client/pom.xml | 23 ++-- storage-service/pom.xml | 46 +++++-- storage-service/src/main/docker/Dockerfile | 6 + storage-service/src/main/docker/wrapper.sh | 14 +++ .../src/main/resources/application.properties | 8 ++ 34 files changed, 741 insertions(+), 81 deletions(-) create mode 100644 api-gateway-service/src/main/docker/Dockerfile create mode 100644 api-gateway-service/src/main/docker/wrapper.sh create mode 100644 config-server/src/main/docker/Dockerfile create mode 100644 config-server/src/main/docker/wrapper.sh create mode 100644 discovery-server/src/main/docker/Dockerfile create mode 100644 discovery-server/src/main/docker/wrapper.sh create mode 100644 hackster-service/src/main/docker/Dockerfile create mode 100644 hackster-service/src/main/docker/wrapper.sh create mode 100644 integration-test/pom.xml create mode 100644 integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java create mode 100644 integration-test/src/test/resources/docker-compose.yml create mode 100644 rating-service/src/main/docker/Dockerfile create mode 100644 rating-service/src/main/docker/wrapper.sh create mode 100644 realtor-service/src/main/docker/Dockerfile create mode 100644 realtor-service/src/main/docker/wrapper.sh create mode 100644 storage-service/src/main/docker/Dockerfile create mode 100644 storage-service/src/main/docker/wrapper.sh diff --git a/api-gateway-service/pom.xml b/api-gateway-service/pom.xml index 9a6df66..1cea81f 100644 --- a/api-gateway-service/pom.xml +++ b/api-gateway-service/pom.xml @@ -23,14 +23,18 @@ UTF-8 1.8 Dalston.RELEASE + ${basedir}/src/main/docker + + org.springframework.boot + spring-boot-starter-actuator + org.springframework.cloud spring-cloud-starter-zuul - org.springframework.cloud spring-cloud-starter-eureka @@ -61,8 +65,48 @@ org.springframework.boot spring-boot-maven-plugin + + maven-antrun-plugin + + + + + + + + install + + run + + + + + + com.spotify + docker-maven-plugin + 1.0.0 + + + build-image + install + + build + + + + + ${project.artifactId} + ${docker.baseDir} + + + / + ${project.build.directory} + ${project.artifactId}.jar + + + + - - diff --git a/api-gateway-service/src/main/docker/Dockerfile b/api-gateway-service/src/main/docker/Dockerfile new file mode 100644 index 0000000..07426c5 --- /dev/null +++ b/api-gateway-service/src/main/docker/Dockerfile @@ -0,0 +1,6 @@ +FROM java:8 +ADD api-gateway-service.jar api-gateway-service.jar +ADD wrapper.sh wrapper.sh +RUN bash -c 'chmod +x /wrapper.sh' +RUN bash -c 'touch /app.jar' +ENTRYPOINT ["/bin/bash", "/wrapper.sh"] diff --git a/api-gateway-service/src/main/docker/wrapper.sh b/api-gateway-service/src/main/docker/wrapper.sh new file mode 100644 index 0000000..f321b77 --- /dev/null +++ b/api-gateway-service/src/main/docker/wrapper.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +if [ "$WATE" == "true" ]; then + + echo "Trying to connect to discovery-server" + until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do + echo '.' + sleep 1 + done + + echo "Trying to connect to storage-service" + until $(curl --output /dev/null --silent --head --fail http://storage-service:8091/info); do + echo '.' + sleep 1 + done + + echo "Trying to connect to realtor-service" + until $(curl --output /dev/null --silent --head --fail http://realtor-service:8080/info); do + echo '.' + sleep 1 + done + echo "Starting" + +fi + +java -jar /api-gateway-service.jar diff --git a/api-gateway-service/src/main/resources/application.properties b/api-gateway-service/src/main/resources/application.properties index be41be7..ae2f9a9 100644 --- a/api-gateway-service/src/main/resources/application.properties +++ b/api-gateway-service/src/main/resources/application.properties @@ -1,2 +1,10 @@ spring.application.name=api-gateway-service -server.port=8090 \ No newline at end of file +server.port=8090 + +eureka.instance.preferIpAddress=true + +endpoints.info.id=info +endpoints.info.sensitive=false +endpoints.info.enabled=true + +info.app.name=Api gateway service diff --git a/config-server/pom.xml b/config-server/pom.xml index d49e884..88b29c2 100644 --- a/config-server/pom.xml +++ b/config-server/pom.xml @@ -23,6 +23,7 @@ UTF-8 1.8 Dalston.RELEASE + ${basedir}/src/main/docker @@ -30,22 +31,24 @@ org.springframework.boot spring-boot-starter-actuator - + + org.springframework.boot + spring-boot-starter-actuator + org.springframework.cloud spring-cloud-config-server + + org.springframework.cloud + spring-cloud-starter-eureka + org.springframework.boot spring-boot-starter-test test - - - org.springframework.cloud - spring-cloud-starter-eureka - @@ -66,8 +69,48 @@ org.springframework.boot spring-boot-maven-plugin + + maven-antrun-plugin + + + + + + + + install + + run + + + + + + com.spotify + docker-maven-plugin + 1.0.0 + + + build-image + install + + build + + + + + ${project.artifactId} + ${docker.baseDir} + + + / + ${project.build.directory} + ${project.artifactId}.jar + + + + - - diff --git a/config-server/src/main/docker/Dockerfile b/config-server/src/main/docker/Dockerfile new file mode 100644 index 0000000..0eefda8 --- /dev/null +++ b/config-server/src/main/docker/Dockerfile @@ -0,0 +1,6 @@ +FROM java:8 +ADD config-server.jar config-server.jar +ADD wrapper.sh wrapper.sh +RUN bash -c 'chmod +x /wrapper.sh' +RUN bash -c 'touch /app.jar' +ENTRYPOINT ["/bin/bash", "/wrapper.sh"] diff --git a/config-server/src/main/docker/wrapper.sh b/config-server/src/main/docker/wrapper.sh new file mode 100644 index 0000000..6e01c3f --- /dev/null +++ b/config-server/src/main/docker/wrapper.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +if [ "$WATE" == "true" ]; then + + echo "Trying to connect to discovery-server" + until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do + echo '.' + sleep 1 + done + echo "Starting" + +fi + +java -jar /config-server.jar diff --git a/config-server/src/main/resources/application.properties b/config-server/src/main/resources/application.properties index 4cf2381..17623bd 100644 --- a/config-server/src/main/resources/application.properties +++ b/config-server/src/main/resources/application.properties @@ -5,3 +5,11 @@ spring.cloud.config.discovery.enabled=true spring.application.name=config-server server.port=8888 + +eureka.instance.preferIpAddress=true + +endpoints.info.id=info +endpoints.info.sensitive=false +endpoints.info.enabled=true + +info.app.name=Config server diff --git a/discovery-server/pom.xml b/discovery-server/pom.xml index 1107e2c..17df683 100644 --- a/discovery-server/pom.xml +++ b/discovery-server/pom.xml @@ -23,9 +23,14 @@ UTF-8 1.8 Dalston.RELEASE + ${basedir}/src/main/docker + + org.springframework.boot + spring-boot-starter-actuator + org.springframework.cloud spring-cloud-starter-eureka-server @@ -56,6 +61,23 @@ org.springframework.boot spring-boot-maven-plugin + + maven-antrun-plugin + + + + + + + + install + + run + + + + com.spotify docker-maven-plugin @@ -70,20 +92,17 @@ - discovery-service - java - ["java", "-jar", "/${project.build.finalName}.jar"] + ${project.artifactId} + ${docker.baseDir} / ${project.build.directory} - ${project.build.finalName}.jar + ${project.artifactId}.jar - - diff --git a/discovery-server/src/main/docker/Dockerfile b/discovery-server/src/main/docker/Dockerfile new file mode 100644 index 0000000..988fcb2 --- /dev/null +++ b/discovery-server/src/main/docker/Dockerfile @@ -0,0 +1,6 @@ +FROM java:8 +ADD discovery-server.jar discovery-server.jar +ADD wrapper.sh wrapper.sh +RUN bash -c 'chmod +x /wrapper.sh' +RUN bash -c 'touch /app.jar' +ENTRYPOINT ["/bin/bash", "/wrapper.sh"] diff --git a/discovery-server/src/main/docker/wrapper.sh b/discovery-server/src/main/docker/wrapper.sh new file mode 100644 index 0000000..96542a8 --- /dev/null +++ b/discovery-server/src/main/docker/wrapper.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +java -jar /discovery-server.jar diff --git a/discovery-server/src/main/resources/application.properties b/discovery-server/src/main/resources/application.properties index bac323d..62a9a22 100644 --- a/discovery-server/src/main/resources/application.properties +++ b/discovery-server/src/main/resources/application.properties @@ -3,3 +3,9 @@ server.port=8761 eureka.client.register-with-eureka=false eureka.client.fetch-registry=false + +endpoints.info.id=info +endpoints.info.sensitive=false +endpoints.info.enabled=true + +info.app.name=Discovery server diff --git a/hackster-service-client/pom.xml b/hackster-service-client/pom.xml index 8583e63..dd3ffc7 100644 --- a/hackster-service-client/pom.xml +++ b/hackster-service-client/pom.xml @@ -9,7 +9,7 @@ 0.0.1-SNAPSHOT jar - hackster-service-client + Hackster service client Client library for Hackster Service @@ -50,6 +50,12 @@ true + + com.lohika.jclub + hackster-service + 0.0.1-SNAPSHOT + test + org.springframework.boot spring-boot-starter-test @@ -67,12 +73,6 @@ 1.3.0 test - - com.lohika.jclub - hackster-service - 0.0.1-SNAPSHOT - test - diff --git a/hackster-service/pom.xml b/hackster-service/pom.xml index 4b21f6c..fb2887d 100644 --- a/hackster-service/pom.xml +++ b/hackster-service/pom.xml @@ -23,6 +23,7 @@ UTF-8 1.8 Dalston.RELEASE + ${basedir}/src/main/docker @@ -30,21 +31,22 @@ org.springframework.boot spring-boot-starter-actuator + + org.springframework.boot + spring-boot-starter-actuator + org.springframework.boot spring-boot-starter-web - org.springframework.boot spring-boot-starter-data-jpa - org.springframework.cloud spring-cloud-starter-eureka - org.springframework.cloud spring-cloud-starter-config @@ -60,6 +62,7 @@ lombok true + org.springframework.boot spring-boot-starter-test @@ -85,6 +88,23 @@ org.springframework.boot spring-boot-maven-plugin + + maven-antrun-plugin + + + + + + + + install + + run + + + + com.spotify docker-maven-plugin @@ -99,20 +119,17 @@ - hackster-service - java - ["java", "-jar", "/${project.build.finalName}.jar"] + ${project.artifactId} + ${docker.baseDir} / ${project.build.directory} - ${project.build.finalName}.jar + ${project.artifactId}.jar - - diff --git a/hackster-service/src/main/docker/Dockerfile b/hackster-service/src/main/docker/Dockerfile new file mode 100644 index 0000000..e76d6ae --- /dev/null +++ b/hackster-service/src/main/docker/Dockerfile @@ -0,0 +1,6 @@ +FROM java:8 +ADD hackster-service.jar hackster-service.jar +ADD wrapper.sh wrapper.sh +RUN bash -c 'chmod +x /wrapper.sh' +RUN bash -c 'touch /app.jar' +ENTRYPOINT ["/bin/bash", "/wrapper.sh"] diff --git a/hackster-service/src/main/docker/wrapper.sh b/hackster-service/src/main/docker/wrapper.sh new file mode 100644 index 0000000..1492689 --- /dev/null +++ b/hackster-service/src/main/docker/wrapper.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +if [ "$WATE" == "true" ]; then + + echo "Trying to connect to discovery-server" + until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do + echo '.' + sleep 1 + done + + echo "Trying to connect to config-server" + until $(curl --output /dev/null --silent --head --fail http://config-server:8888/info); do + echo '.' + sleep 1 + done + echo "Starting" + +fi + +java -jar /hackster-service.jar diff --git a/hackster-service/src/main/resources/application.properties b/hackster-service/src/main/resources/application.properties index c908936..3a1b1a9 100644 --- a/hackster-service/src/main/resources/application.properties +++ b/hackster-service/src/main/resources/application.properties @@ -1,2 +1,10 @@ server.port=8082 -spring.application.name=hackster-service \ No newline at end of file +spring.application.name=hackster-service + +eureka.instance.preferIpAddress=true + +endpoints.info.id=info +endpoints.info.sensitive=false +endpoints.info.enabled=true + +info.app.name=Hackster service diff --git a/integration-test/pom.xml b/integration-test/pom.xml new file mode 100644 index 0000000..920cb56 --- /dev/null +++ b/integration-test/pom.xml @@ -0,0 +1,32 @@ + + + + spring-cloud + com.lohika.jclub + 0.0.1-SNAPSHOT + + 4.0.0 + + com.lohika.jclub.integration + ent-to-ent-integration-test + + Integration test + Ent-to-ent integration test + + + + org.testcontainers + testcontainers + 1.3.0 + test + + + com.lohika.jclub.gateway + api-gateway-service + 0.0.1-SNAPSHOT + test + + + diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java b/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java new file mode 100644 index 0000000..f33e35a --- /dev/null +++ b/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java @@ -0,0 +1,82 @@ +package com.lohika.jclub.integration; + +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.HttpClientBuilder; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.testcontainers.containers.DockerComposeContainer; + +import java.io.File; +import java.io.IOException; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +public class EntToEndIntegrationTest { + + private static final int SLEEP = 5000; + + private static final String API_GATEWAY_SERVICE = "api-gateway-service_1"; + private static final int API_GATEWAY_SERVICE_PORT = 8090; + + private static final String STORAGE_SERVICE = "storage-service_1"; + private static final int STORAGE_SERVICE_PORT = 8091; + + private static final String compose = EntToEndIntegrationTest.class.getClassLoader() + .getResource("./docker-compose.yml").getPath(); + + @ClassRule + public static DockerComposeContainer environment = new DockerComposeContainer(new File(compose)) + .withExposedService(API_GATEWAY_SERVICE, API_GATEWAY_SERVICE_PORT) + .withExposedService(STORAGE_SERVICE, STORAGE_SERVICE_PORT) + .withPull(false); + + + @BeforeClass + public static void init() throws InterruptedException { + HttpClient client = HttpClientBuilder.create().build(); + String gateway = "http://localhost:" + API_GATEWAY_SERVICE_PORT + "/info"; + HttpGet httpGet = new HttpGet(gateway); + + HttpResponse httpResponse = null; + do { + Thread.sleep(SLEEP); + try { + httpResponse = client.execute(httpGet); + } catch (IOException e) { + } + } while (httpResponse == null || httpResponse.getStatusLine().getStatusCode() != 200); + Thread.sleep(SLEEP); + } + + @Test + public void checkIsStarted() throws IOException, InterruptedException { + HttpClient client = HttpClientBuilder.create().build(); + + String gateway = "http://localhost:" + API_GATEWAY_SERVICE_PORT + "/api/realtor-service/storeApartments"; + HttpPost httpPost = new HttpPost(gateway); + httpPost.addHeader("Content-Type", "application/json"); + httpPost.setEntity(new StringEntity("{\n" + + "\"location\" : \"location\",\n" + + "\"price\" : 1500.5,\n" + + "\"sqft\" : 1.5,\n" + + "\"phone\" : \"123\",\n" + + "\"realtorName\" : \"vas\",\n" + + "\"mail\" : \"mail@exem.com\"\n" + + "}")); + HttpResponse httpResponse1 = client.execute(httpPost); + assertThat(httpResponse1.getStatusLine().getStatusCode(), is(200)); + + Thread.sleep(SLEEP); + + String storage = "http://localhost:" + STORAGE_SERVICE_PORT + "/apartments/1"; + HttpGet httpGet = new HttpGet(storage); + HttpResponse httpResponse2 = client.execute(httpGet); + assertThat(httpResponse2.getStatusLine().getStatusCode(), is(200)); + } +} diff --git a/integration-test/src/test/resources/docker-compose.yml b/integration-test/src/test/resources/docker-compose.yml new file mode 100644 index 0000000..3fdeef1 --- /dev/null +++ b/integration-test/src/test/resources/docker-compose.yml @@ -0,0 +1,114 @@ +version: "2" +services: +# + discovery-server: + image: discovery-server + ports: + - "8761:8761" +# + config-server: + image: config-server + ports: + - "8888:8888" + links: + - discovery-server + environment: + - WATE=true + - JAVA_CLUB_SRC_HOME=https://github.com/lvivJavaClub + - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka + depends_on: + - discovery-server +# + storage-service: + image: storage-service + ports: + - "8091:8091" + links: + - discovery-server + environment: + - WATE=true + - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka + - eureka.instance.preferIpAddress=true + depends_on: + - discovery-server +# + rating-service: + image: rating-service + ports: + - "8081:8081" + links: + - discovery-server + - config-server + environment: + - WATE=true + - spring.cloud.config.uri=http://config-server:8888/ + - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka + - eureka.instance.preferIpAddress=true + depends_on: + - discovery-server + - config-server +# + hackster-service: + image: hackster-service + ports: + - "8082:8082" + links: + - discovery-server + - config-server + environment: + - WATE=true + - spring.cloud.config.uri=http://config-server:8888/ + - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka + - eureka.instance.preferIpAddress=true + depends_on: + - discovery-server + - config-server +# + realtor-service: + image: realtor-service + ports: + - "8080:8080" + links: + - discovery-server + environment: + - WATE=true + - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka + - eureka.instance.preferIpAddress=true + depends_on: + - discovery-server + - rating-service + - hackster-service + - storage-service +# + # client-server: + # image: client-server + # ports: + # - "8083:8083" + # links: + # - discovery-server + # environment: + #- WATE=true + # eureka.host: discovery-server + # eureka.instance.preferIpAddress: 'true' + # depends_on: + # - discovery-server + # - storage-service +# + api-gateway-service: + image: api-gateway-service + ports: + - "8090:8090" + links: + - discovery-server + environment: + - WATE=true + - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka + - eureka.instance.preferIpAddress=true + depends_on: + - discovery-server + - realtor-service + # - client-server + +#networks: +# default: +# driver: spring-cloud-driver diff --git a/pom.xml b/pom.xml index 2b67310..c2d65d9 100644 --- a/pom.xml +++ b/pom.xml @@ -8,8 +8,8 @@ 0.0.1-SNAPSHOT pom - spring-cloud - spring cloud + Spring cloud + Spring cloud application config-server @@ -24,6 +24,6 @@ storage-service storage-service-client api-gateway-service - client-service - + integration-test + diff --git a/rating-service/pom.xml b/rating-service/pom.xml index 25862a6..3994c16 100644 --- a/rating-service/pom.xml +++ b/rating-service/pom.xml @@ -23,6 +23,7 @@ UTF-8 1.8 Dalston.RELEASE + ${basedir}/src/main/docker @@ -30,6 +31,10 @@ org.springframework.boot spring-boot-starter-actuator + + org.springframework.boot + spring-boot-starter-actuator + org.springframework.boot spring-boot-starter-web @@ -42,11 +47,14 @@ org.springframework.cloud spring-cloud-starter-eureka + org.projectlombok lombok 1.16.16 + + org.springframework.boot spring-boot-starter-test @@ -72,6 +80,23 @@ org.springframework.boot spring-boot-maven-plugin + + maven-antrun-plugin + + + + + + + + install + + run + + + + com.spotify docker-maven-plugin @@ -86,14 +111,13 @@ - rating-service - java - ["java", "-jar", "/${project.build.finalName}.jar"] + ${project.artifactId} + ${docker.baseDir} / ${project.build.directory} - ${project.build.finalName}.jar + ${project.artifactId}.jar diff --git a/rating-service/src/main/docker/Dockerfile b/rating-service/src/main/docker/Dockerfile new file mode 100644 index 0000000..e8da638 --- /dev/null +++ b/rating-service/src/main/docker/Dockerfile @@ -0,0 +1,6 @@ +FROM java:8 +ADD rating-service.jar rating-service.jar +ADD wrapper.sh wrapper.sh +RUN bash -c 'chmod +x /wrapper.sh' +RUN bash -c 'touch /app.jar' +ENTRYPOINT ["/bin/bash", "/wrapper.sh"] diff --git a/rating-service/src/main/docker/wrapper.sh b/rating-service/src/main/docker/wrapper.sh new file mode 100644 index 0000000..b0f7e59 --- /dev/null +++ b/rating-service/src/main/docker/wrapper.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +if [ "$WATE" == "true" ]; then + + echo "Trying to connect to discovery-server" + until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do + echo '.' + sleep 1 + done + + echo "Trying to connect to config-server" + until $(curl --output /dev/null --silent --head --fail http://config-server:8888/info); do + echo '.' + sleep 1 + done + echo "Starting" + +fi + +java -jar /rating-service.jar diff --git a/rating-service/src/main/resources/application.properties b/rating-service/src/main/resources/application.properties index fc1c858..fa3938b 100644 --- a/rating-service/src/main/resources/application.properties +++ b/rating-service/src/main/resources/application.properties @@ -1,2 +1,10 @@ server.port=8081 spring.application.name=rating-service + +eureka.instance.preferIpAddress=true + +endpoints.info.id=info +endpoints.info.sensitive=false +endpoints.info.enabled=true + +info.app.name=Rating service diff --git a/realtor-service/pom.xml b/realtor-service/pom.xml index 4673e03..04fbd7c 100644 --- a/realtor-service/pom.xml +++ b/realtor-service/pom.xml @@ -23,9 +23,24 @@ UTF-8 1.8 Dalston.RELEASE + ${basedir}/src/main/docker + + com.lohika.jclub.storage.client + storage-service-client + 0.0.1-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-actuator + org.springframework.cloud spring-cloud-starter-eureka @@ -34,25 +49,21 @@ org.springframework.boot spring-boot-starter-web - - org.springframework.boot - spring-boot-starter-test - test + org.springframework.cloud + spring-cloud-starter-feign + org.projectlombok lombok 1.16.12 + - org.springframework.cloud - spring-cloud-starter-feign - - - com.lohika.jclub.storage.client - storage-service-client - 0.0.1-SNAPSHOT + org.springframework.boot + spring-boot-starter-test + test @@ -74,8 +85,48 @@ org.springframework.boot spring-boot-maven-plugin + + maven-antrun-plugin + + + + + + + + install + + run + + + + + + com.spotify + docker-maven-plugin + 1.0.0 + + + build-image + install + + build + + + + + ${project.artifactId} + ${docker.baseDir} + + + / + ${project.build.directory} + ${project.artifactId}.jar + + + + - - diff --git a/realtor-service/src/main/docker/Dockerfile b/realtor-service/src/main/docker/Dockerfile new file mode 100644 index 0000000..59bea61 --- /dev/null +++ b/realtor-service/src/main/docker/Dockerfile @@ -0,0 +1,6 @@ +FROM java:8 +ADD realtor-service.jar realtor-service.jar +ADD wrapper.sh wrapper.sh +RUN bash -c 'chmod +x /wrapper.sh' +RUN bash -c 'touch /app.jar' +ENTRYPOINT ["/bin/bash", "/wrapper.sh"] diff --git a/realtor-service/src/main/docker/wrapper.sh b/realtor-service/src/main/docker/wrapper.sh new file mode 100644 index 0000000..afc4425 --- /dev/null +++ b/realtor-service/src/main/docker/wrapper.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +if [ "$WATE" == "true" ]; then + + echo "Trying to connect to discovery-server" + until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do + echo '.' + sleep 1 + done + + echo "Trying to connect to config-server" + until $(curl --output /dev/null --silent --head --fail http://config-server:8888/info); do + echo '.' + sleep 1 + done + echo "Starting" + +fi + +java -jar /realtor-service.jar diff --git a/realtor-service/src/main/resources/application.properties b/realtor-service/src/main/resources/application.properties index a58c307..ae96fbe 100644 --- a/realtor-service/src/main/resources/application.properties +++ b/realtor-service/src/main/resources/application.properties @@ -1,2 +1,10 @@ spring.application.name=realtor-service -feign.hystrix.enabled=true \ No newline at end of file +feign.hystrix.enabled=true + +eureka.instance.preferIpAddress=true + +endpoints.info.id=info +endpoints.info.sensitive=false +endpoints.info.enabled=true + +info.app.name=Realtor service diff --git a/storage-service-client/pom.xml b/storage-service-client/pom.xml index f849642..87be175 100644 --- a/storage-service-client/pom.xml +++ b/storage-service-client/pom.xml @@ -38,34 +38,35 @@ org.springframework.boot spring-boot-starter-hateoas + com.netflix.hystrix hystrix-javanica - - org.projectlombok - lombok - true - com.lohika.jclub discovery-server 0.0.1-SNAPSHOT test - - org.testcontainers - testcontainers - 1.3.0 - test - com.lohika.jclub.storage.service storage-service 0.0.1-SNAPSHOT test + + org.projectlombok + lombok + true + + + org.testcontainers + testcontainers + 1.3.0 + test + org.springframework.boot spring-boot-starter-test diff --git a/storage-service/pom.xml b/storage-service/pom.xml index 230df06..f502d7b 100644 --- a/storage-service/pom.xml +++ b/storage-service/pom.xml @@ -24,9 +24,14 @@ 1.8 Dalston.RELEASE springio + ${basedir}/src/main/docker + + org.springframework.boot + spring-boot-starter-actuator + org.springframework.cloud spring-cloud-starter-eureka @@ -50,6 +55,7 @@ lombok true + org.springframework.boot spring-boot-starter-test @@ -75,34 +81,48 @@ org.springframework.boot spring-boot-maven-plugin + + maven-antrun-plugin + + + + + + + + install + + run + + + + com.spotify docker-maven-plugin 1.0.0 - - build-image - install - - build - - + + build-image + install + + build + + - storage-service - java - ["java", "-jar", "/${project.build.finalName}.jar"] + ${project.artifactId} + ${docker.baseDir} / ${project.build.directory} - ${project.build.finalName}.jar + ${project.artifactId}.jar - - diff --git a/storage-service/src/main/docker/Dockerfile b/storage-service/src/main/docker/Dockerfile new file mode 100644 index 0000000..eea615e --- /dev/null +++ b/storage-service/src/main/docker/Dockerfile @@ -0,0 +1,6 @@ +FROM java:8 +ADD storage-service.jar storage-service.jar +ADD wrapper.sh wrapper.sh +RUN bash -c 'chmod +x /wrapper.sh' +RUN bash -c 'touch /app.jar' +ENTRYPOINT ["/bin/bash", "/wrapper.sh"] diff --git a/storage-service/src/main/docker/wrapper.sh b/storage-service/src/main/docker/wrapper.sh new file mode 100644 index 0000000..f98340c --- /dev/null +++ b/storage-service/src/main/docker/wrapper.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +if [ "$WATE" == "true" ]; then + + echo "Trying to connect to discovery-server" + until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do + echo '.' + sleep 1 + done + echo "Starting" + +fi + +java -jar /storage-service.jar diff --git a/storage-service/src/main/resources/application.properties b/storage-service/src/main/resources/application.properties index 8554b7f..72a52a8 100644 --- a/storage-service/src/main/resources/application.properties +++ b/storage-service/src/main/resources/application.properties @@ -2,3 +2,11 @@ spring.application.name=storage-service server.port=8091 spring.data.rest.return-body-on-create=true spring.data.rest.return-body-on-update=true + +eureka.instance.preferIpAddress=true + +endpoints.info.id=info +endpoints.info.sensitive=false +endpoints.info.enabled=true + +info.app.name=Storage service From f77ddbd70d668a9ae40ba668ea07521602f88c4f Mon Sep 17 00:00:00 2001 From: Ihor Banadiga Date: Thu, 13 Jul 2017 18:46:54 +0300 Subject: [PATCH 02/10] wrapper fixed --- realtor-service/src/main/docker/wrapper.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/realtor-service/src/main/docker/wrapper.sh b/realtor-service/src/main/docker/wrapper.sh index afc4425..21b78e8 100644 --- a/realtor-service/src/main/docker/wrapper.sh +++ b/realtor-service/src/main/docker/wrapper.sh @@ -8,8 +8,8 @@ if [ "$WATE" == "true" ]; then sleep 1 done - echo "Trying to connect to config-server" - until $(curl --output /dev/null --silent --head --fail http://config-server:8888/info); do + echo "Trying to connect to storage-service" + until $(curl --output /dev/null --silent --head --fail http://storage-service:8091/info); do echo '.' sleep 1 done From ca7397291b677ec24c6b028695b70c4787e27b8b Mon Sep 17 00:00:00 2001 From: Ihor Banadiga Date: Mon, 17 Jul 2017 14:37:06 +0300 Subject: [PATCH 03/10] fixed after code review --- api-gateway-service/src/main/docker/Dockerfile | 2 +- api-gateway-service/src/main/docker/wrapper.sh | 2 +- config-server/src/main/docker/Dockerfile | 2 +- config-server/src/main/docker/wrapper.sh | 2 +- discovery-server/src/main/docker/Dockerfile | 2 +- hackster-service/src/main/docker/Dockerfile | 2 +- hackster-service/src/main/docker/wrapper.sh | 2 +- .../jclub/integration/EntToEndIntegrationTest.java | 4 ++-- .../src/test/resources/docker-compose.yml | 14 +++++++------- rating-service/src/main/docker/Dockerfile | 2 +- rating-service/src/main/docker/wrapper.sh | 2 +- realtor-service/src/main/docker/Dockerfile | 2 +- realtor-service/src/main/docker/wrapper.sh | 2 +- storage-service/src/main/docker/Dockerfile | 2 +- storage-service/src/main/docker/wrapper.sh | 2 +- 15 files changed, 22 insertions(+), 22 deletions(-) diff --git a/api-gateway-service/src/main/docker/Dockerfile b/api-gateway-service/src/main/docker/Dockerfile index 07426c5..acc3d82 100644 --- a/api-gateway-service/src/main/docker/Dockerfile +++ b/api-gateway-service/src/main/docker/Dockerfile @@ -2,5 +2,5 @@ FROM java:8 ADD api-gateway-service.jar api-gateway-service.jar ADD wrapper.sh wrapper.sh RUN bash -c 'chmod +x /wrapper.sh' -RUN bash -c 'touch /app.jar' +RUN bash -c 'touch /api-gateway-service.jar' ENTRYPOINT ["/bin/bash", "/wrapper.sh"] diff --git a/api-gateway-service/src/main/docker/wrapper.sh b/api-gateway-service/src/main/docker/wrapper.sh index f321b77..a000a41 100644 --- a/api-gateway-service/src/main/docker/wrapper.sh +++ b/api-gateway-service/src/main/docker/wrapper.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [ "$WATE" == "true" ]; then +if [ "$WAITING_FOR_DEPENDENCE" == "true" ]; then echo "Trying to connect to discovery-server" until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do diff --git a/config-server/src/main/docker/Dockerfile b/config-server/src/main/docker/Dockerfile index 0eefda8..4324605 100644 --- a/config-server/src/main/docker/Dockerfile +++ b/config-server/src/main/docker/Dockerfile @@ -2,5 +2,5 @@ FROM java:8 ADD config-server.jar config-server.jar ADD wrapper.sh wrapper.sh RUN bash -c 'chmod +x /wrapper.sh' -RUN bash -c 'touch /app.jar' +RUN bash -c 'touch /config-server.jar' ENTRYPOINT ["/bin/bash", "/wrapper.sh"] diff --git a/config-server/src/main/docker/wrapper.sh b/config-server/src/main/docker/wrapper.sh index 6e01c3f..0ac6001 100644 --- a/config-server/src/main/docker/wrapper.sh +++ b/config-server/src/main/docker/wrapper.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [ "$WATE" == "true" ]; then +if [ "$WAITING_FOR_DEPENDENCE" == "true" ]; then echo "Trying to connect to discovery-server" until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do diff --git a/discovery-server/src/main/docker/Dockerfile b/discovery-server/src/main/docker/Dockerfile index 988fcb2..570bf01 100644 --- a/discovery-server/src/main/docker/Dockerfile +++ b/discovery-server/src/main/docker/Dockerfile @@ -2,5 +2,5 @@ FROM java:8 ADD discovery-server.jar discovery-server.jar ADD wrapper.sh wrapper.sh RUN bash -c 'chmod +x /wrapper.sh' -RUN bash -c 'touch /app.jar' +RUN bash -c 'touch /discovery-server.jar' ENTRYPOINT ["/bin/bash", "/wrapper.sh"] diff --git a/hackster-service/src/main/docker/Dockerfile b/hackster-service/src/main/docker/Dockerfile index e76d6ae..d66558f 100644 --- a/hackster-service/src/main/docker/Dockerfile +++ b/hackster-service/src/main/docker/Dockerfile @@ -2,5 +2,5 @@ FROM java:8 ADD hackster-service.jar hackster-service.jar ADD wrapper.sh wrapper.sh RUN bash -c 'chmod +x /wrapper.sh' -RUN bash -c 'touch /app.jar' +RUN bash -c 'touch /hackster-service.jar' ENTRYPOINT ["/bin/bash", "/wrapper.sh"] diff --git a/hackster-service/src/main/docker/wrapper.sh b/hackster-service/src/main/docker/wrapper.sh index 1492689..7722f8c 100644 --- a/hackster-service/src/main/docker/wrapper.sh +++ b/hackster-service/src/main/docker/wrapper.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [ "$WATE" == "true" ]; then +if [ "$WAITING_FOR_DEPENDENCE" == "true" ]; then echo "Trying to connect to discovery-server" until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java b/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java index f33e35a..c516ecd 100644 --- a/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java +++ b/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java @@ -27,11 +27,11 @@ public class EntToEndIntegrationTest { private static final String STORAGE_SERVICE = "storage-service_1"; private static final int STORAGE_SERVICE_PORT = 8091; - private static final String compose = EntToEndIntegrationTest.class.getClassLoader() + private static final String COMPOSE = EntToEndIntegrationTest.class.getClassLoader() .getResource("./docker-compose.yml").getPath(); @ClassRule - public static DockerComposeContainer environment = new DockerComposeContainer(new File(compose)) + public static DockerComposeContainer environment = new DockerComposeContainer(new File(COMPOSE)) .withExposedService(API_GATEWAY_SERVICE, API_GATEWAY_SERVICE_PORT) .withExposedService(STORAGE_SERVICE, STORAGE_SERVICE_PORT) .withPull(false); diff --git a/integration-test/src/test/resources/docker-compose.yml b/integration-test/src/test/resources/docker-compose.yml index 3fdeef1..16b8063 100644 --- a/integration-test/src/test/resources/docker-compose.yml +++ b/integration-test/src/test/resources/docker-compose.yml @@ -13,7 +13,7 @@ services: links: - discovery-server environment: - - WATE=true + - WAITING_FOR_DEPENDENCE=true - JAVA_CLUB_SRC_HOME=https://github.com/lvivJavaClub - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka depends_on: @@ -26,7 +26,7 @@ services: links: - discovery-server environment: - - WATE=true + - WAITING_FOR_DEPENDENCE=true - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka - eureka.instance.preferIpAddress=true depends_on: @@ -40,7 +40,7 @@ services: - discovery-server - config-server environment: - - WATE=true + - WAITING_FOR_DEPENDENCE=true - spring.cloud.config.uri=http://config-server:8888/ - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka - eureka.instance.preferIpAddress=true @@ -56,7 +56,7 @@ services: - discovery-server - config-server environment: - - WATE=true + - WAITING_FOR_DEPENDENCE=true - spring.cloud.config.uri=http://config-server:8888/ - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka - eureka.instance.preferIpAddress=true @@ -71,7 +71,7 @@ services: links: - discovery-server environment: - - WATE=true + - WAITING_FOR_DEPENDENCE=true - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka - eureka.instance.preferIpAddress=true depends_on: @@ -87,7 +87,7 @@ services: # links: # - discovery-server # environment: - #- WATE=true + #- WAITING_FOR_DEPENDENCE=true # eureka.host: discovery-server # eureka.instance.preferIpAddress: 'true' # depends_on: @@ -101,7 +101,7 @@ services: links: - discovery-server environment: - - WATE=true + - WAITING_FOR_DEPENDENCE=true - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka - eureka.instance.preferIpAddress=true depends_on: diff --git a/rating-service/src/main/docker/Dockerfile b/rating-service/src/main/docker/Dockerfile index e8da638..f579015 100644 --- a/rating-service/src/main/docker/Dockerfile +++ b/rating-service/src/main/docker/Dockerfile @@ -2,5 +2,5 @@ FROM java:8 ADD rating-service.jar rating-service.jar ADD wrapper.sh wrapper.sh RUN bash -c 'chmod +x /wrapper.sh' -RUN bash -c 'touch /app.jar' +RUN bash -c 'touch /rating-service.jar' ENTRYPOINT ["/bin/bash", "/wrapper.sh"] diff --git a/rating-service/src/main/docker/wrapper.sh b/rating-service/src/main/docker/wrapper.sh index b0f7e59..0a750e6 100644 --- a/rating-service/src/main/docker/wrapper.sh +++ b/rating-service/src/main/docker/wrapper.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [ "$WATE" == "true" ]; then +if [ "$WAITING_FOR_DEPENDENCE" == "true" ]; then echo "Trying to connect to discovery-server" until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do diff --git a/realtor-service/src/main/docker/Dockerfile b/realtor-service/src/main/docker/Dockerfile index 59bea61..213628c 100644 --- a/realtor-service/src/main/docker/Dockerfile +++ b/realtor-service/src/main/docker/Dockerfile @@ -2,5 +2,5 @@ FROM java:8 ADD realtor-service.jar realtor-service.jar ADD wrapper.sh wrapper.sh RUN bash -c 'chmod +x /wrapper.sh' -RUN bash -c 'touch /app.jar' +RUN bash -c 'touch /realtor-service.jar' ENTRYPOINT ["/bin/bash", "/wrapper.sh"] diff --git a/realtor-service/src/main/docker/wrapper.sh b/realtor-service/src/main/docker/wrapper.sh index 21b78e8..099d461 100644 --- a/realtor-service/src/main/docker/wrapper.sh +++ b/realtor-service/src/main/docker/wrapper.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [ "$WATE" == "true" ]; then +if [ "$WAITING_FOR_DEPENDENCE" == "true" ]; then echo "Trying to connect to discovery-server" until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do diff --git a/storage-service/src/main/docker/Dockerfile b/storage-service/src/main/docker/Dockerfile index eea615e..2a96654 100644 --- a/storage-service/src/main/docker/Dockerfile +++ b/storage-service/src/main/docker/Dockerfile @@ -2,5 +2,5 @@ FROM java:8 ADD storage-service.jar storage-service.jar ADD wrapper.sh wrapper.sh RUN bash -c 'chmod +x /wrapper.sh' -RUN bash -c 'touch /app.jar' +RUN bash -c 'touch /storage-service.jar' ENTRYPOINT ["/bin/bash", "/wrapper.sh"] diff --git a/storage-service/src/main/docker/wrapper.sh b/storage-service/src/main/docker/wrapper.sh index f98340c..e7e8282 100644 --- a/storage-service/src/main/docker/wrapper.sh +++ b/storage-service/src/main/docker/wrapper.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [ "$WATE" == "true" ]; then +if [ "$WAITING_FOR_DEPENDENCE" == "true" ]; then echo "Trying to connect to discovery-server" until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do From e20f028c7971a3104927516cca28a201170afd3c Mon Sep 17 00:00:00 2001 From: Ihor Banadiga Date: Tue, 18 Jul 2017 15:46:23 +0300 Subject: [PATCH 04/10] Replaced hard coded hosts and ports --- .../src/main/docker/Dockerfile | 12 ++- .../src/main/docker/wrapper.sh | 62 ++++++++++----- config-server/src/main/docker/wrapper.sh | 29 ++++--- discovery-server/src/main/docker/Dockerfile | 12 ++- discovery-server/src/main/docker/wrapper.sh | 2 +- hackster-service/src/main/docker/Dockerfile | 12 ++- hackster-service/src/main/docker/wrapper.sh | 45 +++++++---- .../integration/EntToEndIntegrationTest.java | 2 + .../src/test/resources/docker-compose.yml | 76 +++++++++++-------- rating-service/src/main/docker/Dockerfile | 12 ++- rating-service/src/main/docker/wrapper.sh | 45 +++++++---- realtor-service/src/main/docker/Dockerfile | 12 ++- realtor-service/src/main/docker/wrapper.sh | 43 +++++++---- storage-service/src/main/docker/Dockerfile | 12 ++- storage-service/src/main/docker/wrapper.sh | 29 ++++--- 15 files changed, 274 insertions(+), 131 deletions(-) diff --git a/api-gateway-service/src/main/docker/Dockerfile b/api-gateway-service/src/main/docker/Dockerfile index acc3d82..46c7064 100644 --- a/api-gateway-service/src/main/docker/Dockerfile +++ b/api-gateway-service/src/main/docker/Dockerfile @@ -1,6 +1,12 @@ FROM java:8 + +RUN mkdir -p /opt/spring-cloud +WORKDIR /opt/spring-cloud + ADD api-gateway-service.jar api-gateway-service.jar ADD wrapper.sh wrapper.sh -RUN bash -c 'chmod +x /wrapper.sh' -RUN bash -c 'touch /api-gateway-service.jar' -ENTRYPOINT ["/bin/bash", "/wrapper.sh"] + +RUN bash -c 'chmod +x ./wrapper.sh' +RUN bash -c 'touch ./api-gateway-service.jar' + +ENTRYPOINT ["/bin/bash", "./wrapper.sh"] diff --git a/api-gateway-service/src/main/docker/wrapper.sh b/api-gateway-service/src/main/docker/wrapper.sh index a000a41..fc4c80f 100644 --- a/api-gateway-service/src/main/docker/wrapper.sh +++ b/api-gateway-service/src/main/docker/wrapper.sh @@ -1,26 +1,46 @@ #!/bin/bash -if [ "$WAITING_FOR_DEPENDENCE" == "true" ]; then - - echo "Trying to connect to discovery-server" - until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do - echo '.' - sleep 1 - done - - echo "Trying to connect to storage-service" - until $(curl --output /dev/null --silent --head --fail http://storage-service:8091/info); do - echo '.' - sleep 1 - done - - echo "Trying to connect to realtor-service" - until $(curl --output /dev/null --silent --head --fail http://realtor-service:8080/info); do - echo '.' - sleep 1 - done - echo "Starting" +WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'} +if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then + echo "Starting api-gateway server immediately" + java -jar ./api-gateway-service.jar + exit 0 fi -java -jar /api-gateway-service.jar +DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'} +DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761} + +echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do + echo -e ".\c" + sleep 1 +done +echo + +REALTOR_SERVICE_HOST=${REALTOR_SERVICE_HOST:='realtor-service'} +REALTOR_SERVICE_PORT=${REALTOR_SERVICE_PORT:=8080} + +echo "Trying to connect to on ${REALTOR_SERVICE_HOST}:${REALTOR_SERVICE_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${REALTOR_SERVICE_HOST}:${REALTOR_SERVICE_PORT}/info"); do + echo -e ".\c" + sleep 1 +done +echo + +# rem TODO replace with client-service +STORAGE_SERVICE_HOST=${STORAGE_SERVICE_HOST:='storage-service'} +STORAGE_SERVICE_PORT=${STORAGE_SERVICE_PORT:=8091} + +echo "Trying to connect to on ${STORAGE_SERVICE_HOST}:${STORAGE_SERVICE_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${STORAGE_SERVICE_HOST}:${STORAGE_SERVICE_PORT}/info"); do + echo -e ".\c" + sleep 1 +done +echo + +echo "Starting api-gateway server" +echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" + +env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ + java -jar ./api-gateway-service.jar diff --git a/config-server/src/main/docker/wrapper.sh b/config-server/src/main/docker/wrapper.sh index 0ac6001..f6f24f8 100644 --- a/config-server/src/main/docker/wrapper.sh +++ b/config-server/src/main/docker/wrapper.sh @@ -1,14 +1,25 @@ #!/bin/bash -if [ "$WAITING_FOR_DEPENDENCE" == "true" ]; then - - echo "Trying to connect to discovery-server" - until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do - echo '.' - sleep 1 - done - echo "Starting" +WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'} +if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then + echo "Starting config server immediately" + java -jar ./config-server.jar + exit 0 fi -java -jar /config-server.jar +DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'} +DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761} + +echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do + echo -e ".\c" + sleep 1 +done +echo + +echo "Starting config server" +echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" + +env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ + java -jar ./config-server.jar diff --git a/discovery-server/src/main/docker/Dockerfile b/discovery-server/src/main/docker/Dockerfile index 570bf01..bd2406e 100644 --- a/discovery-server/src/main/docker/Dockerfile +++ b/discovery-server/src/main/docker/Dockerfile @@ -1,6 +1,12 @@ FROM java:8 + +RUN mkdir -p /opt/spring-cloud +WORKDIR /opt/spring-cloud + ADD discovery-server.jar discovery-server.jar ADD wrapper.sh wrapper.sh -RUN bash -c 'chmod +x /wrapper.sh' -RUN bash -c 'touch /discovery-server.jar' -ENTRYPOINT ["/bin/bash", "/wrapper.sh"] + +RUN bash -c 'chmod +x ./wrapper.sh' +RUN bash -c 'touch ./discovery-server.jar' + +ENTRYPOINT ["/bin/bash", "./wrapper.sh"] diff --git a/discovery-server/src/main/docker/wrapper.sh b/discovery-server/src/main/docker/wrapper.sh index 96542a8..367e86f 100644 --- a/discovery-server/src/main/docker/wrapper.sh +++ b/discovery-server/src/main/docker/wrapper.sh @@ -1,3 +1,3 @@ #!/bin/bash -java -jar /discovery-server.jar +java -jar ./discovery-server.jar diff --git a/hackster-service/src/main/docker/Dockerfile b/hackster-service/src/main/docker/Dockerfile index d66558f..048cda4 100644 --- a/hackster-service/src/main/docker/Dockerfile +++ b/hackster-service/src/main/docker/Dockerfile @@ -1,6 +1,12 @@ FROM java:8 + +RUN mkdir -p /opt/spring-cloud +WORKDIR /opt/spring-cloud + ADD hackster-service.jar hackster-service.jar ADD wrapper.sh wrapper.sh -RUN bash -c 'chmod +x /wrapper.sh' -RUN bash -c 'touch /hackster-service.jar' -ENTRYPOINT ["/bin/bash", "/wrapper.sh"] + +RUN bash -c 'chmod +x ./wrapper.sh' +RUN bash -c 'touch ./hackster-service.jar' + +ENTRYPOINT ["/bin/bash", "./wrapper.sh"] diff --git a/hackster-service/src/main/docker/wrapper.sh b/hackster-service/src/main/docker/wrapper.sh index 7722f8c..ad57b06 100644 --- a/hackster-service/src/main/docker/wrapper.sh +++ b/hackster-service/src/main/docker/wrapper.sh @@ -1,20 +1,37 @@ #!/bin/bash -if [ "$WAITING_FOR_DEPENDENCE" == "true" ]; then +WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'} - echo "Trying to connect to discovery-server" - until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do - echo '.' - sleep 1 - done +if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then + echo "Starting hackster service immediately" + java -jar ./hackster-service.jar + exit 0 +fi - echo "Trying to connect to config-server" - until $(curl --output /dev/null --silent --head --fail http://config-server:8888/info); do - echo '.' - sleep 1 - done - echo "Starting" +DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'} +DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761} -fi +echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do + echo -e ".\c" + sleep 1 +done +echo + +CONFIG_SERVER_HOST=${CONFIG_SERVER_HOST:='config-server'} +CONFIG_SERVER_PORT=${CONFIG_SERVER_PORT:=8888} + +echo "Trying to connect to on ${CONFIG_SERVER_HOST}:${CONFIG_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${CONFIG_SERVER_HOST}:${CONFIG_SERVER_PORT}/info"); do + echo -e ".\c" + sleep 1 +done +echo + +echo "Starting hackster service" +echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" +echo "Setting spring.cloud.config.uri to http://${DISCOVERY_SERVER_HOST}:${CONFIG_SERVER_PORT}" -java -jar /hackster-service.jar +env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ + "spring.cloud.config.uri=http://${CONFIG_SERVER_HOST}:${CONFIG_SERVER_PORT}/" \ + java -jar ./hackster-service.jar diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java b/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java index c516ecd..074f4bd 100644 --- a/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java +++ b/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java @@ -8,6 +8,7 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.junit.BeforeClass; import org.junit.ClassRule; +import org.junit.Ignore; import org.junit.Test; import org.testcontainers.containers.DockerComposeContainer; @@ -17,6 +18,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +@Ignore public class EntToEndIntegrationTest { private static final int SLEEP = 5000; diff --git a/integration-test/src/test/resources/docker-compose.yml b/integration-test/src/test/resources/docker-compose.yml index 16b8063..b4c337c 100644 --- a/integration-test/src/test/resources/docker-compose.yml +++ b/integration-test/src/test/resources/docker-compose.yml @@ -13,9 +13,10 @@ services: links: - discovery-server environment: - - WAITING_FOR_DEPENDENCE=true - JAVA_CLUB_SRC_HOME=https://github.com/lvivJavaClub - - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka + - WAITING_FOR_DEPENDENCE=true + - DISCOVERY_SERVER_HOST=discovery-server + - DISCOVERY_SERVER_PORT=8761 depends_on: - discovery-server # @@ -27,8 +28,8 @@ services: - discovery-server environment: - WAITING_FOR_DEPENDENCE=true - - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka - - eureka.instance.preferIpAddress=true + - DISCOVERY_SERVER_HOST=discovery-server + - DISCOVERY_SERVER_PORT=8761 depends_on: - discovery-server # @@ -41,9 +42,10 @@ services: - config-server environment: - WAITING_FOR_DEPENDENCE=true - - spring.cloud.config.uri=http://config-server:8888/ - - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka - - eureka.instance.preferIpAddress=true + - DISCOVERY_SERVER_HOST=discovery-server + - DISCOVERY_SERVER_PORT=8761 + - CONFIG_SERVER_HOST=config-server + - CONFIG_SERVER_PORT=8888 depends_on: - discovery-server - config-server @@ -57,9 +59,10 @@ services: - config-server environment: - WAITING_FOR_DEPENDENCE=true - - spring.cloud.config.uri=http://config-server:8888/ - - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka - - eureka.instance.preferIpAddress=true + - DISCOVERY_SERVER_HOST=discovery-server + - DISCOVERY_SERVER_PORT=8761 + - CONFIG_SERVER_HOST=config-server + - CONFIG_SERVER_PORT=8888 depends_on: - discovery-server - config-server @@ -70,29 +73,32 @@ services: - "8080:8080" links: - discovery-server + - storage-service environment: - WAITING_FOR_DEPENDENCE=true - - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka - - eureka.instance.preferIpAddress=true + - DISCOVERY_SERVER_HOST=discovery-server + - DISCOVERY_SERVER_PORT=8761 + - STORAGE_SERVICE_HOST=storage-service + - STORAGE_SERVICE_PORT=8091 depends_on: - discovery-server - rating-service - hackster-service - storage-service # - # client-server: - # image: client-server - # ports: - # - "8083:8083" - # links: - # - discovery-server - # environment: - #- WAITING_FOR_DEPENDENCE=true - # eureka.host: discovery-server - # eureka.instance.preferIpAddress: 'true' - # depends_on: - # - discovery-server - # - storage-service +# client-server: +# image: client-server +# ports: +# - "8083:8083" +# links: +# - discovery-server +# environment: +#- WAITING_FOR_DEPENDENCE=true +# eureka.host: discovery-server +# eureka.instance.preferIpAddress: 'true' +# depends_on: +# - discovery-server +# - storage-service # api-gateway-service: image: api-gateway-service @@ -100,15 +106,23 @@ services: - "8090:8090" links: - discovery-server + - realtor-service + - storage-service environment: - WAITING_FOR_DEPENDENCE=true - - eureka.client.serviceUrl.defaultZone=http://discovery-server:8761/eureka - - eureka.instance.preferIpAddress=true + - DISCOVERY_SERVER_HOST=discovery-server + - DISCOVERY_SERVER_PORT=8761 + - REALTOR_SERVICE_HOST=realtor-service + - REALTOR_SERVICE_PORT=8080 + # TODO replace with client-service + - STORAGE_SERVICE_HOST=storage-service + - STORAGE_SERVICE_PORT=8091 depends_on: - discovery-server - realtor-service + - storage-service # - client-server - -#networks: -# default: -# driver: spring-cloud-driver +# +networks: + default: + driver: bridge diff --git a/rating-service/src/main/docker/Dockerfile b/rating-service/src/main/docker/Dockerfile index f579015..180d61a 100644 --- a/rating-service/src/main/docker/Dockerfile +++ b/rating-service/src/main/docker/Dockerfile @@ -1,6 +1,12 @@ FROM java:8 + +RUN mkdir -p /opt/spring-cloud +WORKDIR /opt/spring-cloud + ADD rating-service.jar rating-service.jar ADD wrapper.sh wrapper.sh -RUN bash -c 'chmod +x /wrapper.sh' -RUN bash -c 'touch /rating-service.jar' -ENTRYPOINT ["/bin/bash", "/wrapper.sh"] + +RUN bash -c 'chmod +x ./wrapper.sh' +RUN bash -c 'touch ./rating-service.jar' + +ENTRYPOINT ["/bin/bash", "./wrapper.sh"] diff --git a/rating-service/src/main/docker/wrapper.sh b/rating-service/src/main/docker/wrapper.sh index 0a750e6..6df2fee 100644 --- a/rating-service/src/main/docker/wrapper.sh +++ b/rating-service/src/main/docker/wrapper.sh @@ -1,20 +1,37 @@ #!/bin/bash -if [ "$WAITING_FOR_DEPENDENCE" == "true" ]; then +WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'} - echo "Trying to connect to discovery-server" - until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do - echo '.' - sleep 1 - done +if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then + echo "Starting rating service immediately" + java -jar ./rating-service.jar + exit 0 +fi - echo "Trying to connect to config-server" - until $(curl --output /dev/null --silent --head --fail http://config-server:8888/info); do - echo '.' - sleep 1 - done - echo "Starting" +DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'} +DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761} -fi +echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do + echo -e ".\c" + sleep 1 +done +echo + +CONFIG_SERVER_HOST=${CONFIG_SERVER_HOST:='config-server'} +CONFIG_SERVER_PORT=${CONFIG_SERVER_PORT:=8888} + +echo "Trying to connect to on ${CONFIG_SERVER_HOST}:${CONFIG_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${CONFIG_SERVER_HOST}:${CONFIG_SERVER_PORT}/info"); do + echo -e ".\c" + sleep 1 +done +echo + +echo "Starting rating service" +echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" +echo "Setting spring.cloud.config.uri to http://${DISCOVERY_SERVER_HOST}:${CONFIG_SERVER_PORT}" -java -jar /rating-service.jar +env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ + "spring.cloud.config.uri=http://${CONFIG_SERVER_HOST}:${CONFIG_SERVER_PORT}/" \ + java -jar ./rating-service.jar diff --git a/realtor-service/src/main/docker/Dockerfile b/realtor-service/src/main/docker/Dockerfile index 213628c..beab733 100644 --- a/realtor-service/src/main/docker/Dockerfile +++ b/realtor-service/src/main/docker/Dockerfile @@ -1,6 +1,12 @@ FROM java:8 + +RUN mkdir -p /opt/spring-cloud +WORKDIR /opt/spring-cloud + ADD realtor-service.jar realtor-service.jar ADD wrapper.sh wrapper.sh -RUN bash -c 'chmod +x /wrapper.sh' -RUN bash -c 'touch /realtor-service.jar' -ENTRYPOINT ["/bin/bash", "/wrapper.sh"] + +RUN bash -c 'chmod +x ./wrapper.sh' +RUN bash -c 'touch ./realtor-service.jar' + +ENTRYPOINT ["/bin/bash", "./wrapper.sh"] diff --git a/realtor-service/src/main/docker/wrapper.sh b/realtor-service/src/main/docker/wrapper.sh index 099d461..869d428 100644 --- a/realtor-service/src/main/docker/wrapper.sh +++ b/realtor-service/src/main/docker/wrapper.sh @@ -1,20 +1,35 @@ #!/bin/bash -if [ "$WAITING_FOR_DEPENDENCE" == "true" ]; then +WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'} - echo "Trying to connect to discovery-server" - until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do - echo '.' - sleep 1 - done +if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then + echo "Starting realtor service immediately" + java -jar ./realtor-service.jar + exit 0 +fi - echo "Trying to connect to storage-service" - until $(curl --output /dev/null --silent --head --fail http://storage-service:8091/info); do - echo '.' - sleep 1 - done - echo "Starting" +DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'} +DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761} -fi +echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do + echo -e ".\c" + sleep 1 +done +echo + +STORAGE_SERVICE_HOST=${STORAGE_SERVICE_HOST:='storage-service'} +STORAGE_SERVICE_PORT=${STORAGE_SERVICE_PORT:=8091} + +echo "Trying to connect to on ${STORAGE_SERVICE_HOST}:${STORAGE_SERVICE_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${STORAGE_SERVICE_HOST}:${STORAGE_SERVICE_PORT}/info"); do + echo -e ".\c" + sleep 1 +done +echo + +echo "Starting realtor service" +echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" -java -jar /realtor-service.jar +env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ + java -jar ./realtor-service.jar diff --git a/storage-service/src/main/docker/Dockerfile b/storage-service/src/main/docker/Dockerfile index 2a96654..4264e79 100644 --- a/storage-service/src/main/docker/Dockerfile +++ b/storage-service/src/main/docker/Dockerfile @@ -1,6 +1,12 @@ FROM java:8 + +RUN mkdir -p /opt/spring-cloud +WORKDIR /opt/spring-cloud + ADD storage-service.jar storage-service.jar ADD wrapper.sh wrapper.sh -RUN bash -c 'chmod +x /wrapper.sh' -RUN bash -c 'touch /storage-service.jar' -ENTRYPOINT ["/bin/bash", "/wrapper.sh"] + +RUN bash -c 'chmod +x ./wrapper.sh' +RUN bash -c 'touch ./storage-service.jar' + +ENTRYPOINT ["/bin/bash", "./wrapper.sh"] diff --git a/storage-service/src/main/docker/wrapper.sh b/storage-service/src/main/docker/wrapper.sh index e7e8282..435987c 100644 --- a/storage-service/src/main/docker/wrapper.sh +++ b/storage-service/src/main/docker/wrapper.sh @@ -1,14 +1,25 @@ #!/bin/bash -if [ "$WAITING_FOR_DEPENDENCE" == "true" ]; then - - echo "Trying to connect to discovery-server" - until $(curl --output /dev/null --silent --head --fail http://discovery-server:8761/info); do - echo '.' - sleep 1 - done - echo "Starting" +WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'} +if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then + echo "Starting storage server immediately" + java -jar ./storage-service.jar + exit 0 fi -java -jar /storage-service.jar +DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'} +DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761} + +echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do + echo -e ".\c" + sleep 1 +done +echo + +echo "Starting storage server" +echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" + +env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ + java -jar ./storage-service.jar From a3a5352d0b3c8a5fb57d23f912938a1de9dcbb88 Mon Sep 17 00:00:00 2001 From: Ihor Banadiga Date: Wed, 19 Jul 2017 10:13:04 +0300 Subject: [PATCH 05/10] remove default value from docker-compose.yml, remove spring.cloud.config.uri from wrapper.sh --- hackster-service/src/main/docker/wrapper.sh | 2 -- .../src/test/resources/docker-compose.yml | 23 ------------------- rating-service/src/main/docker/wrapper.sh | 2 -- 3 files changed, 27 deletions(-) diff --git a/hackster-service/src/main/docker/wrapper.sh b/hackster-service/src/main/docker/wrapper.sh index ad57b06..a046462 100644 --- a/hackster-service/src/main/docker/wrapper.sh +++ b/hackster-service/src/main/docker/wrapper.sh @@ -30,8 +30,6 @@ echo echo "Starting hackster service" echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" -echo "Setting spring.cloud.config.uri to http://${DISCOVERY_SERVER_HOST}:${CONFIG_SERVER_PORT}" env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ - "spring.cloud.config.uri=http://${CONFIG_SERVER_HOST}:${CONFIG_SERVER_PORT}/" \ java -jar ./hackster-service.jar diff --git a/integration-test/src/test/resources/docker-compose.yml b/integration-test/src/test/resources/docker-compose.yml index b4c337c..52d9b06 100644 --- a/integration-test/src/test/resources/docker-compose.yml +++ b/integration-test/src/test/resources/docker-compose.yml @@ -15,8 +15,6 @@ services: environment: - JAVA_CLUB_SRC_HOME=https://github.com/lvivJavaClub - WAITING_FOR_DEPENDENCE=true - - DISCOVERY_SERVER_HOST=discovery-server - - DISCOVERY_SERVER_PORT=8761 depends_on: - discovery-server # @@ -28,8 +26,6 @@ services: - discovery-server environment: - WAITING_FOR_DEPENDENCE=true - - DISCOVERY_SERVER_HOST=discovery-server - - DISCOVERY_SERVER_PORT=8761 depends_on: - discovery-server # @@ -42,10 +38,6 @@ services: - config-server environment: - WAITING_FOR_DEPENDENCE=true - - DISCOVERY_SERVER_HOST=discovery-server - - DISCOVERY_SERVER_PORT=8761 - - CONFIG_SERVER_HOST=config-server - - CONFIG_SERVER_PORT=8888 depends_on: - discovery-server - config-server @@ -59,10 +51,6 @@ services: - config-server environment: - WAITING_FOR_DEPENDENCE=true - - DISCOVERY_SERVER_HOST=discovery-server - - DISCOVERY_SERVER_PORT=8761 - - CONFIG_SERVER_HOST=config-server - - CONFIG_SERVER_PORT=8888 depends_on: - discovery-server - config-server @@ -76,10 +64,6 @@ services: - storage-service environment: - WAITING_FOR_DEPENDENCE=true - - DISCOVERY_SERVER_HOST=discovery-server - - DISCOVERY_SERVER_PORT=8761 - - STORAGE_SERVICE_HOST=storage-service - - STORAGE_SERVICE_PORT=8091 depends_on: - discovery-server - rating-service @@ -110,13 +94,6 @@ services: - storage-service environment: - WAITING_FOR_DEPENDENCE=true - - DISCOVERY_SERVER_HOST=discovery-server - - DISCOVERY_SERVER_PORT=8761 - - REALTOR_SERVICE_HOST=realtor-service - - REALTOR_SERVICE_PORT=8080 - # TODO replace with client-service - - STORAGE_SERVICE_HOST=storage-service - - STORAGE_SERVICE_PORT=8091 depends_on: - discovery-server - realtor-service diff --git a/rating-service/src/main/docker/wrapper.sh b/rating-service/src/main/docker/wrapper.sh index 6df2fee..82d3011 100644 --- a/rating-service/src/main/docker/wrapper.sh +++ b/rating-service/src/main/docker/wrapper.sh @@ -30,8 +30,6 @@ echo echo "Starting rating service" echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" -echo "Setting spring.cloud.config.uri to http://${DISCOVERY_SERVER_HOST}:${CONFIG_SERVER_PORT}" env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ - "spring.cloud.config.uri=http://${CONFIG_SERVER_HOST}:${CONFIG_SERVER_PORT}/" \ java -jar ./rating-service.jar From 7323b5932d3fdfbfd00eca92be04a8004e486e81 Mon Sep 17 00:00:00 2001 From: Ihor Banadiga Date: Mon, 14 Aug 2017 13:47:06 +0300 Subject: [PATCH 06/10] rebased and Integration test RF --- .../src/main/docker/wrapper.sh | 17 ++-- client-service/pom.xml | 57 +++++++---- client-service/src/main/docker/Dockerfile | 6 ++ client-service/src/main/docker/wrapper.sh | 33 +++++++ .../lohika/jclub/client/ClientController.java | 6 +- .../jclub/client/ClientServiceTest.java | 36 +++---- config-server/src/main/docker/wrapper.sh | 1 + hackster-service/src/main/docker/wrapper.sh | 8 +- integration-test/pom.xml | 51 ++++++++-- .../integration/EntToEndIntegrationTest.java | 97 +++++++++++++------ .../IntegrationTestApplication.java | 23 +++++ .../src/test/resources/docker-compose.yml | 29 +++--- pom.xml | 1 + .../client/RatingServiceClientTest.java | 2 + .../src/test/resources/bootstrap.properties | 1 + rating-service/src/main/docker/wrapper.sh | 8 +- realtor-service/src/main/docker/wrapper.sh | 22 ++++- .../jclub/realtor/RealtorController.java | 4 +- storage-service/src/main/docker/wrapper.sh | 1 + 19 files changed, 279 insertions(+), 124 deletions(-) create mode 100644 client-service/src/main/docker/Dockerfile create mode 100644 client-service/src/main/docker/wrapper.sh create mode 100644 integration-test/src/test/java/com/lohika/jclub/integration/IntegrationTestApplication.java create mode 100644 rating-service-client/src/test/resources/bootstrap.properties diff --git a/api-gateway-service/src/main/docker/wrapper.sh b/api-gateway-service/src/main/docker/wrapper.sh index fc4c80f..e70a6b7 100644 --- a/api-gateway-service/src/main/docker/wrapper.sh +++ b/api-gateway-service/src/main/docker/wrapper.sh @@ -18,22 +18,17 @@ until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVE done echo -REALTOR_SERVICE_HOST=${REALTOR_SERVICE_HOST:='realtor-service'} -REALTOR_SERVICE_PORT=${REALTOR_SERVICE_PORT:=8080} - -echo "Trying to connect to on ${REALTOR_SERVICE_HOST}:${REALTOR_SERVICE_PORT}" -until $(curl --output /dev/null --silent --head --fail "http://${REALTOR_SERVICE_HOST}:${REALTOR_SERVICE_PORT}/info"); do +REALTOR_SERVICE=${REALTOR_SERVICE:='realtor-service'} +echo "Trying to get '${REALTOR_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${REALTOR_SERVICE}"); do echo -e ".\c" sleep 1 done echo -# rem TODO replace with client-service -STORAGE_SERVICE_HOST=${STORAGE_SERVICE_HOST:='storage-service'} -STORAGE_SERVICE_PORT=${STORAGE_SERVICE_PORT:=8091} - -echo "Trying to connect to on ${STORAGE_SERVICE_HOST}:${STORAGE_SERVICE_PORT}" -until $(curl --output /dev/null --silent --head --fail "http://${STORAGE_SERVICE_HOST}:${STORAGE_SERVICE_PORT}/info"); do +CLIENT_SERVICE=${CLIENT_SERVICE:='client-service'} +echo "Trying to get '${CLIENT_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${CLIENT_SERVICE}"); do echo -e ".\c" sleep 1 done diff --git a/client-service/pom.xml b/client-service/pom.xml index 3864989..6adc594 100644 --- a/client-service/pom.xml +++ b/client-service/pom.xml @@ -23,9 +23,21 @@ UTF-8 1.8 Dalston.RELEASE + springio + ${basedir}/src/main/docker + + com.lohika.jclub.storage.client + storage-service-client + 0.0.1-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-actuator + org.springframework.cloud spring-cloud-starter-eureka @@ -34,25 +46,20 @@ org.springframework.boot spring-boot-starter-web - - org.springframework.boot - spring-boot-starter-test - test + org.springframework.cloud + spring-cloud-starter-feign + org.projectlombok lombok - 1.16.12 - - - org.springframework.cloud - spring-cloud-starter-feign + - com.lohika.jclub.storage.client - storage-service-client - 0.0.1-SNAPSHOT + org.springframework.boot + spring-boot-starter-test + test org.testcontainers @@ -80,6 +87,23 @@ org.springframework.boot spring-boot-maven-plugin + + maven-antrun-plugin + + + + + + + + install + + run + + + + com.spotify docker-maven-plugin @@ -94,18 +118,17 @@ - client-service - java - ["java", "-jar", "/${project.build.finalName}.jar"] + ${project.artifactId} + ${docker.baseDir} / ${project.build.directory} - ${project.build.finalName}.jar + ${project.artifactId}.jar - \ No newline at end of file + diff --git a/client-service/src/main/docker/Dockerfile b/client-service/src/main/docker/Dockerfile new file mode 100644 index 0000000..b2bbe9e --- /dev/null +++ b/client-service/src/main/docker/Dockerfile @@ -0,0 +1,6 @@ +FROM java:8 +ADD client-service.jar client-service.jar +ADD wrapper.sh wrapper.sh +RUN bash -c 'chmod +x /wrapper.sh' +RUN bash -c 'touch /client-service.jar' +ENTRYPOINT ["/bin/bash", "./wrapper.sh"] diff --git a/client-service/src/main/docker/wrapper.sh b/client-service/src/main/docker/wrapper.sh new file mode 100644 index 0000000..c31958b --- /dev/null +++ b/client-service/src/main/docker/wrapper.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'} + +if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then + echo "Starting config server immediately" + java -jar ./client-service.jar + exit 0 +fi + +DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'} +DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761} + +echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do + echo -e ".\c" + sleep 1 +done +echo + +STORAGE_SERVICE=${STORAGE_SERVICE:='storage-service'} +echo "Trying to get '${STORAGE_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${STORAGE_SERVICE}"); do + echo -e ".\c" + sleep 1 +done +echo + +echo "Starting client service" +echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" + +env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ + java -jar ./client-service.jar diff --git a/client-service/src/main/java/com/lohika/jclub/client/ClientController.java b/client-service/src/main/java/com/lohika/jclub/client/ClientController.java index f52eeed..f191f27 100644 --- a/client-service/src/main/java/com/lohika/jclub/client/ClientController.java +++ b/client-service/src/main/java/com/lohika/jclub/client/ClientController.java @@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.hateoas.PagedResources; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -17,10 +18,9 @@ public class ClientController { @Autowired private StorageServiceClient storageServiceClient; - @GetMapping("/apartments") + @GetMapping(value = "/apartments", produces = MediaType.APPLICATION_JSON_VALUE) public PagedResources getApartments() { PagedResources list = storageServiceClient.list(); return new PagedResources<>(list.getContent(), list.getMetadata()); } - -} \ No newline at end of file +} diff --git a/client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java b/client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java index 2e878f6..96b9bc5 100644 --- a/client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java +++ b/client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java @@ -4,7 +4,6 @@ import com.lohika.jclub.storage.client.StorageServiceClient; import org.junit.ClassRule; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -25,7 +24,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -@Ignore @RunWith(SpringRunner.class) @SpringBootTest(classes = ClientServiceApplication.class) @ContextConfiguration(initializers = ClientServiceTest.Initializer.class) @@ -33,16 +31,9 @@ public class ClientServiceTest { @ClassRule - public static GenericContainer discoveryService = new GenericContainer("discovery-service:latest") - .waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started EurekaServerApplication in.*\\s")) - .withExposedPorts(8761); - - @Rule - public GenericContainer storageService = new GenericContainer("storage-service:latest") - .withExposedPorts(8091) - .withEnv("eureka.client.serviceUrl.defaultZone", "http://" + discoveryService.getContainerIpAddress() + ":" + discoveryService.getMappedPort(8761) + "/eureka") - .withEnv("eureka.instance.preferIpAddress", "true") - .waitingFor(new LogMessageWaitStrategy().withRegEx(".*DiscoveryClient_STORAGE-SERVICE.*registration status: 204.*\\s")); + public static GenericContainer storageService = new GenericContainer("storage-service:latest") + .withExposedPorts(8091) + .waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started StorageServiceApplication in.*\\s")); @Autowired private StorageServiceClient storageServiceClient; @@ -50,16 +41,6 @@ public class ClientServiceTest { @Autowired private MockMvc mockMvc; - public static class Initializer implements ApplicationContextInitializer { - @Override - public void initialize(ConfigurableApplicationContext configurableApplicationContext) { - EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(), - "eureka.client.serviceUrl.defaultZone=http://" + discoveryService.getContainerIpAddress() + - ":" + discoveryService.getMappedPort(8761) + "/eureka", - "storage-service.ribbon.servers=http://"); - } - } - @Test public void testGetApartments() throws Exception { // Given @@ -81,4 +62,15 @@ public void testGetApartments() throws Exception { //TODO storageServiceClient does not creating the records. // fallback is working with 0 paging } + + public static class Initializer implements ApplicationContextInitializer { + @Override + public void initialize(ConfigurableApplicationContext configurableApplicationContext) { + + EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(), + "storage-service.ribbon.servers=http://" + storageService.getContainerIpAddress() + ":" + + storageService.getMappedPort(8091) + "/" + ); + } + } } diff --git a/config-server/src/main/docker/wrapper.sh b/config-server/src/main/docker/wrapper.sh index f6f24f8..8edf1a6 100644 --- a/config-server/src/main/docker/wrapper.sh +++ b/config-server/src/main/docker/wrapper.sh @@ -18,6 +18,7 @@ until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVE done echo +sleep 15 echo "Starting config server" echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" diff --git a/hackster-service/src/main/docker/wrapper.sh b/hackster-service/src/main/docker/wrapper.sh index a046462..e1a6688 100644 --- a/hackster-service/src/main/docker/wrapper.sh +++ b/hackster-service/src/main/docker/wrapper.sh @@ -18,11 +18,9 @@ until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVE done echo -CONFIG_SERVER_HOST=${CONFIG_SERVER_HOST:='config-server'} -CONFIG_SERVER_PORT=${CONFIG_SERVER_PORT:=8888} - -echo "Trying to connect to on ${CONFIG_SERVER_HOST}:${CONFIG_SERVER_PORT}" -until $(curl --output /dev/null --silent --head --fail "http://${CONFIG_SERVER_HOST}:${CONFIG_SERVER_PORT}/info"); do +CONFIG_SERVER=${CONFIG_SERVER:='config-server'} +echo "Trying to get '${CONFIG_SERVER}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${CONFIG_SERVER}"); do echo -e ".\c" sleep 1 done diff --git a/integration-test/pom.xml b/integration-test/pom.xml index 920cb56..7e6d6e3 100644 --- a/integration-test/pom.xml +++ b/integration-test/pom.xml @@ -2,11 +2,6 @@ - - spring-cloud - com.lohika.jclub - 0.0.1-SNAPSHOT - 4.0.0 com.lohika.jclub.integration @@ -15,18 +10,56 @@ Integration test Ent-to-ent integration test + + org.springframework.boot + spring-boot-starter-parent + 1.5.3.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + Dalston.RELEASE + + - org.testcontainers - testcontainers - 1.3.0 - test + org.springframework.cloud + spring-cloud-starter-eureka + com.lohika.jclub.gateway api-gateway-service 0.0.1-SNAPSHOT test + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.testcontainers + testcontainers + 1.3.0 + test + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java b/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java index 074f4bd..b58eb80 100644 --- a/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java +++ b/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java @@ -3,46 +3,62 @@ import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClientBuilder; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Ignore; import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; import org.testcontainers.containers.DockerComposeContainer; import java.io.File; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @Ignore +@RunWith(SpringRunner.class) +@SpringBootTest(classes = IntegrationTestApplication.class) +@ContextConfiguration(initializers = EntToEndIntegrationTest.Initializer.class) public class EntToEndIntegrationTest { - private static final int SLEEP = 5000; - private static final String API_GATEWAY_SERVICE = "api-gateway-service_1"; - private static final int API_GATEWAY_SERVICE_PORT = 8090; + private static final String DISCOVERY_SERVER = "discovery-server"; + private static final int DISCOVERY_SERVER_PORT = 8761; - private static final String STORAGE_SERVICE = "storage-service_1"; - private static final int STORAGE_SERVICE_PORT = 8091; + private static final String API_GATEWAY_SERVICE = "API-GATEWAY-SERVICE"; + private static final int API_GATEWAY_SERVICE_PORT = 8090; private static final String COMPOSE = EntToEndIntegrationTest.class.getClassLoader() .getResource("./docker-compose.yml").getPath(); @ClassRule public static DockerComposeContainer environment = new DockerComposeContainer(new File(COMPOSE)) - .withExposedService(API_GATEWAY_SERVICE, API_GATEWAY_SERVICE_PORT) - .withExposedService(STORAGE_SERVICE, STORAGE_SERVICE_PORT) .withPull(false); + @Autowired + private RestTemplate restTemplate; + @BeforeClass public static void init() throws InterruptedException { HttpClient client = HttpClientBuilder.create().build(); - String gateway = "http://localhost:" + API_GATEWAY_SERVICE_PORT + "/info"; + String gateway = "http://localhost:" + DISCOVERY_SERVER_PORT + "/eureka/apps/" + API_GATEWAY_SERVICE; HttpGet httpGet = new HttpGet(gateway); HttpResponse httpResponse = null; @@ -58,27 +74,46 @@ public static void init() throws InterruptedException { @Test public void checkIsStarted() throws IOException, InterruptedException { - HttpClient client = HttpClientBuilder.create().build(); - - String gateway = "http://localhost:" + API_GATEWAY_SERVICE_PORT + "/api/realtor-service/storeApartments"; - HttpPost httpPost = new HttpPost(gateway); - httpPost.addHeader("Content-Type", "application/json"); - httpPost.setEntity(new StringEntity("{\n" - + "\"location\" : \"location\",\n" - + "\"price\" : 1500.5,\n" - + "\"sqft\" : 1.5,\n" - + "\"phone\" : \"123\",\n" - + "\"realtorName\" : \"vas\",\n" - + "\"mail\" : \"mail@exem.com\"\n" - + "}")); - HttpResponse httpResponse1 = client.execute(httpPost); - assertThat(httpResponse1.getStatusLine().getStatusCode(), is(200)); - - Thread.sleep(SLEEP); + Map params = new HashMap() {{ + put("location", "location"); + put("price", 1500.5); + put("sqft", 1.5); + put("phone", "123"); + put("realtorName", "vas"); + put("mail", "mail@exem.comn"); + + }}; + + ResponseEntity create = restTemplate.exchange( + "http://API-GATEWAY-SERVICE/api/realtor-service/storeApartments", + HttpMethod.POST, + new HttpEntity<>(params), + Map.class + ); + + assertThat(create.getStatusCode().value(), is(200)); + String createdId = (String) create.getBody().get("id"); + assertThat(createdId, notNullValue()); + + + ResponseEntity get = restTemplate.exchange( + "http://API-GATEWAY-SERVICE/api/clien-service/apartments", + HttpMethod.GET, + null, + Map.class + ); + + assertThat(get.getStatusCode().value(), is(200)); + String id = (String) get.getBody().get("id"); + assertThat(createdId, is(id)); + } - String storage = "http://localhost:" + STORAGE_SERVICE_PORT + "/apartments/1"; - HttpGet httpGet = new HttpGet(storage); - HttpResponse httpResponse2 = client.execute(httpGet); - assertThat(httpResponse2.getStatusLine().getStatusCode(), is(200)); + public static class Initializer implements ApplicationContextInitializer { + @Override + public void initialize(ConfigurableApplicationContext configurableApplicationContext) { + EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(), + "eureka.client.serviceUrl.defaultZone=http://localhost:" + DISCOVERY_SERVER_PORT + "/eureka" + ); + } } } diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/IntegrationTestApplication.java b/integration-test/src/test/java/com/lohika/jclub/integration/IntegrationTestApplication.java new file mode 100644 index 0000000..600b0d1 --- /dev/null +++ b/integration-test/src/test/java/com/lohika/jclub/integration/IntegrationTestApplication.java @@ -0,0 +1,23 @@ +package com.lohika.jclub.integration; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; + +@EnableDiscoveryClient +@SpringBootApplication +public class IntegrationTestApplication { + + public static void main(String[] args) { + SpringApplication.run(IntegrationTestApplication.class, args); + } + + @Bean + @LoadBalanced + public RestTemplate restTemplate() { + return new RestTemplate(); + } +} diff --git a/integration-test/src/test/resources/docker-compose.yml b/integration-test/src/test/resources/docker-compose.yml index 52d9b06..37f7adb 100644 --- a/integration-test/src/test/resources/docker-compose.yml +++ b/integration-test/src/test/resources/docker-compose.yml @@ -70,19 +70,17 @@ services: - hackster-service - storage-service # -# client-server: -# image: client-server -# ports: -# - "8083:8083" -# links: -# - discovery-server -# environment: -#- WAITING_FOR_DEPENDENCE=true -# eureka.host: discovery-server -# eureka.instance.preferIpAddress: 'true' -# depends_on: -# - discovery-server -# - storage-service + client-service: + image: client-service + ports: + - "8083:8083" + links: + - discovery-server + environment: + - WAITING_FOR_DEPENDENCE=true + depends_on: + - discovery-server + - storage-service # api-gateway-service: image: api-gateway-service @@ -91,14 +89,13 @@ services: links: - discovery-server - realtor-service - - storage-service + - client-service environment: - WAITING_FOR_DEPENDENCE=true depends_on: - discovery-server - realtor-service - - storage-service - # - client-server + - client-service # networks: default: diff --git a/pom.xml b/pom.xml index c2d65d9..ddcec56 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,7 @@ realtor-service storage-service storage-service-client + client-service api-gateway-service integration-test diff --git a/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTest.java b/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTest.java index 6ad55ae..23d6c51 100644 --- a/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTest.java +++ b/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTest.java @@ -27,6 +27,8 @@ public class RatingServiceClientTest { @ClassRule public static GenericContainer RatingService = new GenericContainer("rating-service:latest") .withExposedPorts(8081) + .withEnv("spring.cloud.config.fail-fast", "false") + .withEnv("spring.cloud.config.discovery.enabled", "false") .withEnv("rate", "100") .withEnv("spring.cloud.config.discovery.enabled", "false") .withEnv("spring.cloud.config.fail-fast", "false") diff --git a/rating-service-client/src/test/resources/bootstrap.properties b/rating-service-client/src/test/resources/bootstrap.properties new file mode 100644 index 0000000..2c48307 --- /dev/null +++ b/rating-service-client/src/test/resources/bootstrap.properties @@ -0,0 +1 @@ +spring.cloud.config.discovery.enabled=false diff --git a/rating-service/src/main/docker/wrapper.sh b/rating-service/src/main/docker/wrapper.sh index 82d3011..bd38cac 100644 --- a/rating-service/src/main/docker/wrapper.sh +++ b/rating-service/src/main/docker/wrapper.sh @@ -18,11 +18,9 @@ until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVE done echo -CONFIG_SERVER_HOST=${CONFIG_SERVER_HOST:='config-server'} -CONFIG_SERVER_PORT=${CONFIG_SERVER_PORT:=8888} - -echo "Trying to connect to on ${CONFIG_SERVER_HOST}:${CONFIG_SERVER_PORT}" -until $(curl --output /dev/null --silent --head --fail "http://${CONFIG_SERVER_HOST}:${CONFIG_SERVER_PORT}/info"); do +CONFIG_SERVER=${CONFIG_SERVER:='config-server'} +echo "Trying to get '${CONFIG_SERVER}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${CONFIG_SERVER}"); do echo -e ".\c" sleep 1 done diff --git a/realtor-service/src/main/docker/wrapper.sh b/realtor-service/src/main/docker/wrapper.sh index 869d428..262851e 100644 --- a/realtor-service/src/main/docker/wrapper.sh +++ b/realtor-service/src/main/docker/wrapper.sh @@ -18,11 +18,25 @@ until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVE done echo -STORAGE_SERVICE_HOST=${STORAGE_SERVICE_HOST:='storage-service'} -STORAGE_SERVICE_PORT=${STORAGE_SERVICE_PORT:=8091} +STORAGE_SERVICE=${STORAGE_SERVICE:='storage-service'} +echo "Trying to get '${STORAGE_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${STORAGE_SERVICE}"); do + echo -e ".\c" + sleep 1 +done +echo + +RATING_SERVICE=${RATING_SERVICE:='rating-service'} +echo "Trying to get '${RATING_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${RATING_SERVICE}"); do + echo -e ".\c" + sleep 1 +done +echo -echo "Trying to connect to on ${STORAGE_SERVICE_HOST}:${STORAGE_SERVICE_PORT}" -until $(curl --output /dev/null --silent --head --fail "http://${STORAGE_SERVICE_HOST}:${STORAGE_SERVICE_PORT}/info"); do +HACKSTER_SERVICE=${HACKSTER_SERVICE:='hackster-service'} +echo "Trying to get '${HACKSTER_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${HACKSTER_SERVICE}"); do echo -e ".\c" sleep 1 done diff --git a/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorController.java b/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorController.java index 055072a..93816a7 100644 --- a/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorController.java +++ b/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorController.java @@ -37,7 +37,8 @@ public void addApartment(@RequestBody ApartmentRecord apartmentRecord) { } @PostMapping("/storeApartments") - public void storeApartment(@RequestBody ApartmentRecord apartmentRecord) { + @ResponseBody + public Apartment storeApartment(@RequestBody ApartmentRecord apartmentRecord) { Apartment newApartment = Apartment.builder() .location(apartmentRecord.getLocation()) @@ -53,6 +54,7 @@ public void storeApartment(@RequestBody ApartmentRecord apartmentRecord) { .decoder(new JacksonDecoder()).target(ApartmentRecordClient.class, "http://storage-service"); apartmentRecordClient.storeApartment(apartmentRecord);*/ log.info("Stored, {}", apartment); + return apartment; } @RequestMapping("/service-instances/{applicationName}") diff --git a/storage-service/src/main/docker/wrapper.sh b/storage-service/src/main/docker/wrapper.sh index 435987c..d32f932 100644 --- a/storage-service/src/main/docker/wrapper.sh +++ b/storage-service/src/main/docker/wrapper.sh @@ -18,6 +18,7 @@ until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVE done echo +sleep 15 echo "Starting storage server" echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" From 1d1d5398d45a225354cac9258673dfb532686ca1 Mon Sep 17 00:00:00 2001 From: Ihor Banadiga Date: Tue, 22 Aug 2017 11:34:03 +0300 Subject: [PATCH 07/10] management.security.enabled=false --- .../src/main/resources/application.properties | 2 ++ .../src/main/resources/application.properties | 11 ++++++++++- .../src/main/resources/application.properties | 2 ++ .../src/main/resources/application.properties | 2 ++ .../src/main/resources/application.properties | 2 ++ .../src/main/resources/application.properties | 2 ++ .../src/main/resources/application.properties | 2 ++ .../src/main/resources/application.properties | 2 ++ 8 files changed, 24 insertions(+), 1 deletion(-) diff --git a/api-gateway-service/src/main/resources/application.properties b/api-gateway-service/src/main/resources/application.properties index ae2f9a9..2e65d5f 100644 --- a/api-gateway-service/src/main/resources/application.properties +++ b/api-gateway-service/src/main/resources/application.properties @@ -3,6 +3,8 @@ server.port=8090 eureka.instance.preferIpAddress=true +management.security.enabled=false + endpoints.info.id=info endpoints.info.sensitive=false endpoints.info.enabled=true diff --git a/client-service/src/main/resources/application.properties b/client-service/src/main/resources/application.properties index 60ea3d6..b327fe7 100644 --- a/client-service/src/main/resources/application.properties +++ b/client-service/src/main/resources/application.properties @@ -1,3 +1,12 @@ spring.application.name=client-service server.port=8083 -eureka.instance.prefer-ip-address=true \ No newline at end of file + +eureka.instance.prefer-ip-address=true + +management.security.enabled=false + +endpoints.info.id=info +endpoints.info.sensitive=false +endpoints.info.enabled=true + +info.app.name=Client service diff --git a/config-server/src/main/resources/application.properties b/config-server/src/main/resources/application.properties index 17623bd..a7f854e 100644 --- a/config-server/src/main/resources/application.properties +++ b/config-server/src/main/resources/application.properties @@ -8,6 +8,8 @@ server.port=8888 eureka.instance.preferIpAddress=true +management.security.enabled=false + endpoints.info.id=info endpoints.info.sensitive=false endpoints.info.enabled=true diff --git a/discovery-server/src/main/resources/application.properties b/discovery-server/src/main/resources/application.properties index 62a9a22..da73450 100644 --- a/discovery-server/src/main/resources/application.properties +++ b/discovery-server/src/main/resources/application.properties @@ -4,6 +4,8 @@ server.port=8761 eureka.client.register-with-eureka=false eureka.client.fetch-registry=false +management.security.enabled=false + endpoints.info.id=info endpoints.info.sensitive=false endpoints.info.enabled=true diff --git a/hackster-service/src/main/resources/application.properties b/hackster-service/src/main/resources/application.properties index 3a1b1a9..20edbde 100644 --- a/hackster-service/src/main/resources/application.properties +++ b/hackster-service/src/main/resources/application.properties @@ -3,6 +3,8 @@ spring.application.name=hackster-service eureka.instance.preferIpAddress=true +management.security.enabled=false + endpoints.info.id=info endpoints.info.sensitive=false endpoints.info.enabled=true diff --git a/rating-service/src/main/resources/application.properties b/rating-service/src/main/resources/application.properties index fa3938b..7a1beaa 100644 --- a/rating-service/src/main/resources/application.properties +++ b/rating-service/src/main/resources/application.properties @@ -3,6 +3,8 @@ spring.application.name=rating-service eureka.instance.preferIpAddress=true +management.security.enabled=false + endpoints.info.id=info endpoints.info.sensitive=false endpoints.info.enabled=true diff --git a/realtor-service/src/main/resources/application.properties b/realtor-service/src/main/resources/application.properties index ae96fbe..d3d918d 100644 --- a/realtor-service/src/main/resources/application.properties +++ b/realtor-service/src/main/resources/application.properties @@ -3,6 +3,8 @@ feign.hystrix.enabled=true eureka.instance.preferIpAddress=true +management.security.enabled=false + endpoints.info.id=info endpoints.info.sensitive=false endpoints.info.enabled=true diff --git a/storage-service/src/main/resources/application.properties b/storage-service/src/main/resources/application.properties index 72a52a8..8fda022 100644 --- a/storage-service/src/main/resources/application.properties +++ b/storage-service/src/main/resources/application.properties @@ -5,6 +5,8 @@ spring.data.rest.return-body-on-update=true eureka.instance.preferIpAddress=true +management.security.enabled=false + endpoints.info.id=info endpoints.info.sensitive=false endpoints.info.enabled=true From 685279e79f1b48d8ab622b30935e6c8da9b7a411 Mon Sep 17 00:00:00 2001 From: Ihor Banadiga Date: Fri, 25 Aug 2017 17:14:30 +0300 Subject: [PATCH 08/10] docker-compose fix added --- api-gateway-service/.gitignore | 24 ---- .../ApiGatewayServiceApplication.java | 2 +- .../src/main/resources/application.properties | 2 + .../ApiGatewayServiceApplicationTests.java | 2 +- client-service/src/main/docker/Dockerfile | 10 +- .../client/ClientServiceApplication.java | 10 +- config-server/src/main/docker/Dockerfile | 12 +- dsl-executor-service/pom.xml | 51 ++++++++ .../src/main/docker/Dockerfile | 12 ++ .../src/main/docker/wrapper.sh | 49 ++++++++ .../src/main/resources/application.properties | 2 + integration-test/pom.xml | 42 ++++++- .../integration/BaseIntegrationTest.java | 66 ++++++++++ .../jclub/integration/DslIntegrationTest.java | 48 +++++++ .../integration/EntToEndIntegrationTest.java | 119 ------------------ .../EntToEndIntegrationTestSuite.java | 24 ++++ .../integration/GetWayIntegrationTest.java | 64 ++++++++++ .../src/test/resources/application.properties | 1 + .../src/test/resources/banner.txt | 5 + .../src/test/resources/docker-compose.yml | 21 ++++ .../src/test/resources/dsl/end-to-end.mydsl | 8 ++ .../src/test/resources/logback-test.xml | 8 ++ .../realtor/RealtorServiceApplication.java | 6 +- 23 files changed, 431 insertions(+), 157 deletions(-) delete mode 100644 api-gateway-service/.gitignore rename api-gateway-service/src/main/java/com/lohika/jclub/{ => gateway}/ApiGatewayServiceApplication.java (93%) rename api-gateway-service/src/test/java/com/lohika/jclub/{ => gateway}/ApiGatewayServiceApplicationTests.java (90%) create mode 100644 dsl-executor-service/src/main/docker/Dockerfile create mode 100644 dsl-executor-service/src/main/docker/wrapper.sh create mode 100644 integration-test/src/test/java/com/lohika/jclub/integration/BaseIntegrationTest.java create mode 100644 integration-test/src/test/java/com/lohika/jclub/integration/DslIntegrationTest.java delete mode 100644 integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java create mode 100644 integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTestSuite.java create mode 100644 integration-test/src/test/java/com/lohika/jclub/integration/GetWayIntegrationTest.java create mode 100644 integration-test/src/test/resources/application.properties create mode 100644 integration-test/src/test/resources/banner.txt create mode 100644 integration-test/src/test/resources/dsl/end-to-end.mydsl create mode 100644 integration-test/src/test/resources/logback-test.xml diff --git a/api-gateway-service/.gitignore b/api-gateway-service/.gitignore deleted file mode 100644 index 2af7cef..0000000 --- a/api-gateway-service/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -nbproject/private/ -build/ -nbbuild/ -dist/ -nbdist/ -.nb-gradle/ \ No newline at end of file diff --git a/api-gateway-service/src/main/java/com/lohika/jclub/ApiGatewayServiceApplication.java b/api-gateway-service/src/main/java/com/lohika/jclub/gateway/ApiGatewayServiceApplication.java similarity index 93% rename from api-gateway-service/src/main/java/com/lohika/jclub/ApiGatewayServiceApplication.java rename to api-gateway-service/src/main/java/com/lohika/jclub/gateway/ApiGatewayServiceApplication.java index c6fc518..0fcd3bc 100644 --- a/api-gateway-service/src/main/java/com/lohika/jclub/ApiGatewayServiceApplication.java +++ b/api-gateway-service/src/main/java/com/lohika/jclub/gateway/ApiGatewayServiceApplication.java @@ -1,4 +1,4 @@ -package com.lohika.jclub; +package com.lohika.jclub.gateway; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/api-gateway-service/src/main/resources/application.properties b/api-gateway-service/src/main/resources/application.properties index 2e65d5f..b08c729 100644 --- a/api-gateway-service/src/main/resources/application.properties +++ b/api-gateway-service/src/main/resources/application.properties @@ -3,6 +3,8 @@ server.port=8090 eureka.instance.preferIpAddress=true +feign.hystrix.enabled=true + management.security.enabled=false endpoints.info.id=info diff --git a/api-gateway-service/src/test/java/com/lohika/jclub/ApiGatewayServiceApplicationTests.java b/api-gateway-service/src/test/java/com/lohika/jclub/gateway/ApiGatewayServiceApplicationTests.java similarity index 90% rename from api-gateway-service/src/test/java/com/lohika/jclub/ApiGatewayServiceApplicationTests.java rename to api-gateway-service/src/test/java/com/lohika/jclub/gateway/ApiGatewayServiceApplicationTests.java index fcc36bd..9bc4c69 100644 --- a/api-gateway-service/src/test/java/com/lohika/jclub/ApiGatewayServiceApplicationTests.java +++ b/api-gateway-service/src/test/java/com/lohika/jclub/gateway/ApiGatewayServiceApplicationTests.java @@ -1,4 +1,4 @@ -package com.lohika.jclub; +package com.lohika.jclub.gateway; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/client-service/src/main/docker/Dockerfile b/client-service/src/main/docker/Dockerfile index b2bbe9e..53d173c 100644 --- a/client-service/src/main/docker/Dockerfile +++ b/client-service/src/main/docker/Dockerfile @@ -1,6 +1,12 @@ FROM java:8 + +RUN mkdir -p /opt/spring-cloud +WORKDIR /opt/spring-cloud + ADD client-service.jar client-service.jar ADD wrapper.sh wrapper.sh -RUN bash -c 'chmod +x /wrapper.sh' -RUN bash -c 'touch /client-service.jar' + +RUN bash -c 'chmod +x ./wrapper.sh' +RUN bash -c 'touch ./client-service.jar' + ENTRYPOINT ["/bin/bash", "./wrapper.sh"] diff --git a/client-service/src/main/java/com/lohika/jclub/client/ClientServiceApplication.java b/client-service/src/main/java/com/lohika/jclub/client/ClientServiceApplication.java index 55a2b86..86cd567 100644 --- a/client-service/src/main/java/com/lohika/jclub/client/ClientServiceApplication.java +++ b/client-service/src/main/java/com/lohika/jclub/client/ClientServiceApplication.java @@ -1,15 +1,17 @@ package com.lohika.jclub.client; import com.lohika.jclub.storage.client.EnableStorageServiceClient; +import com.lohika.jclub.storage.client.StorageServiceClient; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.client.loadbalancer.LoadBalanced; -import org.springframework.context.annotation.Bean; -import org.springframework.web.client.RestTemplate; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.feign.EnableFeignClients; -@SpringBootApplication +@EnableDiscoveryClient @EnableStorageServiceClient +@EnableFeignClients(clients = {StorageServiceClient.class}) +@SpringBootApplication public class ClientServiceApplication { public static void main(String[] args) { diff --git a/config-server/src/main/docker/Dockerfile b/config-server/src/main/docker/Dockerfile index 4324605..2533832 100644 --- a/config-server/src/main/docker/Dockerfile +++ b/config-server/src/main/docker/Dockerfile @@ -1,6 +1,12 @@ FROM java:8 + +RUN mkdir -p /opt/spring-cloud +WORKDIR /opt/spring-cloud + ADD config-server.jar config-server.jar ADD wrapper.sh wrapper.sh -RUN bash -c 'chmod +x /wrapper.sh' -RUN bash -c 'touch /config-server.jar' -ENTRYPOINT ["/bin/bash", "/wrapper.sh"] + +RUN bash -c 'chmod +x ./wrapper.sh' +RUN bash -c 'touch ./config-server.jar' + +ENTRYPOINT ["/bin/bash", "./wrapper.sh"] diff --git a/dsl-executor-service/pom.xml b/dsl-executor-service/pom.xml index bff61af..e549d27 100644 --- a/dsl-executor-service/pom.xml +++ b/dsl-executor-service/pom.xml @@ -23,6 +23,7 @@ UTF-8 1.8 Dalston.RELEASE + ${basedir}/src/main/docker @@ -74,4 +75,54 @@ + + + + org.springframework.boot + spring-boot-maven-plugin + + + maven-antrun-plugin + + + + + + + + install + + run + + + + + + com.spotify + docker-maven-plugin + 1.0.0 + + + build-image + install + + build + + + + + ${project.artifactId} + ${docker.baseDir} + + + / + ${project.build.directory} + ${project.artifactId}.jar + + + + + + diff --git a/dsl-executor-service/src/main/docker/Dockerfile b/dsl-executor-service/src/main/docker/Dockerfile new file mode 100644 index 0000000..65b90b5 --- /dev/null +++ b/dsl-executor-service/src/main/docker/Dockerfile @@ -0,0 +1,12 @@ +FROM java:8 + +RUN mkdir -p /opt/spring-cloud +WORKDIR /opt/spring-cloud + +ADD dsl-executor-service.jar dsl-executor-service.jar +ADD wrapper.sh wrapper.sh + +RUN bash -c 'chmod +x ./wrapper.sh' +RUN bash -c 'touch ./dsl-executor-service.jar' + +ENTRYPOINT ["/bin/bash", "./wrapper.sh"] diff --git a/dsl-executor-service/src/main/docker/wrapper.sh b/dsl-executor-service/src/main/docker/wrapper.sh new file mode 100644 index 0000000..571c7b4 --- /dev/null +++ b/dsl-executor-service/src/main/docker/wrapper.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'} + +if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then + echo "Starting dsl-executor server immediately" + java -jar ./dsl-executor-service.jar + exit 0 +fi + +DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'} +DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761} + +echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do + echo -e ".\c" + sleep 1 +done +echo + +STORAGE_SERVICE=${STORAGE_SERVICE:='storage-service'} +echo "Trying to get '${STORAGE_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${STORAGE_SERVICE}"); do + echo -e ".\c" + sleep 1 +done +echo + +RATING_SERVICE=${RATING_SERVICE:='rating-service'} +echo "Trying to get '${RATING_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${RATING_SERVICE}"); do + echo -e ".\c" + sleep 1 +done +echo + +HACKSTER_SERVICE=${HACKSTER_SERVICE:='hackster-service'} +echo "Trying to get '${HACKSTER_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}" +until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${HACKSTER_SERVICE}"); do + echo -e ".\c" + sleep 1 +done +echo + +echo "Starting dsl-executor server" +echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" + +env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ + java -jar ./dsl-executor-service.jar diff --git a/dsl-executor-service/src/main/resources/application.properties b/dsl-executor-service/src/main/resources/application.properties index 31769f9..6aa6ec6 100644 --- a/dsl-executor-service/src/main/resources/application.properties +++ b/dsl-executor-service/src/main/resources/application.properties @@ -7,6 +7,8 @@ eureka.instance.preferIpAddress=true feign.hystrix.enabled=true +management.security.enabled=false + endpoints.info.id=info endpoints.info.sensitive=false endpoints.info.enabled=true diff --git a/integration-test/pom.xml b/integration-test/pom.xml index 7e6d6e3..7c7d60a 100644 --- a/integration-test/pom.xml +++ b/integration-test/pom.xml @@ -1,6 +1,6 @@ - 4.0.0 @@ -30,6 +30,11 @@ spring-cloud-starter-eureka + + org.projectlombok + lombok + + com.lohika.jclub.gateway api-gateway-service @@ -62,4 +67,37 @@ + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*.java + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + end-to-end-tests + + integration-test + verify + + + + **/*EntToEndIntegrationTestSuite.java + + + + + + + diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/BaseIntegrationTest.java b/integration-test/src/test/java/com/lohika/jclub/integration/BaseIntegrationTest.java new file mode 100644 index 0000000..7176eaa --- /dev/null +++ b/integration-test/src/test/java/com/lohika/jclub/integration/BaseIntegrationTest.java @@ -0,0 +1,66 @@ +package com.lohika.jclub.integration; + +import lombok.extern.log4j.Log4j; + +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.HttpClientBuilder; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.IOException; + +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +@Log4j +@RunWith(SpringRunner.class) +@SpringBootTest(classes = IntegrationTestApplication.class) +@ContextConfiguration(initializers = BaseIntegrationTest.Initializer.class) +public abstract class BaseIntegrationTest { + + protected static final String DSL_EXECUTOR_SERVICE = "DSL-EXECUTOR-SERVICE"; + protected static final String API_GATEWAY_SERVICE = "API-GATEWAY-SERVICE"; + + private static final String DISCOVERY_SERVER = "localhost"; + private static final int DISCOVERY_SERVER_PORT = 8761; + private static final int SLEEP = 5000; + + @BeforeClass + public static void init() { + assertThat(EntToEndIntegrationTestSuite.environment, notNullValue()); + } + + public static void waitFor(String service) throws InterruptedException { + HttpClient client = HttpClientBuilder.create().build(); + String gateway = "http://" + DISCOVERY_SERVER + ":" + DISCOVERY_SERVER_PORT + "/eureka/apps/" + service; + HttpGet httpGet = new HttpGet(gateway); + + log.info("Wait for :" + service); + HttpResponse httpResponse = null; + do { + Thread.sleep(SLEEP); + try { + httpResponse = client.execute(httpGet); + } catch (IOException ignored) { + } + } while (httpResponse == null || httpResponse.getStatusLine().getStatusCode() != 200); + Thread.sleep(SLEEP); + } + + public static class Initializer implements ApplicationContextInitializer { + @Override + public void initialize(ConfigurableApplicationContext configurableApplicationContext) { + EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(), + "eureka.client.serviceUrl.defaultZone=http://" + DISCOVERY_SERVER + ":" + DISCOVERY_SERVER_PORT + "/eureka" + ); + } + } +} diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/DslIntegrationTest.java b/integration-test/src/test/java/com/lohika/jclub/integration/DslIntegrationTest.java new file mode 100644 index 0000000..a3f96e1 --- /dev/null +++ b/integration-test/src/test/java/com/lohika/jclub/integration/DslIntegrationTest.java @@ -0,0 +1,48 @@ +package com.lohika.jclub.integration; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +import java.util.Map; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +public class DslIntegrationTest extends BaseIntegrationTest { + private static final String SIMPLE_DSL_EXECUTE = "http://" + DSL_EXECUTOR_SERVICE + "/dsl/end-to-end"; + private static final String GET_APARTMENTS = "http://" + API_GATEWAY_SERVICE + "/api/client-service/apartments"; + + @Autowired + private RestTemplate restTemplate; + + @BeforeClass + public static void setUpTests() throws InterruptedException { + waitFor(API_GATEWAY_SERVICE); + waitFor(DSL_EXECUTOR_SERVICE); + } + + @Test + public void apartmentShouldBeAvailableAfterDslExecution() { + ResponseEntity dslResult = restTemplate.exchange( + SIMPLE_DSL_EXECUTE, + HttpMethod.GET, + null, + Map.class + ); + + ResponseEntity get = restTemplate.exchange( + GET_APARTMENTS, + HttpMethod.GET, + null, + Map.class + ); + + assertThat(get.getStatusCode().value(), is(200)); + assertThat(get.getBody().get("id"), notNullValue()); + } +} diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java b/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java deleted file mode 100644 index b58eb80..0000000 --- a/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTest.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.lohika.jclub.integration; - -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.HttpClientBuilder; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.context.ApplicationContextInitializer; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.client.RestTemplate; -import org.testcontainers.containers.DockerComposeContainer; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; - -@Ignore -@RunWith(SpringRunner.class) -@SpringBootTest(classes = IntegrationTestApplication.class) -@ContextConfiguration(initializers = EntToEndIntegrationTest.Initializer.class) -public class EntToEndIntegrationTest { - private static final int SLEEP = 5000; - - private static final String DISCOVERY_SERVER = "discovery-server"; - private static final int DISCOVERY_SERVER_PORT = 8761; - - private static final String API_GATEWAY_SERVICE = "API-GATEWAY-SERVICE"; - private static final int API_GATEWAY_SERVICE_PORT = 8090; - - private static final String COMPOSE = EntToEndIntegrationTest.class.getClassLoader() - .getResource("./docker-compose.yml").getPath(); - - @ClassRule - public static DockerComposeContainer environment = new DockerComposeContainer(new File(COMPOSE)) - .withPull(false); - - - @Autowired - private RestTemplate restTemplate; - - @BeforeClass - public static void init() throws InterruptedException { - HttpClient client = HttpClientBuilder.create().build(); - String gateway = "http://localhost:" + DISCOVERY_SERVER_PORT + "/eureka/apps/" + API_GATEWAY_SERVICE; - HttpGet httpGet = new HttpGet(gateway); - - HttpResponse httpResponse = null; - do { - Thread.sleep(SLEEP); - try { - httpResponse = client.execute(httpGet); - } catch (IOException e) { - } - } while (httpResponse == null || httpResponse.getStatusLine().getStatusCode() != 200); - Thread.sleep(SLEEP); - } - - @Test - public void checkIsStarted() throws IOException, InterruptedException { - Map params = new HashMap() {{ - put("location", "location"); - put("price", 1500.5); - put("sqft", 1.5); - put("phone", "123"); - put("realtorName", "vas"); - put("mail", "mail@exem.comn"); - - }}; - - ResponseEntity create = restTemplate.exchange( - "http://API-GATEWAY-SERVICE/api/realtor-service/storeApartments", - HttpMethod.POST, - new HttpEntity<>(params), - Map.class - ); - - assertThat(create.getStatusCode().value(), is(200)); - String createdId = (String) create.getBody().get("id"); - assertThat(createdId, notNullValue()); - - - ResponseEntity get = restTemplate.exchange( - "http://API-GATEWAY-SERVICE/api/clien-service/apartments", - HttpMethod.GET, - null, - Map.class - ); - - assertThat(get.getStatusCode().value(), is(200)); - String id = (String) get.getBody().get("id"); - assertThat(createdId, is(id)); - } - - public static class Initializer implements ApplicationContextInitializer { - @Override - public void initialize(ConfigurableApplicationContext configurableApplicationContext) { - EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(), - "eureka.client.serviceUrl.defaultZone=http://localhost:" + DISCOVERY_SERVER_PORT + "/eureka" - ); - } - } -} diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTestSuite.java b/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTestSuite.java new file mode 100644 index 0000000..2076229 --- /dev/null +++ b/integration-test/src/test/java/com/lohika/jclub/integration/EntToEndIntegrationTestSuite.java @@ -0,0 +1,24 @@ +package com.lohika.jclub.integration; + +import org.junit.ClassRule; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.testcontainers.containers.DockerComposeContainer; + +import java.io.File; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + GetWayIntegrationTest.class, + DslIntegrationTest.class +}) +public class EntToEndIntegrationTestSuite { + + private static final String COMPOSE = GetWayIntegrationTest.class.getClassLoader() + .getResource("./docker-compose.yml").getPath(); + + @ClassRule + public static DockerComposeContainer environment = new DockerComposeContainer(new File(COMPOSE)) + .withPull(false) + .withEnv("TestSuite", "true"); +} diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/GetWayIntegrationTest.java b/integration-test/src/test/java/com/lohika/jclub/integration/GetWayIntegrationTest.java new file mode 100644 index 0000000..e6b7533 --- /dev/null +++ b/integration-test/src/test/java/com/lohika/jclub/integration/GetWayIntegrationTest.java @@ -0,0 +1,64 @@ +package com.lohika.jclub.integration; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +import java.util.HashMap; +import java.util.Map; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +public class GetWayIntegrationTest extends BaseIntegrationTest { + + + private static final String STORE_APARTMENTS = "http://" + API_GATEWAY_SERVICE + + "/api/realtor-service/storeApartments"; + private static final String GET_APARTMENTS = "http://" + API_GATEWAY_SERVICE + "/api/client-service/apartments"; + + @Autowired + private RestTemplate restTemplate; + + @BeforeClass + public static void setUpTests() throws InterruptedException { + waitFor(API_GATEWAY_SERVICE); + } + + @Test + public void apartmentShouldBeAvailableAfterAdding() { + Map params = new HashMap() { + { + put("location", "location"); + put("price", 1500.5); + put("sqft", 1.5); + put("phone", "123"); + put("realtorName", "vas"); + put("mail", "mail@exem.comn"); + + } + }; + + ResponseEntity create = restTemplate.exchange( + STORE_APARTMENTS, + HttpMethod.POST, + new HttpEntity<>(params), + Map.class + ); + + ResponseEntity get = restTemplate.exchange( + GET_APARTMENTS, + HttpMethod.GET, + null, + Map.class + ); + + assertThat(get.getStatusCode().value(), is(200)); + assertThat(get.getBody().get("id"), notNullValue()); + } +} diff --git a/integration-test/src/test/resources/application.properties b/integration-test/src/test/resources/application.properties new file mode 100644 index 0000000..8ca1db7 --- /dev/null +++ b/integration-test/src/test/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=end-to-end-integration-test diff --git a/integration-test/src/test/resources/banner.txt b/integration-test/src/test/resources/banner.txt new file mode 100644 index 0000000..43516dd --- /dev/null +++ b/integration-test/src/test/resources/banner.txt @@ -0,0 +1,5 @@ + _______ ______ __ _______ ______ ______ __ + / ____/ | / / __ \ / /_____ / ____/ | / / __ \ /_ __/__ _____/ /______ + / __/ / |/ / / / / / __/ __ \ / __/ / |/ / / / / / / / _ \/ ___/ __/ ___/ + / /___/ /| / /_/ / / /_/ /_/ / / /___/ /| / /_/ / / / / __(__ ) /_(__ ) +/_____/_/ |_/_____/ \__/\____/ /_____/_/ |_/_____/ /_/ \___/____/\__/____/ diff --git a/integration-test/src/test/resources/docker-compose.yml b/integration-test/src/test/resources/docker-compose.yml index 37f7adb..6bf2423 100644 --- a/integration-test/src/test/resources/docker-compose.yml +++ b/integration-test/src/test/resources/docker-compose.yml @@ -61,6 +61,8 @@ services: - "8080:8080" links: - discovery-server + - rating-service + - hackster-service - storage-service environment: - WAITING_FOR_DEPENDENCE=true @@ -81,6 +83,25 @@ services: depends_on: - discovery-server - storage-service +# + dsl-executor-service: + image: dsl-executor-service + ports: + - "8088:8088" + links: + - discovery-server + - rating-service + - hackster-service + - storage-service + volumes: + - ./dsl:/opt/spring-cloud/dsl-scripts + environment: + - WAITING_FOR_DEPENDENCE=true + depends_on: + - discovery-server + - rating-service + - hackster-service + - storage-service # api-gateway-service: image: api-gateway-service diff --git a/integration-test/src/test/resources/dsl/end-to-end.mydsl b/integration-test/src/test/resources/dsl/end-to-end.mydsl new file mode 100644 index 0000000..14dd27e --- /dev/null +++ b/integration-test/src/test/resources/dsl/end-to-end.mydsl @@ -0,0 +1,8 @@ +apartment { + location "ent-to-end-test-location" + price 2.4 + sqft 3.4 + phone 'phone' + realtorName 'realtorName' + mail 'mail' +} diff --git a/integration-test/src/test/resources/logback-test.xml b/integration-test/src/test/resources/logback-test.xml new file mode 100644 index 0000000..3fcefa8 --- /dev/null +++ b/integration-test/src/test/resources/logback-test.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorServiceApplication.java b/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorServiceApplication.java index e3fb957..a736cef 100644 --- a/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorServiceApplication.java +++ b/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorServiceApplication.java @@ -1,15 +1,19 @@ package com.lohika.jclub.realtor; - import com.lohika.jclub.storage.client.EnableStorageServiceClient; +import com.lohika.jclub.storage.client.StorageServiceClient; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.cloud.netflix.feign.EnableFeignClients; import org.springframework.context.annotation.Bean; import org.springframework.web.client.RestTemplate; +@EnableDiscoveryClient @EnableStorageServiceClient +@EnableFeignClients(clients = {StorageServiceClient.class}) @SpringBootApplication public class RealtorServiceApplication { From b9f92fb992930995edb341da6b55379ba4ffddf7 Mon Sep 17 00:00:00 2001 From: Ihor Banadiga Date: Mon, 28 Aug 2017 19:48:30 +0300 Subject: [PATCH 09/10] end to end test fixed --- .../lohika/jclub/client/ClientController.java | 7 +++++ .../jclub/client/ClientServiceTest.java | 7 +++-- .../lohika/jclub/dsl/service/DslService.java | 7 +++++ .../client/EnableHacksterServiceClient.java | 4 --- integration-test/pom.xml | 6 ++++ .../integration/BaseIntegrationTest.java | 21 +++++++++++++ .../jclub/integration/DslIntegrationTest.java | 21 ++++++++++++- .../integration/GetWayIntegrationTest.java | 31 +++++++++++++++---- .../IntegrationTestApplication.java | 6 ++++ .../src/test/resources/dsl/end-to-end.mydsl | 2 +- .../jclub/realtor/RealtorController.java | 7 +++++ 11 files changed, 105 insertions(+), 14 deletions(-) diff --git a/client-service/src/main/java/com/lohika/jclub/client/ClientController.java b/client-service/src/main/java/com/lohika/jclub/client/ClientController.java index f191f27..da51de1 100644 --- a/client-service/src/main/java/com/lohika/jclub/client/ClientController.java +++ b/client-service/src/main/java/com/lohika/jclub/client/ClientController.java @@ -11,6 +11,8 @@ import lombok.extern.slf4j.Slf4j; +import javax.annotation.PostConstruct; + @Slf4j @RestController public class ClientController { @@ -18,6 +20,11 @@ public class ClientController { @Autowired private StorageServiceClient storageServiceClient; + @PostConstruct + public void warmUp() { + storageServiceClient.list(); + } + @GetMapping(value = "/apartments", produces = MediaType.APPLICATION_JSON_VALUE) public PagedResources getApartments() { PagedResources list = storageServiceClient.list(); diff --git a/client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java b/client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java index 96b9bc5..7e581e1 100644 --- a/client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java +++ b/client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java @@ -20,8 +20,8 @@ import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.LogMessageWaitStrategy; -import java.time.Duration; - +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; @RunWith(SpringRunner.class) @@ -54,6 +54,9 @@ public void testGetApartments() throws Exception { .sqft(55) .build()); + assertThat(lviv, notNullValue()); + assertThat(lviv.getId(), notNullValue()); + // When mockMvc.perform(MockMvcRequestBuilders.get("/apartments")) .andDo(print()); diff --git a/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslService.java b/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslService.java index 52a54ee..f8d61ed 100644 --- a/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslService.java +++ b/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslService.java @@ -17,6 +17,8 @@ import java.nio.file.Files; import java.nio.file.Paths; +import javax.annotation.PostConstruct; + @Service public class DslService { private static final String DSL_EXTENSION = ".mydsl"; @@ -30,6 +32,11 @@ public class DslService { @Autowired private RatingServiceClient ratingServiceClient; + @PostConstruct + public void warmUp() { + storageServiceClient.list(); + } + public MyDsl runScript(String scriptName) throws IOException { String script = getScriptByName(scriptName); return run(script); diff --git a/hackster-service-client/src/main/java/com/lohika/jclub/hackster/client/EnableHacksterServiceClient.java b/hackster-service-client/src/main/java/com/lohika/jclub/hackster/client/EnableHacksterServiceClient.java index e651856..2b2b3ce 100644 --- a/hackster-service-client/src/main/java/com/lohika/jclub/hackster/client/EnableHacksterServiceClient.java +++ b/hackster-service-client/src/main/java/com/lohika/jclub/hackster/client/EnableHacksterServiceClient.java @@ -1,9 +1,7 @@ package com.lohika.jclub.hackster.client; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; import org.springframework.context.annotation.Import; -import org.springframework.hateoas.config.EnableHypermediaSupport; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; @@ -15,9 +13,7 @@ @Retention(RetentionPolicy.RUNTIME) @Documented -@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL) @EnableFeignClients(clients = {HacksterServiceClient.class}) @Import({FeignMappingDefaultConfiguration.class, HacksterServiceClientConfiguration.class}) -@EnableDiscoveryClient public @interface EnableHacksterServiceClient { } diff --git a/integration-test/pom.xml b/integration-test/pom.xml index 7c7d60a..70c18d5 100644 --- a/integration-test/pom.xml +++ b/integration-test/pom.xml @@ -41,6 +41,12 @@ 0.0.1-SNAPSHOT test + + com.lohika.jclub.storage.client + storage-service-client + 0.0.1-SNAPSHOT + test + org.springframework.boot diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/BaseIntegrationTest.java b/integration-test/src/test/java/com/lohika/jclub/integration/BaseIntegrationTest.java index 7176eaa..aabed60 100644 --- a/integration-test/src/test/java/com/lohika/jclub/integration/BaseIntegrationTest.java +++ b/integration-test/src/test/java/com/lohika/jclub/integration/BaseIntegrationTest.java @@ -2,12 +2,17 @@ import lombok.extern.log4j.Log4j; +import com.lohika.jclub.storage.client.StorageServiceClient; + import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; +import org.junit.After; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.ApplicationContextInitializer; @@ -17,6 +22,8 @@ import java.io.IOException; +import javax.annotation.PostConstruct; + import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -33,11 +40,25 @@ public abstract class BaseIntegrationTest { private static final int DISCOVERY_SERVER_PORT = 8761; private static final int SLEEP = 5000; + @Autowired + protected StorageServiceClient storageServiceClient; + @BeforeClass public static void init() { assertThat(EntToEndIntegrationTestSuite.environment, notNullValue()); } + @Before + public void warmUp() { + storageServiceClient.list(); + } + + @Before + public void cleanUp() { + storageServiceClient.list().getContent() + .forEach(apartment -> storageServiceClient.delete(apartment.getId())); + } + public static void waitFor(String service) throws InterruptedException { HttpClient client = HttpClientBuilder.create().build(); String gateway = "http://" + DISCOVERY_SERVER + ":" + DISCOVERY_SERVER_PORT + "/eureka/apps/" + service; diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/DslIntegrationTest.java b/integration-test/src/test/java/com/lohika/jclub/integration/DslIntegrationTest.java index a3f96e1..ad6f7bd 100644 --- a/integration-test/src/test/java/com/lohika/jclub/integration/DslIntegrationTest.java +++ b/integration-test/src/test/java/com/lohika/jclub/integration/DslIntegrationTest.java @@ -1,5 +1,7 @@ package com.lohika.jclub.integration; +import com.lohika.jclub.storage.client.Apartment; + import org.junit.BeforeClass; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -7,11 +9,13 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; +import java.util.Collection; import java.util.Map; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; public class DslIntegrationTest extends BaseIntegrationTest { private static final String SIMPLE_DSL_EXECUTE = "http://" + DSL_EXECUTOR_SERVICE + "/dsl/end-to-end"; @@ -28,6 +32,9 @@ public static void setUpTests() throws InterruptedException { @Test public void apartmentShouldBeAvailableAfterDslExecution() { + /* GIVEN */ + + /* WHEN */ ResponseEntity dslResult = restTemplate.exchange( SIMPLE_DSL_EXECUTE, HttpMethod.GET, @@ -35,6 +42,18 @@ public void apartmentShouldBeAvailableAfterDslExecution() { Map.class ); + /* THEN */ + assertThat(dslResult, notNullValue()); + assertThat(dslResult.getStatusCode().value(), is(200)); + + /* WHEN */ + Collection apartments = storageServiceClient.list().getContent(); + + /* THEN */ + assertThat(apartments, notNullValue()); + assertThat(apartments, hasSize(1)); + + /* WHEN */ ResponseEntity get = restTemplate.exchange( GET_APARTMENTS, HttpMethod.GET, @@ -42,7 +61,7 @@ public void apartmentShouldBeAvailableAfterDslExecution() { Map.class ); + /* THEN */ assertThat(get.getStatusCode().value(), is(200)); - assertThat(get.getBody().get("id"), notNullValue()); } } diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/GetWayIntegrationTest.java b/integration-test/src/test/java/com/lohika/jclub/integration/GetWayIntegrationTest.java index e6b7533..3106b75 100644 --- a/integration-test/src/test/java/com/lohika/jclub/integration/GetWayIntegrationTest.java +++ b/integration-test/src/test/java/com/lohika/jclub/integration/GetWayIntegrationTest.java @@ -1,5 +1,7 @@ package com.lohika.jclub.integration; +import com.lohika.jclub.storage.client.Apartment; + import org.junit.BeforeClass; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -8,16 +10,16 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; +import java.util.Collection; import java.util.HashMap; import java.util.Map; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; public class GetWayIntegrationTest extends BaseIntegrationTest { - - private static final String STORE_APARTMENTS = "http://" + API_GATEWAY_SERVICE + "/api/realtor-service/storeApartments"; private static final String GET_APARTMENTS = "http://" + API_GATEWAY_SERVICE + "/api/client-service/apartments"; @@ -32,18 +34,21 @@ public static void setUpTests() throws InterruptedException { @Test public void apartmentShouldBeAvailableAfterAdding() { - Map params = new HashMap() { + /* GIVEN */ + final String email = "mail@domen.com"; + Map params = new HashMap() { { put("location", "location"); put("price", 1500.5); put("sqft", 1.5); put("phone", "123"); - put("realtorName", "vas"); - put("mail", "mail@exem.comn"); + put("realtorName", "realtorName"); + put("mail", email); } }; + /* WHEN */ ResponseEntity create = restTemplate.exchange( STORE_APARTMENTS, HttpMethod.POST, @@ -51,6 +56,20 @@ public void apartmentShouldBeAvailableAfterAdding() { Map.class ); + /* THEN */ + assertThat(create, notNullValue()); + assertThat(create.getStatusCode().value(), is(200)); + String createdId = (String) create.getBody().get("id"); + assertThat(createdId, notNullValue()); + + /* WHEN */ + Collection apartments = storageServiceClient.list().getContent(); + + /* THEN */ + assertThat(apartments, notNullValue()); + assertThat(apartments, hasSize(1)); + + /* WHEN */ ResponseEntity get = restTemplate.exchange( GET_APARTMENTS, HttpMethod.GET, @@ -58,7 +77,7 @@ public void apartmentShouldBeAvailableAfterAdding() { Map.class ); + /* THEN */ assertThat(get.getStatusCode().value(), is(200)); - assertThat(get.getBody().get("id"), notNullValue()); } } diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/IntegrationTestApplication.java b/integration-test/src/test/java/com/lohika/jclub/integration/IntegrationTestApplication.java index 600b0d1..c3b5645 100644 --- a/integration-test/src/test/java/com/lohika/jclub/integration/IntegrationTestApplication.java +++ b/integration-test/src/test/java/com/lohika/jclub/integration/IntegrationTestApplication.java @@ -1,13 +1,19 @@ package com.lohika.jclub.integration; +import com.lohika.jclub.storage.client.EnableStorageServiceClient; +import com.lohika.jclub.storage.client.StorageServiceClient; + import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.cloud.netflix.feign.EnableFeignClients; import org.springframework.context.annotation.Bean; import org.springframework.web.client.RestTemplate; @EnableDiscoveryClient +@EnableStorageServiceClient +@EnableFeignClients(clients = {StorageServiceClient.class}) @SpringBootApplication public class IntegrationTestApplication { diff --git a/integration-test/src/test/resources/dsl/end-to-end.mydsl b/integration-test/src/test/resources/dsl/end-to-end.mydsl index 14dd27e..f943df1 100644 --- a/integration-test/src/test/resources/dsl/end-to-end.mydsl +++ b/integration-test/src/test/resources/dsl/end-to-end.mydsl @@ -4,5 +4,5 @@ apartment { sqft 3.4 phone 'phone' realtorName 'realtorName' - mail 'mail' + mail 'ent-to-end-mail@domen.com' } diff --git a/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorController.java b/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorController.java index 93816a7..7334d72 100644 --- a/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorController.java +++ b/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorController.java @@ -15,6 +15,8 @@ import java.util.List; +import javax.annotation.PostConstruct; + @Slf4j @RestController public class RealtorController { @@ -28,6 +30,11 @@ public class RealtorController { @Autowired private StorageServiceClient storageServiceClient; + @PostConstruct + public void warmUp() { + storageServiceClient.list(); + } + @PostMapping("/apartments") public void addApartment(@RequestBody ApartmentRecord apartmentRecord) { ResponseEntity isHackster = From c3a9dc1bab4350beac851ea0f876679aa544f66f Mon Sep 17 00:00:00 2001 From: Ihor Banadiga Date: Mon, 4 Sep 2017 20:17:11 +0300 Subject: [PATCH 10/10] some improvements --- api-gateway-service/pom.xml | 4 +- .../src/main/docker/wrapper.sh | 2 +- .../src/test/resources/application.properties | 1 + .../src/test/resources/banner.txt | 6 +++ .../src/test/resources/logback-test.xml | 7 ++++ client-service/pom.xml | 10 ++--- client-service/src/main/docker/wrapper.sh | 2 +- .../jclub/client/ClientServiceTest.java | 1 - .../src/test/resources/application.properties | 3 +- client-service/src/test/resources/banner.txt | 6 +++ config-server/pom.xml | 12 ++---- config-server/src/main/docker/wrapper.sh | 2 +- .../server}/ConfigServerApplication.java | 2 +- .../server}/ConfigServerApplicationTests.java | 2 +- .../src/test/resources/application.properties | 3 ++ config-server/src/test/resources/banner.txt | 6 +++ .../src/test/resources/logback-test.xml | 7 ++++ discovery-server/pom.xml | 8 ++-- .../server}/EurekaServerApplication.java | 2 +- .../src/main/resources/application.properties | 2 +- .../server}/EurekaServerApplicationTests.java | 2 +- .../src/test/resources/banner.txt | 6 +++ .../src/test/resources/logback-test.xml | 7 ++++ {dsl => dsl-core}/pom.xml | 11 +++--- .../jclub/dsl/core}/ApartmentDsl.groovy | 2 +- .../com/lohika/jclub/dsl/core}/MyDsl.groovy | 2 +- .../src/main/java/package-info.java | 0 .../src/main/resources/idea.gdsl | 0 dsl-executor-service/pom.xml | 27 +++++++++---- .../src/main/docker/wrapper.sh | 2 +- .../jclub/dsl/service/DslController.java | 6 +-- .../lohika/jclub/dsl/service/DslService.java | 2 +- .../service/DslServiceApplicationTests.java | 32 +++++++++++++++ .../src/test/resources/application.properties | 3 ++ .../src/test/resources/banner.txt | 6 +++ .../src/test/resources/logback-test.xml | 7 ++++ hackster-service-client/pom.xml | 8 ++-- .../HacksterServiceClientTestApplication.java | 2 + .../src/test/resources/application.properties | 2 - .../src/test/resources/banner.txt | 11 +++--- hackster-service/pom.xml | 12 ++---- hackster-service/src/main/docker/wrapper.sh | 2 +- .../lohika/jclub/{ => service}/Hackster.java | 2 +- .../{ => service}/HacksterController.java | 2 +- .../{ => service}/HacksterRepository.java | 2 +- .../jclub/{ => service}/HacksterService.java | 2 +- .../HacksterServiceApplication.java | 2 +- .../HacksterServiceApplicationTests.java | 4 +- .../{ => service}/HacksterServiceTests.java | 2 +- .../src/test/resources/banner.txt | 6 +++ .../src/test/resources/logback-test.xml | 7 ++++ integration-test/pom.xml | 6 +-- .../integration/GetWayIntegrationTest.java | 2 +- .../src/test/resources/application.properties | 1 + .../src/test/resources/banner.txt | 11 +++--- .../src/test/resources/logback-test.xml | 9 ++--- pom.xml | 8 ++-- rating-service-client/pom.xml | 8 ++-- .../RatingServiceClientFallbackTest.java | 15 +++++++ .../RatingServiceClientTestApplication.java | 2 - .../src/test/resources/application.properties | 2 +- .../src/test/resources/banner.txt | 11 +++--- rating-service/pom.xml | 13 ++----- rating-service/src/main/docker/wrapper.sh | 2 +- .../src/test/resources/application.properties | 1 + rating-service/src/test/resources/banner.txt | 6 +++ .../src/test/resources/logback-test.xml | 7 ++++ realtor-service/pom.xml | 18 +++++---- realtor-service/src/main/docker/wrapper.sh | 2 +- .../RealtorServiceApplicationTests.java | 39 ++++++++++++++++++- .../src/test/resources/application.properties | 2 + realtor-service/src/test/resources/banner.txt | 6 +++ .../src/test/resources/logback-test.xml | 7 ++++ storage-service-client/pom.xml | 8 ++-- .../StorageServiceClientFallbackTest.java | 15 +++++++ .../src/test/resources/application.properties | 3 +- .../src/test/resources/banner.txt | 12 +++--- storage-service/pom.xml | 8 ++-- storage-service/src/main/docker/wrapper.sh | 2 +- .../src/test/resources/application.properties | 1 + storage-service/src/test/resources/banner.txt | 6 +++ .../src/test/resources/logback-test.xml | 7 ++++ 82 files changed, 361 insertions(+), 148 deletions(-) create mode 100644 api-gateway-service/src/test/resources/application.properties create mode 100644 api-gateway-service/src/test/resources/banner.txt create mode 100644 api-gateway-service/src/test/resources/logback-test.xml create mode 100644 client-service/src/test/resources/banner.txt rename config-server/src/main/java/com/lohika/jclub/{ => config/server}/ConfigServerApplication.java (92%) rename config-server/src/test/java/com/lohika/jclub/{ => config/server}/ConfigServerApplicationTests.java (88%) create mode 100644 config-server/src/test/resources/application.properties create mode 100644 config-server/src/test/resources/banner.txt create mode 100644 config-server/src/test/resources/logback-test.xml rename discovery-server/src/main/java/com/lohika/jclub/{ => discovery/server}/EurekaServerApplication.java (90%) rename discovery-server/src/test/java/com/lohika/jclub/{ => discovery/server}/EurekaServerApplicationTests.java (87%) create mode 100644 discovery-server/src/test/resources/banner.txt create mode 100644 discovery-server/src/test/resources/logback-test.xml rename {dsl => dsl-core}/pom.xml (90%) rename {dsl/src/main/groovy/com/lohika/jclub/dsl => dsl-core/src/main/groovy/com/lohika/jclub/dsl/core}/ApartmentDsl.groovy (93%) rename {dsl/src/main/groovy/com/lohika/jclub/dsl => dsl-core/src/main/groovy/com/lohika/jclub/dsl/core}/MyDsl.groovy (97%) rename {dsl => dsl-core}/src/main/java/package-info.java (100%) rename {dsl => dsl-core}/src/main/resources/idea.gdsl (100%) create mode 100644 dsl-executor-service/src/test/java/com/lohika/jclub/dsl/service/DslServiceApplicationTests.java create mode 100644 dsl-executor-service/src/test/resources/application.properties create mode 100644 dsl-executor-service/src/test/resources/banner.txt create mode 100644 dsl-executor-service/src/test/resources/logback-test.xml rename hackster-service/src/main/java/com/lohika/jclub/{ => service}/Hackster.java (92%) rename hackster-service/src/main/java/com/lohika/jclub/{ => service}/HacksterController.java (95%) rename hackster-service/src/main/java/com/lohika/jclub/{ => service}/HacksterRepository.java (86%) rename hackster-service/src/main/java/com/lohika/jclub/{ => service}/HacksterService.java (97%) rename hackster-service/src/main/java/com/lohika/jclub/{ => service}/HacksterServiceApplication.java (92%) rename hackster-service/src/test/java/com/lohika/jclub/{ => service}/HacksterServiceApplicationTests.java (80%) rename hackster-service/src/test/java/com/lohika/jclub/{ => service}/HacksterServiceTests.java (97%) create mode 100644 hackster-service/src/test/resources/banner.txt create mode 100644 hackster-service/src/test/resources/logback-test.xml create mode 100644 rating-service/src/test/resources/banner.txt create mode 100644 rating-service/src/test/resources/logback-test.xml create mode 100644 realtor-service/src/test/resources/application.properties create mode 100644 realtor-service/src/test/resources/banner.txt create mode 100644 realtor-service/src/test/resources/logback-test.xml create mode 100644 storage-service/src/test/resources/application.properties create mode 100644 storage-service/src/test/resources/banner.txt create mode 100644 storage-service/src/test/resources/logback-test.xml diff --git a/api-gateway-service/pom.xml b/api-gateway-service/pom.xml index 1cea81f..d91da73 100644 --- a/api-gateway-service/pom.xml +++ b/api-gateway-service/pom.xml @@ -68,10 +68,10 @@ maven-antrun-plugin - + - + diff --git a/api-gateway-service/src/main/docker/wrapper.sh b/api-gateway-service/src/main/docker/wrapper.sh index e70a6b7..ff22074 100644 --- a/api-gateway-service/src/main/docker/wrapper.sh +++ b/api-gateway-service/src/main/docker/wrapper.sh @@ -36,6 +36,6 @@ echo echo "Starting api-gateway server" echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" - +echo env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ java -jar ./api-gateway-service.jar diff --git a/api-gateway-service/src/test/resources/application.properties b/api-gateway-service/src/test/resources/application.properties new file mode 100644 index 0000000..45cb06e --- /dev/null +++ b/api-gateway-service/src/test/resources/application.properties @@ -0,0 +1 @@ +eureka.client.enabled=false diff --git a/api-gateway-service/src/test/resources/banner.txt b/api-gateway-service/src/test/resources/banner.txt new file mode 100644 index 0000000..0678e6b --- /dev/null +++ b/api-gateway-service/src/test/resources/banner.txt @@ -0,0 +1,6 @@ + _______________________ ___ _ __ _ + /_ __/ ____/ ___/_ __/ / | ____ (_) ____ _____ _/ /____ _ ______ ___ __ ________ ______ __(_)_______ + / / / __/ \__ \ / / / /| | / __ \/ / / __ `/ __ `/ __/ _ \ | /| / / __ `/ / / / / ___/ _ \/ ___/ | / / / ___/ _ \ + / / / /___ ___/ // / / ___ |/ /_/ / / / /_/ / /_/ / /_/ __/ |/ |/ / /_/ / /_/ / (__ ) __/ / | |/ / / /__/ __/ +/_/ /_____//____//_/ /_/ |_/ .___/_/ \__, /\__,_/\__/\___/|__/|__/\__,_/\__, / /____/\___/_/ |___/_/\___/\___/ + /_/ /____/ /____/ diff --git a/api-gateway-service/src/test/resources/logback-test.xml b/api-gateway-service/src/test/resources/logback-test.xml new file mode 100644 index 0000000..d654c6e --- /dev/null +++ b/api-gateway-service/src/test/resources/logback-test.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/client-service/pom.xml b/client-service/pom.xml index 6adc594..777186b 100644 --- a/client-service/pom.xml +++ b/client-service/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.3.RELEASE + 1.5.4.RELEASE @@ -29,7 +29,7 @@ - com.lohika.jclub.storage.client + com.lohika.jclub.storage storage-service-client 0.0.1-SNAPSHOT @@ -64,7 +64,7 @@ org.testcontainers testcontainers - 1.3.0 + 1.4.2 test @@ -90,10 +90,10 @@ maven-antrun-plugin - + - + diff --git a/client-service/src/main/docker/wrapper.sh b/client-service/src/main/docker/wrapper.sh index c31958b..8a3b12a 100644 --- a/client-service/src/main/docker/wrapper.sh +++ b/client-service/src/main/docker/wrapper.sh @@ -28,6 +28,6 @@ echo echo "Starting client service" echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" - +echo env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ java -jar ./client-service.jar diff --git a/client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java b/client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java index 7e581e1..92d97f4 100644 --- a/client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java +++ b/client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java @@ -4,7 +4,6 @@ import com.lohika.jclub.storage.client.StorageServiceClient; import org.junit.ClassRule; -import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/client-service/src/test/resources/application.properties b/client-service/src/test/resources/application.properties index ffb7b0f..c67637e 100644 --- a/client-service/src/test/resources/application.properties +++ b/client-service/src/test/resources/application.properties @@ -1 +1,2 @@ -feign.hystrix.enabled=true \ No newline at end of file +eureka.client.enabled=false +feign.hystrix.enabled=true diff --git a/client-service/src/test/resources/banner.txt b/client-service/src/test/resources/banner.txt new file mode 100644 index 0000000..140d107 --- /dev/null +++ b/client-service/src/test/resources/banner.txt @@ -0,0 +1,6 @@ + _______________________ _________ __ _ + /_ __/ ____/ ___/_ __/ / ____/ (_)__ ____ / /_ ________ ______ __(_)_______ + / / / __/ \__ \ / / / / / / / _ \/ __ \/ __/ / ___/ _ \/ ___/ | / / / ___/ _ \ + / / / /___ ___/ // / / /___/ / / __/ / / / /_ (__ ) __/ / | |/ / / /__/ __/ +/_/ /_____//____//_/ \____/_/_/\___/_/ /_/\__/ /____/\___/_/ |___/_/\___/\___/ + diff --git a/config-server/pom.xml b/config-server/pom.xml index 88b29c2..22fd59d 100644 --- a/config-server/pom.xml +++ b/config-server/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.lohika.jclub + com.lohika.jclub.config config-server 0.0.1-SNAPSHOT jar @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.3.RELEASE + 1.5.4.RELEASE @@ -27,10 +27,6 @@ - - org.springframework.boot - spring-boot-starter-actuator - org.springframework.boot spring-boot-starter-actuator @@ -72,10 +68,10 @@ maven-antrun-plugin - + - + diff --git a/config-server/src/main/docker/wrapper.sh b/config-server/src/main/docker/wrapper.sh index 8edf1a6..30c451d 100644 --- a/config-server/src/main/docker/wrapper.sh +++ b/config-server/src/main/docker/wrapper.sh @@ -21,6 +21,6 @@ echo sleep 15 echo "Starting config server" echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" - +echo env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ java -jar ./config-server.jar diff --git a/config-server/src/main/java/com/lohika/jclub/ConfigServerApplication.java b/config-server/src/main/java/com/lohika/jclub/config/server/ConfigServerApplication.java similarity index 92% rename from config-server/src/main/java/com/lohika/jclub/ConfigServerApplication.java rename to config-server/src/main/java/com/lohika/jclub/config/server/ConfigServerApplication.java index 14a0d57..ce41796 100644 --- a/config-server/src/main/java/com/lohika/jclub/ConfigServerApplication.java +++ b/config-server/src/main/java/com/lohika/jclub/config/server/ConfigServerApplication.java @@ -1,4 +1,4 @@ -package com.lohika.jclub; +package com.lohika.jclub.config.server; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/config-server/src/test/java/com/lohika/jclub/ConfigServerApplicationTests.java b/config-server/src/test/java/com/lohika/jclub/config/server/ConfigServerApplicationTests.java similarity index 88% rename from config-server/src/test/java/com/lohika/jclub/ConfigServerApplicationTests.java rename to config-server/src/test/java/com/lohika/jclub/config/server/ConfigServerApplicationTests.java index f38b62a..7609dcc 100644 --- a/config-server/src/test/java/com/lohika/jclub/ConfigServerApplicationTests.java +++ b/config-server/src/test/java/com/lohika/jclub/config/server/ConfigServerApplicationTests.java @@ -1,4 +1,4 @@ -package com.lohika.jclub; +package com.lohika.jclub.config.server; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/config-server/src/test/resources/application.properties b/config-server/src/test/resources/application.properties new file mode 100644 index 0000000..ba18ddd --- /dev/null +++ b/config-server/src/test/resources/application.properties @@ -0,0 +1,3 @@ +spring.cloud.config.server.git.uri=${JAVA_CLUB_SRC_HOME}/spring-cloud +eureka.client.enabled=false +spring.cloud.config.discovery.enabled=false diff --git a/config-server/src/test/resources/banner.txt b/config-server/src/test/resources/banner.txt new file mode 100644 index 0000000..afa28aa --- /dev/null +++ b/config-server/src/test/resources/banner.txt @@ -0,0 +1,6 @@ + _______________________ ______ _____ + /_ __/ ____/ ___/_ __/ / ____/___ ____ / __(_)___ _ ________ ______ _____ _____ + / / / __/ \__ \ / / / / / __ \/ __ \/ /_/ / __ `/ / ___/ _ \/ ___/ | / / _ \/ ___/ + / / / /___ ___/ // / / /___/ /_/ / / / / __/ / /_/ / (__ ) __/ / | |/ / __/ / +/_/ /_____//____//_/ \____/\____/_/ /_/_/ /_/\__, / /____/\___/_/ |___/\___/_/ + /____/ diff --git a/config-server/src/test/resources/logback-test.xml b/config-server/src/test/resources/logback-test.xml new file mode 100644 index 0000000..d654c6e --- /dev/null +++ b/config-server/src/test/resources/logback-test.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/discovery-server/pom.xml b/discovery-server/pom.xml index 17df683..3eb086f 100644 --- a/discovery-server/pom.xml +++ b/discovery-server/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.lohika.jclub + com.lohika.jclub.discovery discovery-server 0.0.1-SNAPSHOT jar @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.3.RELEASE + 1.5.4.RELEASE @@ -64,10 +64,10 @@ maven-antrun-plugin - + - + diff --git a/discovery-server/src/main/java/com/lohika/jclub/EurekaServerApplication.java b/discovery-server/src/main/java/com/lohika/jclub/discovery/server/EurekaServerApplication.java similarity index 90% rename from discovery-server/src/main/java/com/lohika/jclub/EurekaServerApplication.java rename to discovery-server/src/main/java/com/lohika/jclub/discovery/server/EurekaServerApplication.java index 54c5952..858b42c 100644 --- a/discovery-server/src/main/java/com/lohika/jclub/EurekaServerApplication.java +++ b/discovery-server/src/main/java/com/lohika/jclub/discovery/server/EurekaServerApplication.java @@ -1,4 +1,4 @@ -package com.lohika.jclub; +package com.lohika.jclub.discovery.server; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/discovery-server/src/main/resources/application.properties b/discovery-server/src/main/resources/application.properties index da73450..ff0b0ef 100644 --- a/discovery-server/src/main/resources/application.properties +++ b/discovery-server/src/main/resources/application.properties @@ -1,4 +1,4 @@ -spring.application.name=eureka-server +spring.application.name=discovery-server server.port=8761 eureka.client.register-with-eureka=false diff --git a/discovery-server/src/test/java/com/lohika/jclub/EurekaServerApplicationTests.java b/discovery-server/src/test/java/com/lohika/jclub/discovery/server/EurekaServerApplicationTests.java similarity index 87% rename from discovery-server/src/test/java/com/lohika/jclub/EurekaServerApplicationTests.java rename to discovery-server/src/test/java/com/lohika/jclub/discovery/server/EurekaServerApplicationTests.java index b26359b..2eb3f2b 100644 --- a/discovery-server/src/test/java/com/lohika/jclub/EurekaServerApplicationTests.java +++ b/discovery-server/src/test/java/com/lohika/jclub/discovery/server/EurekaServerApplicationTests.java @@ -1,4 +1,4 @@ -package com.lohika.jclub; +package com.lohika.jclub.discovery.server; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/discovery-server/src/test/resources/banner.txt b/discovery-server/src/test/resources/banner.txt new file mode 100644 index 0000000..01249a8 --- /dev/null +++ b/discovery-server/src/test/resources/banner.txt @@ -0,0 +1,6 @@ + _______________________ ____ _ + /_ __/ ____/ ___/_ __/ / __ \(_)_____________ _ _____ _______ __ ________ ______ _____ _____ + / / / __/ \__ \ / / / / / / / ___/ ___/ __ \ | / / _ \/ ___/ / / / / ___/ _ \/ ___/ | / / _ \/ ___/ + / / / /___ ___/ // / / /_/ / (__ ) /__/ /_/ / |/ / __/ / / /_/ / (__ ) __/ / | |/ / __/ / +/_/ /_____//____//_/ /_____/_/____/\___/\____/|___/\___/_/ \__, / /____/\___/_/ |___/\___/_/ + /____/ diff --git a/discovery-server/src/test/resources/logback-test.xml b/discovery-server/src/test/resources/logback-test.xml new file mode 100644 index 0000000..d654c6e --- /dev/null +++ b/discovery-server/src/test/resources/logback-test.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/dsl/pom.xml b/dsl-core/pom.xml similarity index 90% rename from dsl/pom.xml rename to dsl-core/pom.xml index a8c8164..5dce9d0 100644 --- a/dsl/pom.xml +++ b/dsl-core/pom.xml @@ -4,12 +4,12 @@ 4.0.0 com.lohika.jclub.dsl - dsl + dsl-core 0.0.1-SNAPSHOT jar - DSL - DSL + DSL Core + DSL core UTF-8 @@ -25,6 +25,7 @@ org.apache.maven.plugins maven-compiler-plugin + 3.6.1 groovy-eclipse-compiler @@ -53,12 +54,12 @@ ${groovy.version} - com.lohika.jclub.storage.client + com.lohika.jclub.storage storage-service-client 0.0.1-SNAPSHOT - com.lohika.jclub.rating.client + com.lohika.jclub.rating rating-service-client 0.0.1-SNAPSHOT diff --git a/dsl/src/main/groovy/com/lohika/jclub/dsl/ApartmentDsl.groovy b/dsl-core/src/main/groovy/com/lohika/jclub/dsl/core/ApartmentDsl.groovy similarity index 93% rename from dsl/src/main/groovy/com/lohika/jclub/dsl/ApartmentDsl.groovy rename to dsl-core/src/main/groovy/com/lohika/jclub/dsl/core/ApartmentDsl.groovy index 6edcb53..0e51d14 100644 --- a/dsl/src/main/groovy/com/lohika/jclub/dsl/ApartmentDsl.groovy +++ b/dsl-core/src/main/groovy/com/lohika/jclub/dsl/core/ApartmentDsl.groovy @@ -1,4 +1,4 @@ -package com.lohika.jclub.dsl +package com.lohika.jclub.dsl.core import com.lohika.jclub.storage.client.Apartment import groovy.transform.builder.Builder diff --git a/dsl/src/main/groovy/com/lohika/jclub/dsl/MyDsl.groovy b/dsl-core/src/main/groovy/com/lohika/jclub/dsl/core/MyDsl.groovy similarity index 97% rename from dsl/src/main/groovy/com/lohika/jclub/dsl/MyDsl.groovy rename to dsl-core/src/main/groovy/com/lohika/jclub/dsl/core/MyDsl.groovy index b5ea678..ed8ba84 100644 --- a/dsl/src/main/groovy/com/lohika/jclub/dsl/MyDsl.groovy +++ b/dsl-core/src/main/groovy/com/lohika/jclub/dsl/core/MyDsl.groovy @@ -1,4 +1,4 @@ -package com.lohika.jclub.dsl +package com.lohika.jclub.dsl.core import com.lohika.jclub.rating.client.Apartment import com.lohika.jclub.rating.client.RatingServiceClient diff --git a/dsl/src/main/java/package-info.java b/dsl-core/src/main/java/package-info.java similarity index 100% rename from dsl/src/main/java/package-info.java rename to dsl-core/src/main/java/package-info.java diff --git a/dsl/src/main/resources/idea.gdsl b/dsl-core/src/main/resources/idea.gdsl similarity index 100% rename from dsl/src/main/resources/idea.gdsl rename to dsl-core/src/main/resources/idea.gdsl diff --git a/dsl-executor-service/pom.xml b/dsl-executor-service/pom.xml index e549d27..e7e0e76 100644 --- a/dsl-executor-service/pom.xml +++ b/dsl-executor-service/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.lohika.jclub.dsl.service + com.lohika.jclub.dsl dsl-executor-service 0.0.1-SNAPSHOT jar @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.3.RELEASE + 1.5.4.RELEASE @@ -28,18 +28,23 @@ - com.lohika.jclub.storage.client + com.lohika.jclub.dsl + dsl-core + 0.0.1-SNAPSHOT + + + com.lohika.jclub.storage storage-service-client 0.0.1-SNAPSHOT - com.lohika.jclub.rating.client + com.lohika.jclub.rating rating-service-client 0.0.1-SNAPSHOT - com.lohika.jclub.dsl - dsl + com.lohika.jclub.hackster + hackster-service-client 0.0.1-SNAPSHOT @@ -61,6 +66,12 @@ groovy 2.4.11 + + + org.springframework.boot + spring-boot-starter-test + test + @@ -84,10 +95,10 @@ maven-antrun-plugin - + - + diff --git a/dsl-executor-service/src/main/docker/wrapper.sh b/dsl-executor-service/src/main/docker/wrapper.sh index 571c7b4..9931c0a 100644 --- a/dsl-executor-service/src/main/docker/wrapper.sh +++ b/dsl-executor-service/src/main/docker/wrapper.sh @@ -44,6 +44,6 @@ echo echo "Starting dsl-executor server" echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" - +echo env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ java -jar ./dsl-executor-service.jar diff --git a/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslController.java b/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslController.java index 0ffaf89..4ce0531 100644 --- a/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslController.java +++ b/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslController.java @@ -1,9 +1,8 @@ package com.lohika.jclub.dsl.service; -import com.lohika.jclub.dsl.MyDsl; +import com.lohika.jclub.dsl.core.MyDsl; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -15,9 +14,6 @@ @RequestMapping(path = "/dsl") public class DslController { - @Value("${dsl.basepath}") - private String basepath; - @Autowired private DslService dslService; diff --git a/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslService.java b/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslService.java index f8d61ed..1953e1f 100644 --- a/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslService.java +++ b/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslService.java @@ -3,7 +3,7 @@ import groovy.lang.GroovyShell; import groovy.util.DelegatingScript; -import com.lohika.jclub.dsl.MyDsl; +import com.lohika.jclub.dsl.core.MyDsl; import com.lohika.jclub.rating.client.RatingServiceClient; import com.lohika.jclub.storage.client.StorageServiceClient; diff --git a/dsl-executor-service/src/test/java/com/lohika/jclub/dsl/service/DslServiceApplicationTests.java b/dsl-executor-service/src/test/java/com/lohika/jclub/dsl/service/DslServiceApplicationTests.java new file mode 100644 index 0000000..215e745 --- /dev/null +++ b/dsl-executor-service/src/test/java/com/lohika/jclub/dsl/service/DslServiceApplicationTests.java @@ -0,0 +1,32 @@ +package com.lohika.jclub.dsl.service; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +@ContextConfiguration(initializers = DslServiceApplicationTests.Initializer.class) +public class DslServiceApplicationTests { + + @Test + public void testContextLoad() { + } + + public static class Initializer implements ApplicationContextInitializer { + @Override + public void initialize(ConfigurableApplicationContext configurableApplicationContext) { + + EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(), + "storage-service.ribbon.servers=http://not-existing-url/", + "rating-service.ribbon.servers=http://not-existing-url/", + "hackster-service.ribbon.servers=http://not-existing-url/" + ); + } + } +} diff --git a/dsl-executor-service/src/test/resources/application.properties b/dsl-executor-service/src/test/resources/application.properties new file mode 100644 index 0000000..3da79e9 --- /dev/null +++ b/dsl-executor-service/src/test/resources/application.properties @@ -0,0 +1,3 @@ +eureka.client.enabled=false +feign.hystrix.enabled=true +dsl.basepath=dsl-scripts/ diff --git a/dsl-executor-service/src/test/resources/banner.txt b/dsl-executor-service/src/test/resources/banner.txt new file mode 100644 index 0000000..5776224 --- /dev/null +++ b/dsl-executor-service/src/test/resources/banner.txt @@ -0,0 +1,6 @@ + _______________________ ____ __ __ _ + /_ __/ ____/ ___/_ __/ / __ \_____/ / ___ _ _____ _______ __/ /_____ _____ ________ ______ __(_)_______ + / / / __/ \__ \ / / / / / / ___/ / / _ \| |/_/ _ \/ ___/ / / / __/ __ \/ ___/ / ___/ _ \/ ___/ | / / / ___/ _ \ + / / / /___ ___/ // / / /_/ (__ ) / / __/> + + + + + + \ No newline at end of file diff --git a/hackster-service-client/pom.xml b/hackster-service-client/pom.xml index dd3ffc7..0c8c334 100644 --- a/hackster-service-client/pom.xml +++ b/hackster-service-client/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.lohika.jclub.hackster.client + com.lohika.jclub.hackster hackster-service-client 0.0.1-SNAPSHOT jar @@ -51,7 +51,7 @@ - com.lohika.jclub + com.lohika.jclub.hackster hackster-service 0.0.1-SNAPSHOT test @@ -62,7 +62,7 @@ test - com.lohika.jclub + com.lohika.jclub.discovery discovery-server 0.0.1-SNAPSHOT test @@ -70,7 +70,7 @@ org.testcontainers testcontainers - 1.3.0 + 1.4.2 test diff --git a/hackster-service-client/src/test/java/com/lohika/jclub/hackster/client/HacksterServiceClientTestApplication.java b/hackster-service-client/src/test/java/com/lohika/jclub/hackster/client/HacksterServiceClientTestApplication.java index a581699..869d43c 100644 --- a/hackster-service-client/src/test/java/com/lohika/jclub/hackster/client/HacksterServiceClientTestApplication.java +++ b/hackster-service-client/src/test/java/com/lohika/jclub/hackster/client/HacksterServiceClientTestApplication.java @@ -2,8 +2,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.feign.EnableFeignClients; @EnableHacksterServiceClient +@EnableFeignClients(clients = {HacksterServiceClient.class}) @SpringBootApplication public class HacksterServiceClientTestApplication { diff --git a/hackster-service-client/src/test/resources/application.properties b/hackster-service-client/src/test/resources/application.properties index 6be9bb7..cc29534 100644 --- a/hackster-service-client/src/test/resources/application.properties +++ b/hackster-service-client/src/test/resources/application.properties @@ -1,4 +1,2 @@ spring.application.name=hackster-service-client-testing -feign.hystrix.enabled=true -hackster-service.ribbon.servers=http://localhost:6666/ eureka.client.enabled=false diff --git a/hackster-service-client/src/test/resources/banner.txt b/hackster-service-client/src/test/resources/banner.txt index 56cd009..f3f3f23 100644 --- a/hackster-service-client/src/test/resources/banner.txt +++ b/hackster-service-client/src/test/resources/banner.txt @@ -1,5 +1,6 @@ - _______________________ - /_ __/ ____/ ___/_ __/ - / / / __/ \__ \ / / - / / / /___ ___/ // / -/_/ /_____//____//_/ + _______________________ __ __ __ __ _ ___ __ + /_ __/ ____/ ___/_ __/ / / / /___ ______/ /_______/ /____ _____ ________ ______ __(_)_______ _____/ (_)__ ____ / /_ + / / / __/ \__ \ / / / /_/ / __ `/ ___/ //_/ ___/ __/ _ \/ ___/ / ___/ _ \/ ___/ | / / / ___/ _ \ / ___/ / / _ \/ __ \/ __/ + / / / /___ ___/ // / / __ / /_/ / /__/ ,< (__ ) /_/ __/ / (__ ) __/ / | |/ / / /__/ __/ / /__/ / / __/ / / / /_ +/_/ /_____//____//_/ /_/ /_/\__,_/\___/_/|_/____/\__/\___/_/ /____/\___/_/ |___/_/\___/\___/ \___/_/_/\___/_/ /_/\__/ + diff --git a/hackster-service/pom.xml b/hackster-service/pom.xml index fb2887d..5d22536 100644 --- a/hackster-service/pom.xml +++ b/hackster-service/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.lohika.jclub + com.lohika.jclub.hackster hackster-service 0.0.1-SNAPSHOT jar @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.3.RELEASE + 1.5.4.RELEASE @@ -31,10 +31,6 @@ org.springframework.boot spring-boot-starter-actuator - - org.springframework.boot - spring-boot-starter-actuator - org.springframework.boot spring-boot-starter-web @@ -91,10 +87,10 @@ maven-antrun-plugin - + - + diff --git a/hackster-service/src/main/docker/wrapper.sh b/hackster-service/src/main/docker/wrapper.sh index e1a6688..fb60bab 100644 --- a/hackster-service/src/main/docker/wrapper.sh +++ b/hackster-service/src/main/docker/wrapper.sh @@ -28,6 +28,6 @@ echo echo "Starting hackster service" echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" - +echo env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ java -jar ./hackster-service.jar diff --git a/hackster-service/src/main/java/com/lohika/jclub/Hackster.java b/hackster-service/src/main/java/com/lohika/jclub/service/Hackster.java similarity index 92% rename from hackster-service/src/main/java/com/lohika/jclub/Hackster.java rename to hackster-service/src/main/java/com/lohika/jclub/service/Hackster.java index f8f7c1e..28a3eb9 100644 --- a/hackster-service/src/main/java/com/lohika/jclub/Hackster.java +++ b/hackster-service/src/main/java/com/lohika/jclub/service/Hackster.java @@ -1,4 +1,4 @@ -package com.lohika.jclub; +package com.lohika.jclub.service; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/hackster-service/src/main/java/com/lohika/jclub/HacksterController.java b/hackster-service/src/main/java/com/lohika/jclub/service/HacksterController.java similarity index 95% rename from hackster-service/src/main/java/com/lohika/jclub/HacksterController.java rename to hackster-service/src/main/java/com/lohika/jclub/service/HacksterController.java index ba03389..df4ca73 100644 --- a/hackster-service/src/main/java/com/lohika/jclub/HacksterController.java +++ b/hackster-service/src/main/java/com/lohika/jclub/service/HacksterController.java @@ -1,4 +1,4 @@ -package com.lohika.jclub; +package com.lohika.jclub.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; diff --git a/hackster-service/src/main/java/com/lohika/jclub/HacksterRepository.java b/hackster-service/src/main/java/com/lohika/jclub/service/HacksterRepository.java similarity index 86% rename from hackster-service/src/main/java/com/lohika/jclub/HacksterRepository.java rename to hackster-service/src/main/java/com/lohika/jclub/service/HacksterRepository.java index af26b26..63ea1f4 100644 --- a/hackster-service/src/main/java/com/lohika/jclub/HacksterRepository.java +++ b/hackster-service/src/main/java/com/lohika/jclub/service/HacksterRepository.java @@ -1,4 +1,4 @@ -package com.lohika.jclub; +package com.lohika.jclub.service; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/hackster-service/src/main/java/com/lohika/jclub/HacksterService.java b/hackster-service/src/main/java/com/lohika/jclub/service/HacksterService.java similarity index 97% rename from hackster-service/src/main/java/com/lohika/jclub/HacksterService.java rename to hackster-service/src/main/java/com/lohika/jclub/service/HacksterService.java index b574184..ba10336 100644 --- a/hackster-service/src/main/java/com/lohika/jclub/HacksterService.java +++ b/hackster-service/src/main/java/com/lohika/jclub/service/HacksterService.java @@ -1,4 +1,4 @@ -package com.lohika.jclub; +package com.lohika.jclub.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; diff --git a/hackster-service/src/main/java/com/lohika/jclub/HacksterServiceApplication.java b/hackster-service/src/main/java/com/lohika/jclub/service/HacksterServiceApplication.java similarity index 92% rename from hackster-service/src/main/java/com/lohika/jclub/HacksterServiceApplication.java rename to hackster-service/src/main/java/com/lohika/jclub/service/HacksterServiceApplication.java index 6b3bcf2..b66e144 100644 --- a/hackster-service/src/main/java/com/lohika/jclub/HacksterServiceApplication.java +++ b/hackster-service/src/main/java/com/lohika/jclub/service/HacksterServiceApplication.java @@ -1,4 +1,4 @@ -package com.lohika.jclub; +package com.lohika.jclub.service; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/hackster-service/src/test/java/com/lohika/jclub/HacksterServiceApplicationTests.java b/hackster-service/src/test/java/com/lohika/jclub/service/HacksterServiceApplicationTests.java similarity index 80% rename from hackster-service/src/test/java/com/lohika/jclub/HacksterServiceApplicationTests.java rename to hackster-service/src/test/java/com/lohika/jclub/service/HacksterServiceApplicationTests.java index d5a3b33..2150eac 100644 --- a/hackster-service/src/test/java/com/lohika/jclub/HacksterServiceApplicationTests.java +++ b/hackster-service/src/test/java/com/lohika/jclub/service/HacksterServiceApplicationTests.java @@ -1,9 +1,8 @@ -package com.lohika.jclub; +package com.lohika.jclub.service; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -11,7 +10,6 @@ @RunWith(SpringRunner.class) @SpringBootTest -@AutoConfigureMockMvc public class HacksterServiceApplicationTests { @Autowired private HacksterService hacksterService; diff --git a/hackster-service/src/test/java/com/lohika/jclub/HacksterServiceTests.java b/hackster-service/src/test/java/com/lohika/jclub/service/HacksterServiceTests.java similarity index 97% rename from hackster-service/src/test/java/com/lohika/jclub/HacksterServiceTests.java rename to hackster-service/src/test/java/com/lohika/jclub/service/HacksterServiceTests.java index 469e89c..7fc2df0 100644 --- a/hackster-service/src/test/java/com/lohika/jclub/HacksterServiceTests.java +++ b/hackster-service/src/test/java/com/lohika/jclub/service/HacksterServiceTests.java @@ -1,4 +1,4 @@ -package com.lohika.jclub; +package com.lohika.jclub.service; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/hackster-service/src/test/resources/banner.txt b/hackster-service/src/test/resources/banner.txt new file mode 100644 index 0000000..151fd06 --- /dev/null +++ b/hackster-service/src/test/resources/banner.txt @@ -0,0 +1,6 @@ + _______________________ __ __ __ __ _ + /_ __/ ____/ ___/_ __/ / / / /___ ______/ /_______/ /____ _____ ________ ______ __(_)_______ + / / / __/ \__ \ / / / /_/ / __ `/ ___/ //_/ ___/ __/ _ \/ ___/ / ___/ _ \/ ___/ | / / / ___/ _ \ + / / / /___ ___/ // / / __ / /_/ / /__/ ,< (__ ) /_/ __/ / (__ ) __/ / | |/ / / /__/ __/ +/_/ /_____//____//_/ /_/ /_/\__,_/\___/_/|_/____/\__/\___/_/ /____/\___/_/ |___/_/\___/\___/ + diff --git a/hackster-service/src/test/resources/logback-test.xml b/hackster-service/src/test/resources/logback-test.xml new file mode 100644 index 0000000..d654c6e --- /dev/null +++ b/hackster-service/src/test/resources/logback-test.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/integration-test/pom.xml b/integration-test/pom.xml index 70c18d5..95f1ac4 100644 --- a/integration-test/pom.xml +++ b/integration-test/pom.xml @@ -13,7 +13,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.3.RELEASE + 1.5.4.RELEASE @@ -42,7 +42,7 @@ test - com.lohika.jclub.storage.client + com.lohika.jclub.storage storage-service-client 0.0.1-SNAPSHOT test @@ -57,7 +57,7 @@ org.testcontainers testcontainers - 1.3.0 + 1.4.2 test diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/GetWayIntegrationTest.java b/integration-test/src/test/java/com/lohika/jclub/integration/GetWayIntegrationTest.java index 3106b75..1d76e0b 100644 --- a/integration-test/src/test/java/com/lohika/jclub/integration/GetWayIntegrationTest.java +++ b/integration-test/src/test/java/com/lohika/jclub/integration/GetWayIntegrationTest.java @@ -36,7 +36,7 @@ public static void setUpTests() throws InterruptedException { public void apartmentShouldBeAvailableAfterAdding() { /* GIVEN */ final String email = "mail@domen.com"; - Map params = new HashMap() { + HashMap params = new HashMap() { { put("location", "location"); put("price", 1500.5); diff --git a/integration-test/src/test/resources/application.properties b/integration-test/src/test/resources/application.properties index 8ca1db7..448c158 100644 --- a/integration-test/src/test/resources/application.properties +++ b/integration-test/src/test/resources/application.properties @@ -1 +1,2 @@ spring.application.name=end-to-end-integration-test +feign.hystrix.enabled=true diff --git a/integration-test/src/test/resources/banner.txt b/integration-test/src/test/resources/banner.txt index 43516dd..01d4e05 100644 --- a/integration-test/src/test/resources/banner.txt +++ b/integration-test/src/test/resources/banner.txt @@ -1,5 +1,6 @@ - _______ ______ __ _______ ______ ______ __ - / ____/ | / / __ \ / /_____ / ____/ | / / __ \ /_ __/__ _____/ /______ - / __/ / |/ / / / / / __/ __ \ / __/ / |/ / / / / / / / _ \/ ___/ __/ ___/ - / /___/ /| / /_/ / / /_/ /_/ / / /___/ /| / /_/ / / / / __(__ ) /_(__ ) -/_____/_/ |_/_____/ \__/\____/ /_____/_/ |_/_____/ /_/ \___/____/\__/____/ + ____ __ __ _ __ __ + / _/___ / /____ ____ __________ _/ /_(_)___ ____ / /____ _____/ /_ + / // __ \/ __/ _ \/ __ `/ ___/ __ `/ __/ / __ \/ __ \ / __/ _ \/ ___/ __/ + _/ // / / / /_/ __/ /_/ / / / /_/ / /_/ / /_/ / / / / / /_/ __(__ ) /_ +/___/_/ /_/\__/\___/\__, /_/ \__,_/\__/_/\____/_/ /_/ \__/\___/____/\__/ + /____/ diff --git a/integration-test/src/test/resources/logback-test.xml b/integration-test/src/test/resources/logback-test.xml index 3fcefa8..d654c6e 100644 --- a/integration-test/src/test/resources/logback-test.xml +++ b/integration-test/src/test/resources/logback-test.xml @@ -1,8 +1,7 @@ - + - - - - + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index ddcec56..8d6919b 100644 --- a/pom.xml +++ b/pom.xml @@ -12,17 +12,17 @@ Spring cloud application - config-server - dsl - dsl-executor-service discovery-server + config-server rating-service rating-service-client hackster-service hackster-service-client - realtor-service storage-service storage-service-client + dsl-core + dsl-executor-service + realtor-service client-service api-gateway-service integration-test diff --git a/rating-service-client/pom.xml b/rating-service-client/pom.xml index 2773619..b5ec557 100644 --- a/rating-service-client/pom.xml +++ b/rating-service-client/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.lohika.jclub.rating.client + com.lohika.jclub.rating rating-service-client 0.0.1-SNAPSHOT jar @@ -49,7 +49,7 @@ true - com.lohika.jclub + com.lohika.jclub.discovery discovery-server 0.0.1-SNAPSHOT test @@ -57,11 +57,11 @@ org.testcontainers testcontainers - 1.3.0 + 1.4.2 test - com.lohika.jclub.rating.service + com.lohika.jclub.rating rating-service 0.0.1-SNAPSHOT test diff --git a/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientFallbackTest.java b/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientFallbackTest.java index 32d4be2..66d779c 100644 --- a/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientFallbackTest.java +++ b/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientFallbackTest.java @@ -4,6 +4,10 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import static org.hamcrest.Matchers.nullValue; @@ -11,6 +15,7 @@ @RunWith(SpringRunner.class) @SpringBootTest(classes = RatingServiceClientTestApplication.class) +@ContextConfiguration(initializers = RatingServiceClientFallbackTest.Initializer.class) public class RatingServiceClientFallbackTest { @Autowired @@ -29,4 +34,14 @@ public void getRating() { assertThat(actual, nullValue()); } + + public static class Initializer implements ApplicationContextInitializer { + @Override + public void initialize(ConfigurableApplicationContext configurableApplicationContext) { + + EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(), + "rating-service.ribbon.servers=http://not-existing-url/" + ); + } + } } diff --git a/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTestApplication.java b/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTestApplication.java index 63e5ae9..ccdb620 100644 --- a/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTestApplication.java +++ b/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTestApplication.java @@ -2,10 +2,8 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; -@EnableDiscoveryClient @EnableRatingServiceClient @EnableFeignClients(clients = {RatingServiceClient.class}) @SpringBootApplication diff --git a/rating-service-client/src/test/resources/application.properties b/rating-service-client/src/test/resources/application.properties index 788b4c2..fccaf41 100644 --- a/rating-service-client/src/test/resources/application.properties +++ b/rating-service-client/src/test/resources/application.properties @@ -1,3 +1,3 @@ spring.application.name=rating-service-client-testing feign.hystrix.enabled=true -rating-service.ribbon.servers=http://localhost:6666/ +eureka.client.enabled=false diff --git a/rating-service-client/src/test/resources/banner.txt b/rating-service-client/src/test/resources/banner.txt index 56cd009..795c250 100644 --- a/rating-service-client/src/test/resources/banner.txt +++ b/rating-service-client/src/test/resources/banner.txt @@ -1,5 +1,6 @@ - _______________________ - /_ __/ ____/ ___/_ __/ - / / / __/ \__ \ / / - / / / /___ ___/ // / -/_/ /_____//____//_/ + _______________________ ____ __ _ _ ___ __ + /_ __/ ____/ ___/_ __/ / __ \____ _/ /_(_)___ ____ _ ________ ______ __(_)_______ _____/ (_)__ ____ / /_ + / / / __/ \__ \ / / / /_/ / __ `/ __/ / __ \/ __ `/ / ___/ _ \/ ___/ | / / / ___/ _ \ / ___/ / / _ \/ __ \/ __/ + / / / /___ ___/ // / / _, _/ /_/ / /_/ / / / / /_/ / (__ ) __/ / | |/ / / /__/ __/ / /__/ / / __/ / / / /_ +/_/ /_____//____//_/ /_/ |_|\__,_/\__/_/_/ /_/\__, / /____/\___/_/ |___/_/\___/\___/ \___/_/_/\___/_/ /_/\__/ + /____/ diff --git a/rating-service/pom.xml b/rating-service/pom.xml index 3994c16..2514355 100644 --- a/rating-service/pom.xml +++ b/rating-service/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.lohika.jclub.rating.service + com.lohika.jclub.rating rating-service 0.0.1-SNAPSHOT jar @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.3.RELEASE + 1.5.4.RELEASE @@ -31,10 +31,6 @@ org.springframework.boot spring-boot-starter-actuator - - org.springframework.boot - spring-boot-starter-actuator - org.springframework.boot spring-boot-starter-web @@ -51,7 +47,6 @@ org.projectlombok lombok - 1.16.16 @@ -83,10 +78,10 @@ maven-antrun-plugin - + - + diff --git a/rating-service/src/main/docker/wrapper.sh b/rating-service/src/main/docker/wrapper.sh index bd38cac..a72a599 100644 --- a/rating-service/src/main/docker/wrapper.sh +++ b/rating-service/src/main/docker/wrapper.sh @@ -28,6 +28,6 @@ echo echo "Starting rating service" echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" - +echo env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ java -jar ./rating-service.jar diff --git a/rating-service/src/test/resources/application.properties b/rating-service/src/test/resources/application.properties index f3f2ed0..5cafea3 100644 --- a/rating-service/src/test/resources/application.properties +++ b/rating-service/src/test/resources/application.properties @@ -1 +1,2 @@ rate=100 +eureka.client.enabled=false diff --git a/rating-service/src/test/resources/banner.txt b/rating-service/src/test/resources/banner.txt new file mode 100644 index 0000000..62e4743 --- /dev/null +++ b/rating-service/src/test/resources/banner.txt @@ -0,0 +1,6 @@ + _______________________ ____ __ _ _ + /_ __/ ____/ ___/_ __/ / __ \____ _/ /_(_)___ ____ _ ________ ______ __(_)_______ + / / / __/ \__ \ / / / /_/ / __ `/ __/ / __ \/ __ `/ / ___/ _ \/ ___/ | / / / ___/ _ \ + / / / /___ ___/ // / / _, _/ /_/ / /_/ / / / / /_/ / (__ ) __/ / | |/ / / /__/ __/ +/_/ /_____//____//_/ /_/ |_|\__,_/\__/_/_/ /_/\__, / /____/\___/_/ |___/_/\___/\___/ + /____/ diff --git a/rating-service/src/test/resources/logback-test.xml b/rating-service/src/test/resources/logback-test.xml new file mode 100644 index 0000000..d654c6e --- /dev/null +++ b/rating-service/src/test/resources/logback-test.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/realtor-service/pom.xml b/realtor-service/pom.xml index 04fbd7c..4673c32 100644 --- a/realtor-service/pom.xml +++ b/realtor-service/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.3.RELEASE + 1.5.4.RELEASE @@ -28,15 +28,11 @@ - com.lohika.jclub.storage.client + com.lohika.jclub.storage storage-service-client 0.0.1-SNAPSHOT - - org.springframework.boot - spring-boot-starter-actuator - org.springframework.boot spring-boot-starter-actuator @@ -60,6 +56,12 @@ 1.16.12 + + org.testcontainers + testcontainers + 1.4.2 + test + org.springframework.boot spring-boot-starter-test @@ -88,10 +90,10 @@ maven-antrun-plugin - + - + diff --git a/realtor-service/src/main/docker/wrapper.sh b/realtor-service/src/main/docker/wrapper.sh index 262851e..bde66f0 100644 --- a/realtor-service/src/main/docker/wrapper.sh +++ b/realtor-service/src/main/docker/wrapper.sh @@ -44,6 +44,6 @@ echo echo "Starting realtor service" echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" - +echo env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ java -jar ./realtor-service.jar diff --git a/realtor-service/src/test/java/com/lohika/jclub/realtor/RealtorServiceApplicationTests.java b/realtor-service/src/test/java/com/lohika/jclub/realtor/RealtorServiceApplicationTests.java index ae082e5..1487163 100644 --- a/realtor-service/src/test/java/com/lohika/jclub/realtor/RealtorServiceApplicationTests.java +++ b/realtor-service/src/test/java/com/lohika/jclub/realtor/RealtorServiceApplicationTests.java @@ -2,16 +2,23 @@ import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.ClassRule; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.LogMessageWaitStrategy; import javax.ws.rs.core.MediaType; @@ -20,7 +27,22 @@ @RunWith(SpringRunner.class) @SpringBootTest @AutoConfigureMockMvc +@ContextConfiguration(initializers = RealtorServiceApplicationTests.Initializer.class) public class RealtorServiceApplicationTests { + private static final int MAX_ALLOWED_APARTMENTS_PER_REALTOR = 4; + + @ClassRule + public static GenericContainer storageService = new GenericContainer("storage-service:latest") + .withExposedPorts(8091) + .waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started StorageServiceApplication in.*\\s")); + + @ClassRule + public static GenericContainer HacksterService = new GenericContainer("hackster-service:latest") + .withExposedPorts(8082) + .withEnv("maxAllowedApartmentsPerRealtor", Integer.toString(MAX_ALLOWED_APARTMENTS_PER_REALTOR)) + .withEnv("spring.cloud.config.discovery.enabled", "false") + .withEnv("spring.cloud.config.fail-fast", "false") + .waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started HacksterServiceApplication in.*\\s")); @Autowired private MockMvc mockMvc; @@ -30,20 +52,33 @@ public void contextLoads() throws Exception { } @Test - @Ignore public void apartments() throws Exception { ApartmentRecord apartmentRecord = ApartmentRecord.builder() .phone("123") .realtorName("Anna Realtor") .sqft(44) .price(100) + .mail("mail") .location("Lviv").build(); mockMvc.perform(MockMvcRequestBuilders - .post("/apartments") + .post("/storeApartments") .contentType(MediaType.APPLICATION_JSON) .content(new ObjectMapper().writeValueAsBytes(apartmentRecord))) .andDo(MockMvcResultHandlers.print()) .andExpect(status().isOk()); } + + public static class Initializer implements ApplicationContextInitializer { + @Override + public void initialize(ConfigurableApplicationContext configurableApplicationContext) { + + EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(), + "storage-service.ribbon.servers=http://" + storageService.getContainerIpAddress() + ":" + + storageService.getMappedPort(8091) + "/", + "hackster-service.ribbon.servers=http://" + HacksterService.getContainerIpAddress() + ":" + + HacksterService.getMappedPort(8082) + "/" + ); + } + } } diff --git a/realtor-service/src/test/resources/application.properties b/realtor-service/src/test/resources/application.properties new file mode 100644 index 0000000..c67637e --- /dev/null +++ b/realtor-service/src/test/resources/application.properties @@ -0,0 +1,2 @@ +eureka.client.enabled=false +feign.hystrix.enabled=true diff --git a/realtor-service/src/test/resources/banner.txt b/realtor-service/src/test/resources/banner.txt new file mode 100644 index 0000000..f9717fa --- /dev/null +++ b/realtor-service/src/test/resources/banner.txt @@ -0,0 +1,6 @@ + _______________________ ____ ____ _ + /_ __/ ____/ ___/_ __/ / __ \___ ____ _/ / /_____ _____ ________ ______ __(_)_______ + / / / __/ \__ \ / / / /_/ / _ \/ __ `/ / __/ __ \/ ___/ / ___/ _ \/ ___/ | / / / ___/ _ \ + / / / /___ ___/ // / / _, _/ __/ /_/ / / /_/ /_/ / / (__ ) __/ / | |/ / / /__/ __/ +/_/ /_____//____//_/ /_/ |_|\___/\__,_/_/\__/\____/_/ /____/\___/_/ |___/_/\___/\___/ + diff --git a/realtor-service/src/test/resources/logback-test.xml b/realtor-service/src/test/resources/logback-test.xml new file mode 100644 index 0000000..d654c6e --- /dev/null +++ b/realtor-service/src/test/resources/logback-test.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/storage-service-client/pom.xml b/storage-service-client/pom.xml index 87be175..ec05e52 100644 --- a/storage-service-client/pom.xml +++ b/storage-service-client/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.lohika.jclub.storage.client + com.lohika.jclub.storage storage-service-client 0.0.1-SNAPSHOT jar @@ -45,13 +45,13 @@ - com.lohika.jclub + com.lohika.jclub.discovery discovery-server 0.0.1-SNAPSHOT test - com.lohika.jclub.storage.service + com.lohika.jclub.storage storage-service 0.0.1-SNAPSHOT test @@ -64,7 +64,7 @@ org.testcontainers testcontainers - 1.3.0 + 1.4.2 test diff --git a/storage-service-client/src/test/java/com/lohika/jclub/storage/client/StorageServiceClientFallbackTest.java b/storage-service-client/src/test/java/com/lohika/jclub/storage/client/StorageServiceClientFallbackTest.java index 5e388ba..d1b7164 100644 --- a/storage-service-client/src/test/java/com/lohika/jclub/storage/client/StorageServiceClientFallbackTest.java +++ b/storage-service-client/src/test/java/com/lohika/jclub/storage/client/StorageServiceClientFallbackTest.java @@ -4,7 +4,11 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.hateoas.PagedResources; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import static org.hamcrest.Matchers.hasSize; @@ -14,6 +18,7 @@ @RunWith(SpringRunner.class) @SpringBootTest(classes = StorageServiceClientTestApplication.class) +@ContextConfiguration(initializers = StorageServiceClientFallbackTest.Initializer.class) public class StorageServiceClientFallbackTest { @Autowired @@ -63,4 +68,14 @@ public void update() { public void delete() { storageServiceClient.delete("not-existing-id"); } + + public static class Initializer implements ApplicationContextInitializer { + @Override + public void initialize(ConfigurableApplicationContext configurableApplicationContext) { + + EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(), + "storage-service.ribbon.servers=http://not-existing-url/" + ); + } + } } diff --git a/storage-service-client/src/test/resources/application.properties b/storage-service-client/src/test/resources/application.properties index 9d4c8b6..c67637e 100644 --- a/storage-service-client/src/test/resources/application.properties +++ b/storage-service-client/src/test/resources/application.properties @@ -1,3 +1,2 @@ -spring.application.name=storage-service-client-testing +eureka.client.enabled=false feign.hystrix.enabled=true -storage-service.ribbon.servers=http://localhost:6666/ diff --git a/storage-service-client/src/test/resources/banner.txt b/storage-service-client/src/test/resources/banner.txt index 30c2015..32a8c06 100644 --- a/storage-service-client/src/test/resources/banner.txt +++ b/storage-service-client/src/test/resources/banner.txt @@ -1,6 +1,6 @@ - _______________________ _____ __ _ ___ __ - /_ __/ ____/ ___/_ __/ / ___// /_____ _________ _____ ____ ________ ______ __(_)_______ _____/ (_)__ ____ / /_ - / / / __/ \__ \ / / \__ \/ __/ __ \/ ___/ __ `/ __ `/ _ \ / ___/ _ \/ ___/ | / / / ___/ _ \ / ___/ / / _ \/ __ \/ __/ - / / / /___ ___/ // / ___/ / /_/ /_/ / / / /_/ / /_/ / __/ (__ ) __/ / | |/ / / /__/ __/ / /__/ / / __/ / / / /_ -/_/ /_____//____//_/ /____/\__/\____/_/ \__,_/\__, /\___/ /____/\___/_/ |___/_/\___/\___/ \___/_/_/\___/_/ /_/\__/ - /____/ + _______________________ _____ __ _ ___ __ + /_ __/ ____/ ___/_ __/ / ___// /_____ _________ _____ ____ ________ ______ __(_)_______ _____/ (_)__ ____ / /_ + / / / __/ \__ \ / / \__ \/ __/ __ \/ ___/ __ `/ __ `/ _ \ / ___/ _ \/ ___/ | / / / ___/ _ \ / ___/ / / _ \/ __ \/ __/ + / / / /___ ___/ // / ___/ / /_/ /_/ / / / /_/ / /_/ / __/ (__ ) __/ / | |/ / / /__/ __/ / /__/ / / __/ / / / /_ +/_/ /_____//____//_/ /____/\__/\____/_/ \__,_/\__, /\___/ /____/\___/_/ |___/_/\___/\___/ \___/_/_/\___/_/ /_/\__/ + /____/ diff --git a/storage-service/pom.xml b/storage-service/pom.xml index f502d7b..a6f9f10 100644 --- a/storage-service/pom.xml +++ b/storage-service/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.lohika.jclub.storage.service + com.lohika.jclub.storage storage-service 0.0.1-SNAPSHOT jar @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.3.RELEASE + 1.5.4.RELEASE @@ -84,10 +84,10 @@ maven-antrun-plugin - + - + diff --git a/storage-service/src/main/docker/wrapper.sh b/storage-service/src/main/docker/wrapper.sh index d32f932..ca84638 100644 --- a/storage-service/src/main/docker/wrapper.sh +++ b/storage-service/src/main/docker/wrapper.sh @@ -21,6 +21,6 @@ echo sleep 15 echo "Starting storage server" echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" - +echo env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \ java -jar ./storage-service.jar diff --git a/storage-service/src/test/resources/application.properties b/storage-service/src/test/resources/application.properties new file mode 100644 index 0000000..45cb06e --- /dev/null +++ b/storage-service/src/test/resources/application.properties @@ -0,0 +1 @@ +eureka.client.enabled=false diff --git a/storage-service/src/test/resources/banner.txt b/storage-service/src/test/resources/banner.txt new file mode 100644 index 0000000..a0253c5 --- /dev/null +++ b/storage-service/src/test/resources/banner.txt @@ -0,0 +1,6 @@ + _______________________ _____ __ _ + /_ __/ ____/ ___/_ __/ / ___// /_____ _________ _____ ____ ________ ______ __(_)_______ + / / / __/ \__ \ / / \__ \/ __/ __ \/ ___/ __ `/ __ `/ _ \ / ___/ _ \/ ___/ | / / / ___/ _ \ + / / / /___ ___/ // / ___/ / /_/ /_/ / / / /_/ / /_/ / __/ (__ ) __/ / | |/ / / /__/ __/ +/_/ /_____//____//_/ /____/\__/\____/_/ \__,_/\__, /\___/ /____/\___/_/ |___/_/\___/\___/ + /____/ diff --git a/storage-service/src/test/resources/logback-test.xml b/storage-service/src/test/resources/logback-test.xml new file mode 100644 index 0000000..d654c6e --- /dev/null +++ b/storage-service/src/test/resources/logback-test.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file