1+ /*
2+ * Copyright (c) 2019 IBM Corporation and others
3+ *
4+ * See the NOTICE file(s) distributed with this work for additional
5+ * information regarding copyright ownership.
6+ *
7+ * Licensed under the Apache License, Version 2.0 (the "License");
8+ * You may not use this file except in compliance with the License.
9+ * You may obtain a copy of the License at
10+ *
11+ * http://www.apache.org/licenses/LICENSE-2.0
12+ *
13+ * Unless required by applicable law or agreed to in writing, software
14+ * distributed under the License is distributed on an "AS IS" BASIS,
15+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+ * See the License for the specific language governing permissions and
17+ * limitations under the License.
18+ */
19+ package org .microshed .testing .testcontainers .config ;
20+
21+ import static org .junit .jupiter .api .Assertions .assertEquals ;
22+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
23+ import static org .junit .jupiter .api .Assertions .assertTrue ;
24+
25+ import java .nio .file .Paths ;
26+
27+ import org .junit .jupiter .api .Test ;
28+ import org .microshed .testing .ApplicationEnvironment ;
29+ import org .microshed .testing .jupiter .MicroShedTest ;
30+ import org .microshed .testing .testcontainers .ApplicationContainer ;
31+ import org .testcontainers .containers .MockServerContainer ;
32+ import org .testcontainers .junit .jupiter .Container ;
33+
34+ @ MicroShedTest
35+ public class TestcontainersConfigurationIT {
36+
37+ @ Container
38+ public static ApplicationContainer app = new ApplicationContainer (Paths .get ("src" , "integrationTest" , "resources" , "Dockerfile" ))
39+ .withEnv ("SVC_HOST" , "mockserver" )
40+ .withEnv ("SVC_PORT" , "1080" )
41+ .withEnv ("SVC_URL1" , "mockserver" )
42+ .withEnv ("SVC_URL2" , "mockserver:1080" )
43+ .withEnv ("SVC_URL3" , "http://mockserver:1080" )
44+ .withEnv ("SVC_URL4" , "http://mockserver:1080/hello/world" )
45+ .withEnv ("SVC_URL5" , "http://mockserver:1080/hello/mockserver" )
46+ .withEnv ("SVC_URL6" , oldValue -> "http://mockserver:1080" )
47+ .withMpRestClient ("com.foo.ExampleClass" , "http://mockserver:1080" );
48+
49+ @ Container
50+ public static MockServerContainer mockServer = new MockServerContainer ()
51+ .withNetworkAliases ("mockserver" )
52+ .withEnv ("STAYS_UNCHANGED" , "mockserver" );
53+
54+ @ Test
55+ public void testCorrectEnvironment () {
56+ assertEquals (TestcontainersConfiguration .class , ApplicationEnvironment .load ().getClass ());
57+ assertTrue (ApplicationEnvironment .isSelected (TestcontainersConfiguration .class ),
58+ "Expected TestcontainersConfiguration to be selected but it was not" );
59+ }
60+
61+ @ Test
62+ public void testExposedPort () {
63+ assertTrue (app .getMappedPort (9080 ) != 9080 , "Port 9080 should have been mapped to a random port but was not" );
64+ assertTrue (mockServer .getMappedPort (1080 ) != 1080 , "Port 9080 should have been mapped to a random port but was not" );
65+ }
66+
67+ @ Test
68+ public void testApplicationURL () {
69+ String appUrl = ApplicationEnvironment .load ().getApplicationURL ();
70+ assertNotNull (appUrl );
71+ assertEquals (appUrl , app .getApplicationURL ());
72+ assertTrue (appUrl .startsWith ("http://" ), "Application URL did not start with 'http://' " + appUrl );
73+ }
74+
75+ }
0 commit comments