-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from aguibert/hollowMode-mpRestClient
Do not translate MP Rest Client vars if running in non-Testcontainer mode
- Loading branch information
Showing
9 changed files
with
214 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...src/integrationTest/java/org/microshed/testing/testcontainers/ApplicationContainerIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2019 IBM Corporation and others | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.microshed.testing.testcontainers; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.nio.file.Paths; | ||
import java.util.Map; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ApplicationContainerIT { | ||
|
||
// Base uri configured with: com_example_StringRestClient_mp_rest_url | ||
@RegisterRestClient | ||
public static class SampleRestClient1 { | ||
} | ||
|
||
// Base uri configured with: rc_config_key_mp_rest_url | ||
@RegisterRestClient(configKey = "rc-config-key") | ||
public static class SampleRestClient2 { | ||
} | ||
|
||
// Base uri configured with: CLIENT_CONFIG_KEY_mp_rest_url | ||
@RegisterRestClient(configKey = "CLIENT_CONFIG_KEY") | ||
public static class SampleRestClient3 { | ||
} | ||
|
||
@Test | ||
public void testMpRestClient() { | ||
final String clientUrl = "http://example.com"; | ||
|
||
@SuppressWarnings("resource") | ||
ApplicationContainer app = new ApplicationContainer(Paths.get("src", "integrationTest", "resources", "Dockerfile")) | ||
.withMpRestClient("com.example.StringRestClient", clientUrl) | ||
.withMpRestClient(SampleRestClient1.class, clientUrl) | ||
.withMpRestClient(SampleRestClient2.class, clientUrl) | ||
.withMpRestClient(SampleRestClient3.class, clientUrl); | ||
|
||
Map<String, String> appEnv = app.getEnvMap(); | ||
assertEquals(clientUrl, appEnv.get("com_example_StringRestClient_mp_rest_url")); | ||
assertEquals(clientUrl, appEnv.get("org_microshed_testing_testcontainers_ApplicationContainerIT_SampleRestClient1_mp_rest_url")); | ||
assertEquals(clientUrl, appEnv.get("rc_config_key_mp_rest_url")); | ||
assertEquals(clientUrl, appEnv.get("CLIENT_CONFIG_KEY_mp_rest_url")); | ||
} | ||
|
||
@Test | ||
public void testCorrectServerAdapter() { | ||
@SuppressWarnings("resource") | ||
ApplicationContainer app = new ApplicationContainer(Paths.get("src", "integrationTest", "resources", "Dockerfile")); | ||
assertEquals("org.microshed.testing.testcontainers.ApplicationContainer.DefaultServerAdapter", app.getServerAdapter().getClass().getCanonicalName()); | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
...nTest/java/org/microshed/testing/testcontainers/config/TestcontainersConfigurationIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (c) 2019 IBM Corporation and others | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.microshed.testing.testcontainers.config; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.nio.file.Paths; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.microshed.testing.ApplicationEnvironment; | ||
import org.microshed.testing.jupiter.MicroShedTest; | ||
import org.microshed.testing.testcontainers.ApplicationContainer; | ||
import org.testcontainers.containers.MockServerContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
|
||
@MicroShedTest | ||
public class TestcontainersConfigurationIT { | ||
|
||
@Container | ||
public static ApplicationContainer app = new ApplicationContainer(Paths.get("src", "integrationTest", "resources", "Dockerfile")) | ||
.withEnv("SVC_HOST", "mockserver") | ||
.withEnv("SVC_PORT", "1080") | ||
.withEnv("SVC_URL1", "mockserver") | ||
.withEnv("SVC_URL2", "mockserver:1080") | ||
.withEnv("SVC_URL3", "http://mockserver:1080") | ||
.withEnv("SVC_URL4", "http://mockserver:1080/hello/world") | ||
.withEnv("SVC_URL5", "http://mockserver:1080/hello/mockserver") | ||
.withEnv("SVC_URL6", oldValue -> "http://mockserver:1080") | ||
.withMpRestClient("com.foo.ExampleClass", "http://mockserver:1080"); | ||
|
||
@Container | ||
public static MockServerContainer mockServer = new MockServerContainer() | ||
.withNetworkAliases("mockserver") | ||
.withEnv("STAYS_UNCHANGED", "mockserver"); | ||
|
||
@Test | ||
public void testCorrectEnvironment() { | ||
assertEquals(TestcontainersConfiguration.class, ApplicationEnvironment.load().getClass()); | ||
assertTrue(ApplicationEnvironment.isSelected(TestcontainersConfiguration.class), | ||
"Expected TestcontainersConfiguration to be selected but it was not"); | ||
} | ||
|
||
@Test | ||
public void testExposedPort() { | ||
assertTrue(app.getMappedPort(9080) != 9080, "Port 9080 should have been mapped to a random port but was not"); | ||
assertTrue(mockServer.getMappedPort(1080) != 1080, "Port 9080 should have been mapped to a random port but was not"); | ||
} | ||
|
||
@Test | ||
public void testApplicationURL() { | ||
String appUrl = ApplicationEnvironment.load().getApplicationURL(); | ||
assertNotNull(appUrl); | ||
assertEquals(appUrl, app.getApplicationURL()); | ||
assertTrue(appUrl.startsWith("http://"), "Application URL did not start with 'http://' " + appUrl); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
modules/testcontainers/src/integrationTest/resources/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FROM openliberty/open-liberty:full-java8-openj9-ubi |
8 changes: 8 additions & 0 deletions
8
modules/testcontainers/src/integrationTest/resources/log4j.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
log4j.rootLogger=INFO, stdout | ||
|
||
log4j.appender=org.apache.log4j.ConsoleAppender | ||
log4j.appender.layout=org.apache.log4j.PatternLayout | ||
|
||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender | ||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.stdout.layout.ConversionPattern=%r %p %c %x - %m%n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters