77import java .io .InputStreamReader ;
88import java .net .HttpURLConnection ;
99import java .net .URL ;
10+ import java .net .URLDecoder ;
11+ import java .nio .charset .StandardCharsets ;
1012
1113import org .junit .ClassRule ;
1214import org .junit .Test ;
@@ -16,15 +18,29 @@ public class DockerComposeContainerLiveTest {
1618
1719 @ ClassRule
1820 public static DockerComposeContainer compose =
19- new DockerComposeContainer (
20- new File ("src/test/resources/test-compose.yml" ))
21- .withExposedService ("simpleWebServer_1" , 80 );
21+ new DockerComposeContainer (getDockerComposeFile ())
22+ .withExposedService ("simpleWebServer" , 80 );
23+
24+ private static File getDockerComposeFile () {
25+ try {
26+ URL resource = DockerComposeContainerLiveTest .class
27+ .getClassLoader ()
28+ .getResource ("test-compose.yml" );
29+ if (resource == null ) {
30+ throw new IllegalStateException ("test-compose.yml not found in resources" );
31+ }
32+ String filePath = URLDecoder .decode (resource .getFile (), StandardCharsets .UTF_8 );
33+ return new File (filePath );
34+ } catch (Exception e ) {
35+ throw new IllegalStateException ("Failed to load test-compose.yml" , e );
36+ }
37+ }
2238
2339 @ Test
2440 public void givenSimpleWebServerContainer_whenGetReuqest_thenReturnsResponse ()
2541 throws Exception {
26- String address = "http://" + compose .getServiceHost ("simpleWebServer_1 " , 80 )
27- + ":" + compose .getServicePort ("simpleWebServer_1 " , 80 );
42+ String address = "http://" + compose .getServiceHost ("simpleWebServer " , 80 )
43+ + ":" + compose .getServicePort ("simpleWebServer " , 80 );
2844 String response = simpleGetRequest (address );
2945
3046 assertEquals (response , "Hello World!" );
0 commit comments