From ef2c9896b1c5212ebc704d732f5f1a6ff1b6c26b Mon Sep 17 00:00:00 2001 From: Isabella Date: Fri, 27 Jul 2018 10:33:20 -0400 Subject: [PATCH 01/59] Add notification service to docker compose --- docker-compose.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index e343d0d..b7c4d9f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,18 @@ services: depends_on: - discoveryservice + notificationservice: + depends_on: + - discoveryservice + - rabbitmq + image: aista/notification-service + command: notification-service + ports: + - "32700:32700" + environment: + - RABBIT_HOST=rabbitmq + - EUREKA_SERVER=discoveryservice + discoveryservice: image: aista/eureka ports: From d221cd38e90b317cb662414d2caedc2bb0da4024 Mon Sep 17 00:00:00 2001 From: Isabella Date: Fri, 27 Jul 2018 10:59:21 -0400 Subject: [PATCH 02/59] Fix spacing --- docker-compose.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index b7c4d9f..ba72bdf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,16 +10,16 @@ services: - discoveryservice notificationservice: - depends_on: - - discoveryservice - - rabbitmq - image: aista/notification-service - command: notification-service - ports: - - "32700:32700" - environment: - - RABBIT_HOST=rabbitmq - - EUREKA_SERVER=discoveryservice + depends_on: + - discoveryservice + - rabbitmq + image: aista/notification-service + command: notification-service + ports: + - "32700:32700" + environment: + - RABBIT_HOST=rabbitmq + - EUREKA_SERVER=discoveryservice discoveryservice: image: aista/eureka From dd92e3daf69c5164ed2e5939a7a60a89a671f859 Mon Sep 17 00:00:00 2001 From: jusoto Date: Mon, 30 Jul 2018 17:31:19 -0400 Subject: [PATCH 03/59] Changed Docker-Compose version to 2.3 to run tests in order to limit memory usage per service. Added a waiting line for trim-cmd, trip-query and gmaps-adapter --- .../EdgeServiceIntegrationTests.java | 19 +++++++++++++---- src/test/resources/docker-compose.yml | 21 ++++++++++++++++++- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 0f6f907..f37dd61 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -39,16 +39,15 @@ public class EdgeServiceIntegrationTests { @ClassRule public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) .file("src/test/resources/docker-compose.yml") - .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("discoveryservice", HealthChecks.toRespondOverHttp(8761, - (port) -> port.inFormat("http://localhost:8761"))) .build(); //Get IP addresses and ports to run tests on @@ -59,18 +58,30 @@ public static void initialize() { .port(8080); tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), tripManagementCommand.getExternalPort()); + while (!docker.containers().container("tripmanagementcmd").portIsListeningOnHttp(8080, + (port) -> port.inFormat(tripCommandURL)).succeeded()) { + LOG.info("Waiting for Trip Command to respond over HTTP"); + } LOG.info("Trip Command url found: " + tripCommandURL); DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery") .port(8080); tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(), tripManagementQuery.getExternalPort()); + while (!docker.containers().container("tripmanagementquery").portIsListeningOnHttp(8080, + (port) -> port.inFormat(tripQueryURL)).succeeded()) { + LOG.info("Waiting for Trip Query to respond over HTTP"); + } LOG.info("Trip Query url found: " + tripQueryURL); DockerPort gmapsAdapter = docker.containers().container("gmapsadapter") .port(8080); gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); + while (!docker.containers().container("gmapsadapter").portIsListeningOnHttp(8080, + (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { + LOG.info("Waiting for user service to respond over HTTP"); + } LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); DockerPort calculationService = docker.containers().container("calculationservice") diff --git a/src/test/resources/docker-compose.yml b/src/test/resources/docker-compose.yml index 9c53a4c..85cf43c 100644 --- a/src/test/resources/docker-compose.yml +++ b/src/test/resources/docker-compose.yml @@ -1,14 +1,16 @@ -version: '3' +version: '2.3' services: discoveryservice: image: aista/eureka + mem_limit: 512M ports: - "8761:8761" mysqlserver: image: mysql:5.7 + mem_limit: 512M volumes: - mysql-data:/var/lib/mysql:rw restart: always @@ -23,15 +25,19 @@ services: userservice: image: aista/user-service + mem_limit: 512M container_name: userservice depends_on: - discoveryservice - mysqlserver ports: - '8080' + environment: + - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC mongo: image: 'mongo:3.4.1' + mem_limit: 512M container_name: 'mongo' ports: - '27017:27017' @@ -40,6 +46,7 @@ services: rabbitmq: image: rabbitmq:management + mem_limit: 512M container_name: 'rabbitmq' ports: - "5672:5672" @@ -47,6 +54,7 @@ services: tripmanagementcmd: image: aista/trip-management-cmd + mem_limit: 512M environment: - RABBIT_HOST=rabbitmq - MONGO_HOST=mongo @@ -56,9 +64,12 @@ services: - discoveryservice - rabbitmq - mongo + environment: + - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC tripmanagementquery: image: aista/trip-management-query + mem_limit: 512M environment: - RABBIT_HOST=rabbitmq - MONGO_HOST=mongo @@ -68,20 +79,28 @@ services: - rabbitmq - mongo - discoveryservice + environment: + - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC gmapsadapter: image: aista/gmaps-adapter + mem_limit: 512M environment: - EUREKA_SERVER=discoveryservice + - RABBIT_HOST=rabbitmq ports: - '8080' depends_on: - discoveryservice + environment: + - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC calculationservice: image: aista/calculation-service + mem_limit: 512M environment: - EUREKA_SERVER=discoveryservice + - RABBIT_HOST=rabbitmq command: ["go", "run", "main.go"] ports: - '8080' From d2d370a51a2d26e48c02f6e204775c6fdb4140a7 Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 17 Aug 2018 15:24:46 -0400 Subject: [PATCH 04/59] Changes: - docker-compose version to 2.3 to allow mem_limit per container due to excesive use of memory when launching docker-compose.yml services. - added in IntegrationTests userId for CalculationService new required field - added local profile in application.yml to allow debug edge-service locally --- docker-compose.yml | 103 +++++++------ .../edge/edgeservice/ConfigurationCORS.java | 6 +- src/main/resources/application.yml | 40 ++++- src/main/resources/bootstrap.yml | 9 ++ .../EdgeServiceIntegrationTests.java | 143 ++++++++++-------- src/test/resources/docker-compose.yml | 2 + 6 files changed, 190 insertions(+), 113 deletions(-) create mode 100644 src/main/resources/bootstrap.yml diff --git a/docker-compose.yml b/docker-compose.yml index ba72bdf..29f599a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,10 @@ -version: '3' +version: '2.3' services: edgeservice: image: aista/edge-service + mem_limit: 512M ports: - "8080:8080" depends_on: @@ -14,6 +15,7 @@ services: - discoveryservice - rabbitmq image: aista/notification-service + mem_limit: 512M command: notification-service ports: - "32700:32700" @@ -23,6 +25,7 @@ services: discoveryservice: image: aista/eureka + mem_limit: 512M ports: - "8761:8761" @@ -44,6 +47,7 @@ services: mysqlserver: image: mysql:5.7 + mem_limit: 512M volumes: - mysql-data:/var/lib/mysql:rw restart: always @@ -58,6 +62,7 @@ services: userservice: image: aista/user-service + mem_limit: 512M depends_on: - discoveryservice - mysqlserver @@ -66,27 +71,30 @@ services: mongo: image: 'mongo:3.4.1' + mem_limit: 512M container_name: 'mongo' ports: - '27017:27017' volumes: - 'mongo:/data/db' - postgres: - image: postgres - restart: always - environment: - POSTGRES_DB: 'passenger_db' - POSTGRES_PASSWORD: "admin" - POSTGRES_USER: "admin" - PGDATA: ./postgres-data - ports: - - '5432:5432' - volumes: - - ./db_volume:/var/lib/postgresql +# postgres: +# image: postgres +# mem_limit: 512M +# restart: always +# environment: +# POSTGRES_DB: 'passenger_db' +# POSTGRES_PASSWORD: "admin" +# POSTGRES_USER: "admin" +# PGDATA: ./postgres-data +# ports: +# - '5432:5432' +# volumes: +# - ./db_volume:/var/lib/postgresql rabbitmq: image: rabbitmq:management + mem_limit: 512M container_name: 'rabbitmq' ports: - "5672:5672" @@ -94,6 +102,7 @@ services: tripmanagementcmd: image: aista/trip-management-cmd + mem_limit: 512M environment: - RABBIT_HOST=rabbitmq - MONGO_HOST=mongo @@ -106,6 +115,7 @@ services: tripmanagementquery: image: aista/trip-management-query + mem_limit: 512M environment: - RABBIT_HOST=rabbitmq - MONGO_HOST=mongo @@ -118,6 +128,7 @@ services: gmaps-adapter: image: aista/gmaps-adapter + mem_limit: 512M environment: - EUREKA_SERVER=discoveryservice - RABBIT_HOST=rabbitmq @@ -128,6 +139,7 @@ services: calculation-service: image: aista/calculation-service + mem_limit: 512M environment: - EUREKA_SERVER=discoveryservice - RABBIT_HOST=rabbitmq @@ -137,37 +149,40 @@ services: depends_on: - discoveryservice - passenger: - image: aista/passenger - ports: - - '8080' - depends_on: - - postgres - - discoveryservice - - driver-cmd: - image: aista/driver-cmd - environment: - - EUREKA_SERVER=discoveryservice - ports: - - '8080' - depends_on: - - rabbitmq - - mongo - - discoveryservice - - driver-query: - image: aista/driver-query - container_name: 'driver-query' - environment: - - RABBIT_HOST=rabbitmq - - MONGO_HOST=mongo - ports: - - "8080" - depends_on: - - rabbitmq - - mongo - - discoveryservice +# passenger: +# image: aista/passenger +# mem_limit: 512M +# ports: +# - '8080' +# depends_on: +# - postgres +# - discoveryservice +# +# driver-cmd: +# image: aista/driver-cmd +# mem_limit: 512M +# environment: +# - EUREKA_SERVER=discoveryservice +# ports: +# - '8080' +# depends_on: +# - rabbitmq +# - mongo +# - discoveryservice +# +# driver-query: +# image: aista/driver-query +# mem_limit: 512M +# container_name: 'driver-query' +# environment: +# - RABBIT_HOST=rabbitmq +# - MONGO_HOST=mongo +# ports: +# - "8080" +# depends_on: +# - rabbitmq +# - mongo +# - discoveryservice volumes: mongo: diff --git a/src/main/java/aist/edge/edgeservice/ConfigurationCORS.java b/src/main/java/aist/edge/edgeservice/ConfigurationCORS.java index 6170d9d..28344f0 100644 --- a/src/main/java/aist/edge/edgeservice/ConfigurationCORS.java +++ b/src/main/java/aist/edge/edgeservice/ConfigurationCORS.java @@ -1,6 +1,6 @@ package aist.edge.edgeservice; - +import java.util.Arrays; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -10,8 +10,6 @@ import org.springframework.web.cors.CorsConfigurationSource; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import java.util.Arrays; - @Configuration public class ConfigurationCORS extends WebSecurityConfigurerAdapter { @@ -21,7 +19,7 @@ protected void configure(HttpSecurity http) throws Exception { } @Bean - public CorsConfigurationSource corsConfigurationSource() { + public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); configuration.setAllowedOrigins(Arrays.asList("*")); configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 7232638..c4b0701 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,6 +1,3 @@ -spring: - profiles: - active: development --- spring: profiles: development @@ -36,6 +33,7 @@ management: security: enabled: false context-path: /actuator + --- spring: profiles: docker @@ -68,6 +66,42 @@ eureka: serviceUrl: defaultZone: http://discoveryservice:8761/eureka/ hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000 +ribbon: + ConnectTimeout: 3000 +ReadTimeout: 60000 + +--- +spring: + profiles: local + application: + name: edgeservice +zuul: + prefix: /api + routes: + trip-cmd: + path: /trip/cmd/** + url: http://${DOCKER_MACHINE_IP:localhost}:8080/api + trip-query: + path: /trip/query/** + url: http://${DOCKER_MACHINE_IP:localhost}:8080/api + userservice: + path: /userservice/** + url: http://${DOCKER_MACHINE_IP:localhost}:8080/ + sensitiveHeaders: Cookie,Set-Cookie +security: + oauth2: + resource: + userInfoUri: http://${DOCKER_MACHINE_IP:localhost}:8080/auth/user + ignored: /catalog/** +eureka: + instance: + prefer-ip-address: true + client: + registerWithEureka: true + fetchRegistry: true + serviceUrl: + defaultZone: http://${DOCKER_MACHINE_IP:localhost}:8761/eureka/ +hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000 ribbon: ConnectTimeout: 3000 ReadTimeout: 60000 \ No newline at end of file diff --git a/src/main/resources/bootstrap.yml b/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..ac4fd43 --- /dev/null +++ b/src/main/resources/bootstrap.yml @@ -0,0 +1,9 @@ +spring: + application: + name: edgeservice + profiles: + active: development + cloud: + config: + uri: http://${CONFIGURATION_HOST:localhost}:8888 + enabled: true diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index f37dd61..fe390dc 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -29,13 +29,15 @@ public class EdgeServiceIntegrationTests { protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTests.class); + private static String discoveryServiceURL; + private static String mongoURL; + private static String userServiceURL; private static String tripCommandURL; private static String tripQueryURL; private static String gmapsAdapterURL; private static String calculationServiceURL; - private static String userServiceURL; - //Wait for all services to have ports open + // Wait for all services to have ports open @ClassRule public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) .file("src/test/resources/docker-compose.yml") @@ -47,62 +49,73 @@ public class EdgeServiceIntegrationTests { .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()) - .build(); + .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()).build(); - //Get IP addresses and ports to run tests on + // Get IP addresses and ports to run tests on @BeforeClass public static void initialize() { + LOG.info("Initializing ports from Docker"); - DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd") - .port(8080); + + DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); + discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), + discoveryService.getExternalPort()); + while (!docker.containers().container("discoveryservice") + .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { + LOG.info("Waiting for discovery service to respond over HTTP"); + } + LOG.info("Discovery Service url found: " + discoveryServiceURL); + + DockerPort mongo = docker.containers().container("mongo").port(27017); + mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); + while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) + .succeeded()) { + LOG.info("Waiting for mongo to respond over HTTP"); + } + LOG.info("Mongo url found: " + mongoURL); + + DockerPort userService = docker.containers().container("userservice").port(8080); + userServiceURL = String.format("http://%s:%s", userService.getIp(), userService.getExternalPort()); + while (!docker.containers().container("userservice") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { + LOG.info("Waiting for user service to respond over HTTP"); + } + LOG.info("User Service url found: " + userServiceURL); + + DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd").port(8080); tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), tripManagementCommand.getExternalPort()); - while (!docker.containers().container("tripmanagementcmd").portIsListeningOnHttp(8080, - (port) -> port.inFormat(tripCommandURL)).succeeded()) { + while (!docker.containers().container("tripmanagementcmd") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripCommandURL)).succeeded()) { LOG.info("Waiting for Trip Command to respond over HTTP"); } LOG.info("Trip Command url found: " + tripCommandURL); - DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery") - .port(8080); + DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery").port(8080); tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(), tripManagementQuery.getExternalPort()); - while (!docker.containers().container("tripmanagementquery").portIsListeningOnHttp(8080, - (port) -> port.inFormat(tripQueryURL)).succeeded()) { + while (!docker.containers().container("tripmanagementquery") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripQueryURL)).succeeded()) { LOG.info("Waiting for Trip Query to respond over HTTP"); } LOG.info("Trip Query url found: " + tripQueryURL); - DockerPort gmapsAdapter = docker.containers().container("gmapsadapter") - .port(8080); - gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), - gmapsAdapter.getExternalPort()); - while (!docker.containers().container("gmapsadapter").portIsListeningOnHttp(8080, - (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { + DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); + gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); + while (!docker.containers().container("gmapsadapter") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { LOG.info("Waiting for user service to respond over HTTP"); } LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); - DockerPort calculationService = docker.containers().container("calculationservice") - .port(8080); + DockerPort calculationService = docker.containers().container("calculationservice").port(8080); calculationServiceURL = String.format("http://%s:%s", calculationService.getIp(), calculationService.getExternalPort()); - while (!docker.containers().container("calculationservice").portIsListeningOnHttp(8080, - (port) -> port.inFormat(calculationServiceURL)).succeeded()) { + while (!docker.containers().container("calculationservice") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(calculationServiceURL)).succeeded()) { LOG.info("Waiting for calculation service to respond over HTTP"); } LOG.info("Calculation Service url found: " + calculationServiceURL); - - DockerPort userService = docker.containers().container("userservice") - .port(8080); - userServiceURL = String.format("http://%s:%s", userService.getIp(), - userService.getExternalPort()); - while (!docker.containers().container("userservice").portIsListeningOnHttp(8080, - (port) -> port.inFormat(userServiceURL)).succeeded()) { - LOG.info("Waiting for user service to respond over HTTP"); - } - LOG.info("User Service url found: " + userServiceURL); } private TestRestTemplate restTemplate = new TestRestTemplate(); @@ -127,45 +140,44 @@ public void setUp() throws JSONException { String body = "grant_type=password&scope=webclient&username=passenger&password=password"; HttpEntity request = new HttpEntity<>(body, headers); - //when: - ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", - request, String.class, parameters); + // when: + ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, + String.class, parameters); - //then: + // then: assertThat(response.getStatusCodeValue()).isEqualTo(200); JSONObject json = new JSONObject(response.getBody()); token = json.getString("access_token"); } - @Test public void tripCommandPOSTRequestSuccess() { - //given: + // given: HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + token); headers.add("Content-Type", "application/json"); String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " - + "\"Miami, FL\", \"userId\": \"123e4567-e89b-12d3-a456-426655440000\" }"; + + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; HttpEntity request = new HttpEntity<>(body, headers); - //when: + // when: ResponseEntity response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, String.class); - //then: + // then: assertThat(response.getStatusCodeValue()).isEqualTo(201); } @Test - public void tripQueryGETSpecificTripRequestSuccess() throws JSONException { - //given: + public void tripQueryGETSpecificTripRequestSuccess() throws JSONException, InterruptedException { + // given: HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + token); headers.add("Content-Type", "application/json"); String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " - + "\"Miami, FL\", \"userId\": \"123e4567-e89b-12d3-a456-426655440000\" }"; + + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; HttpEntity request = new HttpEntity<>(body, headers); ResponseEntity postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, String.class); @@ -174,64 +186,71 @@ public void tripQueryGETSpecificTripRequestSuccess() throws JSONException { JSONObject json = new JSONObject(postResponse.getBody()); tripId = json.getString("id"); - //when: + Thread.sleep(1000); + + // when: ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trip/" + tripId, String.class); - //then: + // then: assertThat(response.getStatusCodeValue()).isEqualTo(200); } @Test public void tripQueryGETAllTripsRequestSuccess() { - //given: + // given: HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + token); headers.add("Content-Type", "application/json"); - //when: + // when: ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class); - //then: + // then: assertThat(response.getStatusCodeValue()).isEqualTo(200); } @Test public void calculationServiceRequestSuccess() { - //given: + // given: HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + token); headers.add("Content-Type", "application/json"); - String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\" }"; + String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\"," + + " \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; HttpEntity request = new HttpEntity<>(body, headers); - //when: + // when: ResponseEntity response = restTemplate.postForEntity(calculationServiceURL + "/api/v1/cost", request, String.class); - //then: + // then: assertThat(response.getStatusCodeValue()).isEqualTo(200); - } @Test - public void gmapsAdapterRequestSuccess() { - //given: + public void gmapsAdapterRequestSuccess() throws Exception { + // given: HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + token); headers.add("Content-Type", "application/json"); - String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\"," - + " \"departureTime\": \"15220998650000000\" }"; + String body = "{ \"origin\": \"2250 N Commerce Pkwy, Weston, FL 33326\", \"destination\": \"11200 SW 8th St, " + + "Miami, FL 33199\", \"departureTime\": \"15220998650000000\" }"; HttpEntity request = new HttpEntity<>(body, headers); - //when: + // when: ResponseEntity response = restTemplate.postForEntity(gmapsAdapterURL + "/api/v1/directions", request, String.class); - //then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); + if (response.getStatusCodeValue() != 200) { + throw new Exception( + String.format("Expected 200, actual %s\n%s", response.getStatusCode(), + response.getBody())); + } + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); } } diff --git a/src/test/resources/docker-compose.yml b/src/test/resources/docker-compose.yml index 85cf43c..6cf212e 100644 --- a/src/test/resources/docker-compose.yml +++ b/src/test/resources/docker-compose.yml @@ -54,6 +54,7 @@ services: tripmanagementcmd: image: aista/trip-management-cmd + container_name: tripmanagementcmd mem_limit: 512M environment: - RABBIT_HOST=rabbitmq @@ -69,6 +70,7 @@ services: tripmanagementquery: image: aista/trip-management-query + container_name: tripmanagementquery mem_limit: 512M environment: - RABBIT_HOST=rabbitmq From 361b184981262176c108142f314dcc63c8dc49df Mon Sep 17 00:00:00 2001 From: jusoto Date: Tue, 4 Dec 2018 13:41:11 -0500 Subject: [PATCH 05/59] Added: bin/ folder to gitignore Added environment variables for calculation-service tripId defined as local variable instead of global for test cases --- .gitignore | 3 +++ docker-compose-local.yml | 3 +++ docker-compose.yml | 4 +++- .../aist/edge/edgeservice/EdgeServiceIntegrationTests.java | 6 +++--- src/test/resources/docker-compose.yml | 4 +++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 61e181b..49190b0 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ dist/ nbdist/ .nb-gradle/ \.DS_Store + +### Eclipse ### +bin/ \ No newline at end of file diff --git a/docker-compose-local.yml b/docker-compose-local.yml index d6bedcf..851beb0 100644 --- a/docker-compose-local.yml +++ b/docker-compose-local.yml @@ -116,7 +116,10 @@ services: calculationservice: image: aista/calculation-service environment: + - RABBIT_HOST=rabbitmq - EUREKA_SERVER=discoveryservice + - MONGO_HOST=mongo + - MONGO_PORT=27017 command: ["go", "run", "main.go"] ports: - '8080' diff --git a/docker-compose.yml b/docker-compose.yml index 29f599a..3e904d2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -141,8 +141,10 @@ services: image: aista/calculation-service mem_limit: 512M environment: - - EUREKA_SERVER=discoveryservice - RABBIT_HOST=rabbitmq + - EUREKA_SERVER=discoveryservice + - MONGO_HOST=mongo + - MONGO_PORT=27017 command: ["go", "run", "main.go"] ports: - '8080' diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index fe390dc..c1ec80f 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -121,7 +121,6 @@ public static void initialize() { private TestRestTemplate restTemplate = new TestRestTemplate(); private String token; - private String tripId; @Before public void setUp() throws JSONException { @@ -181,11 +180,12 @@ public void tripQueryGETSpecificTripRequestSuccess() throws JSONException, Inter HttpEntity request = new HttpEntity<>(body, headers); ResponseEntity postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, String.class); + assertThat(postResponse.getStatusCodeValue()).isEqualTo(201); JSONObject json = new JSONObject(postResponse.getBody()); - tripId = json.getString("id"); - + String tripId = json.getString("id"); + Thread.sleep(1000); // when: diff --git a/src/test/resources/docker-compose.yml b/src/test/resources/docker-compose.yml index 6cf212e..ee3cf9f 100644 --- a/src/test/resources/docker-compose.yml +++ b/src/test/resources/docker-compose.yml @@ -101,8 +101,10 @@ services: image: aista/calculation-service mem_limit: 512M environment: - - EUREKA_SERVER=discoveryservice - RABBIT_HOST=rabbitmq + - EUREKA_SERVER=discoveryservice + - MONGO_HOST=mongo + - MONGO_PORT=27017 command: ["go", "run", "main.go"] ports: - '8080' From c6151442856cb0ca89bcfab159486cc6bb5d2c05 Mon Sep 17 00:00:00 2001 From: jusoto Date: Thu, 6 Dec 2018 23:02:04 -0500 Subject: [PATCH 06/59] added travis_wait for tests --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2d29533..b1b2572 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,9 @@ services: sudo: required before_script: - sudo service mysql stop + - export -f travis_wait +script: + - travis_wait 30 ./gradlew check env: global: - secure: WF5U05+p8xQRBhT75aviCl9sXpnzER52xJDkKaZPtsak3B/21rj5FGQ4TTu9ivh0oF56ws8Zy8hzNZhjS09QimqtpD+Zl5m5er4Q2GvrStVDM0k38wqye2IBf7juKIlkfntX1o1E9/xGkUgIW5eQpUt7TDGpon5FCvY8NHqDyVi+ZDU7hGQh8E3oyK+8Dly1ETLxVhoDEY3vG1VyEZ1IDrgAw/N6KlNIyiuWjPMBLTFAjGMzJAaf/MQiKfmB3HUBUtGqEdhobppEqriJkXl/6ov+Np+vh83dIBaOfRUpB1KgvGmefmtL7rb+mIIXOLMm9cpyqmK+6h1JeQrwB3xtWtIIXmmL2VEwmO/2YfTDyu+JpRkkgwDMLgyRKN9wEtaR+4C3X/p9zMysocDhyccOeGVq7XhJwgdosoJ0VRLVtUhPq1T10B/ipp2g8VF9TW1uIfSQJe6YYCrVK+fqtkWG5yuOfqQdGHNZkRJMpeTyzkJQzX7GZb8G0H8EZCsjdJ0FdEpshWcCB2ljozwH3fFMqnzE1thibpg7dC2BXF7aRGjmn/4vqme98i4hP+590FIMF+sdyDItVq7/91EAwh7m35dvszkFruIzLgHFRnrKAgG76bTHTz8bwywhnCZVbDmy/HEDOjj2ykW9jPKJ7buKRKVYbXnSgYqkn/keTHiRvLI= From fdaca35034ec0306e6fbdb253d63000d53ae467e Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 7 Dec 2018 00:21:06 -0500 Subject: [PATCH 07/59] Added ./gradlew clean build to travis_wait --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b1b2572..d91c135 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ before_script: - sudo service mysql stop - export -f travis_wait script: - - travis_wait 30 ./gradlew check + - travis_wait 30 ./gradlew clean build env: global: - secure: WF5U05+p8xQRBhT75aviCl9sXpnzER52xJDkKaZPtsak3B/21rj5FGQ4TTu9ivh0oF56ws8Zy8hzNZhjS09QimqtpD+Zl5m5er4Q2GvrStVDM0k38wqye2IBf7juKIlkfntX1o1E9/xGkUgIW5eQpUt7TDGpon5FCvY8NHqDyVi+ZDU7hGQh8E3oyK+8Dly1ETLxVhoDEY3vG1VyEZ1IDrgAw/N6KlNIyiuWjPMBLTFAjGMzJAaf/MQiKfmB3HUBUtGqEdhobppEqriJkXl/6ov+Np+vh83dIBaOfRUpB1KgvGmefmtL7rb+mIIXOLMm9cpyqmK+6h1JeQrwB3xtWtIIXmmL2VEwmO/2YfTDyu+JpRkkgwDMLgyRKN9wEtaR+4C3X/p9zMysocDhyccOeGVq7XhJwgdosoJ0VRLVtUhPq1T10B/ipp2g8VF9TW1uIfSQJe6YYCrVK+fqtkWG5yuOfqQdGHNZkRJMpeTyzkJQzX7GZb8G0H8EZCsjdJ0FdEpshWcCB2ljozwH3fFMqnzE1thibpg7dC2BXF7aRGjmn/4vqme98i4hP+590FIMF+sdyDItVq7/91EAwh7m35dvszkFruIzLgHFRnrKAgG76bTHTz8bwywhnCZVbDmy/HEDOjj2ykW9jPKJ7buKRKVYbXnSgYqkn/keTHiRvLI= From c377a7189ba1ff90313c255cf33032820e595812 Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 7 Dec 2018 11:30:50 -0500 Subject: [PATCH 08/59] Intregration tests created on independent setups to consume less resources for travis --- .travis.yml | 3 - .../EdgeServiceIntegrationCalculation.java | 115 ++++ .../EdgeServiceIntegrationTests.java | 512 +++++++++--------- ...geServiceIntegrationTestsGmapsAdapter.java | 102 ++++ .../EdgeServiceIntegrationTestsTripCmd.java | 140 +++++ ...geServiceIntegrationTestsTripCmdQuery.java | 160 ++++++ .../EdgeServiceIntegrationTestsTripQuery.java | 134 +++++ .../resources/docker-compose-calculation.yml | 57 ++ .../docker-compose-gmaps-adapter.yml | 34 ++ .../docker-compose-trip-cmd-query.yml | 89 +++ .../resources/docker-compose-trip-cmd.yml | 73 +++ .../resources/docker-compose-trip-query.yml | 73 +++ 12 files changed, 1233 insertions(+), 259 deletions(-) create mode 100644 src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java create mode 100644 src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java create mode 100644 src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java create mode 100644 src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java create mode 100644 src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java create mode 100644 src/test/resources/docker-compose-calculation.yml create mode 100644 src/test/resources/docker-compose-gmaps-adapter.yml create mode 100644 src/test/resources/docker-compose-trip-cmd-query.yml create mode 100644 src/test/resources/docker-compose-trip-cmd.yml create mode 100644 src/test/resources/docker-compose-trip-query.yml diff --git a/.travis.yml b/.travis.yml index d91c135..2d29533 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,6 @@ services: sudo: required before_script: - sudo service mysql stop - - export -f travis_wait -script: - - travis_wait 30 ./gradlew clean build env: global: - secure: WF5U05+p8xQRBhT75aviCl9sXpnzER52xJDkKaZPtsak3B/21rj5FGQ4TTu9ivh0oF56ws8Zy8hzNZhjS09QimqtpD+Zl5m5er4Q2GvrStVDM0k38wqye2IBf7juKIlkfntX1o1E9/xGkUgIW5eQpUt7TDGpon5FCvY8NHqDyVi+ZDU7hGQh8E3oyK+8Dly1ETLxVhoDEY3vG1VyEZ1IDrgAw/N6KlNIyiuWjPMBLTFAjGMzJAaf/MQiKfmB3HUBUtGqEdhobppEqriJkXl/6ov+Np+vh83dIBaOfRUpB1KgvGmefmtL7rb+mIIXOLMm9cpyqmK+6h1JeQrwB3xtWtIIXmmL2VEwmO/2YfTDyu+JpRkkgwDMLgyRKN9wEtaR+4C3X/p9zMysocDhyccOeGVq7XhJwgdosoJ0VRLVtUhPq1T10B/ipp2g8VF9TW1uIfSQJe6YYCrVK+fqtkWG5yuOfqQdGHNZkRJMpeTyzkJQzX7GZb8G0H8EZCsjdJ0FdEpshWcCB2ljozwH3fFMqnzE1thibpg7dC2BXF7aRGjmn/4vqme98i4hP+590FIMF+sdyDItVq7/91EAwh7m35dvszkFruIzLgHFRnrKAgG76bTHTz8bwywhnCZVbDmy/HEDOjj2ykW9jPKJ7buKRKVYbXnSgYqkn/keTHiRvLI= diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java new file mode 100644 index 0000000..ec12526 --- /dev/null +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java @@ -0,0 +1,115 @@ +package aist.edge.edgeservice; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +import com.palantir.docker.compose.DockerComposeRule; +import com.palantir.docker.compose.connection.DockerPort; +import com.palantir.docker.compose.connection.waiting.HealthChecks; + +import java.util.*; + +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.*; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.*; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class EdgeServiceIntegrationCalculation { + protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationCalculation.class); + + private static String discoveryServiceURL; + private static String mongoURL; + private static String gmapsAdapterURL; + private static String calculationServiceURL; + + // Wait for all services to have ports open + @ClassRule + public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) + .file("src/test/resources/docker-compose-calculation.yml") + .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()).build(); + + // Get IP addresses and ports to run tests on + @BeforeClass + public static void initialize() { + + LOG.info("Initializing ports from Docker"); + + DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); + discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), + discoveryService.getExternalPort()); + while (!docker.containers().container("discoveryservice") + .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { + LOG.info("Waiting for discovery service to respond over HTTP"); + } + LOG.info("Discovery Service url found: " + discoveryServiceURL); + + DockerPort mongo = docker.containers().container("mongo").port(27017); + mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); + while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) + .succeeded()) { + LOG.info("Waiting for mongo to respond over HTTP"); + } + LOG.info("Mongo url found: " + mongoURL); + + DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); + gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); + while (!docker.containers().container("gmapsadapter") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { + LOG.info("Waiting for user service to respond over HTTP"); + } + LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); + + DockerPort calculationService = docker.containers().container("calculationservice").port(8080); + calculationServiceURL = String.format("http://%s:%s", calculationService.getIp(), + calculationService.getExternalPort()); + while (!docker.containers().container("calculationservice") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(calculationServiceURL)).succeeded()) { + LOG.info("Waiting for calculation service to respond over HTTP"); + } + LOG.info("Calculation Service url found: " + calculationServiceURL); + } + + private TestRestTemplate restTemplate = new TestRestTemplate(); + + private String token; + + @Before + public void setUp() throws JSONException { + token = ""; + } + + @Test + public void calculationServiceRequestSuccess() { + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); + + String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\"," + + " \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; + HttpEntity request = new HttpEntity<>(body, headers); + + // when: + ResponseEntity response = restTemplate.postForEntity(calculationServiceURL + "/api/v1/cost", request, + String.class); + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); + } +} diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index c1ec80f..8a0fda3 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -1,256 +1,256 @@ -package aist.edge.edgeservice; - -import static org.assertj.core.api.Java6Assertions.assertThat; - -import com.palantir.docker.compose.DockerComposeRule; -import com.palantir.docker.compose.connection.DockerPort; -import com.palantir.docker.compose.connection.waiting.HealthChecks; - -import java.util.*; - -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.*; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.*; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class EdgeServiceIntegrationTests { - protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTests.class); - - private static String discoveryServiceURL; - private static String mongoURL; - private static String userServiceURL; - private static String tripCommandURL; - private static String tripQueryURL; - private static String gmapsAdapterURL; - private static String calculationServiceURL; - - // Wait for all services to have ports open - @ClassRule - public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) - .file("src/test/resources/docker-compose.yml") - .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()).build(); - - // Get IP addresses and ports to run tests on - @BeforeClass - public static void initialize() { - - LOG.info("Initializing ports from Docker"); - - DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); - discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), - discoveryService.getExternalPort()); - while (!docker.containers().container("discoveryservice") - .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { - LOG.info("Waiting for discovery service to respond over HTTP"); - } - LOG.info("Discovery Service url found: " + discoveryServiceURL); - - DockerPort mongo = docker.containers().container("mongo").port(27017); - mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); - while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) - .succeeded()) { - LOG.info("Waiting for mongo to respond over HTTP"); - } - LOG.info("Mongo url found: " + mongoURL); - - DockerPort userService = docker.containers().container("userservice").port(8080); - userServiceURL = String.format("http://%s:%s", userService.getIp(), userService.getExternalPort()); - while (!docker.containers().container("userservice") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { - LOG.info("Waiting for user service to respond over HTTP"); - } - LOG.info("User Service url found: " + userServiceURL); - - DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd").port(8080); - tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), - tripManagementCommand.getExternalPort()); - while (!docker.containers().container("tripmanagementcmd") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripCommandURL)).succeeded()) { - LOG.info("Waiting for Trip Command to respond over HTTP"); - } - LOG.info("Trip Command url found: " + tripCommandURL); - - DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery").port(8080); - tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(), - tripManagementQuery.getExternalPort()); - while (!docker.containers().container("tripmanagementquery") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripQueryURL)).succeeded()) { - LOG.info("Waiting for Trip Query to respond over HTTP"); - } - LOG.info("Trip Query url found: " + tripQueryURL); - - DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); - gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); - while (!docker.containers().container("gmapsadapter") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { - LOG.info("Waiting for user service to respond over HTTP"); - } - LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); - - DockerPort calculationService = docker.containers().container("calculationservice").port(8080); - calculationServiceURL = String.format("http://%s:%s", calculationService.getIp(), - calculationService.getExternalPort()); - while (!docker.containers().container("calculationservice") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(calculationServiceURL)).succeeded()) { - LOG.info("Waiting for calculation service to respond over HTTP"); - } - LOG.info("Calculation Service url found: " + calculationServiceURL); - } - - private TestRestTemplate restTemplate = new TestRestTemplate(); - - private String token; - - @Before - public void setUp() throws JSONException { - String plainCreds = "front-end:front-end"; - byte[] plainCredsBytes = plainCreds.getBytes(); - byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); - String base64Creds = new String(base64CredsBytes); - - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Basic " + base64Creds); - headers.add("Content-Type", "application/x-www-form-urlencoded"); - - MultiValueMap parameters = new LinkedMultiValueMap<>(); - parameters.add("username", "front-end"); - parameters.add("secret", "front-end"); - String body = "grant_type=password&scope=webclient&username=passenger&password=password"; - HttpEntity request = new HttpEntity<>(body, headers); - - // when: - ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, - String.class, parameters); - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); - JSONObject json = new JSONObject(response.getBody()); - token = json.getString("access_token"); - } - - @Test - public void tripCommandPOSTRequestSuccess() { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); - - String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " - + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; - HttpEntity request = new HttpEntity<>(body, headers); - - // when: - ResponseEntity response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, - String.class); - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(201); - } - - @Test - public void tripQueryGETSpecificTripRequestSuccess() throws JSONException, InterruptedException { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); - - String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " - + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; - HttpEntity request = new HttpEntity<>(body, headers); - ResponseEntity postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, - String.class); - - assertThat(postResponse.getStatusCodeValue()).isEqualTo(201); - - JSONObject json = new JSONObject(postResponse.getBody()); - String tripId = json.getString("id"); - - Thread.sleep(1000); - - // when: - ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trip/" + tripId, - String.class); - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); - } - - @Test - public void tripQueryGETAllTripsRequestSuccess() { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); - - // when: - ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class); - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); - } - - @Test - public void calculationServiceRequestSuccess() { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); - - String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\"," - + " \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; - HttpEntity request = new HttpEntity<>(body, headers); - - // when: - ResponseEntity response = restTemplate.postForEntity(calculationServiceURL + "/api/v1/cost", request, - String.class); - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); - } - - @Test - public void gmapsAdapterRequestSuccess() throws Exception { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); - - String body = "{ \"origin\": \"2250 N Commerce Pkwy, Weston, FL 33326\", \"destination\": \"11200 SW 8th St, " - + "Miami, FL 33199\", \"departureTime\": \"15220998650000000\" }"; - HttpEntity request = new HttpEntity<>(body, headers); - - // when: - ResponseEntity response = restTemplate.postForEntity(gmapsAdapterURL + "/api/v1/directions", request, - String.class); - - if (response.getStatusCodeValue() != 200) { - throw new Exception( - String.format("Expected 200, actual %s\n%s", response.getStatusCode(), - response.getBody())); - } - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); - } -} +//package aist.edge.edgeservice; +// +//import static org.assertj.core.api.Java6Assertions.assertThat; +// +//import com.palantir.docker.compose.DockerComposeRule; +//import com.palantir.docker.compose.connection.DockerPort; +//import com.palantir.docker.compose.connection.waiting.HealthChecks; +// +//import java.util.*; +// +//import org.json.JSONException; +//import org.json.JSONObject; +//import org.junit.Before; +//import org.junit.BeforeClass; +//import org.junit.ClassRule; +//import org.junit.Test; +//import org.junit.runner.RunWith; +// +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.boot.test.web.client.TestRestTemplate; +//import org.springframework.http.*; +//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +//import org.springframework.util.*; +// +//@RunWith(SpringJUnit4ClassRunner.class) +//@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +//public class EdgeServiceIntegrationTests { +// protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTests.class); +// +// private static String discoveryServiceURL; +// private static String mongoURL; +// private static String userServiceURL; +// private static String tripCommandURL; +// private static String tripQueryURL; +// private static String gmapsAdapterURL; +// private static String calculationServiceURL; +// +// // Wait for all services to have ports open +// @ClassRule +// public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) +// .file("src/test/resources/docker-compose.yml") +// .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) +// .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) +// .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) +// .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) +// .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) +// .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) +// .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) +// .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) +// .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()).build(); +// +// // Get IP addresses and ports to run tests on +// @BeforeClass +// public static void initialize() { +// +// LOG.info("Initializing ports from Docker"); +// +// DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); +// discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), +// discoveryService.getExternalPort()); +// while (!docker.containers().container("discoveryservice") +// .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { +// LOG.info("Waiting for discovery service to respond over HTTP"); +// } +// LOG.info("Discovery Service url found: " + discoveryServiceURL); +// +// DockerPort mongo = docker.containers().container("mongo").port(27017); +// mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); +// while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) +// .succeeded()) { +// LOG.info("Waiting for mongo to respond over HTTP"); +// } +// LOG.info("Mongo url found: " + mongoURL); +// +// DockerPort userService = docker.containers().container("userservice").port(8080); +// userServiceURL = String.format("http://%s:%s", userService.getIp(), userService.getExternalPort()); +// while (!docker.containers().container("userservice") +// .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { +// LOG.info("Waiting for user service to respond over HTTP"); +// } +// LOG.info("User Service url found: " + userServiceURL); +// +// DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd").port(8080); +// tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), +// tripManagementCommand.getExternalPort()); +// while (!docker.containers().container("tripmanagementcmd") +// .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripCommandURL)).succeeded()) { +// LOG.info("Waiting for Trip Command to respond over HTTP"); +// } +// LOG.info("Trip Command url found: " + tripCommandURL); +// +// DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery").port(8080); +// tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(), +// tripManagementQuery.getExternalPort()); +// while (!docker.containers().container("tripmanagementquery") +// .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripQueryURL)).succeeded()) { +// LOG.info("Waiting for Trip Query to respond over HTTP"); +// } +// LOG.info("Trip Query url found: " + tripQueryURL); +// +// DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); +// gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); +// while (!docker.containers().container("gmapsadapter") +// .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { +// LOG.info("Waiting for user service to respond over HTTP"); +// } +// LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); +// +// DockerPort calculationService = docker.containers().container("calculationservice").port(8080); +// calculationServiceURL = String.format("http://%s:%s", calculationService.getIp(), +// calculationService.getExternalPort()); +// while (!docker.containers().container("calculationservice") +// .portIsListeningOnHttp(8080, (port) -> port.inFormat(calculationServiceURL)).succeeded()) { +// LOG.info("Waiting for calculation service to respond over HTTP"); +// } +// LOG.info("Calculation Service url found: " + calculationServiceURL); +// } +// +// private TestRestTemplate restTemplate = new TestRestTemplate(); +// +// private String token; +// +// @Before +// public void setUp() throws JSONException { +// String plainCreds = "front-end:front-end"; +// byte[] plainCredsBytes = plainCreds.getBytes(); +// byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); +// String base64Creds = new String(base64CredsBytes); +// +// HttpHeaders headers = new HttpHeaders(); +// headers.add("Authorization", "Basic " + base64Creds); +// headers.add("Content-Type", "application/x-www-form-urlencoded"); +// +// MultiValueMap parameters = new LinkedMultiValueMap<>(); +// parameters.add("username", "front-end"); +// parameters.add("secret", "front-end"); +// String body = "grant_type=password&scope=webclient&username=passenger&password=password"; +// HttpEntity request = new HttpEntity<>(body, headers); +// +// // when: +// ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, +// String.class, parameters); +// +// // then: +// assertThat(response.getStatusCodeValue()).isEqualTo(200); +// JSONObject json = new JSONObject(response.getBody()); +// token = json.getString("access_token"); +// } +// +// @Test +// public void tripCommandPOSTRequestSuccess() { +// // given: +// HttpHeaders headers = new HttpHeaders(); +// headers.add("Authorization", "Bearer " + token); +// headers.add("Content-Type", "application/json"); +// +// String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " +// + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; +// HttpEntity request = new HttpEntity<>(body, headers); +// +// // when: +// ResponseEntity response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, +// String.class); +// +// // then: +// assertThat(response.getStatusCodeValue()).isEqualTo(201); +// } +// +// @Test +// public void tripQueryGETSpecificTripRequestSuccess() throws JSONException, InterruptedException { +// // given: +// HttpHeaders headers = new HttpHeaders(); +// headers.add("Authorization", "Bearer " + token); +// headers.add("Content-Type", "application/json"); +// +// String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " +// + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; +// HttpEntity request = new HttpEntity<>(body, headers); +// ResponseEntity postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, +// String.class); +// +// assertThat(postResponse.getStatusCodeValue()).isEqualTo(201); +// +// JSONObject json = new JSONObject(postResponse.getBody()); +// String tripId = json.getString("id"); +// +// Thread.sleep(1000); +// +// // when: +// ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trip/" + tripId, +// String.class); +// +// // then: +// assertThat(response.getStatusCodeValue()).isEqualTo(200); +// } +// +// @Test +// public void tripQueryGETAllTripsRequestSuccess() { +// // given: +// HttpHeaders headers = new HttpHeaders(); +// headers.add("Authorization", "Bearer " + token); +// headers.add("Content-Type", "application/json"); +// +// // when: +// ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class); +// +// // then: +// assertThat(response.getStatusCodeValue()).isEqualTo(200); +// } +// +// @Test +// public void calculationServiceRequestSuccess() { +// // given: +// HttpHeaders headers = new HttpHeaders(); +// headers.add("Authorization", "Bearer " + token); +// headers.add("Content-Type", "application/json"); +// +// String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\"," +// + " \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; +// HttpEntity request = new HttpEntity<>(body, headers); +// +// // when: +// ResponseEntity response = restTemplate.postForEntity(calculationServiceURL + "/api/v1/cost", request, +// String.class); +// +// // then: +// assertThat(response.getStatusCodeValue()).isEqualTo(200); +// } +// +// @Test +// public void gmapsAdapterRequestSuccess() throws Exception { +// // given: +// HttpHeaders headers = new HttpHeaders(); +// headers.add("Authorization", "Bearer " + token); +// headers.add("Content-Type", "application/json"); +// +// String body = "{ \"origin\": \"2250 N Commerce Pkwy, Weston, FL 33326\", \"destination\": \"11200 SW 8th St, " +// + "Miami, FL 33199\", \"departureTime\": \"15220998650000000\" }"; +// HttpEntity request = new HttpEntity<>(body, headers); +// +// // when: +// ResponseEntity response = restTemplate.postForEntity(gmapsAdapterURL + "/api/v1/directions", request, +// String.class); +// +// if (response.getStatusCodeValue() != 200) { +// throw new Exception( +// String.format("Expected 200, actual %s\n%s", response.getStatusCode(), +// response.getBody())); +// } +// +// // then: +// assertThat(response.getStatusCodeValue()).isEqualTo(200); +// } +//} diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java new file mode 100644 index 0000000..a670038 --- /dev/null +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java @@ -0,0 +1,102 @@ +package aist.edge.edgeservice; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +import com.palantir.docker.compose.DockerComposeRule; +import com.palantir.docker.compose.connection.DockerPort; +import com.palantir.docker.compose.connection.waiting.HealthChecks; + +import java.util.*; + +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.*; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.*; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class EdgeServiceIntegrationTestsGmapsAdapter { + protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTestsGmapsAdapter.class); + + private static String discoveryServiceURL; + private static String gmapsAdapterURL; + + // Wait for all services to have ports open + @ClassRule + public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) + .file("src/test/resources/docker-compose-gmaps-adapter.yml") + .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) + .build(); + + // Get IP addresses and ports to run tests on + @BeforeClass + public static void initialize() { + + LOG.info("Initializing ports from Docker"); + + DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); + discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), + discoveryService.getExternalPort()); + while (!docker.containers().container("discoveryservice") + .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { + LOG.info("Waiting for discovery service to respond over HTTP"); + } + LOG.info("Discovery Service url found: " + discoveryServiceURL); + + DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); + gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); + while (!docker.containers().container("gmapsadapter") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { + LOG.info("Waiting for user service to respond over HTTP"); + } + LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); + + } + + private TestRestTemplate restTemplate = new TestRestTemplate(); + + private String token; + + @Before + public void setUp() throws JSONException { + token = ""; + } + + @Test + public void gmapsAdapterRequestSuccess() throws Exception { + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); + + String body = "{ \"origin\": \"2250 N Commerce Pkwy, Weston, FL 33326\", \"destination\": \"11200 SW 8th St, " + + "Miami, FL 33199\", \"departureTime\": \"15220998650000000\" }"; + HttpEntity request = new HttpEntity<>(body, headers); + + // when: + ResponseEntity response = restTemplate.postForEntity(gmapsAdapterURL + "/api/v1/directions", request, + String.class); + + if (response.getStatusCodeValue() != 200) { + throw new Exception( + String.format("Expected 200, actual %s\n%s", response.getStatusCode(), + response.getBody())); + } + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); + } +} diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java new file mode 100644 index 0000000..d96d1c9 --- /dev/null +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java @@ -0,0 +1,140 @@ +package aist.edge.edgeservice; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +import com.palantir.docker.compose.DockerComposeRule; +import com.palantir.docker.compose.connection.DockerPort; +import com.palantir.docker.compose.connection.waiting.HealthChecks; + +import java.util.*; + +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.*; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.*; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class EdgeServiceIntegrationTestsTripCmd { + protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTestsTripCmd.class); + + private static String discoveryServiceURL; + private static String mongoURL; + private static String userServiceURL; + private static String tripCommandURL; + + // Wait for all services to have ports open + @ClassRule + public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) + .file("src/test/resources/docker-compose-trip-cmd.yml") + .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) + .build(); + + // Get IP addresses and ports to run tests on + @BeforeClass + public static void initialize() { + + LOG.info("Initializing ports from Docker"); + + DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); + discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), + discoveryService.getExternalPort()); + while (!docker.containers().container("discoveryservice") + .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { + LOG.info("Waiting for discovery service to respond over HTTP"); + } + LOG.info("Discovery Service url found: " + discoveryServiceURL); + + DockerPort mongo = docker.containers().container("mongo").port(27017); + mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); + while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) + .succeeded()) { + LOG.info("Waiting for mongo to respond over HTTP"); + } + LOG.info("Mongo url found: " + mongoURL); + + DockerPort userService = docker.containers().container("userservice").port(8080); + userServiceURL = String.format("http://%s:%s", userService.getIp(), userService.getExternalPort()); + while (!docker.containers().container("userservice") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { + LOG.info("Waiting for user service to respond over HTTP"); + } + LOG.info("User Service url found: " + userServiceURL); + + DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd").port(8080); + tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), + tripManagementCommand.getExternalPort()); + while (!docker.containers().container("tripmanagementcmd") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripCommandURL)).succeeded()) { + LOG.info("Waiting for Trip Command to respond over HTTP"); + } + LOG.info("Trip Command url found: " + tripCommandURL); + } + + private TestRestTemplate restTemplate = new TestRestTemplate(); + + private String token; + + @Before + public void setUp() throws JSONException { + String plainCreds = "front-end:front-end"; + byte[] plainCredsBytes = plainCreds.getBytes(); + byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); + String base64Creds = new String(base64CredsBytes); + + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Basic " + base64Creds); + headers.add("Content-Type", "application/x-www-form-urlencoded"); + + MultiValueMap parameters = new LinkedMultiValueMap<>(); + parameters.add("username", "front-end"); + parameters.add("secret", "front-end"); + String body = "grant_type=password&scope=webclient&username=passenger&password=password"; + HttpEntity request = new HttpEntity<>(body, headers); + + // when: + ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, + String.class, parameters); + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); + JSONObject json = new JSONObject(response.getBody()); + token = json.getString("access_token"); + } + + @Test + public void tripCommandPOSTRequestSuccess() { + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); + + String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " + + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; + HttpEntity request = new HttpEntity<>(body, headers); + + // when: + ResponseEntity response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, + String.class); + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(201); + } + +} diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java new file mode 100644 index 0000000..d749e43 --- /dev/null +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java @@ -0,0 +1,160 @@ +package aist.edge.edgeservice; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +import com.palantir.docker.compose.DockerComposeRule; +import com.palantir.docker.compose.connection.DockerPort; +import com.palantir.docker.compose.connection.waiting.HealthChecks; + +import java.util.*; + +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.*; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.*; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class EdgeServiceIntegrationTestsTripCmdQuery { + protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTestsTripCmdQuery.class); + + private static String discoveryServiceURL; + private static String mongoURL; + private static String userServiceURL; + private static String tripCommandURL; + private static String tripQueryURL; + + // Wait for all services to have ports open + @ClassRule + public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) + .file("src/test/resources/docker-compose-trip-cmd-query.yml") + .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) + .build(); + + // Get IP addresses and ports to run tests on + @BeforeClass + public static void initialize() { + + LOG.info("Initializing ports from Docker"); + + DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); + discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), + discoveryService.getExternalPort()); + while (!docker.containers().container("discoveryservice") + .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { + LOG.info("Waiting for discovery service to respond over HTTP"); + } + LOG.info("Discovery Service url found: " + discoveryServiceURL); + + DockerPort mongo = docker.containers().container("mongo").port(27017); + mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); + while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) + .succeeded()) { + LOG.info("Waiting for mongo to respond over HTTP"); + } + LOG.info("Mongo url found: " + mongoURL); + + DockerPort userService = docker.containers().container("userservice").port(8080); + userServiceURL = String.format("http://%s:%s", userService.getIp(), userService.getExternalPort()); + while (!docker.containers().container("userservice") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { + LOG.info("Waiting for user service to respond over HTTP"); + } + LOG.info("User Service url found: " + userServiceURL); + + DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd").port(8080); + tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), + tripManagementCommand.getExternalPort()); + while (!docker.containers().container("tripmanagementcmd") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripCommandURL)).succeeded()) { + LOG.info("Waiting for Trip Command to respond over HTTP"); + } + LOG.info("Trip Command url found: " + tripCommandURL); + + DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery").port(8080); + tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(), + tripManagementQuery.getExternalPort()); + while (!docker.containers().container("tripmanagementquery") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripQueryURL)).succeeded()) { + LOG.info("Waiting for Trip Query to respond over HTTP"); + } + LOG.info("Trip Query url found: " + tripQueryURL); + } + + private TestRestTemplate restTemplate = new TestRestTemplate(); + + private String token; + + @Before + public void setUp() throws JSONException { + String plainCreds = "front-end:front-end"; + byte[] plainCredsBytes = plainCreds.getBytes(); + byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); + String base64Creds = new String(base64CredsBytes); + + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Basic " + base64Creds); + headers.add("Content-Type", "application/x-www-form-urlencoded"); + + MultiValueMap parameters = new LinkedMultiValueMap<>(); + parameters.add("username", "front-end"); + parameters.add("secret", "front-end"); + String body = "grant_type=password&scope=webclient&username=passenger&password=password"; + HttpEntity request = new HttpEntity<>(body, headers); + + // when: + ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, + String.class, parameters); + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); + JSONObject json = new JSONObject(response.getBody()); + token = json.getString("access_token"); + } + + @Test + public void tripQueryGETSpecificTripRequestSuccess() throws JSONException, InterruptedException { + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); + + String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " + + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; + HttpEntity request = new HttpEntity<>(body, headers); + ResponseEntity postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, + String.class); + + assertThat(postResponse.getStatusCodeValue()).isEqualTo(201); + + JSONObject json = new JSONObject(postResponse.getBody()); + String tripId = json.getString("id"); + + Thread.sleep(1000); + + // when: + ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trip/" + tripId, + String.class); + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); + } + +} diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java new file mode 100644 index 0000000..9b55504 --- /dev/null +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java @@ -0,0 +1,134 @@ +package aist.edge.edgeservice; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +import com.palantir.docker.compose.DockerComposeRule; +import com.palantir.docker.compose.connection.DockerPort; +import com.palantir.docker.compose.connection.waiting.HealthChecks; + +import java.util.*; + +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.*; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.*; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class EdgeServiceIntegrationTestsTripQuery { + protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTestsTripQuery.class); + + private static String discoveryServiceURL; + private static String mongoURL; + private static String userServiceURL; + private static String tripQueryURL; + + // Wait for all services to have ports open + @ClassRule + public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) + .file("src/test/resources/docker-compose-trip-query.yml") + .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) + .build(); + + // Get IP addresses and ports to run tests on + @BeforeClass + public static void initialize() { + + LOG.info("Initializing ports from Docker"); + + DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); + discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), + discoveryService.getExternalPort()); + while (!docker.containers().container("discoveryservice") + .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { + LOG.info("Waiting for discovery service to respond over HTTP"); + } + LOG.info("Discovery Service url found: " + discoveryServiceURL); + + DockerPort mongo = docker.containers().container("mongo").port(27017); + mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); + while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) + .succeeded()) { + LOG.info("Waiting for mongo to respond over HTTP"); + } + LOG.info("Mongo url found: " + mongoURL); + + DockerPort userService = docker.containers().container("userservice").port(8080); + userServiceURL = String.format("http://%s:%s", userService.getIp(), userService.getExternalPort()); + while (!docker.containers().container("userservice") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { + LOG.info("Waiting for user service to respond over HTTP"); + } + LOG.info("User Service url found: " + userServiceURL); + + DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery").port(8080); + tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(), + tripManagementQuery.getExternalPort()); + while (!docker.containers().container("tripmanagementquery") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripQueryURL)).succeeded()) { + LOG.info("Waiting for Trip Query to respond over HTTP"); + } + LOG.info("Trip Query url found: " + tripQueryURL); + } + + private TestRestTemplate restTemplate = new TestRestTemplate(); + + private String token; + + @Before + public void setUp() throws JSONException { + String plainCreds = "front-end:front-end"; + byte[] plainCredsBytes = plainCreds.getBytes(); + byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); + String base64Creds = new String(base64CredsBytes); + + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Basic " + base64Creds); + headers.add("Content-Type", "application/x-www-form-urlencoded"); + + MultiValueMap parameters = new LinkedMultiValueMap<>(); + parameters.add("username", "front-end"); + parameters.add("secret", "front-end"); + String body = "grant_type=password&scope=webclient&username=passenger&password=password"; + HttpEntity request = new HttpEntity<>(body, headers); + + // when: + ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, + String.class, parameters); + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); + JSONObject json = new JSONObject(response.getBody()); + token = json.getString("access_token"); + } + + @Test + public void tripQueryGETAllTripsRequestSuccess() { + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); + + // when: + ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class); + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); + } +} diff --git a/src/test/resources/docker-compose-calculation.yml b/src/test/resources/docker-compose-calculation.yml new file mode 100644 index 0000000..2e4dc72 --- /dev/null +++ b/src/test/resources/docker-compose-calculation.yml @@ -0,0 +1,57 @@ +version: '2.3' + +services: + + discoveryservice: + image: aista/eureka + mem_limit: 512M + ports: + - "8761:8761" + + mongo: + image: 'mongo:3.4.1' + mem_limit: 512M + container_name: 'mongo' + ports: + - '27017:27017' + volumes: + - 'mongo:/data/db' + + rabbitmq: + image: rabbitmq:management + mem_limit: 512M + container_name: 'rabbitmq' + ports: + - "5672:5672" + - "15672:15672" + + gmapsadapter: + image: aista/gmaps-adapter + mem_limit: 512M + environment: + - EUREKA_SERVER=discoveryservice + - RABBIT_HOST=rabbitmq + ports: + - '8080' + depends_on: + - discoveryservice + environment: + - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC + + calculationservice: + image: aista/calculation-service + mem_limit: 512M + environment: + - RABBIT_HOST=rabbitmq + - EUREKA_SERVER=discoveryservice + - MONGO_HOST=mongo + - MONGO_PORT=27017 + command: ["go", "run", "main.go"] + ports: + - '8080' + depends_on: + - discoveryservice + +volumes: + mongo: + mysql-data: \ No newline at end of file diff --git a/src/test/resources/docker-compose-gmaps-adapter.yml b/src/test/resources/docker-compose-gmaps-adapter.yml new file mode 100644 index 0000000..ef72263 --- /dev/null +++ b/src/test/resources/docker-compose-gmaps-adapter.yml @@ -0,0 +1,34 @@ +version: '2.3' + +services: + + discoveryservice: + image: aista/eureka + mem_limit: 512M + ports: + - "8761:8761" + + rabbitmq: + image: rabbitmq:management + mem_limit: 512M + container_name: 'rabbitmq' + ports: + - "5672:5672" + - "15672:15672" + + gmapsadapter: + image: aista/gmaps-adapter + mem_limit: 512M + environment: + - EUREKA_SERVER=discoveryservice + - RABBIT_HOST=rabbitmq + ports: + - '8080' + depends_on: + - discoveryservice + environment: + - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC + +volumes: + mongo: + mysql-data: \ No newline at end of file diff --git a/src/test/resources/docker-compose-trip-cmd-query.yml b/src/test/resources/docker-compose-trip-cmd-query.yml new file mode 100644 index 0000000..2d300be --- /dev/null +++ b/src/test/resources/docker-compose-trip-cmd-query.yml @@ -0,0 +1,89 @@ +version: '2.3' + +services: + + discoveryservice: + image: aista/eureka + mem_limit: 512M + ports: + - "8761:8761" + + mysqlserver: + image: mysql:5.7 + mem_limit: 512M + volumes: + - mysql-data:/var/lib/mysql:rw + restart: always + ports: + - '3306:3306' + environment: + MYSQL_USER: + MYSQL_PASSWORD: + MYSQL_ROOT_PASSWORD: 'root' + MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' + MYSQL_DATABASE: 'user_service' + + userservice: + image: aista/user-service + mem_limit: 512M + container_name: userservice + depends_on: + - discoveryservice + - mysqlserver + ports: + - '8080' + environment: + - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC + + mongo: + image: 'mongo:3.4.1' + mem_limit: 512M + container_name: 'mongo' + ports: + - '27017:27017' + volumes: + - 'mongo:/data/db' + + rabbitmq: + image: rabbitmq:management + mem_limit: 512M + container_name: 'rabbitmq' + ports: + - "5672:5672" + - "15672:15672" + + tripmanagementcmd: + image: aista/trip-management-cmd + container_name: tripmanagementcmd + mem_limit: 512M + environment: + - RABBIT_HOST=rabbitmq + - MONGO_HOST=mongo + ports: + - '8080' + depends_on: + - discoveryservice + - rabbitmq + - mongo + environment: + - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC + + tripmanagementquery: + image: aista/trip-management-query + container_name: tripmanagementquery + mem_limit: 512M + environment: + - RABBIT_HOST=rabbitmq + - MONGO_HOST=mongo + ports: + - '8080' + depends_on: + - rabbitmq + - mongo + - discoveryservice + environment: + - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC + +volumes: + mongo: + mysql-data: \ No newline at end of file diff --git a/src/test/resources/docker-compose-trip-cmd.yml b/src/test/resources/docker-compose-trip-cmd.yml new file mode 100644 index 0000000..32a0570 --- /dev/null +++ b/src/test/resources/docker-compose-trip-cmd.yml @@ -0,0 +1,73 @@ +version: '2.3' + +services: + + discoveryservice: + image: aista/eureka + mem_limit: 512M + ports: + - "8761:8761" + + mysqlserver: + image: mysql:5.7 + mem_limit: 512M + volumes: + - mysql-data:/var/lib/mysql:rw + restart: always + ports: + - '3306:3306' + environment: + MYSQL_USER: + MYSQL_PASSWORD: + MYSQL_ROOT_PASSWORD: 'root' + MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' + MYSQL_DATABASE: 'user_service' + + userservice: + image: aista/user-service + mem_limit: 512M + container_name: userservice + depends_on: + - discoveryservice + - mysqlserver + ports: + - '8080' + environment: + - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC + + mongo: + image: 'mongo:3.4.1' + mem_limit: 512M + container_name: 'mongo' + ports: + - '27017:27017' + volumes: + - 'mongo:/data/db' + + rabbitmq: + image: rabbitmq:management + mem_limit: 512M + container_name: 'rabbitmq' + ports: + - "5672:5672" + - "15672:15672" + + tripmanagementcmd: + image: aista/trip-management-cmd + container_name: tripmanagementcmd + mem_limit: 512M + environment: + - RABBIT_HOST=rabbitmq + - MONGO_HOST=mongo + ports: + - '8080' + depends_on: + - discoveryservice + - rabbitmq + - mongo + environment: + - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC + +volumes: + mongo: + mysql-data: \ No newline at end of file diff --git a/src/test/resources/docker-compose-trip-query.yml b/src/test/resources/docker-compose-trip-query.yml new file mode 100644 index 0000000..afa2b6b --- /dev/null +++ b/src/test/resources/docker-compose-trip-query.yml @@ -0,0 +1,73 @@ +version: '2.3' + +services: + + discoveryservice: + image: aista/eureka + mem_limit: 512M + ports: + - "8761:8761" + + mysqlserver: + image: mysql:5.7 + mem_limit: 512M + volumes: + - mysql-data:/var/lib/mysql:rw + restart: always + ports: + - '3306:3306' + environment: + MYSQL_USER: + MYSQL_PASSWORD: + MYSQL_ROOT_PASSWORD: 'root' + MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' + MYSQL_DATABASE: 'user_service' + + userservice: + image: aista/user-service + mem_limit: 512M + container_name: userservice + depends_on: + - discoveryservice + - mysqlserver + ports: + - '8080' + environment: + - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC + + mongo: + image: 'mongo:3.4.1' + mem_limit: 512M + container_name: 'mongo' + ports: + - '27017:27017' + volumes: + - 'mongo:/data/db' + + rabbitmq: + image: rabbitmq:management + mem_limit: 512M + container_name: 'rabbitmq' + ports: + - "5672:5672" + - "15672:15672" + + tripmanagementquery: + image: aista/trip-management-query + container_name: tripmanagementquery + mem_limit: 512M + environment: + - RABBIT_HOST=rabbitmq + - MONGO_HOST=mongo + ports: + - '8080' + depends_on: + - rabbitmq + - mongo + - discoveryservice + environment: + - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC + +volumes: + mongo: + mysql-data: \ No newline at end of file From 4a3e1a6e4ec19ab92bfd41bbf46840b25ad17c64 Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 7 Dec 2018 11:44:50 -0500 Subject: [PATCH 09/59] Added time_wait 30 min for ./gradle check --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2d29533..d91c135 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,9 @@ services: sudo: required before_script: - sudo service mysql stop + - export -f travis_wait +script: + - travis_wait 30 ./gradlew clean build env: global: - secure: WF5U05+p8xQRBhT75aviCl9sXpnzER52xJDkKaZPtsak3B/21rj5FGQ4TTu9ivh0oF56ws8Zy8hzNZhjS09QimqtpD+Zl5m5er4Q2GvrStVDM0k38wqye2IBf7juKIlkfntX1o1E9/xGkUgIW5eQpUt7TDGpon5FCvY8NHqDyVi+ZDU7hGQh8E3oyK+8Dly1ETLxVhoDEY3vG1VyEZ1IDrgAw/N6KlNIyiuWjPMBLTFAjGMzJAaf/MQiKfmB3HUBUtGqEdhobppEqriJkXl/6ov+Np+vh83dIBaOfRUpB1KgvGmefmtL7rb+mIIXOLMm9cpyqmK+6h1JeQrwB3xtWtIIXmmL2VEwmO/2YfTDyu+JpRkkgwDMLgyRKN9wEtaR+4C3X/p9zMysocDhyccOeGVq7XhJwgdosoJ0VRLVtUhPq1T10B/ipp2g8VF9TW1uIfSQJe6YYCrVK+fqtkWG5yuOfqQdGHNZkRJMpeTyzkJQzX7GZb8G0H8EZCsjdJ0FdEpshWcCB2ljozwH3fFMqnzE1thibpg7dC2BXF7aRGjmn/4vqme98i4hP+590FIMF+sdyDItVq7/91EAwh7m35dvszkFruIzLgHFRnrKAgG76bTHTz8bwywhnCZVbDmy/HEDOjj2ykW9jPKJ7buKRKVYbXnSgYqkn/keTHiRvLI= From b830898529c266fb83354ed0b275c77719927d20 Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 7 Dec 2018 14:06:33 -0500 Subject: [PATCH 10/59] Show log info on travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d91c135..d08163b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ before_script: - sudo service mysql stop - export -f travis_wait script: - - travis_wait 30 ./gradlew clean build + - travis_wait 30 ./gradlew check -i env: global: - secure: WF5U05+p8xQRBhT75aviCl9sXpnzER52xJDkKaZPtsak3B/21rj5FGQ4TTu9ivh0oF56ws8Zy8hzNZhjS09QimqtpD+Zl5m5er4Q2GvrStVDM0k38wqye2IBf7juKIlkfntX1o1E9/xGkUgIW5eQpUt7TDGpon5FCvY8NHqDyVi+ZDU7hGQh8E3oyK+8Dly1ETLxVhoDEY3vG1VyEZ1IDrgAw/N6KlNIyiuWjPMBLTFAjGMzJAaf/MQiKfmB3HUBUtGqEdhobppEqriJkXl/6ov+Np+vh83dIBaOfRUpB1KgvGmefmtL7rb+mIIXOLMm9cpyqmK+6h1JeQrwB3xtWtIIXmmL2VEwmO/2YfTDyu+JpRkkgwDMLgyRKN9wEtaR+4C3X/p9zMysocDhyccOeGVq7XhJwgdosoJ0VRLVtUhPq1T10B/ipp2g8VF9TW1uIfSQJe6YYCrVK+fqtkWG5yuOfqQdGHNZkRJMpeTyzkJQzX7GZb8G0H8EZCsjdJ0FdEpshWcCB2ljozwH3fFMqnzE1thibpg7dC2BXF7aRGjmn/4vqme98i4hP+590FIMF+sdyDItVq7/91EAwh7m35dvszkFruIzLgHFRnrKAgG76bTHTz8bwywhnCZVbDmy/HEDOjj2ykW9jPKJ7buKRKVYbXnSgYqkn/keTHiRvLI= From e5f139d750eacbab699f071c32680bf651e75f36 Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 7 Dec 2018 15:59:27 -0500 Subject: [PATCH 11/59] Added maximum time wait for running tests with docker containers --- .../EdgeServiceIntegrationCalculation.java | 16 ++++++++++------ ...geServiceIntegrationTestsGmapsAdapter.java | 11 +++++++---- .../EdgeServiceIntegrationTestsTripCmd.java | 17 ++++++++++------- ...geServiceIntegrationTestsTripCmdQuery.java | 19 +++++++++++-------- .../EdgeServiceIntegrationTestsTripQuery.java | 17 ++++++++++------- .../resources/docker-compose-calculation.yml | 13 +++++++++---- .../docker-compose-gmaps-adapter.yml | 9 ++++----- .../docker-compose-trip-cmd-query.yml | 8 +++++--- .../resources/docker-compose-trip-cmd.yml | 8 +++++--- .../resources/docker-compose-trip-query.yml | 8 +++++--- 10 files changed, 76 insertions(+), 50 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java index ec12526..0d56271 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java @@ -3,11 +3,13 @@ import static org.assertj.core.api.Java6Assertions.assertThat; import com.palantir.docker.compose.DockerComposeRule; +import com.palantir.docker.compose.configuration.ShutdownStrategy; import com.palantir.docker.compose.connection.DockerPort; import com.palantir.docker.compose.connection.waiting.HealthChecks; import java.util.*; +import org.joda.time.Duration; import org.json.JSONException; import org.json.JSONObject; import org.junit.Before; @@ -33,16 +35,18 @@ public class EdgeServiceIntegrationCalculation { private static String mongoURL; private static String gmapsAdapterURL; private static String calculationServiceURL; + private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); // Wait for all services to have ports open @ClassRule public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) - .file("src/test/resources/docker-compose-calculation.yml") - .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()).build(); + .file("src/test/resources/docker-compose-calculation.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) + .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .build(); // Get IP addresses and ports to run tests on @BeforeClass diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java index a670038..5238eea 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java @@ -3,11 +3,13 @@ import static org.assertj.core.api.Java6Assertions.assertThat; import com.palantir.docker.compose.DockerComposeRule; +import com.palantir.docker.compose.configuration.ShutdownStrategy; import com.palantir.docker.compose.connection.DockerPort; import com.palantir.docker.compose.connection.waiting.HealthChecks; import java.util.*; +import org.joda.time.Duration; import org.json.JSONException; import org.json.JSONObject; import org.junit.Before; @@ -31,14 +33,15 @@ public class EdgeServiceIntegrationTestsGmapsAdapter { private static String discoveryServiceURL; private static String gmapsAdapterURL; + private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); // Wait for all services to have ports open @ClassRule public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) - .file("src/test/resources/docker-compose-gmaps-adapter.yml") - .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) + .file("src/test/resources/docker-compose-gmaps-adapter.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) + .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) .build(); // Get IP addresses and ports to run tests on diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java index d96d1c9..431e410 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java @@ -3,11 +3,13 @@ import static org.assertj.core.api.Java6Assertions.assertThat; import com.palantir.docker.compose.DockerComposeRule; +import com.palantir.docker.compose.configuration.ShutdownStrategy; import com.palantir.docker.compose.connection.DockerPort; import com.palantir.docker.compose.connection.waiting.HealthChecks; import java.util.*; +import org.joda.time.Duration; import org.json.JSONException; import org.json.JSONObject; import org.junit.Before; @@ -33,17 +35,18 @@ public class EdgeServiceIntegrationTestsTripCmd { private static String mongoURL; private static String userServiceURL; private static String tripCommandURL; + private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); // Wait for all services to have ports open @ClassRule public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) - .file("src/test/resources/docker-compose-trip-cmd.yml") - .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) + .file("src/test/resources/docker-compose-trip-cmd.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) + .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) .build(); // Get IP addresses and ports to run tests on diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java index d749e43..a6bb486 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java @@ -3,11 +3,13 @@ import static org.assertj.core.api.Java6Assertions.assertThat; import com.palantir.docker.compose.DockerComposeRule; +import com.palantir.docker.compose.configuration.ShutdownStrategy; import com.palantir.docker.compose.connection.DockerPort; import com.palantir.docker.compose.connection.waiting.HealthChecks; import java.util.*; +import org.joda.time.Duration; import org.json.JSONException; import org.json.JSONObject; import org.junit.Before; @@ -34,18 +36,19 @@ public class EdgeServiceIntegrationTestsTripCmdQuery { private static String userServiceURL; private static String tripCommandURL; private static String tripQueryURL; + private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); // Wait for all services to have ports open @ClassRule public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) - .file("src/test/resources/docker-compose-trip-cmd-query.yml") - .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) + .file("src/test/resources/docker-compose-trip-cmd-query.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) + .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) .build(); // Get IP addresses and ports to run tests on diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java index 9b55504..d22fe7b 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java @@ -3,11 +3,13 @@ import static org.assertj.core.api.Java6Assertions.assertThat; import com.palantir.docker.compose.DockerComposeRule; +import com.palantir.docker.compose.configuration.ShutdownStrategy; import com.palantir.docker.compose.connection.DockerPort; import com.palantir.docker.compose.connection.waiting.HealthChecks; import java.util.*; +import org.joda.time.Duration; import org.json.JSONException; import org.json.JSONObject; import org.junit.Before; @@ -33,17 +35,18 @@ public class EdgeServiceIntegrationTestsTripQuery { private static String mongoURL; private static String userServiceURL; private static String tripQueryURL; + private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); // Wait for all services to have ports open @ClassRule public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) - .file("src/test/resources/docker-compose-trip-query.yml") - .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) + .file("src/test/resources/docker-compose-trip-query.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) + .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) + .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) .build(); // Get IP addresses and ports to run tests on diff --git a/src/test/resources/docker-compose-calculation.yml b/src/test/resources/docker-compose-calculation.yml index 2e4dc72..26c4474 100644 --- a/src/test/resources/docker-compose-calculation.yml +++ b/src/test/resources/docker-compose-calculation.yml @@ -4,14 +4,15 @@ services: discoveryservice: image: aista/eureka + container_name: 'discoveryservice' mem_limit: 512M ports: - "8761:8761" mongo: image: 'mongo:3.4.1' - mem_limit: 512M container_name: 'mongo' + mem_limit: 512M ports: - '27017:27017' volumes: @@ -19,14 +20,15 @@ services: rabbitmq: image: rabbitmq:management - mem_limit: 512M container_name: 'rabbitmq' + mem_limit: 512M ports: - "5672:5672" - "15672:15672" gmapsadapter: image: aista/gmaps-adapter + container_name: 'gmapsadapter' mem_limit: 512M environment: - EUREKA_SERVER=discoveryservice @@ -35,11 +37,13 @@ services: - '8080' depends_on: - discoveryservice + - rabbitmq environment: - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC calculationservice: image: aista/calculation-service + container_name: 'calculationservice' mem_limit: 512M environment: - RABBIT_HOST=rabbitmq @@ -51,7 +55,8 @@ services: - '8080' depends_on: - discoveryservice + - rabbitmq + - mongo volumes: - mongo: - mysql-data: \ No newline at end of file + mongo: \ No newline at end of file diff --git a/src/test/resources/docker-compose-gmaps-adapter.yml b/src/test/resources/docker-compose-gmaps-adapter.yml index ef72263..943e15d 100644 --- a/src/test/resources/docker-compose-gmaps-adapter.yml +++ b/src/test/resources/docker-compose-gmaps-adapter.yml @@ -4,20 +4,22 @@ services: discoveryservice: image: aista/eureka + container_name: 'discoveryservice' mem_limit: 512M ports: - "8761:8761" rabbitmq: image: rabbitmq:management - mem_limit: 512M container_name: 'rabbitmq' + mem_limit: 512M ports: - "5672:5672" - "15672:15672" gmapsadapter: image: aista/gmaps-adapter + container_name: 'gmapsadapter' mem_limit: 512M environment: - EUREKA_SERVER=discoveryservice @@ -26,9 +28,6 @@ services: - '8080' depends_on: - discoveryservice + - rabbitmq environment: - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC - -volumes: - mongo: - mysql-data: \ No newline at end of file diff --git a/src/test/resources/docker-compose-trip-cmd-query.yml b/src/test/resources/docker-compose-trip-cmd-query.yml index 2d300be..94eb577 100644 --- a/src/test/resources/docker-compose-trip-cmd-query.yml +++ b/src/test/resources/docker-compose-trip-cmd-query.yml @@ -4,12 +4,14 @@ services: discoveryservice: image: aista/eureka + container_name: discoveryservice mem_limit: 512M ports: - "8761:8761" mysqlserver: image: mysql:5.7 + container_name: mysqlserver mem_limit: 512M volumes: - mysql-data:/var/lib/mysql:rw @@ -25,8 +27,8 @@ services: userservice: image: aista/user-service - mem_limit: 512M container_name: userservice + mem_limit: 512M depends_on: - discoveryservice - mysqlserver @@ -37,8 +39,8 @@ services: mongo: image: 'mongo:3.4.1' - mem_limit: 512M container_name: 'mongo' + mem_limit: 512M ports: - '27017:27017' volumes: @@ -46,8 +48,8 @@ services: rabbitmq: image: rabbitmq:management - mem_limit: 512M container_name: 'rabbitmq' + mem_limit: 512M ports: - "5672:5672" - "15672:15672" diff --git a/src/test/resources/docker-compose-trip-cmd.yml b/src/test/resources/docker-compose-trip-cmd.yml index 32a0570..ea54c58 100644 --- a/src/test/resources/docker-compose-trip-cmd.yml +++ b/src/test/resources/docker-compose-trip-cmd.yml @@ -4,12 +4,14 @@ services: discoveryservice: image: aista/eureka + container_name: 'discoveryservice' mem_limit: 512M ports: - "8761:8761" mysqlserver: image: mysql:5.7 + container_name: 'mysqlserver' mem_limit: 512M volumes: - mysql-data:/var/lib/mysql:rw @@ -25,8 +27,8 @@ services: userservice: image: aista/user-service - mem_limit: 512M container_name: userservice + mem_limit: 512M depends_on: - discoveryservice - mysqlserver @@ -37,8 +39,8 @@ services: mongo: image: 'mongo:3.4.1' - mem_limit: 512M container_name: 'mongo' + mem_limit: 512M ports: - '27017:27017' volumes: @@ -46,8 +48,8 @@ services: rabbitmq: image: rabbitmq:management - mem_limit: 512M container_name: 'rabbitmq' + mem_limit: 512M ports: - "5672:5672" - "15672:15672" diff --git a/src/test/resources/docker-compose-trip-query.yml b/src/test/resources/docker-compose-trip-query.yml index afa2b6b..f9370c2 100644 --- a/src/test/resources/docker-compose-trip-query.yml +++ b/src/test/resources/docker-compose-trip-query.yml @@ -4,12 +4,14 @@ services: discoveryservice: image: aista/eureka + container_name: discoveryservice mem_limit: 512M ports: - "8761:8761" mysqlserver: image: mysql:5.7 + container_name: mysqlserver mem_limit: 512M volumes: - mysql-data:/var/lib/mysql:rw @@ -25,8 +27,8 @@ services: userservice: image: aista/user-service - mem_limit: 512M container_name: userservice + mem_limit: 512M depends_on: - discoveryservice - mysqlserver @@ -37,8 +39,8 @@ services: mongo: image: 'mongo:3.4.1' - mem_limit: 512M container_name: 'mongo' + mem_limit: 512M ports: - '27017:27017' volumes: @@ -46,8 +48,8 @@ services: rabbitmq: image: rabbitmq:management - mem_limit: 512M container_name: 'rabbitmq' + mem_limit: 512M ports: - "5672:5672" - "15672:15672" From a162fa69b4dee5eb4f18a6c948db5c0ae48e02ad Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 7 Dec 2018 16:44:33 -0500 Subject: [PATCH 12/59] Added environment variables for tests --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index d08163b..758f6e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,9 @@ script: - travis_wait 30 ./gradlew check -i env: global: + - EUREKA_SERVER="localhost" + - RABBIT_HOST="localhost" + - MONGO_HOST="localhost" - secure: WF5U05+p8xQRBhT75aviCl9sXpnzER52xJDkKaZPtsak3B/21rj5FGQ4TTu9ivh0oF56ws8Zy8hzNZhjS09QimqtpD+Zl5m5er4Q2GvrStVDM0k38wqye2IBf7juKIlkfntX1o1E9/xGkUgIW5eQpUt7TDGpon5FCvY8NHqDyVi+ZDU7hGQh8E3oyK+8Dly1ETLxVhoDEY3vG1VyEZ1IDrgAw/N6KlNIyiuWjPMBLTFAjGMzJAaf/MQiKfmB3HUBUtGqEdhobppEqriJkXl/6ov+Np+vh83dIBaOfRUpB1KgvGmefmtL7rb+mIIXOLMm9cpyqmK+6h1JeQrwB3xtWtIIXmmL2VEwmO/2YfTDyu+JpRkkgwDMLgyRKN9wEtaR+4C3X/p9zMysocDhyccOeGVq7XhJwgdosoJ0VRLVtUhPq1T10B/ipp2g8VF9TW1uIfSQJe6YYCrVK+fqtkWG5yuOfqQdGHNZkRJMpeTyzkJQzX7GZb8G0H8EZCsjdJ0FdEpshWcCB2ljozwH3fFMqnzE1thibpg7dC2BXF7aRGjmn/4vqme98i4hP+590FIMF+sdyDItVq7/91EAwh7m35dvszkFruIzLgHFRnrKAgG76bTHTz8bwywhnCZVbDmy/HEDOjj2ykW9jPKJ7buKRKVYbXnSgYqkn/keTHiRvLI= - secure: KlDa/wnlEEvkH4tnxTtxdWdBHJl8Kuv8tWknqxKL1rWcvo8UXNWXeBtvAB5v7eiCSJLwOqLm9Cl4OVwnZjU3oi4ymECYY296bQRFGS01DDYeExFd/VycDvV2L9FRP+71qZt2k2/DBabheI2WNLXESyAG1oJcI7IYyiDQBoA7hz72dYjQ5T8NISab8KGLCq02mvh3n+rtchgOPtbxU2wGqse+3lzui4m9/qAC+3tZJNXx7l+hzNSh1zqIhjIrzXrPs0PneCLdfTl1lZhSO2DCBo9juz2bisSdOdOWt7hssb7noOByfU9z1O2QVUfWJfUTjVwToxFaP94JeUo6rDo3gRo2WJn313f8ZtgtzQkPYrV8bTTRZ8mhb7D2Eq/2RllBRXJRdQuOv1t7mSr+hdD/mJUyHQY6yvK3YFAKkgK60aUAGMhBE2GBVFzx7qU06OBwdHJ2YBiKSC/+9sGFVhR6zIQxVPV4fdyaLLL4CEJC1vvTmHYZj1hqSZsWhuqddxQNj0RKIsfN8akW/Gi4mv2q32eCwG6XhXIKqLGVGuyHKx1N3gCjBK3Whz5QX/u8ADq7euB+mgyC/wILrzb281VARQkuu5FwUutv0x+y4S/061VZATwhY+ree728mjSxHu5qtoyI3xH6OjWDtmp+zyZOdrF2D+/ReiIRd4vkShme7sI= before_install: From e0f627b29f247a19b82a6baa018c107cc4114e3c Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 7 Dec 2018 18:11:02 -0500 Subject: [PATCH 13/59] Output IP ports in logs --- .travis.yml | 2 +- .../edge/edgeservice/EdgeServiceIntegrationCalculation.java | 2 +- .../edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 758f6e7..c7b5fb2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ before_script: - sudo service mysql stop - export -f travis_wait script: - - travis_wait 30 ./gradlew check -i + - travis_wait 5 ./gradlew check -i env: global: - EUREKA_SERVER="localhost" diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java index 0d56271..a2db308 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java @@ -75,7 +75,7 @@ public static void initialize() { gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); while (!docker.containers().container("gmapsadapter") .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { - LOG.info("Waiting for user service to respond over HTTP"); + LOG.info("Waiting for gmapsadapter to respond over HTTP"); } LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java index 5238eea..ed0323a 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java @@ -56,6 +56,9 @@ public static void initialize() { while (!docker.containers().container("discoveryservice") .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { LOG.info("Waiting for discovery service to respond over HTTP"); + LOG.info("IP: " + discoveryService.getIp()); + LOG.info("Ext Port: " + discoveryService.getExternalPort()); + LOG.info("Int Port: " + discoveryService.getInternalPort()); } LOG.info("Discovery Service url found: " + discoveryServiceURL); @@ -63,7 +66,7 @@ public static void initialize() { gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); while (!docker.containers().container("gmapsadapter") .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { - LOG.info("Waiting for user service to respond over HTTP"); + LOG.info("Waiting for gmapsadapter to respond over HTTP"); } LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); From 36ce47426430551f981c381e05808e121f6e6a6e Mon Sep 17 00:00:00 2001 From: jusoto Date: Mon, 10 Dec 2018 22:51:35 -0500 Subject: [PATCH 14/59] Added new testing variation of healthy container for travis --- build.gradle | 2 +- ...geServiceIntegrationTestsGmapsAdapter.java | 21 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index 83a7850..fbd4b05 100644 --- a/build.gradle +++ b/build.gradle @@ -56,7 +56,7 @@ dependencies { testCompile('com.jayway.restassured:rest-assured:2.5.0') testCompile ('com.jayway.restassured:spring-mock-mvc:2.5.0') testCompile ('org.springframework.cloud:spring-cloud-starter-contract-stub-runner') - testCompile ('com.palantir.docker.compose:docker-compose-rule-junit4:0.33.0') + testCompile ('com.palantir.docker.compose:docker-compose-rule-junit4:0.34.0') } dependencyManagement { diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java index ed0323a..7ec5708 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java @@ -4,6 +4,7 @@ import com.palantir.docker.compose.DockerComposeRule; import com.palantir.docker.compose.configuration.ShutdownStrategy; +import com.palantir.docker.compose.connection.Container; import com.palantir.docker.compose.connection.DockerPort; import com.palantir.docker.compose.connection.waiting.HealthChecks; @@ -46,21 +47,19 @@ public class EdgeServiceIntegrationTestsGmapsAdapter { // Get IP addresses and ports to run tests on @BeforeClass - public static void initialize() { + public static void initialize() throws Exception { LOG.info("Initializing ports from Docker"); - DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); - discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), - discoveryService.getExternalPort()); - while (!docker.containers().container("discoveryservice") - .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { - LOG.info("Waiting for discovery service to respond over HTTP"); - LOG.info("IP: " + discoveryService.getIp()); - LOG.info("Ext Port: " + discoveryService.getExternalPort()); - LOG.info("Int Port: " + discoveryService.getInternalPort()); + Container discoveryContainer = docker.containers().container("discoveryservice"); + DockerPort discoveryPort = discoveryContainer.port(8761); + if(!discoveryPort.isListeningNow()){ + LOG.info("Dscovery service didn't respond over HTTP"); + LOG.info("IP: " + discoveryPort.getIp()); + LOG.info("Ext Port: " + discoveryPort.getExternalPort()); + LOG.info("Int Port: " + discoveryPort.getInternalPort()); + throw new Exception(String.format("Discovery didn't respond, port: %s",discoveryPort.getInternalPort())); } - LOG.info("Discovery Service url found: " + discoveryServiceURL); DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); From fa6a1aeeea36f745ee95fab40b6cad5edaf57c3d Mon Sep 17 00:00:00 2001 From: jusoto Date: Tue, 11 Dec 2018 09:03:03 -0500 Subject: [PATCH 15/59] test changes for travis --- .../EdgeServiceIntegrationCalculation.java | 68 ++++++++------- ...geServiceIntegrationTestsGmapsAdapter.java | 29 ++++--- .../EdgeServiceIntegrationTestsTripCmd.java | 67 ++++++++------- ...geServiceIntegrationTestsTripCmdQuery.java | 84 ++++++++++--------- .../EdgeServiceIntegrationTestsTripQuery.java | 67 ++++++++------- 5 files changed, 174 insertions(+), 141 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java index a2db308..e31381a 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java @@ -4,6 +4,7 @@ import com.palantir.docker.compose.DockerComposeRule; import com.palantir.docker.compose.configuration.ShutdownStrategy; +import com.palantir.docker.compose.connection.Container; import com.palantir.docker.compose.connection.DockerPort; import com.palantir.docker.compose.connection.waiting.HealthChecks; @@ -50,43 +51,50 @@ public class EdgeServiceIntegrationCalculation { // Get IP addresses and ports to run tests on @BeforeClass - public static void initialize() { + public static void initialize() throws Exception { LOG.info("Initializing ports from Docker"); - DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); - discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), - discoveryService.getExternalPort()); - while (!docker.containers().container("discoveryservice") - .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { - LOG.info("Waiting for discovery service to respond over HTTP"); + Container discoveryContainer = docker.containers().container("discoveryservice"); + DockerPort discoveryPort = discoveryContainer.port(8761); + discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), + discoveryPort.getExternalPort()); + if(!discoveryPort.isListeningNow()){ + LOG.info("Discovery service didn't respond over HTTP"); + throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); } - LOG.info("Discovery Service url found: " + discoveryServiceURL); - - DockerPort mongo = docker.containers().container("mongo").port(27017); - mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); - while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) - .succeeded()) { - LOG.info("Waiting for mongo to respond over HTTP"); + LOG.info("Discovery service responded over HTTP"); + + Container mongoContainer = docker.containers().container("mongo"); + DockerPort mongoPort = mongoContainer.port(27017); + mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); + if(!mongoPort.isListeningNow()){ + LOG.info("Mongo service didn't respond over HTTP"); + throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); } - LOG.info("Mongo url found: " + mongoURL); - - DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); - gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); - while (!docker.containers().container("gmapsadapter") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { - LOG.info("Waiting for gmapsadapter to respond over HTTP"); + LOG.info("Mongo service responded over HTTP"); + + Container gmapsAdapterContainer = docker.containers().container("gmapsadapter"); + DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); + gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapterPort.getIp(), + gmapsAdapterPort.getExternalPort()); + if(!gmapsAdapterPort.isListeningNow()){ + LOG.info("Gmaps Adapter service didn't respond over HTTP"); + throw new Exception(String.format("Gmaps Adapter didn't respond, port: %s", gmapsAdapterPort.getInternalPort())); } - LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); - - DockerPort calculationService = docker.containers().container("calculationservice").port(8080); - calculationServiceURL = String.format("http://%s:%s", calculationService.getIp(), - calculationService.getExternalPort()); - while (!docker.containers().container("calculationservice") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(calculationServiceURL)).succeeded()) { - LOG.info("Waiting for calculation service to respond over HTTP"); + LOG.info("Gmaps Adapter service responded over HTTP"); + + Container calculationContainer = docker.containers().container("calculationservice"); + DockerPort calculationPort = calculationContainer.port(8080); + calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), + calculationPort.getExternalPort()); + if(!calculationPort.isListeningNow()){ + LOG.info("Calculation service didn't respond over HTTP"); + throw new Exception(String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); } - LOG.info("Calculation Service url found: " + calculationServiceURL); + LOG.info("Calculation service responded over HTTP"); + + LOG.info("Containers initialized correctly"); } private TestRestTemplate restTemplate = new TestRestTemplate(); diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java index 7ec5708..6164e94 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java @@ -53,22 +53,25 @@ public static void initialize() throws Exception { Container discoveryContainer = docker.containers().container("discoveryservice"); DockerPort discoveryPort = discoveryContainer.port(8761); + discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), + discoveryPort.getExternalPort()); if(!discoveryPort.isListeningNow()){ - LOG.info("Dscovery service didn't respond over HTTP"); - LOG.info("IP: " + discoveryPort.getIp()); - LOG.info("Ext Port: " + discoveryPort.getExternalPort()); - LOG.info("Int Port: " + discoveryPort.getInternalPort()); - throw new Exception(String.format("Discovery didn't respond, port: %s",discoveryPort.getInternalPort())); + LOG.info("Discovery service didn't respond over HTTP"); + throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); } - - DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); - gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); - while (!docker.containers().container("gmapsadapter") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { - LOG.info("Waiting for gmapsadapter to respond over HTTP"); + LOG.info("Discovery service responded over HTTP"); + + Container gmapsAdapterContainer = docker.containers().container("gmapsadapter"); + DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); + gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapterPort.getIp(), + gmapsAdapterPort.getExternalPort()); + if(!gmapsAdapterPort.isListeningNow()){ + LOG.info("Gmaps Adapter service didn't respond over HTTP"); + throw new Exception(String.format("Gmaps Adapter didn't respond, port: %s", gmapsAdapterPort.getInternalPort())); } - LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); - + LOG.info("Gmaps Adapter service responded over HTTP"); + + LOG.info("Containers initialized correctly"); } private TestRestTemplate restTemplate = new TestRestTemplate(); diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java index 431e410..b3e2da8 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java @@ -4,6 +4,7 @@ import com.palantir.docker.compose.DockerComposeRule; import com.palantir.docker.compose.configuration.ShutdownStrategy; +import com.palantir.docker.compose.connection.Container; import com.palantir.docker.compose.connection.DockerPort; import com.palantir.docker.compose.connection.waiting.HealthChecks; @@ -51,43 +52,49 @@ public class EdgeServiceIntegrationTestsTripCmd { // Get IP addresses and ports to run tests on @BeforeClass - public static void initialize() { + public static void initialize() throws Exception { LOG.info("Initializing ports from Docker"); - DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); - discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), - discoveryService.getExternalPort()); - while (!docker.containers().container("discoveryservice") - .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { - LOG.info("Waiting for discovery service to respond over HTTP"); + Container discoveryContainer = docker.containers().container("discoveryservice"); + DockerPort discoveryPort = discoveryContainer.port(8761); + discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), + discoveryPort.getExternalPort()); + if(!discoveryPort.isListeningNow()){ + LOG.info("Discovery service didn't respond over HTTP"); + throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); } - LOG.info("Discovery Service url found: " + discoveryServiceURL); - - DockerPort mongo = docker.containers().container("mongo").port(27017); - mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); - while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) - .succeeded()) { - LOG.info("Waiting for mongo to respond over HTTP"); + LOG.info("Discovery service responded over HTTP"); + + Container mongoContainer = docker.containers().container("mongo"); + DockerPort mongoPort = mongoContainer.port(27017); + mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); + if(!mongoPort.isListeningNow()){ + LOG.info("Mongo service didn't respond over HTTP"); + throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); } - LOG.info("Mongo url found: " + mongoURL); - - DockerPort userService = docker.containers().container("userservice").port(8080); - userServiceURL = String.format("http://%s:%s", userService.getIp(), userService.getExternalPort()); - while (!docker.containers().container("userservice") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { - LOG.info("Waiting for user service to respond over HTTP"); + LOG.info("Mongo service responded over HTTP"); + + Container userContainer = docker.containers().container("userservice"); + DockerPort userPort = userContainer.port(8080); + userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); + if(!userPort.isListeningNow()){ + LOG.info("User service didn't respond over HTTP"); + throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); } - LOG.info("User Service url found: " + userServiceURL); - - DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd").port(8080); - tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), - tripManagementCommand.getExternalPort()); - while (!docker.containers().container("tripmanagementcmd") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripCommandURL)).succeeded()) { - LOG.info("Waiting for Trip Command to respond over HTTP"); + LOG.info("User service responded over HTTP"); + + Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); + DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); + tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), + tripManagementCmdPort.getExternalPort()); + if(!userPort.isListeningNow()){ + LOG.info("TripManagementCmd service didn't respond over HTTP"); + throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", tripManagementCmdPort.getInternalPort())); } - LOG.info("Trip Command url found: " + tripCommandURL); + LOG.info("TripManagementCmd service responded over HTTP"); + + LOG.info("Containers initialized correctly"); } private TestRestTemplate restTemplate = new TestRestTemplate(); diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java index a6bb486..26b9a01 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java @@ -4,6 +4,7 @@ import com.palantir.docker.compose.DockerComposeRule; import com.palantir.docker.compose.configuration.ShutdownStrategy; +import com.palantir.docker.compose.connection.Container; import com.palantir.docker.compose.connection.DockerPort; import com.palantir.docker.compose.connection.waiting.HealthChecks; @@ -53,52 +54,59 @@ public class EdgeServiceIntegrationTestsTripCmdQuery { // Get IP addresses and ports to run tests on @BeforeClass - public static void initialize() { + public static void initialize() throws Exception { LOG.info("Initializing ports from Docker"); - DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); - discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), - discoveryService.getExternalPort()); - while (!docker.containers().container("discoveryservice") - .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { - LOG.info("Waiting for discovery service to respond over HTTP"); + Container discoveryContainer = docker.containers().container("discoveryservice"); + DockerPort discoveryPort = discoveryContainer.port(8761); + discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), + discoveryPort.getExternalPort()); + if(!discoveryPort.isListeningNow()){ + LOG.info("Discovery service didn't respond over HTTP"); + throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); } - LOG.info("Discovery Service url found: " + discoveryServiceURL); - - DockerPort mongo = docker.containers().container("mongo").port(27017); - mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); - while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) - .succeeded()) { - LOG.info("Waiting for mongo to respond over HTTP"); + LOG.info("Discovery service responded over HTTP"); + + Container mongoContainer = docker.containers().container("mongo"); + DockerPort mongoPort = mongoContainer.port(27017); + mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); + if(!mongoPort.isListeningNow()){ + LOG.info("Mongo service didn't respond over HTTP"); + throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); } - LOG.info("Mongo url found: " + mongoURL); - - DockerPort userService = docker.containers().container("userservice").port(8080); - userServiceURL = String.format("http://%s:%s", userService.getIp(), userService.getExternalPort()); - while (!docker.containers().container("userservice") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { - LOG.info("Waiting for user service to respond over HTTP"); + LOG.info("Mongo service responded over HTTP"); + + Container userContainer = docker.containers().container("userservice"); + DockerPort userPort = userContainer.port(8080); + userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); + if(!userPort.isListeningNow()){ + LOG.info("User service didn't respond over HTTP"); + throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); } - LOG.info("User Service url found: " + userServiceURL); - - DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd").port(8080); - tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), - tripManagementCommand.getExternalPort()); - while (!docker.containers().container("tripmanagementcmd") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripCommandURL)).succeeded()) { - LOG.info("Waiting for Trip Command to respond over HTTP"); + LOG.info("User service responded over HTTP"); + + Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); + DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); + tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), + tripManagementCmdPort.getExternalPort()); + if(!tripManagementCmdPort.isListeningNow()){ + LOG.info("TripManagementCmd service didn't respond over HTTP"); + throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", tripManagementCmdPort.getInternalPort())); } - LOG.info("Trip Command url found: " + tripCommandURL); - - DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery").port(8080); - tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(), - tripManagementQuery.getExternalPort()); - while (!docker.containers().container("tripmanagementquery") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripQueryURL)).succeeded()) { - LOG.info("Waiting for Trip Query to respond over HTTP"); + LOG.info("TripManagementCmd service responded over HTTP"); + + Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); + DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); + tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), + tripManagementQueryPort.getExternalPort()); + if(!tripManagementQueryPort.isListeningNow()){ + LOG.info("TripManagementQuery service didn't respond over HTTP"); + throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", tripManagementQueryPort.getInternalPort())); } - LOG.info("Trip Query url found: " + tripQueryURL); + LOG.info("TripManagementQuery service responded over HTTP"); + + LOG.info("Containers initialized correctly"); } private TestRestTemplate restTemplate = new TestRestTemplate(); diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java index d22fe7b..5809429 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java @@ -4,6 +4,7 @@ import com.palantir.docker.compose.DockerComposeRule; import com.palantir.docker.compose.configuration.ShutdownStrategy; +import com.palantir.docker.compose.connection.Container; import com.palantir.docker.compose.connection.DockerPort; import com.palantir.docker.compose.connection.waiting.HealthChecks; @@ -51,43 +52,49 @@ public class EdgeServiceIntegrationTestsTripQuery { // Get IP addresses and ports to run tests on @BeforeClass - public static void initialize() { + public static void initialize() throws Exception { LOG.info("Initializing ports from Docker"); - DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); - discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), - discoveryService.getExternalPort()); - while (!docker.containers().container("discoveryservice") - .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { - LOG.info("Waiting for discovery service to respond over HTTP"); + Container discoveryContainer = docker.containers().container("discoveryservice"); + DockerPort discoveryPort = discoveryContainer.port(8761); + discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), + discoveryPort.getExternalPort()); + if(!discoveryPort.isListeningNow()){ + LOG.info("Discovery service didn't respond over HTTP"); + throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); } - LOG.info("Discovery Service url found: " + discoveryServiceURL); - - DockerPort mongo = docker.containers().container("mongo").port(27017); - mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); - while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) - .succeeded()) { - LOG.info("Waiting for mongo to respond over HTTP"); + LOG.info("Discovery service responded over HTTP"); + + Container mongoContainer = docker.containers().container("mongo"); + DockerPort mongoPort = mongoContainer.port(27017); + mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); + if(!mongoPort.isListeningNow()){ + LOG.info("Mongo service didn't respond over HTTP"); + throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); } - LOG.info("Mongo url found: " + mongoURL); - - DockerPort userService = docker.containers().container("userservice").port(8080); - userServiceURL = String.format("http://%s:%s", userService.getIp(), userService.getExternalPort()); - while (!docker.containers().container("userservice") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { - LOG.info("Waiting for user service to respond over HTTP"); + LOG.info("Mongo service responded over HTTP"); + + Container userContainer = docker.containers().container("userservice"); + DockerPort userPort = userContainer.port(8080); + userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); + if(!userPort.isListeningNow()){ + LOG.info("User service didn't respond over HTTP"); + throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); } - LOG.info("User Service url found: " + userServiceURL); - - DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery").port(8080); - tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(), - tripManagementQuery.getExternalPort()); - while (!docker.containers().container("tripmanagementquery") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripQueryURL)).succeeded()) { - LOG.info("Waiting for Trip Query to respond over HTTP"); + LOG.info("User service responded over HTTP"); + + Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); + DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); + tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), + tripManagementQueryPort.getExternalPort()); + if(!tripManagementQueryPort.isListeningNow()){ + LOG.info("TripManagementQuery service didn't respond over HTTP"); + throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", tripManagementQueryPort.getInternalPort())); } - LOG.info("Trip Query url found: " + tripQueryURL); + LOG.info("TripManagementQuery service responded over HTTP"); + + LOG.info("Containers initialized correctly"); } private TestRestTemplate restTemplate = new TestRestTemplate(); From 19cba196fff72318db1e84fd1bdf52771831ae30 Mon Sep 17 00:00:00 2001 From: jusoto Date: Tue, 11 Dec 2018 09:34:34 -0500 Subject: [PATCH 16/59] join together different test cases files into one for travis --- .../EdgeServiceIntegrationCalculation.java | 254 ++++----- .../EdgeServiceIntegrationTests.java | 523 +++++++++--------- ...geServiceIntegrationTestsGmapsAdapter.java | 220 ++++---- .../EdgeServiceIntegrationTestsTripCmd.java | 300 +++++----- ...geServiceIntegrationTestsTripCmdQuery.java | 342 ++++++------ .../EdgeServiceIntegrationTestsTripQuery.java | 288 +++++----- 6 files changed, 969 insertions(+), 958 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java index e31381a..5355ace 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java @@ -1,127 +1,127 @@ -package aist.edge.edgeservice; - -import static org.assertj.core.api.Java6Assertions.assertThat; - -import com.palantir.docker.compose.DockerComposeRule; -import com.palantir.docker.compose.configuration.ShutdownStrategy; -import com.palantir.docker.compose.connection.Container; -import com.palantir.docker.compose.connection.DockerPort; -import com.palantir.docker.compose.connection.waiting.HealthChecks; - -import java.util.*; - -import org.joda.time.Duration; -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.*; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.*; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class EdgeServiceIntegrationCalculation { - protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationCalculation.class); - - private static String discoveryServiceURL; - private static String mongoURL; - private static String gmapsAdapterURL; - private static String calculationServiceURL; - private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); - - // Wait for all services to have ports open - @ClassRule - public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) - .file("src/test/resources/docker-compose-calculation.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) - .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .build(); - - // Get IP addresses and ports to run tests on - @BeforeClass - public static void initialize() throws Exception { - - LOG.info("Initializing ports from Docker"); - - Container discoveryContainer = docker.containers().container("discoveryservice"); - DockerPort discoveryPort = discoveryContainer.port(8761); - discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), - discoveryPort.getExternalPort()); - if(!discoveryPort.isListeningNow()){ - LOG.info("Discovery service didn't respond over HTTP"); - throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); - } - LOG.info("Discovery service responded over HTTP"); - - Container mongoContainer = docker.containers().container("mongo"); - DockerPort mongoPort = mongoContainer.port(27017); - mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); - if(!mongoPort.isListeningNow()){ - LOG.info("Mongo service didn't respond over HTTP"); - throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); - } - LOG.info("Mongo service responded over HTTP"); - - Container gmapsAdapterContainer = docker.containers().container("gmapsadapter"); - DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); - gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapterPort.getIp(), - gmapsAdapterPort.getExternalPort()); - if(!gmapsAdapterPort.isListeningNow()){ - LOG.info("Gmaps Adapter service didn't respond over HTTP"); - throw new Exception(String.format("Gmaps Adapter didn't respond, port: %s", gmapsAdapterPort.getInternalPort())); - } - LOG.info("Gmaps Adapter service responded over HTTP"); - - Container calculationContainer = docker.containers().container("calculationservice"); - DockerPort calculationPort = calculationContainer.port(8080); - calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), - calculationPort.getExternalPort()); - if(!calculationPort.isListeningNow()){ - LOG.info("Calculation service didn't respond over HTTP"); - throw new Exception(String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); - } - LOG.info("Calculation service responded over HTTP"); - - LOG.info("Containers initialized correctly"); - } - - private TestRestTemplate restTemplate = new TestRestTemplate(); - - private String token; - - @Before - public void setUp() throws JSONException { - token = ""; - } - - @Test - public void calculationServiceRequestSuccess() { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); - - String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\"," - + " \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; - HttpEntity request = new HttpEntity<>(body, headers); - - // when: - ResponseEntity response = restTemplate.postForEntity(calculationServiceURL + "/api/v1/cost", request, - String.class); - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); - } -} +//package aist.edge.edgeservice; +// +//import static org.assertj.core.api.Java6Assertions.assertThat; +// +//import com.palantir.docker.compose.DockerComposeRule; +//import com.palantir.docker.compose.configuration.ShutdownStrategy; +//import com.palantir.docker.compose.connection.Container; +//import com.palantir.docker.compose.connection.DockerPort; +//import com.palantir.docker.compose.connection.waiting.HealthChecks; +// +//import java.util.*; +// +//import org.joda.time.Duration; +//import org.json.JSONException; +//import org.json.JSONObject; +//import org.junit.Before; +//import org.junit.BeforeClass; +//import org.junit.ClassRule; +//import org.junit.Test; +//import org.junit.runner.RunWith; +// +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.boot.test.web.client.TestRestTemplate; +//import org.springframework.http.*; +//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +//import org.springframework.util.*; +// +//@RunWith(SpringJUnit4ClassRunner.class) +//@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +//public class EdgeServiceIntegrationCalculation { +// protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationCalculation.class); +// +// private static String discoveryServiceURL; +// private static String mongoURL; +// private static String gmapsAdapterURL; +// private static String calculationServiceURL; +// private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); +// +// // Wait for all services to have ports open +// @ClassRule +// public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) +// .file("src/test/resources/docker-compose-calculation.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) +// .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .build(); +// +// // Get IP addresses and ports to run tests on +// @BeforeClass +// public static void initialize() throws Exception { +// +// LOG.info("Initializing ports from Docker"); +// +// Container discoveryContainer = docker.containers().container("discoveryservice"); +// DockerPort discoveryPort = discoveryContainer.port(8761); +// discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), +// discoveryPort.getExternalPort()); +// if(!discoveryPort.isListeningNow()){ +// LOG.info("Discovery service didn't respond over HTTP"); +// throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); +// } +// LOG.info("Discovery service responded over HTTP"); +// +// Container mongoContainer = docker.containers().container("mongo"); +// DockerPort mongoPort = mongoContainer.port(27017); +// mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); +// if(!mongoPort.isListeningNow()){ +// LOG.info("Mongo service didn't respond over HTTP"); +// throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); +// } +// LOG.info("Mongo service responded over HTTP"); +// +// Container gmapsAdapterContainer = docker.containers().container("gmapsadapter"); +// DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); +// gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapterPort.getIp(), +// gmapsAdapterPort.getExternalPort()); +// if(!gmapsAdapterPort.isListeningNow()){ +// LOG.info("Gmaps Adapter service didn't respond over HTTP"); +// throw new Exception(String.format("Gmaps Adapter didn't respond, port: %s", gmapsAdapterPort.getInternalPort())); +// } +// LOG.info("Gmaps Adapter service responded over HTTP"); +// +// Container calculationContainer = docker.containers().container("calculationservice"); +// DockerPort calculationPort = calculationContainer.port(8080); +// calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), +// calculationPort.getExternalPort()); +// if(!calculationPort.isListeningNow()){ +// LOG.info("Calculation service didn't respond over HTTP"); +// throw new Exception(String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); +// } +// LOG.info("Calculation service responded over HTTP"); +// +// LOG.info("Containers initialized correctly"); +// } +// +// private TestRestTemplate restTemplate = new TestRestTemplate(); +// +// private String token; +// +// @Before +// public void setUp() throws JSONException { +// token = ""; +// } +// +// @Test +// public void calculationServiceRequestSuccess() { +// // given: +// HttpHeaders headers = new HttpHeaders(); +// headers.add("Authorization", "Bearer " + token); +// headers.add("Content-Type", "application/json"); +// +// String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\"," +// + " \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; +// HttpEntity request = new HttpEntity<>(body, headers); +// +// // when: +// ResponseEntity response = restTemplate.postForEntity(calculationServiceURL + "/api/v1/cost", request, +// String.class); +// +// // then: +// assertThat(response.getStatusCodeValue()).isEqualTo(200); +// } +//} diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 8a0fda3..bd78609 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -1,256 +1,267 @@ -//package aist.edge.edgeservice; -// -//import static org.assertj.core.api.Java6Assertions.assertThat; -// -//import com.palantir.docker.compose.DockerComposeRule; -//import com.palantir.docker.compose.connection.DockerPort; -//import com.palantir.docker.compose.connection.waiting.HealthChecks; -// -//import java.util.*; -// -//import org.json.JSONException; -//import org.json.JSONObject; -//import org.junit.Before; -//import org.junit.BeforeClass; -//import org.junit.ClassRule; -//import org.junit.Test; -//import org.junit.runner.RunWith; -// -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -//import org.springframework.boot.test.context.SpringBootTest; -//import org.springframework.boot.test.web.client.TestRestTemplate; -//import org.springframework.http.*; -//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -//import org.springframework.util.*; -// -//@RunWith(SpringJUnit4ClassRunner.class) -//@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -//public class EdgeServiceIntegrationTests { -// protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTests.class); -// -// private static String discoveryServiceURL; -// private static String mongoURL; -// private static String userServiceURL; -// private static String tripCommandURL; -// private static String tripQueryURL; -// private static String gmapsAdapterURL; -// private static String calculationServiceURL; -// -// // Wait for all services to have ports open -// @ClassRule -// public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) -// .file("src/test/resources/docker-compose.yml") -// .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) -// .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) -// .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) -// .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) -// .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) -// .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) -// .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) -// .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) -// .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()).build(); -// -// // Get IP addresses and ports to run tests on -// @BeforeClass -// public static void initialize() { -// -// LOG.info("Initializing ports from Docker"); -// -// DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); -// discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), -// discoveryService.getExternalPort()); -// while (!docker.containers().container("discoveryservice") -// .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { -// LOG.info("Waiting for discovery service to respond over HTTP"); -// } -// LOG.info("Discovery Service url found: " + discoveryServiceURL); -// -// DockerPort mongo = docker.containers().container("mongo").port(27017); -// mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); -// while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) -// .succeeded()) { -// LOG.info("Waiting for mongo to respond over HTTP"); -// } -// LOG.info("Mongo url found: " + mongoURL); -// -// DockerPort userService = docker.containers().container("userservice").port(8080); -// userServiceURL = String.format("http://%s:%s", userService.getIp(), userService.getExternalPort()); -// while (!docker.containers().container("userservice") -// .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { -// LOG.info("Waiting for user service to respond over HTTP"); -// } -// LOG.info("User Service url found: " + userServiceURL); -// -// DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd").port(8080); -// tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), -// tripManagementCommand.getExternalPort()); -// while (!docker.containers().container("tripmanagementcmd") -// .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripCommandURL)).succeeded()) { -// LOG.info("Waiting for Trip Command to respond over HTTP"); -// } -// LOG.info("Trip Command url found: " + tripCommandURL); -// -// DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery").port(8080); -// tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(), -// tripManagementQuery.getExternalPort()); -// while (!docker.containers().container("tripmanagementquery") -// .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripQueryURL)).succeeded()) { -// LOG.info("Waiting for Trip Query to respond over HTTP"); -// } -// LOG.info("Trip Query url found: " + tripQueryURL); -// -// DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); -// gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); -// while (!docker.containers().container("gmapsadapter") -// .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { -// LOG.info("Waiting for user service to respond over HTTP"); -// } -// LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); -// -// DockerPort calculationService = docker.containers().container("calculationservice").port(8080); -// calculationServiceURL = String.format("http://%s:%s", calculationService.getIp(), -// calculationService.getExternalPort()); -// while (!docker.containers().container("calculationservice") -// .portIsListeningOnHttp(8080, (port) -> port.inFormat(calculationServiceURL)).succeeded()) { -// LOG.info("Waiting for calculation service to respond over HTTP"); -// } -// LOG.info("Calculation Service url found: " + calculationServiceURL); -// } -// -// private TestRestTemplate restTemplate = new TestRestTemplate(); -// -// private String token; -// -// @Before -// public void setUp() throws JSONException { -// String plainCreds = "front-end:front-end"; -// byte[] plainCredsBytes = plainCreds.getBytes(); -// byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); -// String base64Creds = new String(base64CredsBytes); -// -// HttpHeaders headers = new HttpHeaders(); -// headers.add("Authorization", "Basic " + base64Creds); -// headers.add("Content-Type", "application/x-www-form-urlencoded"); -// -// MultiValueMap parameters = new LinkedMultiValueMap<>(); -// parameters.add("username", "front-end"); -// parameters.add("secret", "front-end"); -// String body = "grant_type=password&scope=webclient&username=passenger&password=password"; -// HttpEntity request = new HttpEntity<>(body, headers); -// -// // when: -// ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, -// String.class, parameters); -// -// // then: -// assertThat(response.getStatusCodeValue()).isEqualTo(200); -// JSONObject json = new JSONObject(response.getBody()); -// token = json.getString("access_token"); -// } -// -// @Test -// public void tripCommandPOSTRequestSuccess() { -// // given: -// HttpHeaders headers = new HttpHeaders(); -// headers.add("Authorization", "Bearer " + token); -// headers.add("Content-Type", "application/json"); -// -// String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " -// + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; -// HttpEntity request = new HttpEntity<>(body, headers); -// -// // when: -// ResponseEntity response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, -// String.class); -// -// // then: -// assertThat(response.getStatusCodeValue()).isEqualTo(201); -// } -// -// @Test -// public void tripQueryGETSpecificTripRequestSuccess() throws JSONException, InterruptedException { -// // given: -// HttpHeaders headers = new HttpHeaders(); -// headers.add("Authorization", "Bearer " + token); -// headers.add("Content-Type", "application/json"); -// -// String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " -// + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; -// HttpEntity request = new HttpEntity<>(body, headers); -// ResponseEntity postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, -// String.class); -// -// assertThat(postResponse.getStatusCodeValue()).isEqualTo(201); -// -// JSONObject json = new JSONObject(postResponse.getBody()); -// String tripId = json.getString("id"); -// -// Thread.sleep(1000); -// -// // when: -// ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trip/" + tripId, -// String.class); -// -// // then: -// assertThat(response.getStatusCodeValue()).isEqualTo(200); -// } -// -// @Test -// public void tripQueryGETAllTripsRequestSuccess() { -// // given: -// HttpHeaders headers = new HttpHeaders(); -// headers.add("Authorization", "Bearer " + token); -// headers.add("Content-Type", "application/json"); -// -// // when: -// ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class); -// -// // then: -// assertThat(response.getStatusCodeValue()).isEqualTo(200); -// } -// -// @Test -// public void calculationServiceRequestSuccess() { -// // given: -// HttpHeaders headers = new HttpHeaders(); -// headers.add("Authorization", "Bearer " + token); -// headers.add("Content-Type", "application/json"); -// -// String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\"," -// + " \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; -// HttpEntity request = new HttpEntity<>(body, headers); -// -// // when: -// ResponseEntity response = restTemplate.postForEntity(calculationServiceURL + "/api/v1/cost", request, -// String.class); -// -// // then: -// assertThat(response.getStatusCodeValue()).isEqualTo(200); -// } -// -// @Test -// public void gmapsAdapterRequestSuccess() throws Exception { -// // given: -// HttpHeaders headers = new HttpHeaders(); -// headers.add("Authorization", "Bearer " + token); -// headers.add("Content-Type", "application/json"); -// -// String body = "{ \"origin\": \"2250 N Commerce Pkwy, Weston, FL 33326\", \"destination\": \"11200 SW 8th St, " -// + "Miami, FL 33199\", \"departureTime\": \"15220998650000000\" }"; -// HttpEntity request = new HttpEntity<>(body, headers); -// -// // when: -// ResponseEntity response = restTemplate.postForEntity(gmapsAdapterURL + "/api/v1/directions", request, -// String.class); -// -// if (response.getStatusCodeValue() != 200) { -// throw new Exception( -// String.format("Expected 200, actual %s\n%s", response.getStatusCode(), -// response.getBody())); -// } -// -// // then: -// assertThat(response.getStatusCodeValue()).isEqualTo(200); -// } -//} +package aist.edge.edgeservice; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +import com.palantir.docker.compose.DockerComposeRule; +import com.palantir.docker.compose.connection.Container; +import com.palantir.docker.compose.connection.DockerPort; +import com.palantir.docker.compose.connection.waiting.HealthChecks; + +import java.util.*; + +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.*; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.*; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class EdgeServiceIntegrationTests { + protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTests.class); + + private static String discoveryServiceURL; + private static String mongoURL; + private static String userServiceURL; + private static String tripCommandURL; + private static String tripQueryURL; + private static String gmapsAdapterURL; + private static String calculationServiceURL; + + // Wait for all services to have ports open + @ClassRule + public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) + .file("src/test/resources/docker-compose.yml") + .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()).build(); + + // Get IP addresses and ports to run tests on + @BeforeClass + public static void initialize() throws Exception { + + LOG.info("Initializing ports from Docker"); + + Container discoveryContainer = docker.containers().container("discoveryservice"); + DockerPort discoveryPort = discoveryContainer.port(8761); + discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), + discoveryPort.getExternalPort()); + if(!discoveryPort.isListeningNow()){ + LOG.info("Discovery service didn't respond over HTTP"); + throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); + } + LOG.info("Discovery service responded over HTTP"); + + Container mongoContainer = docker.containers().container("mongo"); + DockerPort mongoPort = mongoContainer.port(27017); + mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); + if(!mongoPort.isListeningNow()){ + LOG.info("Mongo service didn't respond over HTTP"); + throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); + } + LOG.info("Mongo service responded over HTTP"); + + Container userContainer = docker.containers().container("userservice"); + DockerPort userPort = userContainer.port(8080); + userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); + if(!userPort.isListeningNow()){ + LOG.info("User service didn't respond over HTTP"); + throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); + } + LOG.info("User service responded over HTTP"); + + Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); + DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); + tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), + tripManagementCmdPort.getExternalPort()); + if(!tripManagementCmdPort.isListeningNow()){ + LOG.info("TripManagementCmd service didn't respond over HTTP"); + throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", tripManagementCmdPort.getInternalPort())); + } + LOG.info("TripManagementCmd service responded over HTTP"); + + Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); + DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); + tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), + tripManagementQueryPort.getExternalPort()); + if(!tripManagementQueryPort.isListeningNow()){ + LOG.info("TripManagementQuery service didn't respond over HTTP"); + throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", tripManagementQueryPort.getInternalPort())); + } + LOG.info("TripManagementQuery service responded over HTTP"); + + Container gmapsAdapterContainer = docker.containers().container("gmapsadapter"); + DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); + gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapterPort.getIp(), + gmapsAdapterPort.getExternalPort()); + if(!gmapsAdapterPort.isListeningNow()){ + LOG.info("Gmaps Adapter service didn't respond over HTTP"); + throw new Exception(String.format("Gmaps Adapter didn't respond, port: %s", gmapsAdapterPort.getInternalPort())); + } + LOG.info("Gmaps Adapter service responded over HTTP"); + + Container calculationContainer = docker.containers().container("calculationservice"); + DockerPort calculationPort = calculationContainer.port(8080); + calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), + calculationPort.getExternalPort()); + if(!calculationPort.isListeningNow()){ + LOG.info("Calculation service didn't respond over HTTP"); + throw new Exception(String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); + } + LOG.info("Calculation service responded over HTTP"); + + LOG.info("Containers initialized correctly"); + } + + private TestRestTemplate restTemplate = new TestRestTemplate(); + + private String token; + + @Before + public void setUp() throws JSONException { + String plainCreds = "front-end:front-end"; + byte[] plainCredsBytes = plainCreds.getBytes(); + byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); + String base64Creds = new String(base64CredsBytes); + + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Basic " + base64Creds); + headers.add("Content-Type", "application/x-www-form-urlencoded"); + + MultiValueMap parameters = new LinkedMultiValueMap<>(); + parameters.add("username", "front-end"); + parameters.add("secret", "front-end"); + String body = "grant_type=password&scope=webclient&username=passenger&password=password"; + HttpEntity request = new HttpEntity<>(body, headers); + + // when: + ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, + String.class, parameters); + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); + JSONObject json = new JSONObject(response.getBody()); + token = json.getString("access_token"); + } + + @Test + public void tripCommandPOSTRequestSuccess() { + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); + + String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " + + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; + HttpEntity request = new HttpEntity<>(body, headers); + + // when: + ResponseEntity response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, + String.class); + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(201); + } + + @Test + public void tripQueryGETSpecificTripRequestSuccess() throws JSONException, InterruptedException { + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); + + String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " + + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; + HttpEntity request = new HttpEntity<>(body, headers); + ResponseEntity postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, + String.class); + + assertThat(postResponse.getStatusCodeValue()).isEqualTo(201); + + JSONObject json = new JSONObject(postResponse.getBody()); + String tripId = json.getString("id"); + + Thread.sleep(1000); + + // when: + ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trip/" + tripId, + String.class); + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); + } + + @Test + public void tripQueryGETAllTripsRequestSuccess() { + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); + + // when: + ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class); + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); + } + + @Test + public void calculationServiceRequestSuccess() { + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); + + String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\"," + + " \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; + HttpEntity request = new HttpEntity<>(body, headers); + + // when: + ResponseEntity response = restTemplate.postForEntity(calculationServiceURL + "/api/v1/cost", request, + String.class); + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); + } + + @Test + public void gmapsAdapterRequestSuccess() throws Exception { + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); + + String body = "{ \"origin\": \"2250 N Commerce Pkwy, Weston, FL 33326\", \"destination\": \"11200 SW 8th St, " + + "Miami, FL 33199\", \"departureTime\": \"15220998650000000\" }"; + HttpEntity request = new HttpEntity<>(body, headers); + + // when: + ResponseEntity response = restTemplate.postForEntity(gmapsAdapterURL + "/api/v1/directions", request, + String.class); + + if (response.getStatusCodeValue() != 200) { + throw new Exception( + String.format("Expected 200, actual %s\n%s", response.getStatusCode(), + response.getBody())); + } + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); + } +} diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java index 6164e94..12a0afd 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java @@ -1,110 +1,110 @@ -package aist.edge.edgeservice; - -import static org.assertj.core.api.Java6Assertions.assertThat; - -import com.palantir.docker.compose.DockerComposeRule; -import com.palantir.docker.compose.configuration.ShutdownStrategy; -import com.palantir.docker.compose.connection.Container; -import com.palantir.docker.compose.connection.DockerPort; -import com.palantir.docker.compose.connection.waiting.HealthChecks; - -import java.util.*; - -import org.joda.time.Duration; -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.*; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.*; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class EdgeServiceIntegrationTestsGmapsAdapter { - protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTestsGmapsAdapter.class); - - private static String discoveryServiceURL; - private static String gmapsAdapterURL; - private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); - - // Wait for all services to have ports open - @ClassRule - public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) - .file("src/test/resources/docker-compose-gmaps-adapter.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) - .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .build(); - - // Get IP addresses and ports to run tests on - @BeforeClass - public static void initialize() throws Exception { - - LOG.info("Initializing ports from Docker"); - - Container discoveryContainer = docker.containers().container("discoveryservice"); - DockerPort discoveryPort = discoveryContainer.port(8761); - discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), - discoveryPort.getExternalPort()); - if(!discoveryPort.isListeningNow()){ - LOG.info("Discovery service didn't respond over HTTP"); - throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); - } - LOG.info("Discovery service responded over HTTP"); - - Container gmapsAdapterContainer = docker.containers().container("gmapsadapter"); - DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); - gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapterPort.getIp(), - gmapsAdapterPort.getExternalPort()); - if(!gmapsAdapterPort.isListeningNow()){ - LOG.info("Gmaps Adapter service didn't respond over HTTP"); - throw new Exception(String.format("Gmaps Adapter didn't respond, port: %s", gmapsAdapterPort.getInternalPort())); - } - LOG.info("Gmaps Adapter service responded over HTTP"); - - LOG.info("Containers initialized correctly"); - } - - private TestRestTemplate restTemplate = new TestRestTemplate(); - - private String token; - - @Before - public void setUp() throws JSONException { - token = ""; - } - - @Test - public void gmapsAdapterRequestSuccess() throws Exception { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); - - String body = "{ \"origin\": \"2250 N Commerce Pkwy, Weston, FL 33326\", \"destination\": \"11200 SW 8th St, " - + "Miami, FL 33199\", \"departureTime\": \"15220998650000000\" }"; - HttpEntity request = new HttpEntity<>(body, headers); - - // when: - ResponseEntity response = restTemplate.postForEntity(gmapsAdapterURL + "/api/v1/directions", request, - String.class); - - if (response.getStatusCodeValue() != 200) { - throw new Exception( - String.format("Expected 200, actual %s\n%s", response.getStatusCode(), - response.getBody())); - } - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); - } -} +//package aist.edge.edgeservice; +// +//import static org.assertj.core.api.Java6Assertions.assertThat; +// +//import com.palantir.docker.compose.DockerComposeRule; +//import com.palantir.docker.compose.configuration.ShutdownStrategy; +//import com.palantir.docker.compose.connection.Container; +//import com.palantir.docker.compose.connection.DockerPort; +//import com.palantir.docker.compose.connection.waiting.HealthChecks; +// +//import java.util.*; +// +//import org.joda.time.Duration; +//import org.json.JSONException; +//import org.json.JSONObject; +//import org.junit.Before; +//import org.junit.BeforeClass; +//import org.junit.ClassRule; +//import org.junit.Test; +//import org.junit.runner.RunWith; +// +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.boot.test.web.client.TestRestTemplate; +//import org.springframework.http.*; +//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +//import org.springframework.util.*; +// +//@RunWith(SpringJUnit4ClassRunner.class) +//@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +//public class EdgeServiceIntegrationTestsGmapsAdapter { +// protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTestsGmapsAdapter.class); +// +// private static String discoveryServiceURL; +// private static String gmapsAdapterURL; +// private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); +// +// // Wait for all services to have ports open +// @ClassRule +// public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) +// .file("src/test/resources/docker-compose-gmaps-adapter.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) +// .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .build(); +// +// // Get IP addresses and ports to run tests on +// @BeforeClass +// public static void initialize() throws Exception { +// +// LOG.info("Initializing ports from Docker"); +// +// Container discoveryContainer = docker.containers().container("discoveryservice"); +// DockerPort discoveryPort = discoveryContainer.port(8761); +// discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), +// discoveryPort.getExternalPort()); +// if(!discoveryPort.isListeningNow()){ +// LOG.info("Discovery service didn't respond over HTTP"); +// throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); +// } +// LOG.info("Discovery service responded over HTTP"); +// +// Container gmapsAdapterContainer = docker.containers().container("gmapsadapter"); +// DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); +// gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapterPort.getIp(), +// gmapsAdapterPort.getExternalPort()); +// if(!gmapsAdapterPort.isListeningNow()){ +// LOG.info("Gmaps Adapter service didn't respond over HTTP"); +// throw new Exception(String.format("Gmaps Adapter didn't respond, port: %s", gmapsAdapterPort.getInternalPort())); +// } +// LOG.info("Gmaps Adapter service responded over HTTP"); +// +// LOG.info("Containers initialized correctly"); +// } +// +// private TestRestTemplate restTemplate = new TestRestTemplate(); +// +// private String token; +// +// @Before +// public void setUp() throws JSONException { +// token = ""; +// } +// +// @Test +// public void gmapsAdapterRequestSuccess() throws Exception { +// // given: +// HttpHeaders headers = new HttpHeaders(); +// headers.add("Authorization", "Bearer " + token); +// headers.add("Content-Type", "application/json"); +// +// String body = "{ \"origin\": \"2250 N Commerce Pkwy, Weston, FL 33326\", \"destination\": \"11200 SW 8th St, " +// + "Miami, FL 33199\", \"departureTime\": \"15220998650000000\" }"; +// HttpEntity request = new HttpEntity<>(body, headers); +// +// // when: +// ResponseEntity response = restTemplate.postForEntity(gmapsAdapterURL + "/api/v1/directions", request, +// String.class); +// +// if (response.getStatusCodeValue() != 200) { +// throw new Exception( +// String.format("Expected 200, actual %s\n%s", response.getStatusCode(), +// response.getBody())); +// } +// +// // then: +// assertThat(response.getStatusCodeValue()).isEqualTo(200); +// } +//} diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java index b3e2da8..5e66372 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java @@ -1,150 +1,150 @@ -package aist.edge.edgeservice; - -import static org.assertj.core.api.Java6Assertions.assertThat; - -import com.palantir.docker.compose.DockerComposeRule; -import com.palantir.docker.compose.configuration.ShutdownStrategy; -import com.palantir.docker.compose.connection.Container; -import com.palantir.docker.compose.connection.DockerPort; -import com.palantir.docker.compose.connection.waiting.HealthChecks; - -import java.util.*; - -import org.joda.time.Duration; -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.*; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.*; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class EdgeServiceIntegrationTestsTripCmd { - protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTestsTripCmd.class); - - private static String discoveryServiceURL; - private static String mongoURL; - private static String userServiceURL; - private static String tripCommandURL; - private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); - - // Wait for all services to have ports open - @ClassRule - public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) - .file("src/test/resources/docker-compose-trip-cmd.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) - .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .build(); - - // Get IP addresses and ports to run tests on - @BeforeClass - public static void initialize() throws Exception { - - LOG.info("Initializing ports from Docker"); - - Container discoveryContainer = docker.containers().container("discoveryservice"); - DockerPort discoveryPort = discoveryContainer.port(8761); - discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), - discoveryPort.getExternalPort()); - if(!discoveryPort.isListeningNow()){ - LOG.info("Discovery service didn't respond over HTTP"); - throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); - } - LOG.info("Discovery service responded over HTTP"); - - Container mongoContainer = docker.containers().container("mongo"); - DockerPort mongoPort = mongoContainer.port(27017); - mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); - if(!mongoPort.isListeningNow()){ - LOG.info("Mongo service didn't respond over HTTP"); - throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); - } - LOG.info("Mongo service responded over HTTP"); - - Container userContainer = docker.containers().container("userservice"); - DockerPort userPort = userContainer.port(8080); - userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); - if(!userPort.isListeningNow()){ - LOG.info("User service didn't respond over HTTP"); - throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); - } - LOG.info("User service responded over HTTP"); - - Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); - DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); - tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), - tripManagementCmdPort.getExternalPort()); - if(!userPort.isListeningNow()){ - LOG.info("TripManagementCmd service didn't respond over HTTP"); - throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", tripManagementCmdPort.getInternalPort())); - } - LOG.info("TripManagementCmd service responded over HTTP"); - - LOG.info("Containers initialized correctly"); - } - - private TestRestTemplate restTemplate = new TestRestTemplate(); - - private String token; - - @Before - public void setUp() throws JSONException { - String plainCreds = "front-end:front-end"; - byte[] plainCredsBytes = plainCreds.getBytes(); - byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); - String base64Creds = new String(base64CredsBytes); - - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Basic " + base64Creds); - headers.add("Content-Type", "application/x-www-form-urlencoded"); - - MultiValueMap parameters = new LinkedMultiValueMap<>(); - parameters.add("username", "front-end"); - parameters.add("secret", "front-end"); - String body = "grant_type=password&scope=webclient&username=passenger&password=password"; - HttpEntity request = new HttpEntity<>(body, headers); - - // when: - ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, - String.class, parameters); - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); - JSONObject json = new JSONObject(response.getBody()); - token = json.getString("access_token"); - } - - @Test - public void tripCommandPOSTRequestSuccess() { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); - - String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " - + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; - HttpEntity request = new HttpEntity<>(body, headers); - - // when: - ResponseEntity response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, - String.class); - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(201); - } - -} +//package aist.edge.edgeservice; +// +//import static org.assertj.core.api.Java6Assertions.assertThat; +// +//import com.palantir.docker.compose.DockerComposeRule; +//import com.palantir.docker.compose.configuration.ShutdownStrategy; +//import com.palantir.docker.compose.connection.Container; +//import com.palantir.docker.compose.connection.DockerPort; +//import com.palantir.docker.compose.connection.waiting.HealthChecks; +// +//import java.util.*; +// +//import org.joda.time.Duration; +//import org.json.JSONException; +//import org.json.JSONObject; +//import org.junit.Before; +//import org.junit.BeforeClass; +//import org.junit.ClassRule; +//import org.junit.Test; +//import org.junit.runner.RunWith; +// +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.boot.test.web.client.TestRestTemplate; +//import org.springframework.http.*; +//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +//import org.springframework.util.*; +// +//@RunWith(SpringJUnit4ClassRunner.class) +//@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +//public class EdgeServiceIntegrationTestsTripCmd { +// protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTestsTripCmd.class); +// +// private static String discoveryServiceURL; +// private static String mongoURL; +// private static String userServiceURL; +// private static String tripCommandURL; +// private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); +// +// // Wait for all services to have ports open +// @ClassRule +// public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) +// .file("src/test/resources/docker-compose-trip-cmd.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) +// .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .build(); +// +// // Get IP addresses and ports to run tests on +// @BeforeClass +// public static void initialize() throws Exception { +// +// LOG.info("Initializing ports from Docker"); +// +// Container discoveryContainer = docker.containers().container("discoveryservice"); +// DockerPort discoveryPort = discoveryContainer.port(8761); +// discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), +// discoveryPort.getExternalPort()); +// if(!discoveryPort.isListeningNow()){ +// LOG.info("Discovery service didn't respond over HTTP"); +// throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); +// } +// LOG.info("Discovery service responded over HTTP"); +// +// Container mongoContainer = docker.containers().container("mongo"); +// DockerPort mongoPort = mongoContainer.port(27017); +// mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); +// if(!mongoPort.isListeningNow()){ +// LOG.info("Mongo service didn't respond over HTTP"); +// throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); +// } +// LOG.info("Mongo service responded over HTTP"); +// +// Container userContainer = docker.containers().container("userservice"); +// DockerPort userPort = userContainer.port(8080); +// userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); +// if(!userPort.isListeningNow()){ +// LOG.info("User service didn't respond over HTTP"); +// throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); +// } +// LOG.info("User service responded over HTTP"); +// +// Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); +// DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); +// tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), +// tripManagementCmdPort.getExternalPort()); +// if(!userPort.isListeningNow()){ +// LOG.info("TripManagementCmd service didn't respond over HTTP"); +// throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", tripManagementCmdPort.getInternalPort())); +// } +// LOG.info("TripManagementCmd service responded over HTTP"); +// +// LOG.info("Containers initialized correctly"); +// } +// +// private TestRestTemplate restTemplate = new TestRestTemplate(); +// +// private String token; +// +// @Before +// public void setUp() throws JSONException { +// String plainCreds = "front-end:front-end"; +// byte[] plainCredsBytes = plainCreds.getBytes(); +// byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); +// String base64Creds = new String(base64CredsBytes); +// +// HttpHeaders headers = new HttpHeaders(); +// headers.add("Authorization", "Basic " + base64Creds); +// headers.add("Content-Type", "application/x-www-form-urlencoded"); +// +// MultiValueMap parameters = new LinkedMultiValueMap<>(); +// parameters.add("username", "front-end"); +// parameters.add("secret", "front-end"); +// String body = "grant_type=password&scope=webclient&username=passenger&password=password"; +// HttpEntity request = new HttpEntity<>(body, headers); +// +// // when: +// ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, +// String.class, parameters); +// +// // then: +// assertThat(response.getStatusCodeValue()).isEqualTo(200); +// JSONObject json = new JSONObject(response.getBody()); +// token = json.getString("access_token"); +// } +// +// @Test +// public void tripCommandPOSTRequestSuccess() { +// // given: +// HttpHeaders headers = new HttpHeaders(); +// headers.add("Authorization", "Bearer " + token); +// headers.add("Content-Type", "application/json"); +// +// String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " +// + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; +// HttpEntity request = new HttpEntity<>(body, headers); +// +// // when: +// ResponseEntity response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, +// String.class); +// +// // then: +// assertThat(response.getStatusCodeValue()).isEqualTo(201); +// } +// +//} diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java index 26b9a01..a431f94 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java @@ -1,171 +1,171 @@ -package aist.edge.edgeservice; - -import static org.assertj.core.api.Java6Assertions.assertThat; - -import com.palantir.docker.compose.DockerComposeRule; -import com.palantir.docker.compose.configuration.ShutdownStrategy; -import com.palantir.docker.compose.connection.Container; -import com.palantir.docker.compose.connection.DockerPort; -import com.palantir.docker.compose.connection.waiting.HealthChecks; - -import java.util.*; - -import org.joda.time.Duration; -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.*; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.*; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class EdgeServiceIntegrationTestsTripCmdQuery { - protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTestsTripCmdQuery.class); - - private static String discoveryServiceURL; - private static String mongoURL; - private static String userServiceURL; - private static String tripCommandURL; - private static String tripQueryURL; - private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); - - // Wait for all services to have ports open - @ClassRule - public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) - .file("src/test/resources/docker-compose-trip-cmd-query.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) - .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .build(); - - // Get IP addresses and ports to run tests on - @BeforeClass - public static void initialize() throws Exception { - - LOG.info("Initializing ports from Docker"); - - Container discoveryContainer = docker.containers().container("discoveryservice"); - DockerPort discoveryPort = discoveryContainer.port(8761); - discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), - discoveryPort.getExternalPort()); - if(!discoveryPort.isListeningNow()){ - LOG.info("Discovery service didn't respond over HTTP"); - throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); - } - LOG.info("Discovery service responded over HTTP"); - - Container mongoContainer = docker.containers().container("mongo"); - DockerPort mongoPort = mongoContainer.port(27017); - mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); - if(!mongoPort.isListeningNow()){ - LOG.info("Mongo service didn't respond over HTTP"); - throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); - } - LOG.info("Mongo service responded over HTTP"); - - Container userContainer = docker.containers().container("userservice"); - DockerPort userPort = userContainer.port(8080); - userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); - if(!userPort.isListeningNow()){ - LOG.info("User service didn't respond over HTTP"); - throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); - } - LOG.info("User service responded over HTTP"); - - Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); - DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); - tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), - tripManagementCmdPort.getExternalPort()); - if(!tripManagementCmdPort.isListeningNow()){ - LOG.info("TripManagementCmd service didn't respond over HTTP"); - throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", tripManagementCmdPort.getInternalPort())); - } - LOG.info("TripManagementCmd service responded over HTTP"); - - Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); - DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); - tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), - tripManagementQueryPort.getExternalPort()); - if(!tripManagementQueryPort.isListeningNow()){ - LOG.info("TripManagementQuery service didn't respond over HTTP"); - throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", tripManagementQueryPort.getInternalPort())); - } - LOG.info("TripManagementQuery service responded over HTTP"); - - LOG.info("Containers initialized correctly"); - } - - private TestRestTemplate restTemplate = new TestRestTemplate(); - - private String token; - - @Before - public void setUp() throws JSONException { - String plainCreds = "front-end:front-end"; - byte[] plainCredsBytes = plainCreds.getBytes(); - byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); - String base64Creds = new String(base64CredsBytes); - - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Basic " + base64Creds); - headers.add("Content-Type", "application/x-www-form-urlencoded"); - - MultiValueMap parameters = new LinkedMultiValueMap<>(); - parameters.add("username", "front-end"); - parameters.add("secret", "front-end"); - String body = "grant_type=password&scope=webclient&username=passenger&password=password"; - HttpEntity request = new HttpEntity<>(body, headers); - - // when: - ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, - String.class, parameters); - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); - JSONObject json = new JSONObject(response.getBody()); - token = json.getString("access_token"); - } - - @Test - public void tripQueryGETSpecificTripRequestSuccess() throws JSONException, InterruptedException { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); - - String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " - + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; - HttpEntity request = new HttpEntity<>(body, headers); - ResponseEntity postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, - String.class); - - assertThat(postResponse.getStatusCodeValue()).isEqualTo(201); - - JSONObject json = new JSONObject(postResponse.getBody()); - String tripId = json.getString("id"); - - Thread.sleep(1000); - - // when: - ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trip/" + tripId, - String.class); - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); - } - -} +//package aist.edge.edgeservice; +// +//import static org.assertj.core.api.Java6Assertions.assertThat; +// +//import com.palantir.docker.compose.DockerComposeRule; +//import com.palantir.docker.compose.configuration.ShutdownStrategy; +//import com.palantir.docker.compose.connection.Container; +//import com.palantir.docker.compose.connection.DockerPort; +//import com.palantir.docker.compose.connection.waiting.HealthChecks; +// +//import java.util.*; +// +//import org.joda.time.Duration; +//import org.json.JSONException; +//import org.json.JSONObject; +//import org.junit.Before; +//import org.junit.BeforeClass; +//import org.junit.ClassRule; +//import org.junit.Test; +//import org.junit.runner.RunWith; +// +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.boot.test.web.client.TestRestTemplate; +//import org.springframework.http.*; +//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +//import org.springframework.util.*; +// +//@RunWith(SpringJUnit4ClassRunner.class) +//@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +//public class EdgeServiceIntegrationTestsTripCmdQuery { +// protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTestsTripCmdQuery.class); +// +// private static String discoveryServiceURL; +// private static String mongoURL; +// private static String userServiceURL; +// private static String tripCommandURL; +// private static String tripQueryURL; +// private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); +// +// // Wait for all services to have ports open +// @ClassRule +// public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) +// .file("src/test/resources/docker-compose-trip-cmd-query.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) +// .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .build(); +// +// // Get IP addresses and ports to run tests on +// @BeforeClass +// public static void initialize() throws Exception { +// +// LOG.info("Initializing ports from Docker"); +// +// Container discoveryContainer = docker.containers().container("discoveryservice"); +// DockerPort discoveryPort = discoveryContainer.port(8761); +// discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), +// discoveryPort.getExternalPort()); +// if(!discoveryPort.isListeningNow()){ +// LOG.info("Discovery service didn't respond over HTTP"); +// throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); +// } +// LOG.info("Discovery service responded over HTTP"); +// +// Container mongoContainer = docker.containers().container("mongo"); +// DockerPort mongoPort = mongoContainer.port(27017); +// mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); +// if(!mongoPort.isListeningNow()){ +// LOG.info("Mongo service didn't respond over HTTP"); +// throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); +// } +// LOG.info("Mongo service responded over HTTP"); +// +// Container userContainer = docker.containers().container("userservice"); +// DockerPort userPort = userContainer.port(8080); +// userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); +// if(!userPort.isListeningNow()){ +// LOG.info("User service didn't respond over HTTP"); +// throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); +// } +// LOG.info("User service responded over HTTP"); +// +// Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); +// DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); +// tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), +// tripManagementCmdPort.getExternalPort()); +// if(!tripManagementCmdPort.isListeningNow()){ +// LOG.info("TripManagementCmd service didn't respond over HTTP"); +// throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", tripManagementCmdPort.getInternalPort())); +// } +// LOG.info("TripManagementCmd service responded over HTTP"); +// +// Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); +// DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); +// tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), +// tripManagementQueryPort.getExternalPort()); +// if(!tripManagementQueryPort.isListeningNow()){ +// LOG.info("TripManagementQuery service didn't respond over HTTP"); +// throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", tripManagementQueryPort.getInternalPort())); +// } +// LOG.info("TripManagementQuery service responded over HTTP"); +// +// LOG.info("Containers initialized correctly"); +// } +// +// private TestRestTemplate restTemplate = new TestRestTemplate(); +// +// private String token; +// +// @Before +// public void setUp() throws JSONException { +// String plainCreds = "front-end:front-end"; +// byte[] plainCredsBytes = plainCreds.getBytes(); +// byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); +// String base64Creds = new String(base64CredsBytes); +// +// HttpHeaders headers = new HttpHeaders(); +// headers.add("Authorization", "Basic " + base64Creds); +// headers.add("Content-Type", "application/x-www-form-urlencoded"); +// +// MultiValueMap parameters = new LinkedMultiValueMap<>(); +// parameters.add("username", "front-end"); +// parameters.add("secret", "front-end"); +// String body = "grant_type=password&scope=webclient&username=passenger&password=password"; +// HttpEntity request = new HttpEntity<>(body, headers); +// +// // when: +// ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, +// String.class, parameters); +// +// // then: +// assertThat(response.getStatusCodeValue()).isEqualTo(200); +// JSONObject json = new JSONObject(response.getBody()); +// token = json.getString("access_token"); +// } +// +// @Test +// public void tripQueryGETSpecificTripRequestSuccess() throws JSONException, InterruptedException { +// // given: +// HttpHeaders headers = new HttpHeaders(); +// headers.add("Authorization", "Bearer " + token); +// headers.add("Content-Type", "application/json"); +// +// String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " +// + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; +// HttpEntity request = new HttpEntity<>(body, headers); +// ResponseEntity postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, +// String.class); +// +// assertThat(postResponse.getStatusCodeValue()).isEqualTo(201); +// +// JSONObject json = new JSONObject(postResponse.getBody()); +// String tripId = json.getString("id"); +// +// Thread.sleep(1000); +// +// // when: +// ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trip/" + tripId, +// String.class); +// +// // then: +// assertThat(response.getStatusCodeValue()).isEqualTo(200); +// } +// +//} diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java index 5809429..d9c28c8 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java @@ -1,144 +1,144 @@ -package aist.edge.edgeservice; - -import static org.assertj.core.api.Java6Assertions.assertThat; - -import com.palantir.docker.compose.DockerComposeRule; -import com.palantir.docker.compose.configuration.ShutdownStrategy; -import com.palantir.docker.compose.connection.Container; -import com.palantir.docker.compose.connection.DockerPort; -import com.palantir.docker.compose.connection.waiting.HealthChecks; - -import java.util.*; - -import org.joda.time.Duration; -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.*; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.*; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class EdgeServiceIntegrationTestsTripQuery { - protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTestsTripQuery.class); - - private static String discoveryServiceURL; - private static String mongoURL; - private static String userServiceURL; - private static String tripQueryURL; - private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); - - // Wait for all services to have ports open - @ClassRule - public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) - .file("src/test/resources/docker-compose-trip-query.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) - .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) - .build(); - - // Get IP addresses and ports to run tests on - @BeforeClass - public static void initialize() throws Exception { - - LOG.info("Initializing ports from Docker"); - - Container discoveryContainer = docker.containers().container("discoveryservice"); - DockerPort discoveryPort = discoveryContainer.port(8761); - discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), - discoveryPort.getExternalPort()); - if(!discoveryPort.isListeningNow()){ - LOG.info("Discovery service didn't respond over HTTP"); - throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); - } - LOG.info("Discovery service responded over HTTP"); - - Container mongoContainer = docker.containers().container("mongo"); - DockerPort mongoPort = mongoContainer.port(27017); - mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); - if(!mongoPort.isListeningNow()){ - LOG.info("Mongo service didn't respond over HTTP"); - throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); - } - LOG.info("Mongo service responded over HTTP"); - - Container userContainer = docker.containers().container("userservice"); - DockerPort userPort = userContainer.port(8080); - userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); - if(!userPort.isListeningNow()){ - LOG.info("User service didn't respond over HTTP"); - throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); - } - LOG.info("User service responded over HTTP"); - - Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); - DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); - tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), - tripManagementQueryPort.getExternalPort()); - if(!tripManagementQueryPort.isListeningNow()){ - LOG.info("TripManagementQuery service didn't respond over HTTP"); - throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", tripManagementQueryPort.getInternalPort())); - } - LOG.info("TripManagementQuery service responded over HTTP"); - - LOG.info("Containers initialized correctly"); - } - - private TestRestTemplate restTemplate = new TestRestTemplate(); - - private String token; - - @Before - public void setUp() throws JSONException { - String plainCreds = "front-end:front-end"; - byte[] plainCredsBytes = plainCreds.getBytes(); - byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); - String base64Creds = new String(base64CredsBytes); - - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Basic " + base64Creds); - headers.add("Content-Type", "application/x-www-form-urlencoded"); - - MultiValueMap parameters = new LinkedMultiValueMap<>(); - parameters.add("username", "front-end"); - parameters.add("secret", "front-end"); - String body = "grant_type=password&scope=webclient&username=passenger&password=password"; - HttpEntity request = new HttpEntity<>(body, headers); - - // when: - ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, - String.class, parameters); - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); - JSONObject json = new JSONObject(response.getBody()); - token = json.getString("access_token"); - } - - @Test - public void tripQueryGETAllTripsRequestSuccess() { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); - - // when: - ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class); - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); - } -} +//package aist.edge.edgeservice; +// +//import static org.assertj.core.api.Java6Assertions.assertThat; +// +//import com.palantir.docker.compose.DockerComposeRule; +//import com.palantir.docker.compose.configuration.ShutdownStrategy; +//import com.palantir.docker.compose.connection.Container; +//import com.palantir.docker.compose.connection.DockerPort; +//import com.palantir.docker.compose.connection.waiting.HealthChecks; +// +//import java.util.*; +// +//import org.joda.time.Duration; +//import org.json.JSONException; +//import org.json.JSONObject; +//import org.junit.Before; +//import org.junit.BeforeClass; +//import org.junit.ClassRule; +//import org.junit.Test; +//import org.junit.runner.RunWith; +// +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.boot.test.web.client.TestRestTemplate; +//import org.springframework.http.*; +//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +//import org.springframework.util.*; +// +//@RunWith(SpringJUnit4ClassRunner.class) +//@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +//public class EdgeServiceIntegrationTestsTripQuery { +// protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTestsTripQuery.class); +// +// private static String discoveryServiceURL; +// private static String mongoURL; +// private static String userServiceURL; +// private static String tripQueryURL; +// private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); +// +// // Wait for all services to have ports open +// @ClassRule +// public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) +// .file("src/test/resources/docker-compose-trip-query.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) +// .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) +// .build(); +// +// // Get IP addresses and ports to run tests on +// @BeforeClass +// public static void initialize() throws Exception { +// +// LOG.info("Initializing ports from Docker"); +// +// Container discoveryContainer = docker.containers().container("discoveryservice"); +// DockerPort discoveryPort = discoveryContainer.port(8761); +// discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), +// discoveryPort.getExternalPort()); +// if(!discoveryPort.isListeningNow()){ +// LOG.info("Discovery service didn't respond over HTTP"); +// throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); +// } +// LOG.info("Discovery service responded over HTTP"); +// +// Container mongoContainer = docker.containers().container("mongo"); +// DockerPort mongoPort = mongoContainer.port(27017); +// mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); +// if(!mongoPort.isListeningNow()){ +// LOG.info("Mongo service didn't respond over HTTP"); +// throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); +// } +// LOG.info("Mongo service responded over HTTP"); +// +// Container userContainer = docker.containers().container("userservice"); +// DockerPort userPort = userContainer.port(8080); +// userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); +// if(!userPort.isListeningNow()){ +// LOG.info("User service didn't respond over HTTP"); +// throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); +// } +// LOG.info("User service responded over HTTP"); +// +// Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); +// DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); +// tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), +// tripManagementQueryPort.getExternalPort()); +// if(!tripManagementQueryPort.isListeningNow()){ +// LOG.info("TripManagementQuery service didn't respond over HTTP"); +// throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", tripManagementQueryPort.getInternalPort())); +// } +// LOG.info("TripManagementQuery service responded over HTTP"); +// +// LOG.info("Containers initialized correctly"); +// } +// +// private TestRestTemplate restTemplate = new TestRestTemplate(); +// +// private String token; +// +// @Before +// public void setUp() throws JSONException { +// String plainCreds = "front-end:front-end"; +// byte[] plainCredsBytes = plainCreds.getBytes(); +// byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); +// String base64Creds = new String(base64CredsBytes); +// +// HttpHeaders headers = new HttpHeaders(); +// headers.add("Authorization", "Basic " + base64Creds); +// headers.add("Content-Type", "application/x-www-form-urlencoded"); +// +// MultiValueMap parameters = new LinkedMultiValueMap<>(); +// parameters.add("username", "front-end"); +// parameters.add("secret", "front-end"); +// String body = "grant_type=password&scope=webclient&username=passenger&password=password"; +// HttpEntity request = new HttpEntity<>(body, headers); +// +// // when: +// ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, +// String.class, parameters); +// +// // then: +// assertThat(response.getStatusCodeValue()).isEqualTo(200); +// JSONObject json = new JSONObject(response.getBody()); +// token = json.getString("access_token"); +// } +// +// @Test +// public void tripQueryGETAllTripsRequestSuccess() { +// // given: +// HttpHeaders headers = new HttpHeaders(); +// headers.add("Authorization", "Bearer " + token); +// headers.add("Content-Type", "application/json"); +// +// // when: +// ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class); +// +// // then: +// assertThat(response.getStatusCodeValue()).isEqualTo(200); +// } +//} From ba625777f2850f4336b4699a8d42a9f60a72be4f Mon Sep 17 00:00:00 2001 From: jusoto Date: Tue, 11 Dec 2018 10:13:10 -0500 Subject: [PATCH 17/59] add previous setup for testing ports on containers for travis --- .../EdgeServiceIntegrationTests.java | 166 ++++++++++++------ 1 file changed, 112 insertions(+), 54 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index bd78609..fed0a82 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -57,7 +57,7 @@ public class EdgeServiceIntegrationTests { public static void initialize() throws Exception { LOG.info("Initializing ports from Docker"); - + Container discoveryContainer = docker.containers().container("discoveryservice"); DockerPort discoveryPort = discoveryContainer.port(8761); discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), @@ -68,65 +68,123 @@ public static void initialize() throws Exception { } LOG.info("Discovery service responded over HTTP"); - Container mongoContainer = docker.containers().container("mongo"); - DockerPort mongoPort = mongoContainer.port(27017); - mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); - if(!mongoPort.isListeningNow()){ - LOG.info("Mongo service didn't respond over HTTP"); - throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); +// Container mongoContainer = docker.containers().container("mongo"); +// DockerPort mongoPort = mongoContainer.port(27017); +// mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); +// if(!mongoPort.isListeningNow()){ +// LOG.info("Mongo service didn't respond over HTTP"); +// throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); +// } +// LOG.info("Mongo service responded over HTTP"); +// +// Container userContainer = docker.containers().container("userservice"); +// DockerPort userPort = userContainer.port(8080); +// userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); +// if(!userPort.isListeningNow()){ +// LOG.info("User service didn't respond over HTTP"); +// throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); +// } +// LOG.info("User service responded over HTTP"); +// +// Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); +// DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); +// tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), +// tripManagementCmdPort.getExternalPort()); +// if(!tripManagementCmdPort.isListeningNow()){ +// LOG.info("TripManagementCmd service didn't respond over HTTP"); +// throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", tripManagementCmdPort.getInternalPort())); +// } +// LOG.info("TripManagementCmd service responded over HTTP"); +// +// Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); +// DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); +// tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), +// tripManagementQueryPort.getExternalPort()); +// if(!tripManagementQueryPort.isListeningNow()){ +// LOG.info("TripManagementQuery service didn't respond over HTTP"); +// throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", tripManagementQueryPort.getInternalPort())); +// } +// LOG.info("TripManagementQuery service responded over HTTP"); +// +// Container gmapsAdapterContainer = docker.containers().container("gmapsadapter"); +// DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); +// gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapterPort.getIp(), +// gmapsAdapterPort.getExternalPort()); +// if(!gmapsAdapterPort.isListeningNow()){ +// LOG.info("Gmaps Adapter service didn't respond over HTTP"); +// throw new Exception(String.format("Gmaps Adapter didn't respond, port: %s", gmapsAdapterPort.getInternalPort())); +// } +// LOG.info("Gmaps Adapter service responded over HTTP"); +// +// Container calculationContainer = docker.containers().container("calculationservice"); +// DockerPort calculationPort = calculationContainer.port(8080); +// calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), +// calculationPort.getExternalPort()); +// if(!calculationPort.isListeningNow()){ +// LOG.info("Calculation service didn't respond over HTTP"); +// throw new Exception(String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); +// } +// LOG.info("Calculation service responded over HTTP"); +// +// DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); +// discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), +// discoveryService.getExternalPort()); +// while (!docker.containers().container("discoveryservice") +// .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { +// LOG.info("Waiting for discovery service to respond over HTTP"); +// } +// LOG.info("Discovery Service url found: " + discoveryServiceURL); + + DockerPort mongo = docker.containers().container("mongo").port(27017); + mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); + while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) + .succeeded()) { + LOG.info("Waiting for mongo to respond over HTTP"); } - LOG.info("Mongo service responded over HTTP"); - - Container userContainer = docker.containers().container("userservice"); - DockerPort userPort = userContainer.port(8080); - userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); - if(!userPort.isListeningNow()){ - LOG.info("User service didn't respond over HTTP"); - throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); + LOG.info("Mongo url found: " + mongoURL); + + DockerPort userService = docker.containers().container("userservice").port(8080); + userServiceURL = String.format("http://%s:%s", userService.getIp(), userService.getExternalPort()); + while (!docker.containers().container("userservice") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { + LOG.info("Waiting for user service to respond over HTTP"); } - LOG.info("User service responded over HTTP"); - - Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); - DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); - tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), - tripManagementCmdPort.getExternalPort()); - if(!tripManagementCmdPort.isListeningNow()){ - LOG.info("TripManagementCmd service didn't respond over HTTP"); - throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", tripManagementCmdPort.getInternalPort())); + LOG.info("User Service url found: " + userServiceURL); + + DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd").port(8080); + tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), + tripManagementCommand.getExternalPort()); + while (!docker.containers().container("tripmanagementcmd") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripCommandURL)).succeeded()) { + LOG.info("Waiting for Trip Command to respond over HTTP"); } - LOG.info("TripManagementCmd service responded over HTTP"); - - Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); - DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); - tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), - tripManagementQueryPort.getExternalPort()); - if(!tripManagementQueryPort.isListeningNow()){ - LOG.info("TripManagementQuery service didn't respond over HTTP"); - throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", tripManagementQueryPort.getInternalPort())); + LOG.info("Trip Command url found: " + tripCommandURL); + + DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery").port(8080); + tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(), + tripManagementQuery.getExternalPort()); + while (!docker.containers().container("tripmanagementquery") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripQueryURL)).succeeded()) { + LOG.info("Waiting for Trip Query to respond over HTTP"); } - LOG.info("TripManagementQuery service responded over HTTP"); - - Container gmapsAdapterContainer = docker.containers().container("gmapsadapter"); - DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); - gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapterPort.getIp(), - gmapsAdapterPort.getExternalPort()); - if(!gmapsAdapterPort.isListeningNow()){ - LOG.info("Gmaps Adapter service didn't respond over HTTP"); - throw new Exception(String.format("Gmaps Adapter didn't respond, port: %s", gmapsAdapterPort.getInternalPort())); + LOG.info("Trip Query url found: " + tripQueryURL); + + DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); + gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); + while (!docker.containers().container("gmapsadapter") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { + LOG.info("Waiting for user service to respond over HTTP"); } - LOG.info("Gmaps Adapter service responded over HTTP"); - - Container calculationContainer = docker.containers().container("calculationservice"); - DockerPort calculationPort = calculationContainer.port(8080); - calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), - calculationPort.getExternalPort()); - if(!calculationPort.isListeningNow()){ - LOG.info("Calculation service didn't respond over HTTP"); - throw new Exception(String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); + LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); + + DockerPort calculationService = docker.containers().container("calculationservice").port(8080); + calculationServiceURL = String.format("http://%s:%s", calculationService.getIp(), + calculationService.getExternalPort()); + while (!docker.containers().container("calculationservice") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(calculationServiceURL)).succeeded()) { + LOG.info("Waiting for calculation service to respond over HTTP"); } - LOG.info("Calculation service responded over HTTP"); - - LOG.info("Containers initialized correctly"); + LOG.info("Calculation Service url found: " + calculationServiceURL); } private TestRestTemplate restTemplate = new TestRestTemplate(); From 4488eb3dc924829fc5e0a42a686afa08e298ba79 Mon Sep 17 00:00:00 2001 From: jusoto Date: Tue, 11 Dec 2018 10:32:56 -0500 Subject: [PATCH 18/59] userservice test case port validation --- .../EdgeServiceIntegrationTests.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index fed0a82..1f29ba5 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -77,14 +77,14 @@ public static void initialize() throws Exception { // } // LOG.info("Mongo service responded over HTTP"); // -// Container userContainer = docker.containers().container("userservice"); -// DockerPort userPort = userContainer.port(8080); -// userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); -// if(!userPort.isListeningNow()){ -// LOG.info("User service didn't respond over HTTP"); -// throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); -// } -// LOG.info("User service responded over HTTP"); + Container userContainer = docker.containers().container("userservice"); + DockerPort userPort = userContainer.port(8080); + userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); + if(!userPort.isListeningNow()){ + LOG.info("User service didn't respond over HTTP"); + throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); + } + LOG.info("User service responded over HTTP"); // // Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); // DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); @@ -143,13 +143,13 @@ public static void initialize() throws Exception { } LOG.info("Mongo url found: " + mongoURL); - DockerPort userService = docker.containers().container("userservice").port(8080); - userServiceURL = String.format("http://%s:%s", userService.getIp(), userService.getExternalPort()); - while (!docker.containers().container("userservice") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { - LOG.info("Waiting for user service to respond over HTTP"); - } - LOG.info("User Service url found: " + userServiceURL); +// DockerPort userService = docker.containers().container("userservice").port(8080); +// userServiceURL = String.format("http://%s:%s", userService.getIp(), userService.getExternalPort()); +// while (!docker.containers().container("userservice") +// .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { +// LOG.info("Waiting for user service to respond over HTTP"); +// } +// LOG.info("User Service url found: " + userServiceURL); DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd").port(8080); tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), From 71a86074676879cd7973a880ee1324eee44b47c8 Mon Sep 17 00:00:00 2001 From: jusoto Date: Tue, 11 Dec 2018 11:02:30 -0500 Subject: [PATCH 19/59] test cases trip query containers validation port --- .../EdgeServiceIntegrationTests.java | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 1f29ba5..2b67406 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -85,26 +85,26 @@ public static void initialize() throws Exception { throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); } LOG.info("User service responded over HTTP"); -// -// Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); -// DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); -// tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), -// tripManagementCmdPort.getExternalPort()); -// if(!tripManagementCmdPort.isListeningNow()){ -// LOG.info("TripManagementCmd service didn't respond over HTTP"); -// throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", tripManagementCmdPort.getInternalPort())); -// } -// LOG.info("TripManagementCmd service responded over HTTP"); -// -// Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); -// DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); -// tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), -// tripManagementQueryPort.getExternalPort()); -// if(!tripManagementQueryPort.isListeningNow()){ -// LOG.info("TripManagementQuery service didn't respond over HTTP"); -// throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", tripManagementQueryPort.getInternalPort())); -// } -// LOG.info("TripManagementQuery service responded over HTTP"); + + Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); + DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); + tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), + tripManagementCmdPort.getExternalPort()); + if(!tripManagementCmdPort.isListeningNow()){ + LOG.info("TripManagementCmd service didn't respond over HTTP"); + throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", tripManagementCmdPort.getInternalPort())); + } + LOG.info("TripManagementCmd service responded over HTTP"); + + Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); + DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); + tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), + tripManagementQueryPort.getExternalPort()); + if(!tripManagementQueryPort.isListeningNow()){ + LOG.info("TripManagementQuery service didn't respond over HTTP"); + throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", tripManagementQueryPort.getInternalPort())); + } + LOG.info("TripManagementQuery service responded over HTTP"); // // Container gmapsAdapterContainer = docker.containers().container("gmapsadapter"); // DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); @@ -151,23 +151,23 @@ public static void initialize() throws Exception { // } // LOG.info("User Service url found: " + userServiceURL); - DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd").port(8080); - tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), - tripManagementCommand.getExternalPort()); - while (!docker.containers().container("tripmanagementcmd") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripCommandURL)).succeeded()) { - LOG.info("Waiting for Trip Command to respond over HTTP"); - } - LOG.info("Trip Command url found: " + tripCommandURL); - - DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery").port(8080); - tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(), - tripManagementQuery.getExternalPort()); - while (!docker.containers().container("tripmanagementquery") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripQueryURL)).succeeded()) { - LOG.info("Waiting for Trip Query to respond over HTTP"); - } - LOG.info("Trip Query url found: " + tripQueryURL); +// DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd").port(8080); +// tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), +// tripManagementCommand.getExternalPort()); +// while (!docker.containers().container("tripmanagementcmd") +// .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripCommandURL)).succeeded()) { +// LOG.info("Waiting for Trip Command to respond over HTTP"); +// } +// LOG.info("Trip Command url found: " + tripCommandURL); +// +// DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery").port(8080); +// tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(), +// tripManagementQuery.getExternalPort()); +// while (!docker.containers().container("tripmanagementquery") +// .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripQueryURL)).succeeded()) { +// LOG.info("Waiting for Trip Query to respond over HTTP"); +// } +// LOG.info("Trip Query url found: " + tripQueryURL); DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); From 01b860e037277c900761ca0af2166200fdbb240f Mon Sep 17 00:00:00 2001 From: jusoto Date: Tue, 11 Dec 2018 11:19:21 -0500 Subject: [PATCH 20/59] test cases included calculation port validation --- .../EdgeServiceIntegrationTests.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 2b67406..1b59203 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -116,15 +116,15 @@ public static void initialize() throws Exception { // } // LOG.info("Gmaps Adapter service responded over HTTP"); // -// Container calculationContainer = docker.containers().container("calculationservice"); -// DockerPort calculationPort = calculationContainer.port(8080); -// calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), -// calculationPort.getExternalPort()); -// if(!calculationPort.isListeningNow()){ -// LOG.info("Calculation service didn't respond over HTTP"); -// throw new Exception(String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); -// } -// LOG.info("Calculation service responded over HTTP"); + Container calculationContainer = docker.containers().container("calculationservice"); + DockerPort calculationPort = calculationContainer.port(8080); + calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), + calculationPort.getExternalPort()); + if(!calculationPort.isListeningNow()){ + LOG.info("Calculation service didn't respond over HTTP"); + throw new Exception(String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); + } + LOG.info("Calculation service responded over HTTP"); // // DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); // discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), @@ -177,14 +177,14 @@ public static void initialize() throws Exception { } LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); - DockerPort calculationService = docker.containers().container("calculationservice").port(8080); - calculationServiceURL = String.format("http://%s:%s", calculationService.getIp(), - calculationService.getExternalPort()); - while (!docker.containers().container("calculationservice") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(calculationServiceURL)).succeeded()) { - LOG.info("Waiting for calculation service to respond over HTTP"); - } - LOG.info("Calculation Service url found: " + calculationServiceURL); +// DockerPort calculationService = docker.containers().container("calculationservice").port(8080); +// calculationServiceURL = String.format("http://%s:%s", calculationService.getIp(), +// calculationService.getExternalPort()); +// while (!docker.containers().container("calculationservice") +// .portIsListeningOnHttp(8080, (port) -> port.inFormat(calculationServiceURL)).succeeded()) { +// LOG.info("Waiting for calculation service to respond over HTTP"); +// } +// LOG.info("Calculation Service url found: " + calculationServiceURL); } private TestRestTemplate restTemplate = new TestRestTemplate(); From 1084fe420c20668ae5baa7d3116e900b373f15ea Mon Sep 17 00:00:00 2001 From: jusoto Date: Tue, 11 Dec 2018 11:31:37 -0500 Subject: [PATCH 21/59] test cases use container name to create HTTP requests --- .../aist/edge/edgeservice/EdgeServiceIntegrationTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 1b59203..e09ec04 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -60,7 +60,7 @@ public static void initialize() throws Exception { Container discoveryContainer = docker.containers().container("discoveryservice"); DockerPort discoveryPort = discoveryContainer.port(8761); - discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), + discoveryServiceURL = String.format("http://%s:%s", discoveryContainer.getContainerName(), discoveryPort.getExternalPort()); if(!discoveryPort.isListeningNow()){ LOG.info("Discovery service didn't respond over HTTP"); @@ -79,7 +79,7 @@ public static void initialize() throws Exception { // Container userContainer = docker.containers().container("userservice"); DockerPort userPort = userContainer.port(8080); - userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); + userServiceURL = String.format("http://%s:%s", userContainer.getContainerName(), userPort.getExternalPort()); if(!userPort.isListeningNow()){ LOG.info("User service didn't respond over HTTP"); throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); From d3fe1f4c359b970a92d10c89b13477a37467b527 Mon Sep 17 00:00:00 2001 From: jusoto Date: Tue, 11 Dec 2018 11:46:54 -0500 Subject: [PATCH 22/59] test cases, use localhost instead of container name --- .../aist/edge/edgeservice/EdgeServiceIntegrationTests.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index e09ec04..e458642 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -60,8 +60,7 @@ public static void initialize() throws Exception { Container discoveryContainer = docker.containers().container("discoveryservice"); DockerPort discoveryPort = discoveryContainer.port(8761); - discoveryServiceURL = String.format("http://%s:%s", discoveryContainer.getContainerName(), - discoveryPort.getExternalPort()); + discoveryServiceURL = String.format("http://%s:%s", "localhost", discoveryPort.getExternalPort()); if(!discoveryPort.isListeningNow()){ LOG.info("Discovery service didn't respond over HTTP"); throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); @@ -79,7 +78,7 @@ public static void initialize() throws Exception { // Container userContainer = docker.containers().container("userservice"); DockerPort userPort = userContainer.port(8080); - userServiceURL = String.format("http://%s:%s", userContainer.getContainerName(), userPort.getExternalPort()); + userServiceURL = String.format("http://%s:%s", "localhost", userPort.getExternalPort()); if(!userPort.isListeningNow()){ LOG.info("User service didn't respond over HTTP"); throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); From e5c759ff22aac8eb5785d6482ca0eba2333e6b95 Mon Sep 17 00:00:00 2001 From: jusoto Date: Tue, 11 Dec 2018 14:07:18 -0500 Subject: [PATCH 23/59] added environment variables for dependencies host names --- .travis.yml | 3 +++ src/main/resources/application.yml | 12 ++++++------ .../edgeservice/EdgeServiceIntegrationTests.java | 3 +-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index c7b5fb2..30f2ac5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,9 @@ script: env: global: - EUREKA_SERVER="localhost" + - TRIP_CMD_HOST="localhost" + - TRIP_QUERY_HOST="localhost" + - USER_SERVICE_HOST="localhost" - RABBIT_HOST="localhost" - MONGO_HOST="localhost" - secure: WF5U05+p8xQRBhT75aviCl9sXpnzER52xJDkKaZPtsak3B/21rj5FGQ4TTu9ivh0oF56ws8Zy8hzNZhjS09QimqtpD+Zl5m5er4Q2GvrStVDM0k38wqye2IBf7juKIlkfntX1o1E9/xGkUgIW5eQpUt7TDGpon5FCvY8NHqDyVi+ZDU7hGQh8E3oyK+8Dly1ETLxVhoDEY3vG1VyEZ1IDrgAw/N6KlNIyiuWjPMBLTFAjGMzJAaf/MQiKfmB3HUBUtGqEdhobppEqriJkXl/6ov+Np+vh83dIBaOfRUpB1KgvGmefmtL7rb+mIIXOLMm9cpyqmK+6h1JeQrwB3xtWtIIXmmL2VEwmO/2YfTDyu+JpRkkgwDMLgyRKN9wEtaR+4C3X/p9zMysocDhyccOeGVq7XhJwgdosoJ0VRLVtUhPq1T10B/ipp2g8VF9TW1uIfSQJe6YYCrVK+fqtkWG5yuOfqQdGHNZkRJMpeTyzkJQzX7GZb8G0H8EZCsjdJ0FdEpshWcCB2ljozwH3fFMqnzE1thibpg7dC2BXF7aRGjmn/4vqme98i4hP+590FIMF+sdyDItVq7/91EAwh7m35dvszkFruIzLgHFRnrKAgG76bTHTz8bwywhnCZVbDmy/HEDOjj2ykW9jPKJ7buKRKVYbXnSgYqkn/keTHiRvLI= diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c4b0701..1d0db3d 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -8,18 +8,18 @@ zuul: routes: trip-cmd: path: /trip/cmd/** - url: http://tripmanagementcmd:8080/api + url: http://${TRIP_CMD_HOST:localhost}:8080/api trip-query: path: /trip/query/** - url: http://tripmanagementquery:8080/api + url: http://${TRIP_QUERY_HOST:localhost}:8080/api userservice: - path: /userservice/** - url: http://userservice:8080/ + path: /${USER_SERVICE_HOST:localhost}/** + url: http://${USER_SERVICE_HOST:localhost}:8080/ sensitiveHeaders: Cookie,Set-Cookie security: oauth2: resource: - userInfoUri: http://userservice:8080/auth/user + userInfoUri: http://${USER_SERVICE_HOST:localhost}:8080/auth/user ignored: /catalog/** eureka: instance: @@ -28,7 +28,7 @@ eureka: registerWithEureka: true fetchRegistry: true serviceUrl: - defaultZone: http://discoveryservice:8761/eureka/ + defaultZone: http://${EUREKA_SERVER:localhost}:8761/eureka/ management: security: enabled: false diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index e458642..1733496 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -30,7 +30,7 @@ public class EdgeServiceIntegrationTests { protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTests.class); - private static String discoveryServiceURL; + //private static String discoveryServiceURL; private static String mongoURL; private static String userServiceURL; private static String tripCommandURL; @@ -60,7 +60,6 @@ public static void initialize() throws Exception { Container discoveryContainer = docker.containers().container("discoveryservice"); DockerPort discoveryPort = discoveryContainer.port(8761); - discoveryServiceURL = String.format("http://%s:%s", "localhost", discoveryPort.getExternalPort()); if(!discoveryPort.isListeningNow()){ LOG.info("Discovery service didn't respond over HTTP"); throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); From 185ecb8d4e07cbd40cb6614686b442b3a6a26f2e Mon Sep 17 00:00:00 2001 From: jusoto Date: Tue, 11 Dec 2018 16:33:03 -0500 Subject: [PATCH 24/59] test cases remove localhost from userServiceURL --- src/main/resources/application.yml | 12 ++++++------ .../edgeservice/EdgeServiceIntegrationTests.java | 5 +++-- src/test/resources/docker-compose.yml | 15 +++++++++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 1d0db3d..dc1af40 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -8,18 +8,18 @@ zuul: routes: trip-cmd: path: /trip/cmd/** - url: http://${TRIP_CMD_HOST:localhost}:8080/api + url: http://${TRIP_CMD_HOST:tripmanagementcmd}:8080/api trip-query: path: /trip/query/** - url: http://${TRIP_QUERY_HOST:localhost}:8080/api + url: http://${TRIP_QUERY_HOST:tripmanagementquery}:8080/api userservice: - path: /${USER_SERVICE_HOST:localhost}/** - url: http://${USER_SERVICE_HOST:localhost}:8080/ + path: /${USER_SERVICE_HOST:userservice}/** + url: http://${USER_SERVICE_HOST:userservice}:8080/ sensitiveHeaders: Cookie,Set-Cookie security: oauth2: resource: - userInfoUri: http://${USER_SERVICE_HOST:localhost}:8080/auth/user + userInfoUri: http://${USER_SERVICE_HOST:userservice}:8080/auth/user ignored: /catalog/** eureka: instance: @@ -28,7 +28,7 @@ eureka: registerWithEureka: true fetchRegistry: true serviceUrl: - defaultZone: http://${EUREKA_SERVER:localhost}:8761/eureka/ + defaultZone: http://${EUREKA_SERVER:discoveryservice}:8761/eureka/ management: security: enabled: false diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 1733496..edaec90 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -50,7 +50,8 @@ public class EdgeServiceIntegrationTests { .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()).build(); + .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()) + .build(); // Get IP addresses and ports to run tests on @BeforeClass @@ -77,7 +78,7 @@ public static void initialize() throws Exception { // Container userContainer = docker.containers().container("userservice"); DockerPort userPort = userContainer.port(8080); - userServiceURL = String.format("http://%s:%s", "localhost", userPort.getExternalPort()); + userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); if(!userPort.isListeningNow()){ LOG.info("User service didn't respond over HTTP"); throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); diff --git a/src/test/resources/docker-compose.yml b/src/test/resources/docker-compose.yml index ee3cf9f..fe934b3 100644 --- a/src/test/resources/docker-compose.yml +++ b/src/test/resources/docker-compose.yml @@ -4,12 +4,14 @@ services: discoveryservice: image: aista/eureka + container_name: discoveryservice mem_limit: 512M ports: - "8761:8761" mysqlserver: image: mysql:5.7 + container_name: mysqlserver mem_limit: 512M volumes: - mysql-data:/var/lib/mysql:rw @@ -25,8 +27,8 @@ services: userservice: image: aista/user-service - mem_limit: 512M container_name: userservice + mem_limit: 512M depends_on: - discoveryservice - mysqlserver @@ -37,8 +39,8 @@ services: mongo: image: 'mongo:3.4.1' + container_name: mongo mem_limit: 512M - container_name: 'mongo' ports: - '27017:27017' volumes: @@ -46,8 +48,8 @@ services: rabbitmq: image: rabbitmq:management + container_name: rabbitmq mem_limit: 512M - container_name: 'rabbitmq' ports: - "5672:5672" - "15672:15672" @@ -86,6 +88,7 @@ services: gmapsadapter: image: aista/gmaps-adapter + container_name: gmapsadapter mem_limit: 512M environment: - EUREKA_SERVER=discoveryservice @@ -94,11 +97,13 @@ services: - '8080' depends_on: - discoveryservice + - rabbitmq environment: - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC calculationservice: image: aista/calculation-service + container_name: calculationservice mem_limit: 512M environment: - RABBIT_HOST=rabbitmq @@ -110,7 +115,9 @@ services: - '8080' depends_on: - discoveryservice + - rabbitmq + - mongo volumes: mongo: - mysql-data: \ No newline at end of file + mysql-data: From 54884009c331051bed90ca8a0d1a8de72560ef10 Mon Sep 17 00:00:00 2001 From: jusoto Date: Wed, 12 Dec 2018 08:43:51 -0500 Subject: [PATCH 25/59] Added output aid to check active containers before running tests --- .../EdgeServiceIntegrationTests.java | 68 ++++++++++++++++--- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index edaec90..c115d35 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -2,12 +2,9 @@ import static org.assertj.core.api.Java6Assertions.assertThat; -import com.palantir.docker.compose.DockerComposeRule; -import com.palantir.docker.compose.connection.Container; -import com.palantir.docker.compose.connection.DockerPort; -import com.palantir.docker.compose.connection.waiting.HealthChecks; - -import java.util.*; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Base64; import org.json.JSONException; import org.json.JSONObject; @@ -16,14 +13,21 @@ import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.*; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.*; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; + +import com.palantir.docker.compose.DockerComposeRule; +import com.palantir.docker.compose.connection.Container; +import com.palantir.docker.compose.connection.DockerPort; +import com.palantir.docker.compose.connection.waiting.HealthChecks; @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @@ -33,6 +37,9 @@ public class EdgeServiceIntegrationTests { //private static String discoveryServiceURL; private static String mongoURL; private static String userServiceURL; + private static String userServiceURL1; + private static String userServiceURL2; + private static String userServiceURL3; private static String tripCommandURL; private static String tripQueryURL; private static String gmapsAdapterURL; @@ -78,12 +85,17 @@ public static void initialize() throws Exception { // Container userContainer = docker.containers().container("userservice"); DockerPort userPort = userContainer.port(8080); - userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); + userServiceURL = String.format("http://%s:%s", userContainer.getContainerName(), userPort.getInternalPort()); + userServiceURL1 = String.format("http://%s:%s", userContainer.getContainerName(), userPort.getExternalPort()); + userServiceURL2 = String.format("http://%s:%s", userPort.getIp(), userPort.getInternalPort()); + userServiceURL3 = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); if(!userPort.isListeningNow()){ LOG.info("User service didn't respond over HTTP"); throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); } LOG.info("User service responded over HTTP"); + LOG.info(String.format("User Service docker-name: %s - IP: %s - Int Port: %s - Ext Port: %s" + , userContainer.getContainerName(), userPort.getIp(), userPort.getInternalPort(), userPort.getExternalPort())); Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); @@ -208,7 +220,41 @@ public void setUp() throws JSONException { HttpEntity request = new HttpEntity<>(body, headers); // when: - ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, + ResponseEntity response; + + Runtime rt = Runtime.getRuntime(); + + ////////////////////////////////////////////// + + Runtime rt = Runtime.getRuntime(); + String[] commands = {"docker","ps"}; + Process proc = rt.exec(commands); + + BufferedReader stdInput = new BufferedReader(new + InputStreamReader(proc.getInputStream())); + + BufferedReader stdError = new BufferedReader(new + InputStreamReader(proc.getErrorStream())); + + // read the output from the command + System.out.println("Here is the standard output of the command:\n"); + String s = null; + while ((s = stdInput.readLine()) != null) { + System.out.println(s); + LOG.info(s); + } + + // read any errors from the attempted command + System.out.println("Here is the standard error of the command (if any):\n"); + while ((s = stdError.readLine()) != null) { + System.out.println(s); + LOG.info(s); + } + + ////////////////////////////////////////////// + + LOG.info(String.format("User Service - Trying url: %s", userServiceURL3)); + response = restTemplate.postForEntity(userServiceURL3 + "/auth/oauth/token", request, String.class, parameters); // then: From 3c741b0dc2805de0071c2bc671b12f4f902ef7c9 Mon Sep 17 00:00:00 2001 From: jusoto Date: Wed, 12 Dec 2018 08:50:47 -0500 Subject: [PATCH 26/59] Removed duplicated rt line on tests file --- .../java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index c115d35..8426e4b 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -222,8 +222,6 @@ public void setUp() throws JSONException { // when: ResponseEntity response; - Runtime rt = Runtime.getRuntime(); - ////////////////////////////////////////////// Runtime rt = Runtime.getRuntime(); From 89ab3d72edba857a3c81294dd3e677f224ce8f0c Mon Sep 17 00:00:00 2001 From: jusoto Date: Wed, 12 Dec 2018 08:52:35 -0500 Subject: [PATCH 27/59] Added missing IOException on tests --- .../aist/edge/edgeservice/EdgeServiceIntegrationTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 8426e4b..8b73b64 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Java6Assertions.assertThat; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStreamReader; import java.util.Base64; @@ -203,7 +204,7 @@ public static void initialize() throws Exception { private String token; @Before - public void setUp() throws JSONException { + public void setUp() throws JSONException, IOException { String plainCreds = "front-end:front-end"; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); From 2504807a3a4274f28cad91b0fd112be33ee5e88d Mon Sep 17 00:00:00 2001 From: jusoto Date: Wed, 12 Dec 2018 09:46:24 -0500 Subject: [PATCH 28/59] Added docker inspect to show details of docker environment on travis --- .../EdgeServiceIntegrationTests.java | 571 +++++++++--------- 1 file changed, 295 insertions(+), 276 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 8b73b64..dc71e38 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -35,7 +35,7 @@ public class EdgeServiceIntegrationTests { protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTests.class); - //private static String discoveryServiceURL; + // private static String discoveryServiceURL; private static String mongoURL; private static String userServiceURL; private static String userServiceURL1; @@ -49,154 +49,177 @@ public class EdgeServiceIntegrationTests { // Wait for all services to have ports open @ClassRule public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) - .file("src/test/resources/docker-compose.yml") - .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()) - .build(); + .file("src/test/resources/docker-compose.yml") + .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()).build(); // Get IP addresses and ports to run tests on @BeforeClass public static void initialize() throws Exception { - LOG.info("Initializing ports from Docker"); - - Container discoveryContainer = docker.containers().container("discoveryservice"); - DockerPort discoveryPort = discoveryContainer.port(8761); - if(!discoveryPort.isListeningNow()){ - LOG.info("Discovery service didn't respond over HTTP"); - throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); - } - LOG.info("Discovery service responded over HTTP"); - -// Container mongoContainer = docker.containers().container("mongo"); -// DockerPort mongoPort = mongoContainer.port(27017); -// mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); -// if(!mongoPort.isListeningNow()){ -// LOG.info("Mongo service didn't respond over HTTP"); -// throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); -// } -// LOG.info("Mongo service responded over HTTP"); -// - Container userContainer = docker.containers().container("userservice"); - DockerPort userPort = userContainer.port(8080); - userServiceURL = String.format("http://%s:%s", userContainer.getContainerName(), userPort.getInternalPort()); - userServiceURL1 = String.format("http://%s:%s", userContainer.getContainerName(), userPort.getExternalPort()); - userServiceURL2 = String.format("http://%s:%s", userPort.getIp(), userPort.getInternalPort()); - userServiceURL3 = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); - if(!userPort.isListeningNow()){ - LOG.info("User service didn't respond over HTTP"); - throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); - } - LOG.info("User service responded over HTTP"); - LOG.info(String.format("User Service docker-name: %s - IP: %s - Int Port: %s - Ext Port: %s" - , userContainer.getContainerName(), userPort.getIp(), userPort.getInternalPort(), userPort.getExternalPort())); - - Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); - DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); - tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), - tripManagementCmdPort.getExternalPort()); - if(!tripManagementCmdPort.isListeningNow()){ - LOG.info("TripManagementCmd service didn't respond over HTTP"); - throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", tripManagementCmdPort.getInternalPort())); - } - LOG.info("TripManagementCmd service responded over HTTP"); - - Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); - DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); - tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), - tripManagementQueryPort.getExternalPort()); - if(!tripManagementQueryPort.isListeningNow()){ - LOG.info("TripManagementQuery service didn't respond over HTTP"); - throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", tripManagementQueryPort.getInternalPort())); - } - LOG.info("TripManagementQuery service responded over HTTP"); -// -// Container gmapsAdapterContainer = docker.containers().container("gmapsadapter"); -// DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); -// gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapterPort.getIp(), -// gmapsAdapterPort.getExternalPort()); -// if(!gmapsAdapterPort.isListeningNow()){ -// LOG.info("Gmaps Adapter service didn't respond over HTTP"); -// throw new Exception(String.format("Gmaps Adapter didn't respond, port: %s", gmapsAdapterPort.getInternalPort())); -// } -// LOG.info("Gmaps Adapter service responded over HTTP"); -// - Container calculationContainer = docker.containers().container("calculationservice"); - DockerPort calculationPort = calculationContainer.port(8080); - calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), - calculationPort.getExternalPort()); - if(!calculationPort.isListeningNow()){ - LOG.info("Calculation service didn't respond over HTTP"); - throw new Exception(String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); - } - LOG.info("Calculation service responded over HTTP"); -// -// DockerPort discoveryService = docker.containers().container("discoveryservice").port(8761); -// discoveryServiceURL = String.format("http://%s:%s", discoveryService.getIp(), -// discoveryService.getExternalPort()); -// while (!docker.containers().container("discoveryservice") -// .portIsListeningOnHttp(8761, (port) -> port.inFormat(discoveryServiceURL)).succeeded()) { -// LOG.info("Waiting for discovery service to respond over HTTP"); -// } -// LOG.info("Discovery Service url found: " + discoveryServiceURL); - - DockerPort mongo = docker.containers().container("mongo").port(27017); - mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); - while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) - .succeeded()) { - LOG.info("Waiting for mongo to respond over HTTP"); - } - LOG.info("Mongo url found: " + mongoURL); - -// DockerPort userService = docker.containers().container("userservice").port(8080); -// userServiceURL = String.format("http://%s:%s", userService.getIp(), userService.getExternalPort()); -// while (!docker.containers().container("userservice") -// .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { -// LOG.info("Waiting for user service to respond over HTTP"); -// } -// LOG.info("User Service url found: " + userServiceURL); - -// DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd").port(8080); -// tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), -// tripManagementCommand.getExternalPort()); -// while (!docker.containers().container("tripmanagementcmd") -// .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripCommandURL)).succeeded()) { -// LOG.info("Waiting for Trip Command to respond over HTTP"); -// } -// LOG.info("Trip Command url found: " + tripCommandURL); -// -// DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery").port(8080); -// tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(), -// tripManagementQuery.getExternalPort()); -// while (!docker.containers().container("tripmanagementquery") -// .portIsListeningOnHttp(8080, (port) -> port.inFormat(tripQueryURL)).succeeded()) { -// LOG.info("Waiting for Trip Query to respond over HTTP"); -// } -// LOG.info("Trip Query url found: " + tripQueryURL); - - DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); - gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); - while (!docker.containers().container("gmapsadapter") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { - LOG.info("Waiting for user service to respond over HTTP"); - } - LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); - -// DockerPort calculationService = docker.containers().container("calculationservice").port(8080); -// calculationServiceURL = String.format("http://%s:%s", calculationService.getIp(), -// calculationService.getExternalPort()); -// while (!docker.containers().container("calculationservice") -// .portIsListeningOnHttp(8080, (port) -> port.inFormat(calculationServiceURL)).succeeded()) { -// LOG.info("Waiting for calculation service to respond over HTTP"); -// } -// LOG.info("Calculation Service url found: " + calculationServiceURL); + LOG.info("Initializing ports from Docker"); + + Container discoveryContainer = docker.containers().container("discoveryservice"); + DockerPort discoveryPort = discoveryContainer.port(8761); + if (!discoveryPort.isListeningNow()) { + LOG.info("Discovery service didn't respond over HTTP"); + throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); + } + LOG.info("Discovery service responded over HTTP"); + + // Container mongoContainer = docker.containers().container("mongo"); + // DockerPort mongoPort = mongoContainer.port(27017); + // mongoURL = String.format("http://%s:%s", mongoPort.getIp(), + // mongoPort.getExternalPort()); + // if(!mongoPort.isListeningNow()){ + // LOG.info("Mongo service didn't respond over HTTP"); + // throw new Exception(String.format("Mongo didn't respond, port: %s", + // mongoPort.getInternalPort())); + // } + // LOG.info("Mongo service responded over HTTP"); + // + Container userContainer = docker.containers().container("userservice"); + DockerPort userPort = userContainer.port(8080); + userServiceURL = String.format("http://%s:%s", userContainer.getContainerName(), userPort.getInternalPort()); + userServiceURL1 = String.format("http://%s:%s", userContainer.getContainerName(), userPort.getExternalPort()); + userServiceURL2 = String.format("http://%s:%s", userPort.getIp(), userPort.getInternalPort()); + userServiceURL3 = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); + if (!userPort.isListeningNow()) { + LOG.info("User service didn't respond over HTTP"); + throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); + } + LOG.info("User service responded over HTTP"); + LOG.info(String.format("User Service docker-name: %s - IP: %s - Int Port: %s - Ext Port: %s", + userContainer.getContainerName(), userPort.getIp(), userPort.getInternalPort(), + userPort.getExternalPort())); + + Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); + DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); + tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), + tripManagementCmdPort.getExternalPort()); + if (!tripManagementCmdPort.isListeningNow()) { + LOG.info("TripManagementCmd service didn't respond over HTTP"); + throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", + tripManagementCmdPort.getInternalPort())); + } + LOG.info("TripManagementCmd service responded over HTTP"); + + Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); + DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); + tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), + tripManagementQueryPort.getExternalPort()); + if (!tripManagementQueryPort.isListeningNow()) { + LOG.info("TripManagementQuery service didn't respond over HTTP"); + throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", + tripManagementQueryPort.getInternalPort())); + } + LOG.info("TripManagementQuery service responded over HTTP"); + // + // Container gmapsAdapterContainer = + // docker.containers().container("gmapsadapter"); + // DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); + // gmapsAdapterURL = String.format("http://%s:%s", + // gmapsAdapterPort.getIp(), + // gmapsAdapterPort.getExternalPort()); + // if(!gmapsAdapterPort.isListeningNow()){ + // LOG.info("Gmaps Adapter service didn't respond over HTTP"); + // throw new Exception(String.format("Gmaps Adapter didn't respond, + // port: %s", gmapsAdapterPort.getInternalPort())); + // } + // LOG.info("Gmaps Adapter service responded over HTTP"); + // + Container calculationContainer = docker.containers().container("calculationservice"); + DockerPort calculationPort = calculationContainer.port(8080); + calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), + calculationPort.getExternalPort()); + if (!calculationPort.isListeningNow()) { + LOG.info("Calculation service didn't respond over HTTP"); + throw new Exception( + String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); + } + LOG.info("Calculation service responded over HTTP"); + // + // DockerPort discoveryService = + // docker.containers().container("discoveryservice").port(8761); + // discoveryServiceURL = String.format("http://%s:%s", + // discoveryService.getIp(), + // discoveryService.getExternalPort()); + // while (!docker.containers().container("discoveryservice") + // .portIsListeningOnHttp(8761, (port) -> + // port.inFormat(discoveryServiceURL)).succeeded()) { + // LOG.info("Waiting for discovery service to respond over HTTP"); + // } + // LOG.info("Discovery Service url found: " + discoveryServiceURL); + + DockerPort mongo = docker.containers().container("mongo").port(27017); + mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); + while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) + .succeeded()) { + LOG.info("Waiting for mongo to respond over HTTP"); + } + LOG.info("Mongo url found: " + mongoURL); + + // DockerPort userService = + // docker.containers().container("userservice").port(8080); + // userServiceURL = String.format("http://%s:%s", userService.getIp(), + // userService.getExternalPort()); + // while (!docker.containers().container("userservice") + // .portIsListeningOnHttp(8080, (port) -> + // port.inFormat(userServiceURL)).succeeded()) { + // LOG.info("Waiting for user service to respond over HTTP"); + // } + // LOG.info("User Service url found: " + userServiceURL); + + // DockerPort tripManagementCommand = + // docker.containers().container("tripmanagementcmd").port(8080); + // tripCommandURL = String.format("http://%s:%s", + // tripManagementCommand.getIp(), + // tripManagementCommand.getExternalPort()); + // while (!docker.containers().container("tripmanagementcmd") + // .portIsListeningOnHttp(8080, (port) -> + // port.inFormat(tripCommandURL)).succeeded()) { + // LOG.info("Waiting for Trip Command to respond over HTTP"); + // } + // LOG.info("Trip Command url found: " + tripCommandURL); + // + // DockerPort tripManagementQuery = + // docker.containers().container("tripmanagementquery").port(8080); + // tripQueryURL = String.format("http://%s:%s", + // tripManagementQuery.getIp(), + // tripManagementQuery.getExternalPort()); + // while (!docker.containers().container("tripmanagementquery") + // .portIsListeningOnHttp(8080, (port) -> + // port.inFormat(tripQueryURL)).succeeded()) { + // LOG.info("Waiting for Trip Query to respond over HTTP"); + // } + // LOG.info("Trip Query url found: " + tripQueryURL); + + DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); + gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); + while (!docker.containers().container("gmapsadapter") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { + LOG.info("Waiting for user service to respond over HTTP"); + } + LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); + + // DockerPort calculationService = + // docker.containers().container("calculationservice").port(8080); + // calculationServiceURL = String.format("http://%s:%s", + // calculationService.getIp(), + // calculationService.getExternalPort()); + // while (!docker.containers().container("calculationservice") + // .portIsListeningOnHttp(8080, (port) -> + // port.inFormat(calculationServiceURL)).succeeded()) { + // LOG.info("Waiting for calculation service to respond over HTTP"); + // } + // LOG.info("Calculation Service url found: " + calculationServiceURL); } private TestRestTemplate restTemplate = new TestRestTemplate(); @@ -205,165 +228,161 @@ public static void initialize() throws Exception { @Before public void setUp() throws JSONException, IOException { - String plainCreds = "front-end:front-end"; - byte[] plainCredsBytes = plainCreds.getBytes(); - byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); - String base64Creds = new String(base64CredsBytes); - - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Basic " + base64Creds); - headers.add("Content-Type", "application/x-www-form-urlencoded"); - - MultiValueMap parameters = new LinkedMultiValueMap<>(); - parameters.add("username", "front-end"); - parameters.add("secret", "front-end"); - String body = "grant_type=password&scope=webclient&username=passenger&password=password"; - HttpEntity request = new HttpEntity<>(body, headers); - - // when: - ResponseEntity response; - - ////////////////////////////////////////////// - - Runtime rt = Runtime.getRuntime(); - String[] commands = {"docker","ps"}; - Process proc = rt.exec(commands); - - BufferedReader stdInput = new BufferedReader(new - InputStreamReader(proc.getInputStream())); - - BufferedReader stdError = new BufferedReader(new - InputStreamReader(proc.getErrorStream())); - - // read the output from the command - System.out.println("Here is the standard output of the command:\n"); - String s = null; - while ((s = stdInput.readLine()) != null) { - System.out.println(s); - LOG.info(s); - } - - // read any errors from the attempted command - System.out.println("Here is the standard error of the command (if any):\n"); - while ((s = stdError.readLine()) != null) { - System.out.println(s); - LOG.info(s); - } - - ////////////////////////////////////////////// - - LOG.info(String.format("User Service - Trying url: %s", userServiceURL3)); - response = restTemplate.postForEntity(userServiceURL3 + "/auth/oauth/token", request, - String.class, parameters); - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); - JSONObject json = new JSONObject(response.getBody()); - token = json.getString("access_token"); + String plainCreds = "front-end:front-end"; + byte[] plainCredsBytes = plainCreds.getBytes(); + byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); + String base64Creds = new String(base64CredsBytes); + + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Basic " + base64Creds); + headers.add("Content-Type", "application/x-www-form-urlencoded"); + + MultiValueMap parameters = new LinkedMultiValueMap<>(); + parameters.add("username", "front-end"); + parameters.add("secret", "front-end"); + String body = "grant_type=password&scope=webclient&username=passenger&password=password"; + HttpEntity request = new HttpEntity<>(body, headers); + + // when: + ResponseEntity response; + + ////////////////////////////////////////////// + + Runtime rt = Runtime.getRuntime(); + String[] commands = { "docker", "inspect $(docker ps)" }; + Process proc = rt.exec(commands); + + BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); + + BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream())); + + // read the output from the command + System.out.println("Here is the standard output of the command:\n"); + String s = null; + while ((s = stdInput.readLine()) != null) { + System.out.println(s); + LOG.info(s); + } + + // read any errors from the attempted command + System.out.println("Here is the standard error of the command (if any):\n"); + while ((s = stdError.readLine()) != null) { + System.out.println(s); + LOG.info(s); + } + + ////////////////////////////////////////////// + + LOG.info(String.format("User Service - Trying url: %s", userServiceURL3)); + response = restTemplate.postForEntity(userServiceURL3 + "/auth/oauth/token", request, String.class, parameters); + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); + JSONObject json = new JSONObject(response.getBody()); + token = json.getString("access_token"); } @Test public void tripCommandPOSTRequestSuccess() { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); - String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " - + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; - HttpEntity request = new HttpEntity<>(body, headers); + String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " + + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; + HttpEntity request = new HttpEntity<>(body, headers); - // when: - ResponseEntity response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, - String.class); + // when: + ResponseEntity response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, + String.class); - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(201); + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(201); } @Test public void tripQueryGETSpecificTripRequestSuccess() throws JSONException, InterruptedException { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); - - String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " - + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; - HttpEntity request = new HttpEntity<>(body, headers); - ResponseEntity postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, - String.class); - - assertThat(postResponse.getStatusCodeValue()).isEqualTo(201); - - JSONObject json = new JSONObject(postResponse.getBody()); - String tripId = json.getString("id"); - - Thread.sleep(1000); - - // when: - ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trip/" + tripId, - String.class); - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); + + String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " + + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; + HttpEntity request = new HttpEntity<>(body, headers); + ResponseEntity postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, + String.class); + + assertThat(postResponse.getStatusCodeValue()).isEqualTo(201); + + JSONObject json = new JSONObject(postResponse.getBody()); + String tripId = json.getString("id"); + + Thread.sleep(1000); + + // when: + ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trip/" + tripId, + String.class); + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); } @Test public void tripQueryGETAllTripsRequestSuccess() { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); - // when: - ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class); + // when: + ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class); - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); } @Test public void calculationServiceRequestSuccess() { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); - String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\"," - + " \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; - HttpEntity request = new HttpEntity<>(body, headers); + String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\"," + + " \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; + HttpEntity request = new HttpEntity<>(body, headers); - // when: - ResponseEntity response = restTemplate.postForEntity(calculationServiceURL + "/api/v1/cost", request, - String.class); + // when: + ResponseEntity response = restTemplate.postForEntity(calculationServiceURL + "/api/v1/cost", request, + String.class); - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); } @Test public void gmapsAdapterRequestSuccess() throws Exception { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); - - String body = "{ \"origin\": \"2250 N Commerce Pkwy, Weston, FL 33326\", \"destination\": \"11200 SW 8th St, " - + "Miami, FL 33199\", \"departureTime\": \"15220998650000000\" }"; - HttpEntity request = new HttpEntity<>(body, headers); - - // when: - ResponseEntity response = restTemplate.postForEntity(gmapsAdapterURL + "/api/v1/directions", request, - String.class); - - if (response.getStatusCodeValue() != 200) { - throw new Exception( - String.format("Expected 200, actual %s\n%s", response.getStatusCode(), - response.getBody())); - } - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); + + String body = "{ \"origin\": \"2250 N Commerce Pkwy, Weston, FL 33326\", \"destination\": \"11200 SW 8th St, " + + "Miami, FL 33199\", \"departureTime\": \"15220998650000000\" }"; + HttpEntity request = new HttpEntity<>(body, headers); + + // when: + ResponseEntity response = restTemplate.postForEntity(gmapsAdapterURL + "/api/v1/directions", request, + String.class); + + if (response.getStatusCodeValue() != 200) { + throw new Exception( + String.format("Expected 200, actual %s\n%s", response.getStatusCode(), response.getBody())); + } + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); } } From e02f6f3cac19793f17420ad3aa80ce269eec34da Mon Sep 17 00:00:00 2001 From: jusoto Date: Wed, 12 Dec 2018 10:18:02 -0500 Subject: [PATCH 29/59] removed $ from docker inspect --- .../java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index dc71e38..b75e231 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -249,7 +249,7 @@ public void setUp() throws JSONException, IOException { ////////////////////////////////////////////// Runtime rt = Runtime.getRuntime(); - String[] commands = { "docker", "inspect $(docker ps)" }; + String[] commands = { "docker", "inspect", "(docker ps)" }; Process proc = rt.exec(commands); BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); From 3f37e3c279c0a2042cbbbcd67d3e4a10bc2cb2c1 Mon Sep 17 00:00:00 2001 From: jusoto Date: Wed, 12 Dec 2018 11:11:24 -0500 Subject: [PATCH 30/59] Added flag for docker inspect on test cases --- .../java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index b75e231..a650e21 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -249,7 +249,7 @@ public void setUp() throws JSONException, IOException { ////////////////////////////////////////////// Runtime rt = Runtime.getRuntime(); - String[] commands = { "docker", "inspect", "(docker ps)" }; + String[] commands = { "docker", "inspect", "(docker ps -q)" }; Process proc = rt.exec(commands); BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); From 26be5c08570fa6ac151c4bc7047c718d7808db7b Mon Sep 17 00:00:00 2001 From: jusoto Date: Wed, 12 Dec 2018 23:25:11 -0500 Subject: [PATCH 31/59] test cases - added log feature with details of running containers --- .../EdgeServiceIntegrationTests.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index a650e21..b2e0709 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -5,7 +5,9 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.util.ArrayList; import java.util.Base64; +import java.util.List; import org.json.JSONException; import org.json.JSONObject; @@ -248,8 +250,10 @@ public void setUp() throws JSONException, IOException { ////////////////////////////////////////////// + List containerList = new ArrayList(); Runtime rt = Runtime.getRuntime(); - String[] commands = { "docker", "inspect", "(docker ps -q)" }; + + String[] commands = { "docker", "ps", "-q" }; Process proc = rt.exec(commands); BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); @@ -260,6 +264,7 @@ public void setUp() throws JSONException, IOException { System.out.println("Here is the standard output of the command:\n"); String s = null; while ((s = stdInput.readLine()) != null) { + containerList.add(s); System.out.println(s); LOG.info(s); } @@ -271,6 +276,30 @@ public void setUp() throws JSONException, IOException { LOG.info(s); } + for (String containerId : containerList) { + + String[] commands1 = { "docker", "inspect", containerId }; + Process proc1 = rt.exec(commands1); + + BufferedReader stdInput1 = new BufferedReader(new InputStreamReader(proc1.getInputStream())); + + BufferedReader stdError1 = new BufferedReader(new InputStreamReader(proc1.getErrorStream())); + + // read the output from the command + System.out.println("Here is the standard output of the command:\n"); + String s1 = null; + while ((s1 = stdInput1.readLine()) != null) { + System.out.println(s1); + LOG.info(s1); + } + + // read any errors from the attempted command + System.out.println("Here is the standard error of the command (if any):\n"); + while ((s1 = stdError1.readLine()) != null) { + System.out.println(s1); + LOG.info(s1); + } + } ////////////////////////////////////////////// LOG.info(String.format("User Service - Trying url: %s", userServiceURL3)); From cac6b5013c8ac19d54ca7d1ba1e3a4fd5e9c7612 Mon Sep 17 00:00:00 2001 From: jusoto Date: Thu, 13 Dec 2018 23:11:31 -0500 Subject: [PATCH 32/59] Tests: Added ip address 0.0.0.0 to communicate with containers --- .../EdgeServiceIntegrationTests.java | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index b2e0709..6fdf2bb 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -92,7 +92,7 @@ public static void initialize() throws Exception { userServiceURL = String.format("http://%s:%s", userContainer.getContainerName(), userPort.getInternalPort()); userServiceURL1 = String.format("http://%s:%s", userContainer.getContainerName(), userPort.getExternalPort()); userServiceURL2 = String.format("http://%s:%s", userPort.getIp(), userPort.getInternalPort()); - userServiceURL3 = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); + userServiceURL3 = String.format("http://0.0.0.0:%s", userPort.getExternalPort()); if (!userPort.isListeningNow()) { LOG.info("User service didn't respond over HTTP"); throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); @@ -250,56 +250,56 @@ public void setUp() throws JSONException, IOException { ////////////////////////////////////////////// - List containerList = new ArrayList(); - Runtime rt = Runtime.getRuntime(); - - String[] commands = { "docker", "ps", "-q" }; - Process proc = rt.exec(commands); - - BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); - - BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream())); - - // read the output from the command - System.out.println("Here is the standard output of the command:\n"); - String s = null; - while ((s = stdInput.readLine()) != null) { - containerList.add(s); - System.out.println(s); - LOG.info(s); - } - - // read any errors from the attempted command - System.out.println("Here is the standard error of the command (if any):\n"); - while ((s = stdError.readLine()) != null) { - System.out.println(s); - LOG.info(s); - } - - for (String containerId : containerList) { - - String[] commands1 = { "docker", "inspect", containerId }; - Process proc1 = rt.exec(commands1); - - BufferedReader stdInput1 = new BufferedReader(new InputStreamReader(proc1.getInputStream())); - - BufferedReader stdError1 = new BufferedReader(new InputStreamReader(proc1.getErrorStream())); - - // read the output from the command - System.out.println("Here is the standard output of the command:\n"); - String s1 = null; - while ((s1 = stdInput1.readLine()) != null) { - System.out.println(s1); - LOG.info(s1); - } - - // read any errors from the attempted command - System.out.println("Here is the standard error of the command (if any):\n"); - while ((s1 = stdError1.readLine()) != null) { - System.out.println(s1); - LOG.info(s1); - } - } +// List containerList = new ArrayList(); +// Runtime rt = Runtime.getRuntime(); +// +// String[] commands = { "docker", "ps", "-q" }; +// Process proc = rt.exec(commands); +// +// BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); +// +// BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream())); +// +// // read the output from the command +// System.out.println("Here is the standard output of the command:\n"); +// String s = null; +// while ((s = stdInput.readLine()) != null) { +// containerList.add(s); +// System.out.println(s); +// LOG.info(s); +// } +// +// // read any errors from the attempted command +// System.out.println("Here is the standard error of the command (if any):\n"); +// while ((s = stdError.readLine()) != null) { +// System.out.println(s); +// LOG.info(s); +// } +// +// for (String containerId : containerList) { +// +// String[] commands1 = { "docker", "inspect", containerId }; +// Process proc1 = rt.exec(commands1); +// +// BufferedReader stdInput1 = new BufferedReader(new InputStreamReader(proc1.getInputStream())); +// +// BufferedReader stdError1 = new BufferedReader(new InputStreamReader(proc1.getErrorStream())); +// +// // read the output from the command +// System.out.println("Here is the standard output of the command:\n"); +// String s1 = null; +// while ((s1 = stdInput1.readLine()) != null) { +// System.out.println(s1); +// LOG.info(s1); +// } +// +// // read any errors from the attempted command +// System.out.println("Here is the standard error of the command (if any):\n"); +// while ((s1 = stdError1.readLine()) != null) { +// System.out.println(s1); +// LOG.info(s1); +// } +// } ////////////////////////////////////////////// LOG.info(String.format("User Service - Trying url: %s", userServiceURL3)); From 7c56a8c59f53140e990a4f15f614e26db9572e15 Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 14 Dec 2018 08:22:34 -0500 Subject: [PATCH 33/59] Tests: retrieve information about docker environment --- .../EdgeServiceIntegrationTests.java | 74 ++++++++++++------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 6fdf2bb..973333a 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -250,31 +250,55 @@ public void setUp() throws JSONException, IOException { ////////////////////////////////////////////// -// List containerList = new ArrayList(); -// Runtime rt = Runtime.getRuntime(); -// -// String[] commands = { "docker", "ps", "-q" }; -// Process proc = rt.exec(commands); -// -// BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); -// -// BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream())); -// -// // read the output from the command -// System.out.println("Here is the standard output of the command:\n"); -// String s = null; -// while ((s = stdInput.readLine()) != null) { -// containerList.add(s); -// System.out.println(s); -// LOG.info(s); -// } -// -// // read any errors from the attempted command -// System.out.println("Here is the standard error of the command (if any):\n"); -// while ((s = stdError.readLine()) != null) { -// System.out.println(s); -// LOG.info(s); -// } + List containerList = new ArrayList(); + Runtime rt = Runtime.getRuntime(); + + String[] commands = { "docker-machine", "env" }; + Process proc = rt.exec(commands); + + BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); + + BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream())); + + // read the output from the command + System.out.println("Here is the standard output of the command:\n"); + String s = null; + while ((s = stdInput.readLine()) != null) { + containerList.add(s); + System.out.println(s); + LOG.info(s); + } + + // read any errors from the attempted command + System.out.println("Here is the standard error of the command (if any):\n"); + while ((s = stdError.readLine()) != null) { + System.out.println(s); + LOG.info(s); + } + + + String[] commands1 = { "docker", "info" }; + Process proc1 = rt.exec(commands1); + + BufferedReader stdInput1 = new BufferedReader(new InputStreamReader(proc1.getInputStream())); + + BufferedReader stdError1 = new BufferedReader(new InputStreamReader(proc1.getErrorStream())); + + // read the output from the command + System.out.println("Here is the standard output of the command:\n"); + String s1 = null; + while ((s1 = stdInput1.readLine()) != null) { + //containerList.add(s); + System.out.println(s1); + LOG.info(s1); + } + + // read any errors from the attempted command + System.out.println("Here is the standard error of the command (if any):\n"); + while ((s1 = stdError1.readLine()) != null) { + System.out.println(s1); + LOG.info(s1); + } // // for (String containerId : containerList) { // From c10cac559d3cdb4750be844c1a5010418b13b30e Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 14 Dec 2018 08:54:02 -0500 Subject: [PATCH 34/59] Tests: Removed container named URLs --- .../EdgeServiceIntegrationTests.java | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 973333a..cbca476 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -40,8 +40,6 @@ public class EdgeServiceIntegrationTests { // private static String discoveryServiceURL; private static String mongoURL; private static String userServiceURL; - private static String userServiceURL1; - private static String userServiceURL2; private static String userServiceURL3; private static String tripCommandURL; private static String tripQueryURL; @@ -89,10 +87,7 @@ public static void initialize() throws Exception { // Container userContainer = docker.containers().container("userservice"); DockerPort userPort = userContainer.port(8080); - userServiceURL = String.format("http://%s:%s", userContainer.getContainerName(), userPort.getInternalPort()); - userServiceURL1 = String.format("http://%s:%s", userContainer.getContainerName(), userPort.getExternalPort()); - userServiceURL2 = String.format("http://%s:%s", userPort.getIp(), userPort.getInternalPort()); - userServiceURL3 = String.format("http://0.0.0.0:%s", userPort.getExternalPort()); + userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); if (!userPort.isListeningNow()) { LOG.info("User service didn't respond over HTTP"); throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); @@ -250,7 +245,7 @@ public void setUp() throws JSONException, IOException { ////////////////////////////////////////////// - List containerList = new ArrayList(); + //List containerList = new ArrayList(); Runtime rt = Runtime.getRuntime(); String[] commands = { "docker-machine", "env" }; @@ -261,16 +256,16 @@ public void setUp() throws JSONException, IOException { BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream())); // read the output from the command - System.out.println("Here is the standard output of the command:\n"); + System.out.println("***************** Here is the standard output of the command:\n"); String s = null; while ((s = stdInput.readLine()) != null) { - containerList.add(s); + // containerList.add(s); System.out.println(s); LOG.info(s); } // read any errors from the attempted command - System.out.println("Here is the standard error of the command (if any):\n"); + System.out.println("***************** Here is the standard error of the command (if any):\n"); while ((s = stdError.readLine()) != null) { System.out.println(s); LOG.info(s); @@ -285,7 +280,7 @@ public void setUp() throws JSONException, IOException { BufferedReader stdError1 = new BufferedReader(new InputStreamReader(proc1.getErrorStream())); // read the output from the command - System.out.println("Here is the standard output of the command:\n"); + System.out.println("***************** Here is the standard output of the command:\n"); String s1 = null; while ((s1 = stdInput1.readLine()) != null) { //containerList.add(s); @@ -294,7 +289,7 @@ public void setUp() throws JSONException, IOException { } // read any errors from the attempted command - System.out.println("Here is the standard error of the command (if any):\n"); + System.out.println("***************** Here is the standard error of the command (if any):\n"); while ((s1 = stdError1.readLine()) != null) { System.out.println(s1); LOG.info(s1); @@ -326,8 +321,8 @@ public void setUp() throws JSONException, IOException { // } ////////////////////////////////////////////// - LOG.info(String.format("User Service - Trying url: %s", userServiceURL3)); - response = restTemplate.postForEntity(userServiceURL3 + "/auth/oauth/token", request, String.class, parameters); + LOG.info(String.format("User Service - Trying url: %s", userServiceURL)); + response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, String.class, parameters); // then: assertThat(response.getStatusCodeValue()).isEqualTo(200); From 7b48a60a472f82ba44944daea49b1ded44127843 Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 14 Dec 2018 09:26:22 -0500 Subject: [PATCH 35/59] Tests: fixed style issues. Travis: removed env variables --- .travis.yml | 6 - .../EdgeServiceIntegrationTests.java | 660 +++++++++--------- 2 files changed, 330 insertions(+), 336 deletions(-) diff --git a/.travis.yml b/.travis.yml index 30f2ac5..e79fa71 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,12 +11,6 @@ script: - travis_wait 5 ./gradlew check -i env: global: - - EUREKA_SERVER="localhost" - - TRIP_CMD_HOST="localhost" - - TRIP_QUERY_HOST="localhost" - - USER_SERVICE_HOST="localhost" - - RABBIT_HOST="localhost" - - MONGO_HOST="localhost" - secure: WF5U05+p8xQRBhT75aviCl9sXpnzER52xJDkKaZPtsak3B/21rj5FGQ4TTu9ivh0oF56ws8Zy8hzNZhjS09QimqtpD+Zl5m5er4Q2GvrStVDM0k38wqye2IBf7juKIlkfntX1o1E9/xGkUgIW5eQpUt7TDGpon5FCvY8NHqDyVi+ZDU7hGQh8E3oyK+8Dly1ETLxVhoDEY3vG1VyEZ1IDrgAw/N6KlNIyiuWjPMBLTFAjGMzJAaf/MQiKfmB3HUBUtGqEdhobppEqriJkXl/6ov+Np+vh83dIBaOfRUpB1KgvGmefmtL7rb+mIIXOLMm9cpyqmK+6h1JeQrwB3xtWtIIXmmL2VEwmO/2YfTDyu+JpRkkgwDMLgyRKN9wEtaR+4C3X/p9zMysocDhyccOeGVq7XhJwgdosoJ0VRLVtUhPq1T10B/ipp2g8VF9TW1uIfSQJe6YYCrVK+fqtkWG5yuOfqQdGHNZkRJMpeTyzkJQzX7GZb8G0H8EZCsjdJ0FdEpshWcCB2ljozwH3fFMqnzE1thibpg7dC2BXF7aRGjmn/4vqme98i4hP+590FIMF+sdyDItVq7/91EAwh7m35dvszkFruIzLgHFRnrKAgG76bTHTz8bwywhnCZVbDmy/HEDOjj2ykW9jPKJ7buKRKVYbXnSgYqkn/keTHiRvLI= - secure: KlDa/wnlEEvkH4tnxTtxdWdBHJl8Kuv8tWknqxKL1rWcvo8UXNWXeBtvAB5v7eiCSJLwOqLm9Cl4OVwnZjU3oi4ymECYY296bQRFGS01DDYeExFd/VycDvV2L9FRP+71qZt2k2/DBabheI2WNLXESyAG1oJcI7IYyiDQBoA7hz72dYjQ5T8NISab8KGLCq02mvh3n+rtchgOPtbxU2wGqse+3lzui4m9/qAC+3tZJNXx7l+hzNSh1zqIhjIrzXrPs0PneCLdfTl1lZhSO2DCBo9juz2bisSdOdOWt7hssb7noOByfU9z1O2QVUfWJfUTjVwToxFaP94JeUo6rDo3gRo2WJn313f8ZtgtzQkPYrV8bTTRZ8mhb7D2Eq/2RllBRXJRdQuOv1t7mSr+hdD/mJUyHQY6yvK3YFAKkgK60aUAGMhBE2GBVFzx7qU06OBwdHJ2YBiKSC/+9sGFVhR6zIQxVPV4fdyaLLL4CEJC1vvTmHYZj1hqSZsWhuqddxQNj0RKIsfN8akW/Gi4mv2q32eCwG6XhXIKqLGVGuyHKx1N3gCjBK3Whz5QX/u8ADq7euB+mgyC/wILrzb281VARQkuu5FwUutv0x+y4S/061VZATwhY+ree728mjSxHu5qtoyI3xH6OjWDtmp+zyZOdrF2D+/ReiIRd4vkShme7sI= before_install: diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index cbca476..588d0e7 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -49,174 +49,174 @@ public class EdgeServiceIntegrationTests { // Wait for all services to have ports open @ClassRule public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) - .file("src/test/resources/docker-compose.yml") - .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()).build(); + .file("src/test/resources/docker-compose.yml") + .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()).build(); // Get IP addresses and ports to run tests on @BeforeClass public static void initialize() throws Exception { - LOG.info("Initializing ports from Docker"); - - Container discoveryContainer = docker.containers().container("discoveryservice"); - DockerPort discoveryPort = discoveryContainer.port(8761); - if (!discoveryPort.isListeningNow()) { - LOG.info("Discovery service didn't respond over HTTP"); - throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); - } - LOG.info("Discovery service responded over HTTP"); - - // Container mongoContainer = docker.containers().container("mongo"); - // DockerPort mongoPort = mongoContainer.port(27017); - // mongoURL = String.format("http://%s:%s", mongoPort.getIp(), - // mongoPort.getExternalPort()); - // if(!mongoPort.isListeningNow()){ - // LOG.info("Mongo service didn't respond over HTTP"); - // throw new Exception(String.format("Mongo didn't respond, port: %s", - // mongoPort.getInternalPort())); - // } - // LOG.info("Mongo service responded over HTTP"); - // - Container userContainer = docker.containers().container("userservice"); - DockerPort userPort = userContainer.port(8080); - userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); - if (!userPort.isListeningNow()) { - LOG.info("User service didn't respond over HTTP"); - throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); - } - LOG.info("User service responded over HTTP"); - LOG.info(String.format("User Service docker-name: %s - IP: %s - Int Port: %s - Ext Port: %s", - userContainer.getContainerName(), userPort.getIp(), userPort.getInternalPort(), - userPort.getExternalPort())); - - Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); - DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); - tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), - tripManagementCmdPort.getExternalPort()); - if (!tripManagementCmdPort.isListeningNow()) { - LOG.info("TripManagementCmd service didn't respond over HTTP"); - throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", - tripManagementCmdPort.getInternalPort())); - } - LOG.info("TripManagementCmd service responded over HTTP"); - - Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); - DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); - tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), - tripManagementQueryPort.getExternalPort()); - if (!tripManagementQueryPort.isListeningNow()) { - LOG.info("TripManagementQuery service didn't respond over HTTP"); - throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", - tripManagementQueryPort.getInternalPort())); - } - LOG.info("TripManagementQuery service responded over HTTP"); - // - // Container gmapsAdapterContainer = - // docker.containers().container("gmapsadapter"); - // DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); - // gmapsAdapterURL = String.format("http://%s:%s", - // gmapsAdapterPort.getIp(), - // gmapsAdapterPort.getExternalPort()); - // if(!gmapsAdapterPort.isListeningNow()){ - // LOG.info("Gmaps Adapter service didn't respond over HTTP"); - // throw new Exception(String.format("Gmaps Adapter didn't respond, - // port: %s", gmapsAdapterPort.getInternalPort())); - // } - // LOG.info("Gmaps Adapter service responded over HTTP"); - // - Container calculationContainer = docker.containers().container("calculationservice"); - DockerPort calculationPort = calculationContainer.port(8080); - calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), - calculationPort.getExternalPort()); - if (!calculationPort.isListeningNow()) { - LOG.info("Calculation service didn't respond over HTTP"); - throw new Exception( - String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); - } - LOG.info("Calculation service responded over HTTP"); - // - // DockerPort discoveryService = - // docker.containers().container("discoveryservice").port(8761); - // discoveryServiceURL = String.format("http://%s:%s", - // discoveryService.getIp(), - // discoveryService.getExternalPort()); - // while (!docker.containers().container("discoveryservice") - // .portIsListeningOnHttp(8761, (port) -> - // port.inFormat(discoveryServiceURL)).succeeded()) { - // LOG.info("Waiting for discovery service to respond over HTTP"); - // } - // LOG.info("Discovery Service url found: " + discoveryServiceURL); - - DockerPort mongo = docker.containers().container("mongo").port(27017); - mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); - while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) - .succeeded()) { - LOG.info("Waiting for mongo to respond over HTTP"); - } - LOG.info("Mongo url found: " + mongoURL); - - // DockerPort userService = - // docker.containers().container("userservice").port(8080); - // userServiceURL = String.format("http://%s:%s", userService.getIp(), - // userService.getExternalPort()); - // while (!docker.containers().container("userservice") - // .portIsListeningOnHttp(8080, (port) -> - // port.inFormat(userServiceURL)).succeeded()) { - // LOG.info("Waiting for user service to respond over HTTP"); - // } - // LOG.info("User Service url found: " + userServiceURL); - - // DockerPort tripManagementCommand = - // docker.containers().container("tripmanagementcmd").port(8080); - // tripCommandURL = String.format("http://%s:%s", - // tripManagementCommand.getIp(), - // tripManagementCommand.getExternalPort()); - // while (!docker.containers().container("tripmanagementcmd") - // .portIsListeningOnHttp(8080, (port) -> - // port.inFormat(tripCommandURL)).succeeded()) { - // LOG.info("Waiting for Trip Command to respond over HTTP"); - // } - // LOG.info("Trip Command url found: " + tripCommandURL); - // - // DockerPort tripManagementQuery = - // docker.containers().container("tripmanagementquery").port(8080); - // tripQueryURL = String.format("http://%s:%s", - // tripManagementQuery.getIp(), - // tripManagementQuery.getExternalPort()); - // while (!docker.containers().container("tripmanagementquery") - // .portIsListeningOnHttp(8080, (port) -> - // port.inFormat(tripQueryURL)).succeeded()) { - // LOG.info("Waiting for Trip Query to respond over HTTP"); - // } - // LOG.info("Trip Query url found: " + tripQueryURL); - - DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); - gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); - while (!docker.containers().container("gmapsadapter") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { - LOG.info("Waiting for user service to respond over HTTP"); - } - LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); - - // DockerPort calculationService = - // docker.containers().container("calculationservice").port(8080); - // calculationServiceURL = String.format("http://%s:%s", - // calculationService.getIp(), - // calculationService.getExternalPort()); - // while (!docker.containers().container("calculationservice") - // .portIsListeningOnHttp(8080, (port) -> - // port.inFormat(calculationServiceURL)).succeeded()) { - // LOG.info("Waiting for calculation service to respond over HTTP"); - // } - // LOG.info("Calculation Service url found: " + calculationServiceURL); + LOG.info("Initializing ports from Docker"); + + Container discoveryContainer = docker.containers().container("discoveryservice"); + DockerPort discoveryPort = discoveryContainer.port(8761); + if (!discoveryPort.isListeningNow()) { + LOG.info("Discovery service didn't respond over HTTP"); + throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); + } + LOG.info("Discovery service responded over HTTP"); + + // Container mongoContainer = docker.containers().container("mongo"); + // DockerPort mongoPort = mongoContainer.port(27017); + // mongoURL = String.format("http://%s:%s", mongoPort.getIp(), + // mongoPort.getExternalPort()); + // if(!mongoPort.isListeningNow()){ + // LOG.info("Mongo service didn't respond over HTTP"); + // throw new Exception(String.format("Mongo didn't respond, port: %s", + // mongoPort.getInternalPort())); + // } + // LOG.info("Mongo service responded over HTTP"); + // + Container userContainer = docker.containers().container("userservice"); + DockerPort userPort = userContainer.port(8080); + userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); + if (!userPort.isListeningNow()) { + LOG.info("User service didn't respond over HTTP"); + throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); + } + LOG.info("User service responded over HTTP"); + LOG.info(String.format("User Service docker-name: %s - IP: %s - Int Port: %s - Ext Port: %s", + userContainer.getContainerName(), userPort.getIp(), userPort.getInternalPort(), + userPort.getExternalPort())); + + Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); + DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); + tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), + tripManagementCmdPort.getExternalPort()); + if (!tripManagementCmdPort.isListeningNow()) { + LOG.info("TripManagementCmd service didn't respond over HTTP"); + throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", + tripManagementCmdPort.getInternalPort())); + } + LOG.info("TripManagementCmd service responded over HTTP"); + + Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); + DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); + tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), + tripManagementQueryPort.getExternalPort()); + if (!tripManagementQueryPort.isListeningNow()) { + LOG.info("TripManagementQuery service didn't respond over HTTP"); + throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", + tripManagementQueryPort.getInternalPort())); + } + LOG.info("TripManagementQuery service responded over HTTP"); + // + // Container gmapsAdapterContainer = + // docker.containers().container("gmapsadapter"); + // DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); + // gmapsAdapterURL = String.format("http://%s:%s", + // gmapsAdapterPort.getIp(), + // gmapsAdapterPort.getExternalPort()); + // if(!gmapsAdapterPort.isListeningNow()){ + // LOG.info("Gmaps Adapter service didn't respond over HTTP"); + // throw new Exception(String.format("Gmaps Adapter didn't respond, + // port: %s", gmapsAdapterPort.getInternalPort())); + // } + // LOG.info("Gmaps Adapter service responded over HTTP"); + // + Container calculationContainer = docker.containers().container("calculationservice"); + DockerPort calculationPort = calculationContainer.port(8080); + calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), + calculationPort.getExternalPort()); + if (!calculationPort.isListeningNow()) { + LOG.info("Calculation service didn't respond over HTTP"); + throw new Exception( + String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); + } + LOG.info("Calculation service responded over HTTP"); + // + // DockerPort discoveryService = + // docker.containers().container("discoveryservice").port(8761); + // discoveryServiceURL = String.format("http://%s:%s", + // discoveryService.getIp(), + // discoveryService.getExternalPort()); + // while (!docker.containers().container("discoveryservice") + // .portIsListeningOnHttp(8761, (port) -> + // port.inFormat(discoveryServiceURL)).succeeded()) { + // LOG.info("Waiting for discovery service to respond over HTTP"); + // } + // LOG.info("Discovery Service url found: " + discoveryServiceURL); + + DockerPort mongo = docker.containers().container("mongo").port(27017); + mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); + while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) + .succeeded()) { + LOG.info("Waiting for mongo to respond over HTTP"); + } + LOG.info("Mongo url found: " + mongoURL); + + // DockerPort userService = + // docker.containers().container("userservice").port(8080); + // userServiceURL = String.format("http://%s:%s", userService.getIp(), + // userService.getExternalPort()); + // while (!docker.containers().container("userservice") + // .portIsListeningOnHttp(8080, (port) -> + // port.inFormat(userServiceURL)).succeeded()) { + // LOG.info("Waiting for user service to respond over HTTP"); + // } + // LOG.info("User Service url found: " + userServiceURL); + + // DockerPort tripManagementCommand = + // docker.containers().container("tripmanagementcmd").port(8080); + // tripCommandURL = String.format("http://%s:%s", + // tripManagementCommand.getIp(), + // tripManagementCommand.getExternalPort()); + // while (!docker.containers().container("tripmanagementcmd") + // .portIsListeningOnHttp(8080, (port) -> + // port.inFormat(tripCommandURL)).succeeded()) { + // LOG.info("Waiting for Trip Command to respond over HTTP"); + // } + // LOG.info("Trip Command url found: " + tripCommandURL); + // + // DockerPort tripManagementQuery = + // docker.containers().container("tripmanagementquery").port(8080); + // tripQueryURL = String.format("http://%s:%s", + // tripManagementQuery.getIp(), + // tripManagementQuery.getExternalPort()); + // while (!docker.containers().container("tripmanagementquery") + // .portIsListeningOnHttp(8080, (port) -> + // port.inFormat(tripQueryURL)).succeeded()) { + // LOG.info("Waiting for Trip Query to respond over HTTP"); + // } + // LOG.info("Trip Query url found: " + tripQueryURL); + + DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); + gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); + while (!docker.containers().container("gmapsadapter") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { + LOG.info("Waiting for user service to respond over HTTP"); + } + LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); + + // DockerPort calculationService = + // docker.containers().container("calculationservice").port(8080); + // calculationServiceURL = String.format("http://%s:%s", + // calculationService.getIp(), + // calculationService.getExternalPort()); + // while (!docker.containers().container("calculationservice") + // .portIsListeningOnHttp(8080, (port) -> + // port.inFormat(calculationServiceURL)).succeeded()) { + // LOG.info("Waiting for calculation service to respond over HTTP"); + // } + // LOG.info("Calculation Service url found: " + calculationServiceURL); } private TestRestTemplate restTemplate = new TestRestTemplate(); @@ -225,212 +225,212 @@ public static void initialize() throws Exception { @Before public void setUp() throws JSONException, IOException { - String plainCreds = "front-end:front-end"; - byte[] plainCredsBytes = plainCreds.getBytes(); - byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); - String base64Creds = new String(base64CredsBytes); - - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Basic " + base64Creds); - headers.add("Content-Type", "application/x-www-form-urlencoded"); - - MultiValueMap parameters = new LinkedMultiValueMap<>(); - parameters.add("username", "front-end"); - parameters.add("secret", "front-end"); - String body = "grant_type=password&scope=webclient&username=passenger&password=password"; - HttpEntity request = new HttpEntity<>(body, headers); - - // when: - ResponseEntity response; - - ////////////////////////////////////////////// - - //List containerList = new ArrayList(); - Runtime rt = Runtime.getRuntime(); - - String[] commands = { "docker-machine", "env" }; - Process proc = rt.exec(commands); - - BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); - - BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream())); - - // read the output from the command - System.out.println("***************** Here is the standard output of the command:\n"); - String s = null; - while ((s = stdInput.readLine()) != null) { - // containerList.add(s); - System.out.println(s); - LOG.info(s); - } - - // read any errors from the attempted command - System.out.println("***************** Here is the standard error of the command (if any):\n"); - while ((s = stdError.readLine()) != null) { - System.out.println(s); - LOG.info(s); - } - - - String[] commands1 = { "docker", "info" }; - Process proc1 = rt.exec(commands1); - - BufferedReader stdInput1 = new BufferedReader(new InputStreamReader(proc1.getInputStream())); - - BufferedReader stdError1 = new BufferedReader(new InputStreamReader(proc1.getErrorStream())); - - // read the output from the command - System.out.println("***************** Here is the standard output of the command:\n"); - String s1 = null; - while ((s1 = stdInput1.readLine()) != null) { - //containerList.add(s); - System.out.println(s1); - LOG.info(s1); - } - - // read any errors from the attempted command - System.out.println("***************** Here is the standard error of the command (if any):\n"); - while ((s1 = stdError1.readLine()) != null) { - System.out.println(s1); - LOG.info(s1); - } + String plainCreds = "front-end:front-end"; + byte[] plainCredsBytes = plainCreds.getBytes(); + byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); + String base64Creds = new String(base64CredsBytes); + + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Basic " + base64Creds); + headers.add("Content-Type", "application/x-www-form-urlencoded"); + + MultiValueMap parameters = new LinkedMultiValueMap<>(); + parameters.add("username", "front-end"); + parameters.add("secret", "front-end"); + String body = "grant_type=password&scope=webclient&username=passenger&password=password"; + HttpEntity request = new HttpEntity<>(body, headers); + + // when: + ResponseEntity response; + + ////////////////////////////////////////////// + + //List containerList = new ArrayList(); + Runtime rt = Runtime.getRuntime(); + + String[] commands = { "docker-machine", "env" }; + Process proc = rt.exec(commands); + + BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); + + BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream())); + + // read the output from the command + System.out.println("***************** Here is the standard output of the command:\n"); + String s = null; + while ((s = stdInput.readLine()) != null) { + // containerList.add(s); + System.out.println(s); + LOG.info(s); + } + + // read any errors from the attempted command + System.out.println("***************** Here is the standard error of the command (if any):\n"); + while ((s = stdError.readLine()) != null) { + System.out.println(s); + LOG.info(s); + } + + + String[] commands1 = { "docker", "info" }; + Process proc1 = rt.exec(commands1); + + BufferedReader stdInput1 = new BufferedReader(new InputStreamReader(proc1.getInputStream())); + + BufferedReader stdError1 = new BufferedReader(new InputStreamReader(proc1.getErrorStream())); + + // read the output from the command + System.out.println("***************** Here is the standard output of the command:\n"); + String s1 = null; + while ((s1 = stdInput1.readLine()) != null) { + //containerList.add(s); + System.out.println(s1); + LOG.info(s1); + } + + // read any errors from the attempted command + System.out.println("***************** Here is the standard error of the command (if any):\n"); + while ((s1 = stdError1.readLine()) != null) { + System.out.println(s1); + LOG.info(s1); + } // -// for (String containerId : containerList) { +// for (String containerId : containerList) { // -// String[] commands1 = { "docker", "inspect", containerId }; -// Process proc1 = rt.exec(commands1); +// String[] commands1 = { "docker", "inspect", containerId }; +// Process proc1 = rt.exec(commands1); // -// BufferedReader stdInput1 = new BufferedReader(new InputStreamReader(proc1.getInputStream())); +// BufferedReader stdInput1 = new BufferedReader(new InputStreamReader(proc1.getInputStream())); // -// BufferedReader stdError1 = new BufferedReader(new InputStreamReader(proc1.getErrorStream())); +// BufferedReader stdError1 = new BufferedReader(new InputStreamReader(proc1.getErrorStream())); // -// // read the output from the command -// System.out.println("Here is the standard output of the command:\n"); -// String s1 = null; -// while ((s1 = stdInput1.readLine()) != null) { -// System.out.println(s1); -// LOG.info(s1); -// } +// // read the output from the command +// System.out.println("Here is the standard output of the command:\n"); +// String s1 = null; +// while ((s1 = stdInput1.readLine()) != null) { +// System.out.println(s1); +// LOG.info(s1); +// } // -// // read any errors from the attempted command -// System.out.println("Here is the standard error of the command (if any):\n"); -// while ((s1 = stdError1.readLine()) != null) { -// System.out.println(s1); -// LOG.info(s1); -// } -// } - ////////////////////////////////////////////// - - LOG.info(String.format("User Service - Trying url: %s", userServiceURL)); - response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, String.class, parameters); - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); - JSONObject json = new JSONObject(response.getBody()); - token = json.getString("access_token"); +// // read any errors from the attempted command +// System.out.println("Here is the standard error of the command (if any):\n"); +// while ((s1 = stdError1.readLine()) != null) { +// System.out.println(s1); +// LOG.info(s1); +// } +// } + ////////////////////////////////////////////// + + LOG.info(String.format("User Service - Trying url: %s", userServiceURL)); + response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, String.class, parameters); + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); + JSONObject json = new JSONObject(response.getBody()); + token = json.getString("access_token"); } @Test public void tripCommandPOSTRequestSuccess() { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); - String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " - + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; - HttpEntity request = new HttpEntity<>(body, headers); + String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " + + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; + HttpEntity request = new HttpEntity<>(body, headers); - // when: - ResponseEntity response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, - String.class); + // when: + ResponseEntity response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, + String.class); - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(201); + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(201); } @Test public void tripQueryGETSpecificTripRequestSuccess() throws JSONException, InterruptedException { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); - String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " - + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; - HttpEntity request = new HttpEntity<>(body, headers); - ResponseEntity postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, - String.class); + String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " + + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; + HttpEntity request = new HttpEntity<>(body, headers); + ResponseEntity postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, + String.class); - assertThat(postResponse.getStatusCodeValue()).isEqualTo(201); + assertThat(postResponse.getStatusCodeValue()).isEqualTo(201); - JSONObject json = new JSONObject(postResponse.getBody()); - String tripId = json.getString("id"); + JSONObject json = new JSONObject(postResponse.getBody()); + String tripId = json.getString("id"); - Thread.sleep(1000); + Thread.sleep(1000); - // when: - ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trip/" + tripId, - String.class); + // when: + ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trip/" + tripId, + String.class); - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); } @Test public void tripQueryGETAllTripsRequestSuccess() { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); - // when: - ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class); + // when: + ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class); - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); } @Test public void calculationServiceRequestSuccess() { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); - String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\"," - + " \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; - HttpEntity request = new HttpEntity<>(body, headers); + String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\"," + + " \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; + HttpEntity request = new HttpEntity<>(body, headers); - // when: - ResponseEntity response = restTemplate.postForEntity(calculationServiceURL + "/api/v1/cost", request, - String.class); + // when: + ResponseEntity response = restTemplate.postForEntity(calculationServiceURL + "/api/v1/cost", request, + String.class); - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); } @Test public void gmapsAdapterRequestSuccess() throws Exception { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); - - String body = "{ \"origin\": \"2250 N Commerce Pkwy, Weston, FL 33326\", \"destination\": \"11200 SW 8th St, " - + "Miami, FL 33199\", \"departureTime\": \"15220998650000000\" }"; - HttpEntity request = new HttpEntity<>(body, headers); - - // when: - ResponseEntity response = restTemplate.postForEntity(gmapsAdapterURL + "/api/v1/directions", request, - String.class); - - if (response.getStatusCodeValue() != 200) { - throw new Exception( - String.format("Expected 200, actual %s\n%s", response.getStatusCode(), response.getBody())); - } - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); + + String body = "{ \"origin\": \"2250 N Commerce Pkwy, Weston, FL 33326\", \"destination\": \"11200 SW 8th St, " + + "Miami, FL 33199\", \"departureTime\": \"15220998650000000\" }"; + HttpEntity request = new HttpEntity<>(body, headers); + + // when: + ResponseEntity response = restTemplate.postForEntity(gmapsAdapterURL + "/api/v1/directions", request, + String.class); + + if (response.getStatusCodeValue() != 200) { + throw new Exception( + String.format("Expected 200, actual %s\n%s", response.getStatusCode(), response.getBody())); + } + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); } } From 8253287e3689beb891e241cf04703c0092958541 Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 14 Dec 2018 10:04:12 -0500 Subject: [PATCH 36/59] Tests: added docker info command to log --- .../EdgeServiceIntegrationTests.java | 26 +------------------ 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 588d0e7..66332f7 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -248,7 +248,7 @@ public void setUp() throws JSONException, IOException { //List containerList = new ArrayList(); Runtime rt = Runtime.getRuntime(); - String[] commands = { "docker-machine", "env" }; + String[] commands = { "docker", "info" }; Process proc = rt.exec(commands); BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); @@ -270,30 +270,6 @@ public void setUp() throws JSONException, IOException { System.out.println(s); LOG.info(s); } - - - String[] commands1 = { "docker", "info" }; - Process proc1 = rt.exec(commands1); - - BufferedReader stdInput1 = new BufferedReader(new InputStreamReader(proc1.getInputStream())); - - BufferedReader stdError1 = new BufferedReader(new InputStreamReader(proc1.getErrorStream())); - - // read the output from the command - System.out.println("***************** Here is the standard output of the command:\n"); - String s1 = null; - while ((s1 = stdInput1.readLine()) != null) { - //containerList.add(s); - System.out.println(s1); - LOG.info(s1); - } - - // read any errors from the attempted command - System.out.println("***************** Here is the standard error of the command (if any):\n"); - while ((s1 = stdError1.readLine()) != null) { - System.out.println(s1); - LOG.info(s1); - } // // for (String containerId : containerList) { // From 3b624599481c32b02ac612e39e79e6cc6dc0aadf Mon Sep 17 00:00:00 2001 From: jusoto Date: Mon, 17 Dec 2018 17:13:10 -0500 Subject: [PATCH 37/59] Test cases: added links for dependencies --- src/test/resources/docker-compose.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/resources/docker-compose.yml b/src/test/resources/docker-compose.yml index fe934b3..c96c068 100644 --- a/src/test/resources/docker-compose.yml +++ b/src/test/resources/docker-compose.yml @@ -32,6 +32,9 @@ services: depends_on: - discoveryservice - mysqlserver + links: + - discoveryservice + - mysqlserver ports: - '8080' environment: @@ -67,6 +70,10 @@ services: - discoveryservice - rabbitmq - mongo + links: + - discoveryservice + - rabbitmq + - mongo environment: - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC @@ -83,6 +90,10 @@ services: - rabbitmq - mongo - discoveryservice + links: + - rabbitmq + - mongo + - discoveryservice environment: - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC @@ -98,6 +109,9 @@ services: depends_on: - discoveryservice - rabbitmq + links: + - discoveryservice + - rabbitmq environment: - JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC @@ -117,6 +131,10 @@ services: - discoveryservice - rabbitmq - mongo + links: + - discoveryservice + - rabbitmq + - mongo volumes: mongo: From b0b9da3fac4de83aade1be876bd78ff6de86475a Mon Sep 17 00:00:00 2001 From: jusoto Date: Mon, 17 Dec 2018 18:01:39 -0500 Subject: [PATCH 38/59] Test cases: changed to localhost --- .../EdgeServiceIntegrationTests.java | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 66332f7..517e079 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -87,7 +87,7 @@ public static void initialize() throws Exception { // Container userContainer = docker.containers().container("userservice"); DockerPort userPort = userContainer.port(8080); - userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); + userServiceURL = String.format("http://localhost:%s", userPort.getIp(), userPort.getExternalPort()); if (!userPort.isListeningNow()) { LOG.info("User service didn't respond over HTTP"); throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); @@ -245,31 +245,31 @@ public void setUp() throws JSONException, IOException { ////////////////////////////////////////////// - //List containerList = new ArrayList(); - Runtime rt = Runtime.getRuntime(); - - String[] commands = { "docker", "info" }; - Process proc = rt.exec(commands); - - BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); - - BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream())); - - // read the output from the command - System.out.println("***************** Here is the standard output of the command:\n"); - String s = null; - while ((s = stdInput.readLine()) != null) { - // containerList.add(s); - System.out.println(s); - LOG.info(s); - } - - // read any errors from the attempted command - System.out.println("***************** Here is the standard error of the command (if any):\n"); - while ((s = stdError.readLine()) != null) { - System.out.println(s); - LOG.info(s); - } +// //List containerList = new ArrayList(); +// Runtime rt = Runtime.getRuntime(); +// +// String[] commands = { "docker", "info" }; +// Process proc = rt.exec(commands); +// +// BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); +// +// BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream())); +// +// // read the output from the command +// System.out.println("***************** Here is the standard output of the command:\n"); +// String s = null; +// while ((s = stdInput.readLine()) != null) { +// // containerList.add(s); +// System.out.println(s); +// LOG.info(s); +// } +// +// // read any errors from the attempted command +// System.out.println("***************** Here is the standard error of the command (if any):\n"); +// while ((s = stdError.readLine()) != null) { +// System.out.println(s); +// LOG.info(s); +// } // // for (String containerId : containerList) { // From 9ec2613286460db1b2ba1bccea943800cbaaad51 Mon Sep 17 00:00:00 2001 From: jusoto Date: Wed, 19 Dec 2018 11:42:10 -0500 Subject: [PATCH 39/59] Test cases: Added log info to track requests --- .../edge/edgeservice/EdgeServiceIntegrationTests.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 517e079..d778e87 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -40,7 +40,6 @@ public class EdgeServiceIntegrationTests { // private static String discoveryServiceURL; private static String mongoURL; private static String userServiceURL; - private static String userServiceURL3; private static String tripCommandURL; private static String tripQueryURL; private static String gmapsAdapterURL; @@ -87,15 +86,13 @@ public static void initialize() throws Exception { // Container userContainer = docker.containers().container("userservice"); DockerPort userPort = userContainer.port(8080); - userServiceURL = String.format("http://localhost:%s", userPort.getIp(), userPort.getExternalPort()); + userServiceURL = String.format("http://%s:%s", System.getenv("DOCKER_IP"), userPort.getExternalPort()); if (!userPort.isListeningNow()) { LOG.info("User service didn't respond over HTTP"); throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); } LOG.info("User service responded over HTTP"); - LOG.info(String.format("User Service docker-name: %s - IP: %s - Int Port: %s - Ext Port: %s", - userContainer.getContainerName(), userPort.getIp(), userPort.getInternalPort(), - userPort.getExternalPort())); + LOG.info("Url to be used: %s", userServiceURL); Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); @@ -299,6 +296,7 @@ public void setUp() throws JSONException, IOException { LOG.info(String.format("User Service - Trying url: %s", userServiceURL)); response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, String.class, parameters); + LOG.info("Request succeded"); // then: assertThat(response.getStatusCodeValue()).isEqualTo(200); From f5f076831f3cc2b4c276a1129a85f89c308a119a Mon Sep 17 00:00:00 2001 From: jusoto Date: Wed, 19 Dec 2018 13:45:32 -0500 Subject: [PATCH 40/59] Test cases: DOCKER_IP env changed to localhost --- .../java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index d778e87..9958756 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -86,7 +86,7 @@ public static void initialize() throws Exception { // Container userContainer = docker.containers().container("userservice"); DockerPort userPort = userContainer.port(8080); - userServiceURL = String.format("http://%s:%s", System.getenv("DOCKER_IP"), userPort.getExternalPort()); + userServiceURL = String.format("http://%s:%s", "localhost", userPort.getExternalPort()); if (!userPort.isListeningNow()) { LOG.info("User service didn't respond over HTTP"); throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); From df7bc705a3ee44d22179d2e4ccd1e14036dd3061 Mon Sep 17 00:00:00 2001 From: jusoto Date: Wed, 19 Dec 2018 14:25:17 -0500 Subject: [PATCH 41/59] Test cases: exchanged localhost by env HOST --- .../java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 9958756..7333a62 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -86,7 +86,7 @@ public static void initialize() throws Exception { // Container userContainer = docker.containers().container("userservice"); DockerPort userPort = userContainer.port(8080); - userServiceURL = String.format("http://%s:%s", "localhost", userPort.getExternalPort()); + userServiceURL = String.format("http://%s:%s", System.getenv("HOST"), userPort.getExternalPort()); if (!userPort.isListeningNow()) { LOG.info("User service didn't respond over HTTP"); throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); From 17fd8b7deca3e7da09e7235de6a26c016ef64193 Mon Sep 17 00:00:00 2001 From: jusoto Date: Wed, 19 Dec 2018 14:54:49 -0500 Subject: [PATCH 42/59] Test cases: replaced env HOST by inFormat function --- .../EdgeServiceIntegrationTests.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 7333a62..ff4c385 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -67,7 +67,7 @@ public static void initialize() throws Exception { Container discoveryContainer = docker.containers().container("discoveryservice"); DockerPort discoveryPort = discoveryContainer.port(8761); - if (!discoveryPort.isListeningNow()) { + while (!discoveryPort.isListeningNow()) { LOG.info("Discovery service didn't respond over HTTP"); throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); } @@ -84,32 +84,32 @@ public static void initialize() throws Exception { // } // LOG.info("Mongo service responded over HTTP"); // - Container userContainer = docker.containers().container("userservice"); - DockerPort userPort = userContainer.port(8080); - userServiceURL = String.format("http://%s:%s", System.getenv("HOST"), userPort.getExternalPort()); - if (!userPort.isListeningNow()) { +// Container userContainer = docker.containers().container("userservice"); + DockerPort userPort = docker.containers().container("userservice").port(8080); + userServiceURL = String.format("http://%s:%s", userPort.inFormat("$HOST"), userPort.getExternalPort()); + while (!userPort.isListeningNow()) { LOG.info("User service didn't respond over HTTP"); throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); } LOG.info("User service responded over HTTP"); LOG.info("Url to be used: %s", userServiceURL); - Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); - DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); +// Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); + DockerPort tripManagementCmdPort = docker.containers().container("tripmanagementcmd").port(8080); tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), tripManagementCmdPort.getExternalPort()); - if (!tripManagementCmdPort.isListeningNow()) { + while (!tripManagementCmdPort.isListeningNow()) { LOG.info("TripManagementCmd service didn't respond over HTTP"); throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", tripManagementCmdPort.getInternalPort())); } LOG.info("TripManagementCmd service responded over HTTP"); - Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); - DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); +// Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); + DockerPort tripManagementQueryPort = docker.containers().container("tripmanagementquery").port(8080); tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), tripManagementQueryPort.getExternalPort()); - if (!tripManagementQueryPort.isListeningNow()) { + while (!tripManagementQueryPort.isListeningNow()) { LOG.info("TripManagementQuery service didn't respond over HTTP"); throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", tripManagementQueryPort.getInternalPort())); @@ -129,11 +129,11 @@ public static void initialize() throws Exception { // } // LOG.info("Gmaps Adapter service responded over HTTP"); // - Container calculationContainer = docker.containers().container("calculationservice"); - DockerPort calculationPort = calculationContainer.port(8080); +// Container calculationContainer = docker.containers().container("calculationservice"); + DockerPort calculationPort = docker.containers().container("calculationservice").port(8080); calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), calculationPort.getExternalPort()); - if (!calculationPort.isListeningNow()) { + while (!calculationPort.isListeningNow()) { LOG.info("Calculation service didn't respond over HTTP"); throw new Exception( String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); From fa07e6e80f628119a3aed128b938b7945b767972 Mon Sep 17 00:00:00 2001 From: jusoto Date: Wed, 19 Dec 2018 15:56:18 -0500 Subject: [PATCH 43/59] Test cases: changed HOST to DOCKER_HOST --- .../java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index ff4c385..2aedd22 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -86,7 +86,7 @@ public static void initialize() throws Exception { // // Container userContainer = docker.containers().container("userservice"); DockerPort userPort = docker.containers().container("userservice").port(8080); - userServiceURL = String.format("http://%s:%s", userPort.inFormat("$HOST"), userPort.getExternalPort()); + userServiceURL = String.format("http://%s:%s", System.getenv("DOCKER_HOST"), userPort.getExternalPort()); while (!userPort.isListeningNow()) { LOG.info("User service didn't respond over HTTP"); throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); From b36bba882f28b68bd1a49616828717b3ae915a4c Mon Sep 17 00:00:00 2001 From: jusoto Date: Wed, 19 Dec 2018 16:05:37 -0500 Subject: [PATCH 44/59] Test cases: double check user service --- .../EdgeServiceIntegrationTests.java | 641 +++++++++--------- 1 file changed, 330 insertions(+), 311 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 2aedd22..8c44886 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -48,172 +48,184 @@ public class EdgeServiceIntegrationTests { // Wait for all services to have ports open @ClassRule public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) - .file("src/test/resources/docker-compose.yml") - .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()).build(); + .file("src/test/resources/docker-compose.yml") + .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("userservice", + HealthChecks.toRespondOverHttp(8080, (port) -> port.inFormat("https://$HOST:$EXTERNAL_PORT"))) + .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()).build(); // Get IP addresses and ports to run tests on @BeforeClass public static void initialize() throws Exception { - LOG.info("Initializing ports from Docker"); - - Container discoveryContainer = docker.containers().container("discoveryservice"); - DockerPort discoveryPort = discoveryContainer.port(8761); - while (!discoveryPort.isListeningNow()) { - LOG.info("Discovery service didn't respond over HTTP"); - throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); - } - LOG.info("Discovery service responded over HTTP"); - - // Container mongoContainer = docker.containers().container("mongo"); - // DockerPort mongoPort = mongoContainer.port(27017); - // mongoURL = String.format("http://%s:%s", mongoPort.getIp(), - // mongoPort.getExternalPort()); - // if(!mongoPort.isListeningNow()){ - // LOG.info("Mongo service didn't respond over HTTP"); - // throw new Exception(String.format("Mongo didn't respond, port: %s", - // mongoPort.getInternalPort())); - // } - // LOG.info("Mongo service responded over HTTP"); - // -// Container userContainer = docker.containers().container("userservice"); - DockerPort userPort = docker.containers().container("userservice").port(8080); - userServiceURL = String.format("http://%s:%s", System.getenv("DOCKER_HOST"), userPort.getExternalPort()); - while (!userPort.isListeningNow()) { - LOG.info("User service didn't respond over HTTP"); - throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); - } - LOG.info("User service responded over HTTP"); - LOG.info("Url to be used: %s", userServiceURL); - -// Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); - DockerPort tripManagementCmdPort = docker.containers().container("tripmanagementcmd").port(8080); - tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), - tripManagementCmdPort.getExternalPort()); - while (!tripManagementCmdPort.isListeningNow()) { - LOG.info("TripManagementCmd service didn't respond over HTTP"); - throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", - tripManagementCmdPort.getInternalPort())); - } - LOG.info("TripManagementCmd service responded over HTTP"); - -// Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); - DockerPort tripManagementQueryPort = docker.containers().container("tripmanagementquery").port(8080); - tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), - tripManagementQueryPort.getExternalPort()); - while (!tripManagementQueryPort.isListeningNow()) { - LOG.info("TripManagementQuery service didn't respond over HTTP"); - throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", - tripManagementQueryPort.getInternalPort())); - } - LOG.info("TripManagementQuery service responded over HTTP"); - // - // Container gmapsAdapterContainer = - // docker.containers().container("gmapsadapter"); - // DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); - // gmapsAdapterURL = String.format("http://%s:%s", - // gmapsAdapterPort.getIp(), - // gmapsAdapterPort.getExternalPort()); - // if(!gmapsAdapterPort.isListeningNow()){ - // LOG.info("Gmaps Adapter service didn't respond over HTTP"); - // throw new Exception(String.format("Gmaps Adapter didn't respond, - // port: %s", gmapsAdapterPort.getInternalPort())); - // } - // LOG.info("Gmaps Adapter service responded over HTTP"); - // -// Container calculationContainer = docker.containers().container("calculationservice"); - DockerPort calculationPort = docker.containers().container("calculationservice").port(8080); - calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), - calculationPort.getExternalPort()); - while (!calculationPort.isListeningNow()) { - LOG.info("Calculation service didn't respond over HTTP"); - throw new Exception( - String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); - } - LOG.info("Calculation service responded over HTTP"); - // - // DockerPort discoveryService = - // docker.containers().container("discoveryservice").port(8761); - // discoveryServiceURL = String.format("http://%s:%s", - // discoveryService.getIp(), - // discoveryService.getExternalPort()); - // while (!docker.containers().container("discoveryservice") - // .portIsListeningOnHttp(8761, (port) -> - // port.inFormat(discoveryServiceURL)).succeeded()) { - // LOG.info("Waiting for discovery service to respond over HTTP"); - // } - // LOG.info("Discovery Service url found: " + discoveryServiceURL); - - DockerPort mongo = docker.containers().container("mongo").port(27017); - mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); - while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) - .succeeded()) { - LOG.info("Waiting for mongo to respond over HTTP"); - } - LOG.info("Mongo url found: " + mongoURL); - - // DockerPort userService = - // docker.containers().container("userservice").port(8080); - // userServiceURL = String.format("http://%s:%s", userService.getIp(), - // userService.getExternalPort()); - // while (!docker.containers().container("userservice") - // .portIsListeningOnHttp(8080, (port) -> - // port.inFormat(userServiceURL)).succeeded()) { - // LOG.info("Waiting for user service to respond over HTTP"); - // } - // LOG.info("User Service url found: " + userServiceURL); - - // DockerPort tripManagementCommand = - // docker.containers().container("tripmanagementcmd").port(8080); - // tripCommandURL = String.format("http://%s:%s", - // tripManagementCommand.getIp(), - // tripManagementCommand.getExternalPort()); - // while (!docker.containers().container("tripmanagementcmd") - // .portIsListeningOnHttp(8080, (port) -> - // port.inFormat(tripCommandURL)).succeeded()) { - // LOG.info("Waiting for Trip Command to respond over HTTP"); - // } - // LOG.info("Trip Command url found: " + tripCommandURL); - // - // DockerPort tripManagementQuery = - // docker.containers().container("tripmanagementquery").port(8080); - // tripQueryURL = String.format("http://%s:%s", - // tripManagementQuery.getIp(), - // tripManagementQuery.getExternalPort()); - // while (!docker.containers().container("tripmanagementquery") - // .portIsListeningOnHttp(8080, (port) -> - // port.inFormat(tripQueryURL)).succeeded()) { - // LOG.info("Waiting for Trip Query to respond over HTTP"); - // } - // LOG.info("Trip Query url found: " + tripQueryURL); - - DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); - gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); - while (!docker.containers().container("gmapsadapter") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { - LOG.info("Waiting for user service to respond over HTTP"); - } - LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); - - // DockerPort calculationService = - // docker.containers().container("calculationservice").port(8080); - // calculationServiceURL = String.format("http://%s:%s", - // calculationService.getIp(), - // calculationService.getExternalPort()); - // while (!docker.containers().container("calculationservice") - // .portIsListeningOnHttp(8080, (port) -> - // port.inFormat(calculationServiceURL)).succeeded()) { - // LOG.info("Waiting for calculation service to respond over HTTP"); - // } - // LOG.info("Calculation Service url found: " + calculationServiceURL); + LOG.info("Initializing ports from Docker"); + + Container discoveryContainer = docker.containers().container("discoveryservice"); + DockerPort discoveryPort = discoveryContainer.port(8761); + if (!discoveryPort.isListeningNow()) { + LOG.info("Discovery service didn't respond over HTTP"); + throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); + } + LOG.info("Discovery service responded over HTTP"); + + // Container mongoContainer = docker.containers().container("mongo"); + // DockerPort mongoPort = mongoContainer.port(27017); + // mongoURL = String.format("http://%s:%s", mongoPort.getIp(), + // mongoPort.getExternalPort()); + // if(!mongoPort.isListeningNow()){ + // LOG.info("Mongo service didn't respond over HTTP"); + // throw new Exception(String.format("Mongo didn't respond, port: %s", + // mongoPort.getInternalPort())); + // } + // LOG.info("Mongo service responded over HTTP"); + // + // Container userContainer = + // docker.containers().container("userservice"); + DockerPort userPort = docker.containers().container("userservice").port(8080); + userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); + if (!userPort.isListeningNow()) { + LOG.info("User service didn't respond over HTTP"); + throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); + } + LOG.info("User service responded over HTTP"); + LOG.info("Url to be used: %s", userServiceURL); + + while (!docker.containers().container("userservice") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { + LOG.info("Waiting for user service to respond over HTTP"); + } + LOG.info("user service url found: " + userServiceURL); + + // Container tripManagementCmdContainer = + // docker.containers().container("tripmanagementcmd"); + DockerPort tripManagementCmdPort = docker.containers().container("tripmanagementcmd").port(8080); + tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), + tripManagementCmdPort.getExternalPort()); + if (!tripManagementCmdPort.isListeningNow()) { + LOG.info("TripManagementCmd service didn't respond over HTTP"); + throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", + tripManagementCmdPort.getInternalPort())); + } + LOG.info("TripManagementCmd service responded over HTTP"); + + // Container tripManagementQueryContainer = + // docker.containers().container("tripmanagementquery"); + DockerPort tripManagementQueryPort = docker.containers().container("tripmanagementquery").port(8080); + tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), + tripManagementQueryPort.getExternalPort()); + if (!tripManagementQueryPort.isListeningNow()) { + LOG.info("TripManagementQuery service didn't respond over HTTP"); + throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", + tripManagementQueryPort.getInternalPort())); + } + LOG.info("TripManagementQuery service responded over HTTP"); + // + // Container gmapsAdapterContainer = + // docker.containers().container("gmapsadapter"); + // DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); + // gmapsAdapterURL = String.format("http://%s:%s", + // gmapsAdapterPort.getIp(), + // gmapsAdapterPort.getExternalPort()); + // if(!gmapsAdapterPort.isListeningNow()){ + // LOG.info("Gmaps Adapter service didn't respond over HTTP"); + // throw new Exception(String.format("Gmaps Adapter didn't respond, + // port: %s", gmapsAdapterPort.getInternalPort())); + // } + // LOG.info("Gmaps Adapter service responded over HTTP"); + // + // Container calculationContainer = + // docker.containers().container("calculationservice"); + DockerPort calculationPort = docker.containers().container("calculationservice").port(8080); + calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), + calculationPort.getExternalPort()); + if (!calculationPort.isListeningNow()) { + LOG.info("Calculation service didn't respond over HTTP"); + throw new Exception( + String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); + } + LOG.info("Calculation service responded over HTTP"); + // + // DockerPort discoveryService = + // docker.containers().container("discoveryservice").port(8761); + // discoveryServiceURL = String.format("http://%s:%s", + // discoveryService.getIp(), + // discoveryService.getExternalPort()); + // while (!docker.containers().container("discoveryservice") + // .portIsListeningOnHttp(8761, (port) -> + // port.inFormat(discoveryServiceURL)).succeeded()) { + // LOG.info("Waiting for discovery service to respond over HTTP"); + // } + // LOG.info("Discovery Service url found: " + discoveryServiceURL); + + DockerPort mongo = docker.containers().container("mongo").port(27017); + mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); + while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) + .succeeded()) { + LOG.info("Waiting for mongo to respond over HTTP"); + } + LOG.info("Mongo url found: " + mongoURL); + + // DockerPort userService = + // docker.containers().container("userservice").port(8080); + // userServiceURL = String.format("http://%s:%s", userService.getIp(), + // userService.getExternalPort()); + // while (!docker.containers().container("userservice") + // .portIsListeningOnHttp(8080, (port) -> + // port.inFormat(userServiceURL)).succeeded()) { + // LOG.info("Waiting for user service to respond over HTTP"); + // } + // LOG.info("User Service url found: " + userServiceURL); + + // DockerPort tripManagementCommand = + // docker.containers().container("tripmanagementcmd").port(8080); + // tripCommandURL = String.format("http://%s:%s", + // tripManagementCommand.getIp(), + // tripManagementCommand.getExternalPort()); + // while (!docker.containers().container("tripmanagementcmd") + // .portIsListeningOnHttp(8080, (port) -> + // port.inFormat(tripCommandURL)).succeeded()) { + // LOG.info("Waiting for Trip Command to respond over HTTP"); + // } + // LOG.info("Trip Command url found: " + tripCommandURL); + // + // DockerPort tripManagementQuery = + // docker.containers().container("tripmanagementquery").port(8080); + // tripQueryURL = String.format("http://%s:%s", + // tripManagementQuery.getIp(), + // tripManagementQuery.getExternalPort()); + // while (!docker.containers().container("tripmanagementquery") + // .portIsListeningOnHttp(8080, (port) -> + // port.inFormat(tripQueryURL)).succeeded()) { + // LOG.info("Waiting for Trip Query to respond over HTTP"); + // } + // LOG.info("Trip Query url found: " + tripQueryURL); + + DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); + gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); + while (!docker.containers().container("gmapsadapter") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { + LOG.info("Waiting for user service to respond over HTTP"); + } + LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); + + // DockerPort calculationService = + // docker.containers().container("calculationservice").port(8080); + // calculationServiceURL = String.format("http://%s:%s", + // calculationService.getIp(), + // calculationService.getExternalPort()); + // while (!docker.containers().container("calculationservice") + // .portIsListeningOnHttp(8080, (port) -> + // port.inFormat(calculationServiceURL)).succeeded()) { + // LOG.info("Waiting for calculation service to respond over HTTP"); + // } + // LOG.info("Calculation Service url found: " + calculationServiceURL); } private TestRestTemplate restTemplate = new TestRestTemplate(); @@ -222,189 +234,196 @@ public static void initialize() throws Exception { @Before public void setUp() throws JSONException, IOException { - String plainCreds = "front-end:front-end"; - byte[] plainCredsBytes = plainCreds.getBytes(); - byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); - String base64Creds = new String(base64CredsBytes); - - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Basic " + base64Creds); - headers.add("Content-Type", "application/x-www-form-urlencoded"); - - MultiValueMap parameters = new LinkedMultiValueMap<>(); - parameters.add("username", "front-end"); - parameters.add("secret", "front-end"); - String body = "grant_type=password&scope=webclient&username=passenger&password=password"; - HttpEntity request = new HttpEntity<>(body, headers); - - // when: - ResponseEntity response; - - ////////////////////////////////////////////// - -// //List containerList = new ArrayList(); -// Runtime rt = Runtime.getRuntime(); -// -// String[] commands = { "docker", "info" }; -// Process proc = rt.exec(commands); -// -// BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); -// -// BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream())); -// -// // read the output from the command -// System.out.println("***************** Here is the standard output of the command:\n"); -// String s = null; -// while ((s = stdInput.readLine()) != null) { -// // containerList.add(s); -// System.out.println(s); -// LOG.info(s); -// } -// -// // read any errors from the attempted command -// System.out.println("***************** Here is the standard error of the command (if any):\n"); -// while ((s = stdError.readLine()) != null) { -// System.out.println(s); -// LOG.info(s); -// } -// -// for (String containerId : containerList) { -// -// String[] commands1 = { "docker", "inspect", containerId }; -// Process proc1 = rt.exec(commands1); -// -// BufferedReader stdInput1 = new BufferedReader(new InputStreamReader(proc1.getInputStream())); -// -// BufferedReader stdError1 = new BufferedReader(new InputStreamReader(proc1.getErrorStream())); -// -// // read the output from the command -// System.out.println("Here is the standard output of the command:\n"); -// String s1 = null; -// while ((s1 = stdInput1.readLine()) != null) { -// System.out.println(s1); -// LOG.info(s1); -// } -// -// // read any errors from the attempted command -// System.out.println("Here is the standard error of the command (if any):\n"); -// while ((s1 = stdError1.readLine()) != null) { -// System.out.println(s1); -// LOG.info(s1); -// } -// } - ////////////////////////////////////////////// - - LOG.info(String.format("User Service - Trying url: %s", userServiceURL)); - response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, String.class, parameters); - LOG.info("Request succeded"); - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); - JSONObject json = new JSONObject(response.getBody()); - token = json.getString("access_token"); + String plainCreds = "front-end:front-end"; + byte[] plainCredsBytes = plainCreds.getBytes(); + byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); + String base64Creds = new String(base64CredsBytes); + + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Basic " + base64Creds); + headers.add("Content-Type", "application/x-www-form-urlencoded"); + + MultiValueMap parameters = new LinkedMultiValueMap<>(); + parameters.add("username", "front-end"); + parameters.add("secret", "front-end"); + String body = "grant_type=password&scope=webclient&username=passenger&password=password"; + HttpEntity request = new HttpEntity<>(body, headers); + + // when: + ResponseEntity response; + + ////////////////////////////////////////////// + + // //List containerList = new ArrayList(); + // Runtime rt = Runtime.getRuntime(); + // + // String[] commands = { "docker", "info" }; + // Process proc = rt.exec(commands); + // + // BufferedReader stdInput = new BufferedReader(new + // InputStreamReader(proc.getInputStream())); + // + // BufferedReader stdError = new BufferedReader(new + // InputStreamReader(proc.getErrorStream())); + // + // // read the output from the command + // System.out.println("***************** Here is the standard output of + // the command:\n"); + // String s = null; + // while ((s = stdInput.readLine()) != null) { + // // containerList.add(s); + // System.out.println(s); + // LOG.info(s); + // } + // + // // read any errors from the attempted command + // System.out.println("***************** Here is the standard error of + // the command (if any):\n"); + // while ((s = stdError.readLine()) != null) { + // System.out.println(s); + // LOG.info(s); + // } + // + // for (String containerId : containerList) { + // + // String[] commands1 = { "docker", "inspect", containerId }; + // Process proc1 = rt.exec(commands1); + // + // BufferedReader stdInput1 = new BufferedReader(new + // InputStreamReader(proc1.getInputStream())); + // + // BufferedReader stdError1 = new BufferedReader(new + // InputStreamReader(proc1.getErrorStream())); + // + // // read the output from the command + // System.out.println("Here is the standard output of the command:\n"); + // String s1 = null; + // while ((s1 = stdInput1.readLine()) != null) { + // System.out.println(s1); + // LOG.info(s1); + // } + // + // // read any errors from the attempted command + // System.out.println("Here is the standard error of the command (if + // any):\n"); + // while ((s1 = stdError1.readLine()) != null) { + // System.out.println(s1); + // LOG.info(s1); + // } + // } + ////////////////////////////////////////////// + + LOG.info(String.format("User Service - Trying url: %s", userServiceURL)); + response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, String.class, parameters); + LOG.info("Request succeded"); + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); + JSONObject json = new JSONObject(response.getBody()); + token = json.getString("access_token"); } @Test public void tripCommandPOSTRequestSuccess() { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); - String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " - + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; - HttpEntity request = new HttpEntity<>(body, headers); + String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " + + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; + HttpEntity request = new HttpEntity<>(body, headers); - // when: - ResponseEntity response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, - String.class); + // when: + ResponseEntity response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, + String.class); - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(201); + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(201); } @Test public void tripQueryGETSpecificTripRequestSuccess() throws JSONException, InterruptedException { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); - String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " - + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; - HttpEntity request = new HttpEntity<>(body, headers); - ResponseEntity postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, - String.class); + String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " + + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; + HttpEntity request = new HttpEntity<>(body, headers); + ResponseEntity postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, + String.class); - assertThat(postResponse.getStatusCodeValue()).isEqualTo(201); + assertThat(postResponse.getStatusCodeValue()).isEqualTo(201); - JSONObject json = new JSONObject(postResponse.getBody()); - String tripId = json.getString("id"); + JSONObject json = new JSONObject(postResponse.getBody()); + String tripId = json.getString("id"); - Thread.sleep(1000); + Thread.sleep(1000); - // when: - ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trip/" + tripId, - String.class); + // when: + ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trip/" + tripId, + String.class); - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); } @Test public void tripQueryGETAllTripsRequestSuccess() { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); - // when: - ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class); + // when: + ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class); - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); } @Test public void calculationServiceRequestSuccess() { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); - String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\"," - + " \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; - HttpEntity request = new HttpEntity<>(body, headers); + String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\"," + + " \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; + HttpEntity request = new HttpEntity<>(body, headers); - // when: - ResponseEntity response = restTemplate.postForEntity(calculationServiceURL + "/api/v1/cost", request, - String.class); + // when: + ResponseEntity response = restTemplate.postForEntity(calculationServiceURL + "/api/v1/cost", request, + String.class); - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); } @Test public void gmapsAdapterRequestSuccess() throws Exception { - // given: - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - headers.add("Content-Type", "application/json"); - - String body = "{ \"origin\": \"2250 N Commerce Pkwy, Weston, FL 33326\", \"destination\": \"11200 SW 8th St, " - + "Miami, FL 33199\", \"departureTime\": \"15220998650000000\" }"; - HttpEntity request = new HttpEntity<>(body, headers); - - // when: - ResponseEntity response = restTemplate.postForEntity(gmapsAdapterURL + "/api/v1/directions", request, - String.class); - - if (response.getStatusCodeValue() != 200) { - throw new Exception( - String.format("Expected 200, actual %s\n%s", response.getStatusCode(), response.getBody())); - } - - // then: - assertThat(response.getStatusCodeValue()).isEqualTo(200); + // given: + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + headers.add("Content-Type", "application/json"); + + String body = "{ \"origin\": \"2250 N Commerce Pkwy, Weston, FL 33326\", \"destination\": \"11200 SW 8th St, " + + "Miami, FL 33199\", \"departureTime\": \"15220998650000000\" }"; + HttpEntity request = new HttpEntity<>(body, headers); + + // when: + ResponseEntity response = restTemplate.postForEntity(gmapsAdapterURL + "/api/v1/directions", request, + String.class); + + if (response.getStatusCodeValue() != 200) { + throw new Exception( + String.format("Expected 200, actual %s\n%s", response.getStatusCode(), response.getBody())); + } + + // then: + assertThat(response.getStatusCodeValue()).isEqualTo(200); } } From 6ae04108838ae3176c22d735c057185cf3347b13 Mon Sep 17 00:00:00 2001 From: jusoto Date: Wed, 19 Dec 2018 16:12:57 -0500 Subject: [PATCH 45/59] Test cases: removed initial check on user service --- .../edgeservice/EdgeServiceIntegrationTests.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 8c44886..917ad86 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -90,12 +90,12 @@ public static void initialize() throws Exception { // docker.containers().container("userservice"); DockerPort userPort = docker.containers().container("userservice").port(8080); userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); - if (!userPort.isListeningNow()) { - LOG.info("User service didn't respond over HTTP"); - throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); - } - LOG.info("User service responded over HTTP"); - LOG.info("Url to be used: %s", userServiceURL); +// if (!userPort.isListeningNow()) { +// LOG.info("User service didn't respond over HTTP"); +// throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); +// } +// LOG.info("User service responded over HTTP"); +// LOG.info("Url to be used: %s", userServiceURL); while (!docker.containers().container("userservice") .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { From f2a99566e048c538f37e564d8f027c5a55185899 Mon Sep 17 00:00:00 2001 From: jusoto Date: Wed, 19 Dec 2018 16:25:01 -0500 Subject: [PATCH 46/59] Test cases: fix https for http --- .../java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 917ad86..0a1d390 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -55,7 +55,7 @@ public class EdgeServiceIntegrationTests { .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) .waitingForService("userservice", - HealthChecks.toRespondOverHttp(8080, (port) -> port.inFormat("https://$HOST:$EXTERNAL_PORT"))) + HealthChecks.toRespondOverHttp(8080, (port) -> port.inFormat("http://$HOST:$EXTERNAL_PORT"))) .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) From c3cdb26b27731707bc3c848f78a97b2deeb263e0 Mon Sep 17 00:00:00 2001 From: jusoto Date: Wed, 19 Dec 2018 17:06:53 -0500 Subject: [PATCH 47/59] Test cases: removed individual integration test files --- .../EdgeServiceIntegrationCalculation.java | 127 ------------- ...geServiceIntegrationTestsGmapsAdapter.java | 110 ----------- .../EdgeServiceIntegrationTestsTripCmd.java | 150 --------------- ...geServiceIntegrationTestsTripCmdQuery.java | 171 ------------------ .../EdgeServiceIntegrationTestsTripQuery.java | 144 --------------- 5 files changed, 702 deletions(-) delete mode 100644 src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java delete mode 100644 src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java delete mode 100644 src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java delete mode 100644 src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java delete mode 100644 src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java deleted file mode 100644 index 5355ace..0000000 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationCalculation.java +++ /dev/null @@ -1,127 +0,0 @@ -//package aist.edge.edgeservice; -// -//import static org.assertj.core.api.Java6Assertions.assertThat; -// -//import com.palantir.docker.compose.DockerComposeRule; -//import com.palantir.docker.compose.configuration.ShutdownStrategy; -//import com.palantir.docker.compose.connection.Container; -//import com.palantir.docker.compose.connection.DockerPort; -//import com.palantir.docker.compose.connection.waiting.HealthChecks; -// -//import java.util.*; -// -//import org.joda.time.Duration; -//import org.json.JSONException; -//import org.json.JSONObject; -//import org.junit.Before; -//import org.junit.BeforeClass; -//import org.junit.ClassRule; -//import org.junit.Test; -//import org.junit.runner.RunWith; -// -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -//import org.springframework.boot.test.context.SpringBootTest; -//import org.springframework.boot.test.web.client.TestRestTemplate; -//import org.springframework.http.*; -//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -//import org.springframework.util.*; -// -//@RunWith(SpringJUnit4ClassRunner.class) -//@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -//public class EdgeServiceIntegrationCalculation { -// protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationCalculation.class); -// -// private static String discoveryServiceURL; -// private static String mongoURL; -// private static String gmapsAdapterURL; -// private static String calculationServiceURL; -// private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); -// -// // Wait for all services to have ports open -// @ClassRule -// public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) -// .file("src/test/resources/docker-compose-calculation.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) -// .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .build(); -// -// // Get IP addresses and ports to run tests on -// @BeforeClass -// public static void initialize() throws Exception { -// -// LOG.info("Initializing ports from Docker"); -// -// Container discoveryContainer = docker.containers().container("discoveryservice"); -// DockerPort discoveryPort = discoveryContainer.port(8761); -// discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), -// discoveryPort.getExternalPort()); -// if(!discoveryPort.isListeningNow()){ -// LOG.info("Discovery service didn't respond over HTTP"); -// throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); -// } -// LOG.info("Discovery service responded over HTTP"); -// -// Container mongoContainer = docker.containers().container("mongo"); -// DockerPort mongoPort = mongoContainer.port(27017); -// mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); -// if(!mongoPort.isListeningNow()){ -// LOG.info("Mongo service didn't respond over HTTP"); -// throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); -// } -// LOG.info("Mongo service responded over HTTP"); -// -// Container gmapsAdapterContainer = docker.containers().container("gmapsadapter"); -// DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); -// gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapterPort.getIp(), -// gmapsAdapterPort.getExternalPort()); -// if(!gmapsAdapterPort.isListeningNow()){ -// LOG.info("Gmaps Adapter service didn't respond over HTTP"); -// throw new Exception(String.format("Gmaps Adapter didn't respond, port: %s", gmapsAdapterPort.getInternalPort())); -// } -// LOG.info("Gmaps Adapter service responded over HTTP"); -// -// Container calculationContainer = docker.containers().container("calculationservice"); -// DockerPort calculationPort = calculationContainer.port(8080); -// calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), -// calculationPort.getExternalPort()); -// if(!calculationPort.isListeningNow()){ -// LOG.info("Calculation service didn't respond over HTTP"); -// throw new Exception(String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); -// } -// LOG.info("Calculation service responded over HTTP"); -// -// LOG.info("Containers initialized correctly"); -// } -// -// private TestRestTemplate restTemplate = new TestRestTemplate(); -// -// private String token; -// -// @Before -// public void setUp() throws JSONException { -// token = ""; -// } -// -// @Test -// public void calculationServiceRequestSuccess() { -// // given: -// HttpHeaders headers = new HttpHeaders(); -// headers.add("Authorization", "Bearer " + token); -// headers.add("Content-Type", "application/json"); -// -// String body = "{ \"origin\": \"Weston, FL\", \"destination\": \"Miami, FL\"," -// + " \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; -// HttpEntity request = new HttpEntity<>(body, headers); -// -// // when: -// ResponseEntity response = restTemplate.postForEntity(calculationServiceURL + "/api/v1/cost", request, -// String.class); -// -// // then: -// assertThat(response.getStatusCodeValue()).isEqualTo(200); -// } -//} diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java deleted file mode 100644 index 12a0afd..0000000 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsGmapsAdapter.java +++ /dev/null @@ -1,110 +0,0 @@ -//package aist.edge.edgeservice; -// -//import static org.assertj.core.api.Java6Assertions.assertThat; -// -//import com.palantir.docker.compose.DockerComposeRule; -//import com.palantir.docker.compose.configuration.ShutdownStrategy; -//import com.palantir.docker.compose.connection.Container; -//import com.palantir.docker.compose.connection.DockerPort; -//import com.palantir.docker.compose.connection.waiting.HealthChecks; -// -//import java.util.*; -// -//import org.joda.time.Duration; -//import org.json.JSONException; -//import org.json.JSONObject; -//import org.junit.Before; -//import org.junit.BeforeClass; -//import org.junit.ClassRule; -//import org.junit.Test; -//import org.junit.runner.RunWith; -// -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -//import org.springframework.boot.test.context.SpringBootTest; -//import org.springframework.boot.test.web.client.TestRestTemplate; -//import org.springframework.http.*; -//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -//import org.springframework.util.*; -// -//@RunWith(SpringJUnit4ClassRunner.class) -//@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -//public class EdgeServiceIntegrationTestsGmapsAdapter { -// protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTestsGmapsAdapter.class); -// -// private static String discoveryServiceURL; -// private static String gmapsAdapterURL; -// private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); -// -// // Wait for all services to have ports open -// @ClassRule -// public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) -// .file("src/test/resources/docker-compose-gmaps-adapter.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) -// .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .build(); -// -// // Get IP addresses and ports to run tests on -// @BeforeClass -// public static void initialize() throws Exception { -// -// LOG.info("Initializing ports from Docker"); -// -// Container discoveryContainer = docker.containers().container("discoveryservice"); -// DockerPort discoveryPort = discoveryContainer.port(8761); -// discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), -// discoveryPort.getExternalPort()); -// if(!discoveryPort.isListeningNow()){ -// LOG.info("Discovery service didn't respond over HTTP"); -// throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); -// } -// LOG.info("Discovery service responded over HTTP"); -// -// Container gmapsAdapterContainer = docker.containers().container("gmapsadapter"); -// DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); -// gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapterPort.getIp(), -// gmapsAdapterPort.getExternalPort()); -// if(!gmapsAdapterPort.isListeningNow()){ -// LOG.info("Gmaps Adapter service didn't respond over HTTP"); -// throw new Exception(String.format("Gmaps Adapter didn't respond, port: %s", gmapsAdapterPort.getInternalPort())); -// } -// LOG.info("Gmaps Adapter service responded over HTTP"); -// -// LOG.info("Containers initialized correctly"); -// } -// -// private TestRestTemplate restTemplate = new TestRestTemplate(); -// -// private String token; -// -// @Before -// public void setUp() throws JSONException { -// token = ""; -// } -// -// @Test -// public void gmapsAdapterRequestSuccess() throws Exception { -// // given: -// HttpHeaders headers = new HttpHeaders(); -// headers.add("Authorization", "Bearer " + token); -// headers.add("Content-Type", "application/json"); -// -// String body = "{ \"origin\": \"2250 N Commerce Pkwy, Weston, FL 33326\", \"destination\": \"11200 SW 8th St, " -// + "Miami, FL 33199\", \"departureTime\": \"15220998650000000\" }"; -// HttpEntity request = new HttpEntity<>(body, headers); -// -// // when: -// ResponseEntity response = restTemplate.postForEntity(gmapsAdapterURL + "/api/v1/directions", request, -// String.class); -// -// if (response.getStatusCodeValue() != 200) { -// throw new Exception( -// String.format("Expected 200, actual %s\n%s", response.getStatusCode(), -// response.getBody())); -// } -// -// // then: -// assertThat(response.getStatusCodeValue()).isEqualTo(200); -// } -//} diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java deleted file mode 100644 index 5e66372..0000000 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmd.java +++ /dev/null @@ -1,150 +0,0 @@ -//package aist.edge.edgeservice; -// -//import static org.assertj.core.api.Java6Assertions.assertThat; -// -//import com.palantir.docker.compose.DockerComposeRule; -//import com.palantir.docker.compose.configuration.ShutdownStrategy; -//import com.palantir.docker.compose.connection.Container; -//import com.palantir.docker.compose.connection.DockerPort; -//import com.palantir.docker.compose.connection.waiting.HealthChecks; -// -//import java.util.*; -// -//import org.joda.time.Duration; -//import org.json.JSONException; -//import org.json.JSONObject; -//import org.junit.Before; -//import org.junit.BeforeClass; -//import org.junit.ClassRule; -//import org.junit.Test; -//import org.junit.runner.RunWith; -// -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -//import org.springframework.boot.test.context.SpringBootTest; -//import org.springframework.boot.test.web.client.TestRestTemplate; -//import org.springframework.http.*; -//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -//import org.springframework.util.*; -// -//@RunWith(SpringJUnit4ClassRunner.class) -//@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -//public class EdgeServiceIntegrationTestsTripCmd { -// protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTestsTripCmd.class); -// -// private static String discoveryServiceURL; -// private static String mongoURL; -// private static String userServiceURL; -// private static String tripCommandURL; -// private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); -// -// // Wait for all services to have ports open -// @ClassRule -// public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) -// .file("src/test/resources/docker-compose-trip-cmd.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) -// .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .build(); -// -// // Get IP addresses and ports to run tests on -// @BeforeClass -// public static void initialize() throws Exception { -// -// LOG.info("Initializing ports from Docker"); -// -// Container discoveryContainer = docker.containers().container("discoveryservice"); -// DockerPort discoveryPort = discoveryContainer.port(8761); -// discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), -// discoveryPort.getExternalPort()); -// if(!discoveryPort.isListeningNow()){ -// LOG.info("Discovery service didn't respond over HTTP"); -// throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); -// } -// LOG.info("Discovery service responded over HTTP"); -// -// Container mongoContainer = docker.containers().container("mongo"); -// DockerPort mongoPort = mongoContainer.port(27017); -// mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); -// if(!mongoPort.isListeningNow()){ -// LOG.info("Mongo service didn't respond over HTTP"); -// throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); -// } -// LOG.info("Mongo service responded over HTTP"); -// -// Container userContainer = docker.containers().container("userservice"); -// DockerPort userPort = userContainer.port(8080); -// userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); -// if(!userPort.isListeningNow()){ -// LOG.info("User service didn't respond over HTTP"); -// throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); -// } -// LOG.info("User service responded over HTTP"); -// -// Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); -// DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); -// tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), -// tripManagementCmdPort.getExternalPort()); -// if(!userPort.isListeningNow()){ -// LOG.info("TripManagementCmd service didn't respond over HTTP"); -// throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", tripManagementCmdPort.getInternalPort())); -// } -// LOG.info("TripManagementCmd service responded over HTTP"); -// -// LOG.info("Containers initialized correctly"); -// } -// -// private TestRestTemplate restTemplate = new TestRestTemplate(); -// -// private String token; -// -// @Before -// public void setUp() throws JSONException { -// String plainCreds = "front-end:front-end"; -// byte[] plainCredsBytes = plainCreds.getBytes(); -// byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); -// String base64Creds = new String(base64CredsBytes); -// -// HttpHeaders headers = new HttpHeaders(); -// headers.add("Authorization", "Basic " + base64Creds); -// headers.add("Content-Type", "application/x-www-form-urlencoded"); -// -// MultiValueMap parameters = new LinkedMultiValueMap<>(); -// parameters.add("username", "front-end"); -// parameters.add("secret", "front-end"); -// String body = "grant_type=password&scope=webclient&username=passenger&password=password"; -// HttpEntity request = new HttpEntity<>(body, headers); -// -// // when: -// ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, -// String.class, parameters); -// -// // then: -// assertThat(response.getStatusCodeValue()).isEqualTo(200); -// JSONObject json = new JSONObject(response.getBody()); -// token = json.getString("access_token"); -// } -// -// @Test -// public void tripCommandPOSTRequestSuccess() { -// // given: -// HttpHeaders headers = new HttpHeaders(); -// headers.add("Authorization", "Bearer " + token); -// headers.add("Content-Type", "application/json"); -// -// String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " -// + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; -// HttpEntity request = new HttpEntity<>(body, headers); -// -// // when: -// ResponseEntity response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, -// String.class); -// -// // then: -// assertThat(response.getStatusCodeValue()).isEqualTo(201); -// } -// -//} diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java deleted file mode 100644 index a431f94..0000000 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripCmdQuery.java +++ /dev/null @@ -1,171 +0,0 @@ -//package aist.edge.edgeservice; -// -//import static org.assertj.core.api.Java6Assertions.assertThat; -// -//import com.palantir.docker.compose.DockerComposeRule; -//import com.palantir.docker.compose.configuration.ShutdownStrategy; -//import com.palantir.docker.compose.connection.Container; -//import com.palantir.docker.compose.connection.DockerPort; -//import com.palantir.docker.compose.connection.waiting.HealthChecks; -// -//import java.util.*; -// -//import org.joda.time.Duration; -//import org.json.JSONException; -//import org.json.JSONObject; -//import org.junit.Before; -//import org.junit.BeforeClass; -//import org.junit.ClassRule; -//import org.junit.Test; -//import org.junit.runner.RunWith; -// -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -//import org.springframework.boot.test.context.SpringBootTest; -//import org.springframework.boot.test.web.client.TestRestTemplate; -//import org.springframework.http.*; -//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -//import org.springframework.util.*; -// -//@RunWith(SpringJUnit4ClassRunner.class) -//@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -//public class EdgeServiceIntegrationTestsTripCmdQuery { -// protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTestsTripCmdQuery.class); -// -// private static String discoveryServiceURL; -// private static String mongoURL; -// private static String userServiceURL; -// private static String tripCommandURL; -// private static String tripQueryURL; -// private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); -// -// // Wait for all services to have ports open -// @ClassRule -// public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) -// .file("src/test/resources/docker-compose-trip-cmd-query.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) -// .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .build(); -// -// // Get IP addresses and ports to run tests on -// @BeforeClass -// public static void initialize() throws Exception { -// -// LOG.info("Initializing ports from Docker"); -// -// Container discoveryContainer = docker.containers().container("discoveryservice"); -// DockerPort discoveryPort = discoveryContainer.port(8761); -// discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), -// discoveryPort.getExternalPort()); -// if(!discoveryPort.isListeningNow()){ -// LOG.info("Discovery service didn't respond over HTTP"); -// throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); -// } -// LOG.info("Discovery service responded over HTTP"); -// -// Container mongoContainer = docker.containers().container("mongo"); -// DockerPort mongoPort = mongoContainer.port(27017); -// mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); -// if(!mongoPort.isListeningNow()){ -// LOG.info("Mongo service didn't respond over HTTP"); -// throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); -// } -// LOG.info("Mongo service responded over HTTP"); -// -// Container userContainer = docker.containers().container("userservice"); -// DockerPort userPort = userContainer.port(8080); -// userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); -// if(!userPort.isListeningNow()){ -// LOG.info("User service didn't respond over HTTP"); -// throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); -// } -// LOG.info("User service responded over HTTP"); -// -// Container tripManagementCmdContainer = docker.containers().container("tripmanagementcmd"); -// DockerPort tripManagementCmdPort = tripManagementCmdContainer.port(8080); -// tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), -// tripManagementCmdPort.getExternalPort()); -// if(!tripManagementCmdPort.isListeningNow()){ -// LOG.info("TripManagementCmd service didn't respond over HTTP"); -// throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", tripManagementCmdPort.getInternalPort())); -// } -// LOG.info("TripManagementCmd service responded over HTTP"); -// -// Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); -// DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); -// tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), -// tripManagementQueryPort.getExternalPort()); -// if(!tripManagementQueryPort.isListeningNow()){ -// LOG.info("TripManagementQuery service didn't respond over HTTP"); -// throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", tripManagementQueryPort.getInternalPort())); -// } -// LOG.info("TripManagementQuery service responded over HTTP"); -// -// LOG.info("Containers initialized correctly"); -// } -// -// private TestRestTemplate restTemplate = new TestRestTemplate(); -// -// private String token; -// -// @Before -// public void setUp() throws JSONException { -// String plainCreds = "front-end:front-end"; -// byte[] plainCredsBytes = plainCreds.getBytes(); -// byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); -// String base64Creds = new String(base64CredsBytes); -// -// HttpHeaders headers = new HttpHeaders(); -// headers.add("Authorization", "Basic " + base64Creds); -// headers.add("Content-Type", "application/x-www-form-urlencoded"); -// -// MultiValueMap parameters = new LinkedMultiValueMap<>(); -// parameters.add("username", "front-end"); -// parameters.add("secret", "front-end"); -// String body = "grant_type=password&scope=webclient&username=passenger&password=password"; -// HttpEntity request = new HttpEntity<>(body, headers); -// -// // when: -// ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, -// String.class, parameters); -// -// // then: -// assertThat(response.getStatusCodeValue()).isEqualTo(200); -// JSONObject json = new JSONObject(response.getBody()); -// token = json.getString("access_token"); -// } -// -// @Test -// public void tripQueryGETSpecificTripRequestSuccess() throws JSONException, InterruptedException { -// // given: -// HttpHeaders headers = new HttpHeaders(); -// headers.add("Authorization", "Bearer " + token); -// headers.add("Content-Type", "application/json"); -// -// String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": " -// + "\"Miami, FL\", \"userId\": \"4eaf29bc-3909-49d4-a104-3d17f68ba672\" }"; -// HttpEntity request = new HttpEntity<>(body, headers); -// ResponseEntity postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, -// String.class); -// -// assertThat(postResponse.getStatusCodeValue()).isEqualTo(201); -// -// JSONObject json = new JSONObject(postResponse.getBody()); -// String tripId = json.getString("id"); -// -// Thread.sleep(1000); -// -// // when: -// ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trip/" + tripId, -// String.class); -// -// // then: -// assertThat(response.getStatusCodeValue()).isEqualTo(200); -// } -// -//} diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java deleted file mode 100644 index d9c28c8..0000000 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTestsTripQuery.java +++ /dev/null @@ -1,144 +0,0 @@ -//package aist.edge.edgeservice; -// -//import static org.assertj.core.api.Java6Assertions.assertThat; -// -//import com.palantir.docker.compose.DockerComposeRule; -//import com.palantir.docker.compose.configuration.ShutdownStrategy; -//import com.palantir.docker.compose.connection.Container; -//import com.palantir.docker.compose.connection.DockerPort; -//import com.palantir.docker.compose.connection.waiting.HealthChecks; -// -//import java.util.*; -// -//import org.joda.time.Duration; -//import org.json.JSONException; -//import org.json.JSONObject; -//import org.junit.Before; -//import org.junit.BeforeClass; -//import org.junit.ClassRule; -//import org.junit.Test; -//import org.junit.runner.RunWith; -// -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -//import org.springframework.boot.test.context.SpringBootTest; -//import org.springframework.boot.test.web.client.TestRestTemplate; -//import org.springframework.http.*; -//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -//import org.springframework.util.*; -// -//@RunWith(SpringJUnit4ClassRunner.class) -//@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -//public class EdgeServiceIntegrationTestsTripQuery { -// protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTestsTripQuery.class); -// -// private static String discoveryServiceURL; -// private static String mongoURL; -// private static String userServiceURL; -// private static String tripQueryURL; -// private static Duration DEFAULT_TIMEOUT = Duration.standardMinutes(2); -// -// // Wait for all services to have ports open -// @ClassRule -// public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) -// .file("src/test/resources/docker-compose-trip-query.yml").shutdownStrategy(ShutdownStrategy.KILL_DOWN) -// .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen(), DEFAULT_TIMEOUT) -// .build(); -// -// // Get IP addresses and ports to run tests on -// @BeforeClass -// public static void initialize() throws Exception { -// -// LOG.info("Initializing ports from Docker"); -// -// Container discoveryContainer = docker.containers().container("discoveryservice"); -// DockerPort discoveryPort = discoveryContainer.port(8761); -// discoveryServiceURL = String.format("http://%s:%s", discoveryPort.getIp(), -// discoveryPort.getExternalPort()); -// if(!discoveryPort.isListeningNow()){ -// LOG.info("Discovery service didn't respond over HTTP"); -// throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); -// } -// LOG.info("Discovery service responded over HTTP"); -// -// Container mongoContainer = docker.containers().container("mongo"); -// DockerPort mongoPort = mongoContainer.port(27017); -// mongoURL = String.format("http://%s:%s", mongoPort.getIp(), mongoPort.getExternalPort()); -// if(!mongoPort.isListeningNow()){ -// LOG.info("Mongo service didn't respond over HTTP"); -// throw new Exception(String.format("Mongo didn't respond, port: %s", mongoPort.getInternalPort())); -// } -// LOG.info("Mongo service responded over HTTP"); -// -// Container userContainer = docker.containers().container("userservice"); -// DockerPort userPort = userContainer.port(8080); -// userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); -// if(!userPort.isListeningNow()){ -// LOG.info("User service didn't respond over HTTP"); -// throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); -// } -// LOG.info("User service responded over HTTP"); -// -// Container tripManagementQueryContainer = docker.containers().container("tripmanagementquery"); -// DockerPort tripManagementQueryPort = tripManagementQueryContainer.port(8080); -// tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), -// tripManagementQueryPort.getExternalPort()); -// if(!tripManagementQueryPort.isListeningNow()){ -// LOG.info("TripManagementQuery service didn't respond over HTTP"); -// throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", tripManagementQueryPort.getInternalPort())); -// } -// LOG.info("TripManagementQuery service responded over HTTP"); -// -// LOG.info("Containers initialized correctly"); -// } -// -// private TestRestTemplate restTemplate = new TestRestTemplate(); -// -// private String token; -// -// @Before -// public void setUp() throws JSONException { -// String plainCreds = "front-end:front-end"; -// byte[] plainCredsBytes = plainCreds.getBytes(); -// byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes); -// String base64Creds = new String(base64CredsBytes); -// -// HttpHeaders headers = new HttpHeaders(); -// headers.add("Authorization", "Basic " + base64Creds); -// headers.add("Content-Type", "application/x-www-form-urlencoded"); -// -// MultiValueMap parameters = new LinkedMultiValueMap<>(); -// parameters.add("username", "front-end"); -// parameters.add("secret", "front-end"); -// String body = "grant_type=password&scope=webclient&username=passenger&password=password"; -// HttpEntity request = new HttpEntity<>(body, headers); -// -// // when: -// ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, -// String.class, parameters); -// -// // then: -// assertThat(response.getStatusCodeValue()).isEqualTo(200); -// JSONObject json = new JSONObject(response.getBody()); -// token = json.getString("access_token"); -// } -// -// @Test -// public void tripQueryGETAllTripsRequestSuccess() { -// // given: -// HttpHeaders headers = new HttpHeaders(); -// headers.add("Authorization", "Bearer " + token); -// headers.add("Content-Type", "application/json"); -// -// // when: -// ResponseEntity response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class); -// -// // then: -// assertThat(response.getStatusCodeValue()).isEqualTo(200); -// } -//} From ea031a345c688ce55aac449a73a2bf597354abc0 Mon Sep 17 00:00:00 2001 From: jusoto Date: Thu, 20 Dec 2018 21:58:58 -0500 Subject: [PATCH 48/59] Test cases: replaced if for while for checking opened ports --- .../EdgeServiceIntegrationTests.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 0a1d390..2ec5ed4 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -69,7 +69,7 @@ public static void initialize() throws Exception { Container discoveryContainer = docker.containers().container("discoveryservice"); DockerPort discoveryPort = discoveryContainer.port(8761); - if (!discoveryPort.isListeningNow()) { + while (!discoveryPort.isListeningNow()) { LOG.info("Discovery service didn't respond over HTTP"); throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); } @@ -108,10 +108,10 @@ public static void initialize() throws Exception { DockerPort tripManagementCmdPort = docker.containers().container("tripmanagementcmd").port(8080); tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), tripManagementCmdPort.getExternalPort()); - if (!tripManagementCmdPort.isListeningNow()) { + while (!tripManagementCmdPort.isListeningNow()) { LOG.info("TripManagementCmd service didn't respond over HTTP"); - throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", - tripManagementCmdPort.getInternalPort())); +// throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", +// tripManagementCmdPort.getInternalPort())); } LOG.info("TripManagementCmd service responded over HTTP"); @@ -120,10 +120,10 @@ public static void initialize() throws Exception { DockerPort tripManagementQueryPort = docker.containers().container("tripmanagementquery").port(8080); tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), tripManagementQueryPort.getExternalPort()); - if (!tripManagementQueryPort.isListeningNow()) { + while (!tripManagementQueryPort.isListeningNow()) { LOG.info("TripManagementQuery service didn't respond over HTTP"); - throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", - tripManagementQueryPort.getInternalPort())); +// throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", +// tripManagementQueryPort.getInternalPort())); } LOG.info("TripManagementQuery service responded over HTTP"); // @@ -145,10 +145,10 @@ public static void initialize() throws Exception { DockerPort calculationPort = docker.containers().container("calculationservice").port(8080); calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), calculationPort.getExternalPort()); - if (!calculationPort.isListeningNow()) { + while (!calculationPort.isListeningNow()) { LOG.info("Calculation service didn't respond over HTTP"); - throw new Exception( - String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); +// throw new Exception( +// String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); } LOG.info("Calculation service responded over HTTP"); // From 2203a6c3bd4f9efc0d0688a1ebb32cc5b93d8450 Mon Sep 17 00:00:00 2001 From: jusoto Date: Thu, 20 Dec 2018 23:16:26 -0500 Subject: [PATCH 49/59] Travis time_wait 15 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e79fa71..ce5ecaf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ before_script: - sudo service mysql stop - export -f travis_wait script: - - travis_wait 5 ./gradlew check -i + - travis_wait 15 ./gradlew check -i env: global: - secure: WF5U05+p8xQRBhT75aviCl9sXpnzER52xJDkKaZPtsak3B/21rj5FGQ4TTu9ivh0oF56ws8Zy8hzNZhjS09QimqtpD+Zl5m5er4Q2GvrStVDM0k38wqye2IBf7juKIlkfntX1o1E9/xGkUgIW5eQpUt7TDGpon5FCvY8NHqDyVi+ZDU7hGQh8E3oyK+8Dly1ETLxVhoDEY3vG1VyEZ1IDrgAw/N6KlNIyiuWjPMBLTFAjGMzJAaf/MQiKfmB3HUBUtGqEdhobppEqriJkXl/6ov+Np+vh83dIBaOfRUpB1KgvGmefmtL7rb+mIIXOLMm9cpyqmK+6h1JeQrwB3xtWtIIXmmL2VEwmO/2YfTDyu+JpRkkgwDMLgyRKN9wEtaR+4C3X/p9zMysocDhyccOeGVq7XhJwgdosoJ0VRLVtUhPq1T10B/ipp2g8VF9TW1uIfSQJe6YYCrVK+fqtkWG5yuOfqQdGHNZkRJMpeTyzkJQzX7GZb8G0H8EZCsjdJ0FdEpshWcCB2ljozwH3fFMqnzE1thibpg7dC2BXF7aRGjmn/4vqme98i4hP+590FIMF+sdyDItVq7/91EAwh7m35dvszkFruIzLgHFRnrKAgG76bTHTz8bwywhnCZVbDmy/HEDOjj2ykW9jPKJ7buKRKVYbXnSgYqkn/keTHiRvLI= From 0d1471dcaf0c1a40e9274bb18566d7019371ac5b Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 21 Dec 2018 08:38:59 -0500 Subject: [PATCH 50/59] Travis time_wait changed to 10 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ce5ecaf..0efdc86 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ before_script: - sudo service mysql stop - export -f travis_wait script: - - travis_wait 15 ./gradlew check -i + - travis_wait 10 ./gradlew check -i env: global: - secure: WF5U05+p8xQRBhT75aviCl9sXpnzER52xJDkKaZPtsak3B/21rj5FGQ4TTu9ivh0oF56ws8Zy8hzNZhjS09QimqtpD+Zl5m5er4Q2GvrStVDM0k38wqye2IBf7juKIlkfntX1o1E9/xGkUgIW5eQpUt7TDGpon5FCvY8NHqDyVi+ZDU7hGQh8E3oyK+8Dly1ETLxVhoDEY3vG1VyEZ1IDrgAw/N6KlNIyiuWjPMBLTFAjGMzJAaf/MQiKfmB3HUBUtGqEdhobppEqriJkXl/6ov+Np+vh83dIBaOfRUpB1KgvGmefmtL7rb+mIIXOLMm9cpyqmK+6h1JeQrwB3xtWtIIXmmL2VEwmO/2YfTDyu+JpRkkgwDMLgyRKN9wEtaR+4C3X/p9zMysocDhyccOeGVq7XhJwgdosoJ0VRLVtUhPq1T10B/ipp2g8VF9TW1uIfSQJe6YYCrVK+fqtkWG5yuOfqQdGHNZkRJMpeTyzkJQzX7GZb8G0H8EZCsjdJ0FdEpshWcCB2ljozwH3fFMqnzE1thibpg7dC2BXF7aRGjmn/4vqme98i4hP+590FIMF+sdyDItVq7/91EAwh7m35dvszkFruIzLgHFRnrKAgG76bTHTz8bwywhnCZVbDmy/HEDOjj2ykW9jPKJ7buKRKVYbXnSgYqkn/keTHiRvLI= From 146161f97f9fc51e353bdda35aaed3de1653110e Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 21 Dec 2018 08:51:38 -0500 Subject: [PATCH 51/59] Removed travis time_wait configuration --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0efdc86..464b111 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,11 +4,6 @@ jdk: services: - docker sudo: required -before_script: - - sudo service mysql stop - - export -f travis_wait -script: - - travis_wait 10 ./gradlew check -i env: global: - secure: WF5U05+p8xQRBhT75aviCl9sXpnzER52xJDkKaZPtsak3B/21rj5FGQ4TTu9ivh0oF56ws8Zy8hzNZhjS09QimqtpD+Zl5m5er4Q2GvrStVDM0k38wqye2IBf7juKIlkfntX1o1E9/xGkUgIW5eQpUt7TDGpon5FCvY8NHqDyVi+ZDU7hGQh8E3oyK+8Dly1ETLxVhoDEY3vG1VyEZ1IDrgAw/N6KlNIyiuWjPMBLTFAjGMzJAaf/MQiKfmB3HUBUtGqEdhobppEqriJkXl/6ov+Np+vh83dIBaOfRUpB1KgvGmefmtL7rb+mIIXOLMm9cpyqmK+6h1JeQrwB3xtWtIIXmmL2VEwmO/2YfTDyu+JpRkkgwDMLgyRKN9wEtaR+4C3X/p9zMysocDhyccOeGVq7XhJwgdosoJ0VRLVtUhPq1T10B/ipp2g8VF9TW1uIfSQJe6YYCrVK+fqtkWG5yuOfqQdGHNZkRJMpeTyzkJQzX7GZb8G0H8EZCsjdJ0FdEpshWcCB2ljozwH3fFMqnzE1thibpg7dC2BXF7aRGjmn/4vqme98i4hP+590FIMF+sdyDItVq7/91EAwh7m35dvszkFruIzLgHFRnrKAgG76bTHTz8bwywhnCZVbDmy/HEDOjj2ykW9jPKJ7buKRKVYbXnSgYqkn/keTHiRvLI= From 7f0f214f6fddbedb22e292fc85931c6d8e696ede Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 21 Dec 2018 09:11:17 -0500 Subject: [PATCH 52/59] Changed travis script to gradle instead of gradlew --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 464b111..24b6398 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,11 @@ jdk: services: - docker sudo: required +before_script: + - sudo service mysql stop + - export -f travis_wait +script: + - travis_wait 10 gradle check -i env: global: - secure: WF5U05+p8xQRBhT75aviCl9sXpnzER52xJDkKaZPtsak3B/21rj5FGQ4TTu9ivh0oF56ws8Zy8hzNZhjS09QimqtpD+Zl5m5er4Q2GvrStVDM0k38wqye2IBf7juKIlkfntX1o1E9/xGkUgIW5eQpUt7TDGpon5FCvY8NHqDyVi+ZDU7hGQh8E3oyK+8Dly1ETLxVhoDEY3vG1VyEZ1IDrgAw/N6KlNIyiuWjPMBLTFAjGMzJAaf/MQiKfmB3HUBUtGqEdhobppEqriJkXl/6ov+Np+vh83dIBaOfRUpB1KgvGmefmtL7rb+mIIXOLMm9cpyqmK+6h1JeQrwB3xtWtIIXmmL2VEwmO/2YfTDyu+JpRkkgwDMLgyRKN9wEtaR+4C3X/p9zMysocDhyccOeGVq7XhJwgdosoJ0VRLVtUhPq1T10B/ipp2g8VF9TW1uIfSQJe6YYCrVK+fqtkWG5yuOfqQdGHNZkRJMpeTyzkJQzX7GZb8G0H8EZCsjdJ0FdEpshWcCB2ljozwH3fFMqnzE1thibpg7dC2BXF7aRGjmn/4vqme98i4hP+590FIMF+sdyDItVq7/91EAwh7m35dvszkFruIzLgHFRnrKAgG76bTHTz8bwywhnCZVbDmy/HEDOjj2ykW9jPKJ7buKRKVYbXnSgYqkn/keTHiRvLI= From 953caa03bdb3f2247babb2ec2a427f02ab0d4516 Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 21 Dec 2018 09:31:08 -0500 Subject: [PATCH 53/59] removed travis time_wait --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 24b6398..63b16a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,8 @@ services: sudo: required before_script: - sudo service mysql stop - - export -f travis_wait script: - - travis_wait 10 gradle check -i + - ./gradlew check -i env: global: - secure: WF5U05+p8xQRBhT75aviCl9sXpnzER52xJDkKaZPtsak3B/21rj5FGQ4TTu9ivh0oF56ws8Zy8hzNZhjS09QimqtpD+Zl5m5er4Q2GvrStVDM0k38wqye2IBf7juKIlkfntX1o1E9/xGkUgIW5eQpUt7TDGpon5FCvY8NHqDyVi+ZDU7hGQh8E3oyK+8Dly1ETLxVhoDEY3vG1VyEZ1IDrgAw/N6KlNIyiuWjPMBLTFAjGMzJAaf/MQiKfmB3HUBUtGqEdhobppEqriJkXl/6ov+Np+vh83dIBaOfRUpB1KgvGmefmtL7rb+mIIXOLMm9cpyqmK+6h1JeQrwB3xtWtIIXmmL2VEwmO/2YfTDyu+JpRkkgwDMLgyRKN9wEtaR+4C3X/p9zMysocDhyccOeGVq7XhJwgdosoJ0VRLVtUhPq1T10B/ipp2g8VF9TW1uIfSQJe6YYCrVK+fqtkWG5yuOfqQdGHNZkRJMpeTyzkJQzX7GZb8G0H8EZCsjdJ0FdEpshWcCB2ljozwH3fFMqnzE1thibpg7dC2BXF7aRGjmn/4vqme98i4hP+590FIMF+sdyDItVq7/91EAwh7m35dvszkFruIzLgHFRnrKAgG76bTHTz8bwywhnCZVbDmy/HEDOjj2ykW9jPKJ7buKRKVYbXnSgYqkn/keTHiRvLI= From 69a9d4237c41ab79c483bad242541272feb0c100 Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 21 Dec 2018 09:57:24 -0500 Subject: [PATCH 54/59] Test cases: removed userservice check on dockercomposerule initialization --- .../aist/edge/edgeservice/EdgeServiceIntegrationTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 2ec5ed4..62f1695 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -54,8 +54,8 @@ public class EdgeServiceIntegrationTests { .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("userservice", - HealthChecks.toRespondOverHttp(8080, (port) -> port.inFormat("http://$HOST:$EXTERNAL_PORT"))) + //.waitingForService("userservice", + // HealthChecks.toRespondOverHttp(8080, (port) -> port.inFormat("http://$HOST:$EXTERNAL_PORT"))) .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) From cb43eadf1fae44454dd79574e846a954693e0e30 Mon Sep 17 00:00:00 2001 From: jusoto Date: Fri, 21 Dec 2018 10:05:18 -0500 Subject: [PATCH 55/59] Test cases: included debug info with opened ports --- .../EdgeServiceIntegrationTests.java | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 62f1695..24d2a9a 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -254,35 +254,33 @@ public void setUp() throws JSONException, IOException { ////////////////////////////////////////////// - // //List containerList = new ArrayList(); - // Runtime rt = Runtime.getRuntime(); - // - // String[] commands = { "docker", "info" }; - // Process proc = rt.exec(commands); - // - // BufferedReader stdInput = new BufferedReader(new - // InputStreamReader(proc.getInputStream())); - // - // BufferedReader stdError = new BufferedReader(new - // InputStreamReader(proc.getErrorStream())); - // - // // read the output from the command - // System.out.println("***************** Here is the standard output of - // the command:\n"); - // String s = null; - // while ((s = stdInput.readLine()) != null) { - // // containerList.add(s); - // System.out.println(s); - // LOG.info(s); - // } - // - // // read any errors from the attempted command - // System.out.println("***************** Here is the standard error of - // the command (if any):\n"); - // while ((s = stdError.readLine()) != null) { - // System.out.println(s); - // LOG.info(s); - // } + //List containerList = new ArrayList(); + Runtime rt = Runtime.getRuntime(); + + String[] commands = { "netstat", "-an" }; + Process proc = rt.exec(commands); + + BufferedReader stdInput = new BufferedReader(new + InputStreamReader(proc.getInputStream())); + + BufferedReader stdError = new BufferedReader(new + InputStreamReader(proc.getErrorStream())); + + // read the output from the command + System.out.println("****** Here is the standard output of the command:\n"); + String s = null; + while ((s = stdInput.readLine()) != null) { + // containerList.add(s); + System.out.println(s); + LOG.info(s); + } + + // read any errors from the attempted command + System.out.println("****** Here is the standard error of the command (if any):\n"); + while ((s = stdError.readLine()) != null) { + System.out.println(s); + LOG.info(s); + } // // for (String containerId : containerList) { // From bec603c9eb4ba2148da342b5a8b47045ff2271b7 Mon Sep 17 00:00:00 2001 From: jusoto Date: Tue, 29 Jan 2019 17:21:34 -0500 Subject: [PATCH 56/59] Travis: Fix health checks for test cases --- .../EdgeServiceIntegrationTests.java | 208 ++++-------------- src/test/resources/docker-compose.yml | 1 - 2 files changed, 42 insertions(+), 167 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 24d2a9a..a036b17 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -45,187 +45,63 @@ public class EdgeServiceIntegrationTests { private static String gmapsAdapterURL; private static String calculationServiceURL; - // Wait for all services to have ports open + //Wait for all services to have ports open @ClassRule public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) .file("src/test/resources/docker-compose.yml") - .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mysqlserver", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) .waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("userservice", HealthChecks.toHaveAllPortsOpen()) - //.waitingForService("userservice", - // HealthChecks.toRespondOverHttp(8080, (port) -> port.inFormat("http://$HOST:$EXTERNAL_PORT"))) .waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen()) .waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen()) .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()).build(); + .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("discoveryservice", HealthChecks.toRespondOverHttp(8761, + (port) -> port.inFormat("http://$HOST:$EXTERNAL_PORT"))) + .build(); - // Get IP addresses and ports to run tests on + //Get IP addresses and ports to run tests on @BeforeClass - public static void initialize() throws Exception { - + public static void initialize() { LOG.info("Initializing ports from Docker"); + DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd") + .port(8080); + tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), + tripManagementCommand.getExternalPort()); + LOG.info("Trip Command url found: " + tripCommandURL); + + DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery") + .port(8080); + tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(), + tripManagementQuery.getExternalPort()); + LOG.info("Trip Query url found: " + tripQueryURL); + + DockerPort gmapsAdapter = docker.containers().container("gmapsadapter") + .port(8080); + gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), + gmapsAdapter.getExternalPort()); + LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); - Container discoveryContainer = docker.containers().container("discoveryservice"); - DockerPort discoveryPort = discoveryContainer.port(8761); - while (!discoveryPort.isListeningNow()) { - LOG.info("Discovery service didn't respond over HTTP"); - throw new Exception(String.format("Discovery didn't respond, port: %s", discoveryPort.getInternalPort())); - } - LOG.info("Discovery service responded over HTTP"); - - // Container mongoContainer = docker.containers().container("mongo"); - // DockerPort mongoPort = mongoContainer.port(27017); - // mongoURL = String.format("http://%s:%s", mongoPort.getIp(), - // mongoPort.getExternalPort()); - // if(!mongoPort.isListeningNow()){ - // LOG.info("Mongo service didn't respond over HTTP"); - // throw new Exception(String.format("Mongo didn't respond, port: %s", - // mongoPort.getInternalPort())); - // } - // LOG.info("Mongo service responded over HTTP"); - // - // Container userContainer = - // docker.containers().container("userservice"); - DockerPort userPort = docker.containers().container("userservice").port(8080); - userServiceURL = String.format("http://%s:%s", userPort.getIp(), userPort.getExternalPort()); -// if (!userPort.isListeningNow()) { -// LOG.info("User service didn't respond over HTTP"); -// throw new Exception(String.format("User didn't respond, port: %s", userPort.getInternalPort())); -// } -// LOG.info("User service responded over HTTP"); -// LOG.info("Url to be used: %s", userServiceURL); - - while (!docker.containers().container("userservice") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { - LOG.info("Waiting for user service to respond over HTTP"); - } - LOG.info("user service url found: " + userServiceURL); - - // Container tripManagementCmdContainer = - // docker.containers().container("tripmanagementcmd"); - DockerPort tripManagementCmdPort = docker.containers().container("tripmanagementcmd").port(8080); - tripCommandURL = String.format("http://%s:%s", tripManagementCmdPort.getIp(), - tripManagementCmdPort.getExternalPort()); - while (!tripManagementCmdPort.isListeningNow()) { - LOG.info("TripManagementCmd service didn't respond over HTTP"); -// throw new Exception(String.format("TripManagementCmd didn't respond, port: %s", -// tripManagementCmdPort.getInternalPort())); - } - LOG.info("TripManagementCmd service responded over HTTP"); - - // Container tripManagementQueryContainer = - // docker.containers().container("tripmanagementquery"); - DockerPort tripManagementQueryPort = docker.containers().container("tripmanagementquery").port(8080); - tripQueryURL = String.format("http://%s:%s", tripManagementQueryPort.getIp(), - tripManagementQueryPort.getExternalPort()); - while (!tripManagementQueryPort.isListeningNow()) { - LOG.info("TripManagementQuery service didn't respond over HTTP"); -// throw new Exception(String.format("TripManagementQuery didn't respond, port: %s", -// tripManagementQueryPort.getInternalPort())); - } - LOG.info("TripManagementQuery service responded over HTTP"); - // - // Container gmapsAdapterContainer = - // docker.containers().container("gmapsadapter"); - // DockerPort gmapsAdapterPort = gmapsAdapterContainer.port(8080); - // gmapsAdapterURL = String.format("http://%s:%s", - // gmapsAdapterPort.getIp(), - // gmapsAdapterPort.getExternalPort()); - // if(!gmapsAdapterPort.isListeningNow()){ - // LOG.info("Gmaps Adapter service didn't respond over HTTP"); - // throw new Exception(String.format("Gmaps Adapter didn't respond, - // port: %s", gmapsAdapterPort.getInternalPort())); - // } - // LOG.info("Gmaps Adapter service responded over HTTP"); - // - // Container calculationContainer = - // docker.containers().container("calculationservice"); - DockerPort calculationPort = docker.containers().container("calculationservice").port(8080); - calculationServiceURL = String.format("http://%s:%s", calculationPort.getIp(), - calculationPort.getExternalPort()); - while (!calculationPort.isListeningNow()) { - LOG.info("Calculation service didn't respond over HTTP"); -// throw new Exception( -// String.format("Calculation didn't respond, port: %s", calculationPort.getInternalPort())); - } - LOG.info("Calculation service responded over HTTP"); - // - // DockerPort discoveryService = - // docker.containers().container("discoveryservice").port(8761); - // discoveryServiceURL = String.format("http://%s:%s", - // discoveryService.getIp(), - // discoveryService.getExternalPort()); - // while (!docker.containers().container("discoveryservice") - // .portIsListeningOnHttp(8761, (port) -> - // port.inFormat(discoveryServiceURL)).succeeded()) { - // LOG.info("Waiting for discovery service to respond over HTTP"); - // } - // LOG.info("Discovery Service url found: " + discoveryServiceURL); - - DockerPort mongo = docker.containers().container("mongo").port(27017); - mongoURL = String.format("http://%s:%s", mongo.getIp(), mongo.getExternalPort()); - while (!docker.containers().container("mongo").portIsListeningOnHttp(27017, (port) -> port.inFormat(mongoURL)) - .succeeded()) { - LOG.info("Waiting for mongo to respond over HTTP"); + DockerPort calculationService = docker.containers().container("calculationservice") + .port(8080); + calculationServiceURL = String.format("http://%s:%s", calculationService.getIp(), + calculationService.getExternalPort()); + while (!docker.containers().container("calculationservice").portIsListeningOnHttp(8080, + (port) -> port.inFormat(calculationServiceURL)).succeeded()) { + LOG.info("Waiting for calculation service to respond over HTTP"); } - LOG.info("Mongo url found: " + mongoURL); - - // DockerPort userService = - // docker.containers().container("userservice").port(8080); - // userServiceURL = String.format("http://%s:%s", userService.getIp(), - // userService.getExternalPort()); - // while (!docker.containers().container("userservice") - // .portIsListeningOnHttp(8080, (port) -> - // port.inFormat(userServiceURL)).succeeded()) { - // LOG.info("Waiting for user service to respond over HTTP"); - // } - // LOG.info("User Service url found: " + userServiceURL); - - // DockerPort tripManagementCommand = - // docker.containers().container("tripmanagementcmd").port(8080); - // tripCommandURL = String.format("http://%s:%s", - // tripManagementCommand.getIp(), - // tripManagementCommand.getExternalPort()); - // while (!docker.containers().container("tripmanagementcmd") - // .portIsListeningOnHttp(8080, (port) -> - // port.inFormat(tripCommandURL)).succeeded()) { - // LOG.info("Waiting for Trip Command to respond over HTTP"); - // } - // LOG.info("Trip Command url found: " + tripCommandURL); - // - // DockerPort tripManagementQuery = - // docker.containers().container("tripmanagementquery").port(8080); - // tripQueryURL = String.format("http://%s:%s", - // tripManagementQuery.getIp(), - // tripManagementQuery.getExternalPort()); - // while (!docker.containers().container("tripmanagementquery") - // .portIsListeningOnHttp(8080, (port) -> - // port.inFormat(tripQueryURL)).succeeded()) { - // LOG.info("Waiting for Trip Query to respond over HTTP"); - // } - // LOG.info("Trip Query url found: " + tripQueryURL); - - DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); - gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); - while (!docker.containers().container("gmapsadapter") - .portIsListeningOnHttp(8080, (port) -> port.inFormat(gmapsAdapterURL)).succeeded()) { + LOG.info("Calculation Service url found: " + calculationServiceURL); + + DockerPort userService = docker.containers().container("userservice") + .port(8080); + userServiceURL = String.format("http://%s:%s", userService.getIp(), + userService.getExternalPort()); + while (!docker.containers().container("userservice").portIsListeningOnHttp(8080, + (port) -> port.inFormat(userServiceURL)).succeeded()) { LOG.info("Waiting for user service to respond over HTTP"); } - LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); - - // DockerPort calculationService = - // docker.containers().container("calculationservice").port(8080); - // calculationServiceURL = String.format("http://%s:%s", - // calculationService.getIp(), - // calculationService.getExternalPort()); - // while (!docker.containers().container("calculationservice") - // .portIsListeningOnHttp(8080, (port) -> - // port.inFormat(calculationServiceURL)).succeeded()) { - // LOG.info("Waiting for calculation service to respond over HTTP"); - // } - // LOG.info("Calculation Service url found: " + calculationServiceURL); + LOG.info("User Service url found: " + userServiceURL); } private TestRestTemplate restTemplate = new TestRestTemplate(); diff --git a/src/test/resources/docker-compose.yml b/src/test/resources/docker-compose.yml index c96c068..d22af15 100644 --- a/src/test/resources/docker-compose.yml +++ b/src/test/resources/docker-compose.yml @@ -124,7 +124,6 @@ services: - EUREKA_SERVER=discoveryservice - MONGO_HOST=mongo - MONGO_PORT=27017 - command: ["go", "run", "main.go"] ports: - '8080' depends_on: From 1eaa86880243f9dd6672de7962045a2329549fb6 Mon Sep 17 00:00:00 2001 From: jusoto Date: Tue, 29 Jan 2019 17:37:42 -0500 Subject: [PATCH 57/59] Travis: remove health check for port 8761 in test cases --- .../aist/edge/edgeservice/EdgeServiceIntegrationTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index a036b17..c89639a 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -57,8 +57,8 @@ public class EdgeServiceIntegrationTests { .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()) .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("discoveryservice", HealthChecks.toRespondOverHttp(8761, - (port) -> port.inFormat("http://$HOST:$EXTERNAL_PORT"))) +// .waitingForService("discoveryservice", HealthChecks.toRespondOverHttp(8761, +// (port) -> port.inFormat("http://$HOST:$EXTERNAL_PORT"))) .build(); //Get IP addresses and ports to run tests on From 3e47f979660538a5bc2eed2da8ffa772e1007230 Mon Sep 17 00:00:00 2001 From: Juan Date: Mon, 25 Feb 2019 18:12:59 -0500 Subject: [PATCH 58/59] Travis: Pushing files from linux environment --- src/main/resources/application.yml | 29 +++-- .../EdgeServiceIntegrationTests.java | 114 ++++-------------- 2 files changed, 40 insertions(+), 103 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index dc1af40..5ef922a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -4,22 +4,31 @@ spring: application: name: edgeservice zuul: + host: + connect-timeout-millis: 20000 + socket-timeout-millis: 240000 prefix: /api routes: trip-cmd: path: /trip/cmd/** - url: http://${TRIP_CMD_HOST:tripmanagementcmd}:8080/api + url: http://${TRIP_CMD_HOST:tripmanagementcmd}:${TRIP_CMD_PORT:8080}/api trip-query: path: /trip/query/** - url: http://${TRIP_QUERY_HOST:tripmanagementquery}:8080/api + url: http://${TRIP_QUERY_HOST:tripmanagementquery}:${TRIP_QUERY_PORT:8080}/api userservice: - path: /${USER_SERVICE_HOST:userservice}/** - url: http://${USER_SERVICE_HOST:userservice}:8080/ + path: /userservice/** + url: http://${USER_SERVICE_HOST:userservice}:${USER_SERVICE_PORT:8080}/ sensitiveHeaders: Cookie,Set-Cookie + calculation: + path: /calculationservice/** + url: http://${CALCULATION_HOST:calculationservice}:${CALCULATION_PORT:8080}/ + gmapsadapter: + path: /gmapsadapter/** + url: http://${GMAPS_ADAPTER_HOST:gmapsadapter}:${GMAPS_ADAPTER_PORT:8080}/ security: oauth2: resource: - userInfoUri: http://${USER_SERVICE_HOST:userservice}:8080/auth/user + userInfoUri: http://${USER_SERVICE_HOST:userservice}:${USER_SERVICE_PORT:8080}/auth/user ignored: /catalog/** eureka: instance: @@ -28,11 +37,15 @@ eureka: registerWithEureka: true fetchRegistry: true serviceUrl: - defaultZone: http://${EUREKA_SERVER:discoveryservice}:8761/eureka/ + defaultZone: http://${EUREKA_SERVER:discoveryservice}:${EUREKA_PORT:8761}/eureka/ management: security: enabled: false context-path: /actuator +hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000 +ribbon: + ConnectTimeout: 60000 +ReadTimeout: 60000 --- spring: @@ -65,10 +78,6 @@ eureka: fetchRegistry: true serviceUrl: defaultZone: http://discoveryservice:8761/eureka/ -hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000 -ribbon: - ConnectTimeout: 3000 -ReadTimeout: 60000 --- spring: diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index c89639a..36d024a 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -2,12 +2,14 @@ import static org.assertj.core.api.Java6Assertions.assertThat; +import com.palantir.docker.compose.DockerComposeRule; +import com.palantir.docker.compose.connection.DockerPort; +import com.palantir.docker.compose.connection.waiting.HealthChecks; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.util.ArrayList; import java.util.Base64; -import java.util.List; import org.json.JSONException; import org.json.JSONObject; @@ -27,11 +29,6 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import com.palantir.docker.compose.DockerComposeRule; -import com.palantir.docker.compose.connection.Container; -import com.palantir.docker.compose.connection.DockerPort; -import com.palantir.docker.compose.connection.waiting.HealthChecks; - @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) public class EdgeServiceIntegrationTests { @@ -45,7 +42,7 @@ public class EdgeServiceIntegrationTests { private static String gmapsAdapterURL; private static String calculationServiceURL; - //Wait for all services to have ports open + // Wait for all services to have ports open @ClassRule public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true) .file("src/test/resources/docker-compose.yml") @@ -57,48 +54,41 @@ public class EdgeServiceIntegrationTests { .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()) .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) -// .waitingForService("discoveryservice", HealthChecks.toRespondOverHttp(8761, -// (port) -> port.inFormat("http://$HOST:$EXTERNAL_PORT"))) + .waitingForService("discoveryservice", + HealthChecks.toRespondOverHttp(8761, (port) -> port.inFormat("http://$HOST:$EXTERNAL_PORT"))) .build(); - //Get IP addresses and ports to run tests on + // Get IP addresses and ports to run tests on @BeforeClass public static void initialize() { LOG.info("Initializing ports from Docker"); - DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd") - .port(8080); + DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd").port(8080); tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), tripManagementCommand.getExternalPort()); LOG.info("Trip Command url found: " + tripCommandURL); - DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery") - .port(8080); + DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery").port(8080); tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(), tripManagementQuery.getExternalPort()); LOG.info("Trip Query url found: " + tripQueryURL); - DockerPort gmapsAdapter = docker.containers().container("gmapsadapter") - .port(8080); - gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), - gmapsAdapter.getExternalPort()); + DockerPort gmapsAdapter = docker.containers().container("gmapsadapter").port(8080); + gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(), gmapsAdapter.getExternalPort()); LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL); - DockerPort calculationService = docker.containers().container("calculationservice") - .port(8080); + DockerPort calculationService = docker.containers().container("calculationservice").port(8080); calculationServiceURL = String.format("http://%s:%s", calculationService.getIp(), calculationService.getExternalPort()); - while (!docker.containers().container("calculationservice").portIsListeningOnHttp(8080, - (port) -> port.inFormat(calculationServiceURL)).succeeded()) { + while (!docker.containers().container("calculationservice") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(calculationServiceURL)).succeeded()) { LOG.info("Waiting for calculation service to respond over HTTP"); } LOG.info("Calculation Service url found: " + calculationServiceURL); - DockerPort userService = docker.containers().container("userservice") - .port(8080); - userServiceURL = String.format("http://%s:%s", userService.getIp(), - userService.getExternalPort()); - while (!docker.containers().container("userservice").portIsListeningOnHttp(8080, - (port) -> port.inFormat(userServiceURL)).succeeded()) { + DockerPort userService = docker.containers().container("userservice").port(8080); + userServiceURL = String.format("http://%s:%s", userService.getIp(), userService.getExternalPort()); + while (!docker.containers().container("userservice") + .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { LOG.info("Waiting for user service to respond over HTTP"); } LOG.info("User Service url found: " + userServiceURL); @@ -126,70 +116,8 @@ public void setUp() throws JSONException, IOException { HttpEntity request = new HttpEntity<>(body, headers); // when: - ResponseEntity response; - - ////////////////////////////////////////////// - - //List containerList = new ArrayList(); - Runtime rt = Runtime.getRuntime(); - - String[] commands = { "netstat", "-an" }; - Process proc = rt.exec(commands); - - BufferedReader stdInput = new BufferedReader(new - InputStreamReader(proc.getInputStream())); - - BufferedReader stdError = new BufferedReader(new - InputStreamReader(proc.getErrorStream())); - - // read the output from the command - System.out.println("****** Here is the standard output of the command:\n"); - String s = null; - while ((s = stdInput.readLine()) != null) { - // containerList.add(s); - System.out.println(s); - LOG.info(s); - } - - // read any errors from the attempted command - System.out.println("****** Here is the standard error of the command (if any):\n"); - while ((s = stdError.readLine()) != null) { - System.out.println(s); - LOG.info(s); - } - // - // for (String containerId : containerList) { - // - // String[] commands1 = { "docker", "inspect", containerId }; - // Process proc1 = rt.exec(commands1); - // - // BufferedReader stdInput1 = new BufferedReader(new - // InputStreamReader(proc1.getInputStream())); - // - // BufferedReader stdError1 = new BufferedReader(new - // InputStreamReader(proc1.getErrorStream())); - // - // // read the output from the command - // System.out.println("Here is the standard output of the command:\n"); - // String s1 = null; - // while ((s1 = stdInput1.readLine()) != null) { - // System.out.println(s1); - // LOG.info(s1); - // } - // - // // read any errors from the attempted command - // System.out.println("Here is the standard error of the command (if - // any):\n"); - // while ((s1 = stdError1.readLine()) != null) { - // System.out.println(s1); - // LOG.info(s1); - // } - // } - ////////////////////////////////////////////// - - LOG.info(String.format("User Service - Trying url: %s", userServiceURL)); - response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, String.class, parameters); - LOG.info("Request succeded"); + ResponseEntity response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token", request, + String.class, parameters); // then: assertThat(response.getStatusCodeValue()).isEqualTo(200); From 568110727a9f674b1df5b394081103f975186c02 Mon Sep 17 00:00:00 2001 From: Juan Date: Fri, 1 Mar 2019 15:07:31 -0500 Subject: [PATCH 59/59] travis: Added time sleep 20 seconds during test setup to allow pulling images from docker hub --- .gitignore | 3 +- build.gradle | 2 +- src/main/resources/logback-spring.xml | 42 +++++++++++++++++++ .../EdgeServiceIntegrationTests.java | 32 ++++++++++++-- 4 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/logback-spring.xml diff --git a/.gitignore b/.gitignore index 49190b0..e540fda 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,5 @@ nbdist/ \.DS_Store ### Eclipse ### -bin/ \ No newline at end of file +bin/ +logs/ diff --git a/build.gradle b/build.gradle index fbd4b05..272f808 100644 --- a/build.gradle +++ b/build.gradle @@ -56,7 +56,7 @@ dependencies { testCompile('com.jayway.restassured:rest-assured:2.5.0') testCompile ('com.jayway.restassured:spring-mock-mvc:2.5.0') testCompile ('org.springframework.cloud:spring-cloud-starter-contract-stub-runner') - testCompile ('com.palantir.docker.compose:docker-compose-rule-junit4:0.34.0') + testCompile ('com.palantir.docker.compose:docker-compose-rule-junit4:0.35.0') } dependencyManagement { diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..a9b59f3 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,42 @@ + + + + + + + + + + %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable + + + + + + ${LOGS}/spring-boot-logger.log + + %d %p %C{1.} [%t] %m%n + + + + + ${LOGS}/archived/spring-boot-logger-%d{yyyy-MM-dd}.%i.log + + + 10MB + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java index 36d024a..62b900f 100644 --- a/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java +++ b/src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java @@ -10,6 +10,8 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.Base64; +import java.util.concurrent.TimeUnit; +import java.util.logging.FileHandler; import org.json.JSONException; import org.json.JSONObject; @@ -41,6 +43,7 @@ public class EdgeServiceIntegrationTests { private static String tripQueryURL; private static String gmapsAdapterURL; private static String calculationServiceURL; + private static int MAX_HEALTH_CHECK_TRIES = 100000; // value based on local environment time // Wait for all services to have ports open @ClassRule @@ -54,13 +57,14 @@ public class EdgeServiceIntegrationTests { .waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen()) .waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen()) .waitingForService("discoveryservice", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("discoveryservice", - HealthChecks.toRespondOverHttp(8761, (port) -> port.inFormat("http://$HOST:$EXTERNAL_PORT"))) +// .waitingForService("discoveryservice", +// HealthChecks.toRespondOverHttp(8761, (port) -> port.inFormat("http://$HOST:$EXTERNAL_PORT"))) .build(); // Get IP addresses and ports to run tests on @BeforeClass - public static void initialize() { + public static void initialize() throws InterruptedException { + TimeUnit.SECONDS.sleep(20); LOG.info("Initializing ports from Docker"); DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd").port(8080); tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(), @@ -79,19 +83,41 @@ public static void initialize() { DockerPort calculationService = docker.containers().container("calculationservice").port(8080); calculationServiceURL = String.format("http://%s:%s", calculationService.getIp(), calculationService.getExternalPort()); + int tryCount = 0; while (!docker.containers().container("calculationservice") .portIsListeningOnHttp(8080, (port) -> port.inFormat(calculationServiceURL)).succeeded()) { + tryCount++; LOG.info("Waiting for calculation service to respond over HTTP"); + if (tryCount == MAX_HEALTH_CHECK_TRIES) { + LOG.error("Error. Max tries (" + tryCount + + ") for health checks on calculationservice reached.\n Calculation Service needs to register " + + "with Eureka before serving on designated port."); + System.exit(100); + } } LOG.info("Calculation Service url found: " + calculationServiceURL); + LOG.warn("Calculation Service tryCount: " + tryCount); + System.out.println("********************************************"); + System.out.println("Calculation Service tryCount: " + tryCount); + System.out.println("********************************************"); DockerPort userService = docker.containers().container("userservice").port(8080); userServiceURL = String.format("http://%s:%s", userService.getIp(), userService.getExternalPort()); + tryCount = 0; while (!docker.containers().container("userservice") .portIsListeningOnHttp(8080, (port) -> port.inFormat(userServiceURL)).succeeded()) { + tryCount++; LOG.info("Waiting for user service to respond over HTTP"); + if (tryCount == MAX_HEALTH_CHECK_TRIES) { + LOG.error("Error. Max tries (" + tryCount + ") for health checks on userservice reached."); + System.exit(100); + } } LOG.info("User Service url found: " + userServiceURL); + LOG.warn("User Service tryCount: " + tryCount); + System.out.println("********************************************"); + System.out.println("User Service tryCount: " + tryCount); + System.out.println("********************************************"); } private TestRestTemplate restTemplate = new TestRestTemplate();