33import static org .assertj .core .api .Java6Assertions .assertThat ;
44
55import com .palantir .docker .compose .DockerComposeRule ;
6+ import com .palantir .docker .compose .connection .DockerPort ;
67import com .palantir .docker .compose .connection .waiting .HealthChecks ;
78
89import java .util .*;
910
1011import org .json .JSONException ;
1112import org .json .JSONObject ;
1213import org .junit .Before ;
14+ import org .junit .BeforeClass ;
1315import org .junit .ClassRule ;
1416import org .junit .Test ;
1517import org .junit .runner .RunWith ;
1618
19+ import org .slf4j .Logger ;
20+ import org .slf4j .LoggerFactory ;
1721import org .springframework .boot .test .context .SpringBootTest ;
1822import org .springframework .boot .test .web .client .TestRestTemplate ;
1923import org .springframework .http .*;
2327@ RunWith (SpringJUnit4ClassRunner .class )
2428@ SpringBootTest (classes = EdgeServiceApplication .class , webEnvironment = SpringBootTest .WebEnvironment .DEFINED_PORT )
2529public class EdgeServiceIntegrationTests {
30+ protected static final Logger LOG = LoggerFactory .getLogger (EdgeServiceIntegrationTests .class );
2631
32+ private static String tripCommandURL ;
33+ private static String tripQueryURL ;
34+ private static String gmapsAdapterURL ;
35+ private static String calculationServiceURL ;
36+ // private static String userServiceEndpoint;
37+
38+ //Wait for all services to have ports open
2739 @ ClassRule
2840 public static DockerComposeRule docker = DockerComposeRule .builder ().pullOnStartup (true )
2941 .file ("src/test/resources/docker-compose.yml" )
30- .waitingForService ("microservice--user-service" , HealthChecks .toHaveAllPortsOpen ())
31- .waitingForService ("microservice--user-service" , HealthChecks .toRespondOverHttp (8091 ,
32- (port ) -> port .inFormat ("http://localhost:8091" )))
33- .waitingForService ("trip-management-cmd" , HealthChecks .toHaveAllPortsOpen ())
34- .waitingForService ("trip-management-cmd" , HealthChecks .toRespondOverHttp (8080 ,
35- (port ) -> port .inFormat ("http://localhost:8092" )))
36- .waitingForService ("trip-management-query" , HealthChecks .toHaveAllPortsOpen ())
37- .waitingForService ("trip-management-query" , HealthChecks .toRespondOverHttp (8080 ,
38- (port ) -> port .inFormat ("http://localhost:8093" )))
42+ .waitingForService ("userservice" , HealthChecks .toHaveAllPortsOpen ())
43+ .waitingForService ("tripmanagementcmd" , HealthChecks .toHaveAllPortsOpen ())
44+ .waitingForService ("tripmanagementquery" , HealthChecks .toHaveAllPortsOpen ())
45+ .waitingForService ("gmapsadapter" , HealthChecks .toHaveAllPortsOpen ())
46+ .waitingForService ("calculationservice" , HealthChecks .toHaveAllPortsOpen ())
3947 .waitingForService ("discovery-service" , HealthChecks .toHaveAllPortsOpen ())
48+ .waitingForService ("userservice" , HealthChecks .toRespondOverHttp (8091 ,
49+ (port ) -> port .inFormat ("http://localhost:8091" )))
4050 .waitingForService ("discovery-service" , HealthChecks .toRespondOverHttp (8761 ,
41- (port ) -> port .inFormat ("http://localhost:8761" )))
51+ (port ) -> port .inFormat ("http://localhost:8761" )))
4252 .build ();
4353
54+ //Get IP addresses and ports to run tests on
55+ @ BeforeClass
56+ public static void initialize () {
57+ LOG .info ("Initializing ports from Docker" );
58+ DockerPort tripManagementCommand = docker .containers ().container ("tripmanagementcmd" )
59+ .port (8080 );
60+ tripCommandURL = String .format ("http://%s:%s" , tripManagementCommand .getIp (),
61+ tripManagementCommand .getExternalPort ());
62+ LOG .info ("Trip Command endpoint found: " + tripCommandURL );
63+
64+ DockerPort tripManagementQuery = docker .containers ().container ("tripmanagementquery" )
65+ .port (8080 );
66+ tripQueryURL = String .format ("http://%s:%s" , tripManagementQuery .getIp (),
67+ tripManagementQuery .getExternalPort ());
68+ LOG .info ("Trip Query endpoint found: " + tripQueryURL );
69+
70+ DockerPort gmapsAdapter = docker .containers ().container ("gmapsadapter" )
71+ .port (8080 );
72+ gmapsAdapterURL = String .format ("http://%s:%s" , gmapsAdapter .getIp (),
73+ gmapsAdapter .getExternalPort ());
74+ LOG .info ("Gmaps Adapter endpoint found: " + gmapsAdapterURL );
75+
76+ DockerPort calculationService = docker .containers ().container ("calculationservice" )
77+ .port (8080 );
78+ calculationServiceURL = String .format ("http://%s:%s" , calculationService .getIp (),
79+ calculationService .getExternalPort ());
80+ LOG .info ("Calculation Service endpoint found: " + calculationServiceURL );
81+
82+ // DockerPort userService = docker.containers().container("userservice")
83+ // .port(8091);
84+ // userServiceEndpoint = String.format("http://%s:%s", userService.getIp(),
85+ // userService.getExternalPort());
86+ // LOG.info("User Service Endpoint found: " + userServiceEndpoint);
87+ }
88+
4489 private TestRestTemplate restTemplate = new TestRestTemplate ();
4590
4691 private String token ;
@@ -83,10 +128,10 @@ public void tripCommandPOSTRequestSuccess() {
83128 HttpEntity <String > request = new HttpEntity <>(body , headers );
84129
85130 //when:
86- ResponseEntity <String > response = restTemplate .postForEntity ("http://localhost:8092/ api/trip" , request , String .class );
131+ ResponseEntity <String > response = restTemplate .postForEntity (tripCommandURL + "/ api/v1 /trip" , request , String .class );
87132
88133 //then:
89- assertThat (response .getStatusCodeValue ()).isEqualTo (200 );
134+ assertThat (response .getStatusCodeValue ()).isEqualTo (201 );
90135 }
91136
92137 @ Test
@@ -96,7 +141,7 @@ public void tripQueryGETRequestSuccess() {
96141 headers .add ("Authorization" , "Bearer " + token );
97142
98143 //when:
99- ResponseEntity <String > response = restTemplate .getForEntity ("http://localhost:8093/ api/trips" , String .class );
144+ ResponseEntity <String > response = restTemplate .getForEntity (tripQueryURL + "/ api/v1 /trips" , String .class );
100145
101146 //then:
102147 assertThat (response .getStatusCodeValue ()).isEqualTo (200 );
0 commit comments