Skip to content

Commit

Permalink
System.properties not recognized if set in Test Resource #2572
Browse files Browse the repository at this point in the history
  • Loading branch information
zbendhiba committed May 11, 2021
1 parent 0eb7619 commit a22c165
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -135,8 +136,8 @@ public void testAQLQuery() {

@BeforeAll
public static void setup() {
String host = System.getProperty("camel.arangodb.host");
Integer port = Integer.valueOf(System.getProperty("camel.arangodb.port"));
String host = ConfigProvider.getConfig().getValue("camel.arangodb.host", String.class);
Integer port = ConfigProvider.getConfig().getValue("camel.arangodb.port", Integer.class);
arangoDb = new ArangoDB.Builder().host(host, port).build();
arangoDb.createDatabase(DATABASE_NAME);
ArangoDatabase arangoDatabase = arangoDb.db(DATABASE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.camel.quarkus.component.as2.it.transport.Request;
import org.apache.camel.quarkus.component.as2.it.transport.ServerResult;
import org.apache.http.protocol.HttpCoreContext;
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;

@Path("/as2")
Expand Down Expand Up @@ -117,14 +118,14 @@ public ServerResult server() throws Exception {

private String getServerEndpoint() {
String url = String.format("as2://server/listen?serverPortNumber=%s&clientFqdn=%s&requestUriPattern=/",
System.getProperty(SERVER_PORT_PARAMETER), "example.com");
ConfigProvider.getConfig().getValue(SERVER_PORT_PARAMETER, String.class), "example.com");

return url;
}

private String getClientEndpoint() {
String url = String.format("as2://client/send?inBody=ediMessage&targetPortNumber=%s&targetHostname=%s",
System.getProperty(CLIENT_PORT_PARAMETER), "localhost");
ConfigProvider.getConfig().getValue(CLIENT_PORT_PARAMETER, String.class), "localhost");

return url;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.camel.quarkus.component.as2.it.transport.Request;
import org.apache.camel.quarkus.component.as2.it.transport.ServerResult;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
Expand Down Expand Up @@ -63,7 +64,7 @@ public void serverPlainTest() throws Exception {

//create client for sending message to server
As2Sender.As2SenderClient client = As2Sender
.createClient(Integer.parseInt(System.getProperty(As2Resource.SERVER_PORT_PARAMETER)));
.createClient(ConfigProvider.getConfig().getValue(As2Resource.SERVER_PORT_PARAMETER, Integer.class));

//send message to server
client.sendMessage(As2Helper.EDI_MESSAGE);
Expand Down Expand Up @@ -101,7 +102,7 @@ private ClientResult clientTest(Request request) throws Exception {

//start server (not component)
As2Receiver.RequestHandler requestHandler = As2Receiver
.startReceiver(Integer.parseInt(System.getProperty(As2Resource.CLIENT_PORT_PARAMETER)));
.startReceiver(ConfigProvider.getConfig().getValue(As2Resource.CLIENT_PORT_PARAMETER, Integer.class));

//send message by component (as client)
ClientResult clientResult = RestAssured.given() //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.camel.quarkus.component.avro.rpc.it.specific.generated.KeyValueProtocol;
import org.apache.camel.quarkus.component.avro.rpc.it.specific.generated.Value;
import org.apache.camel.quarkus.component.avro.rpc.it.specific.impl.KeyValueProtocolImpl;
import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -160,11 +161,13 @@ void initReflectRequestor() throws IOException {
if (isHttp()) {
reflectTransceiver = new HttpTransceiver(
new URL("http://localhost:"
+ System.getProperty(AvroRpcResource.REFLECTIVE_HTTP_TRANSCEIVER_PORT_PARAM)));
+ ConfigProvider.getConfig().getValue(AvroRpcResource.REFLECTIVE_HTTP_TRANSCEIVER_PORT_PARAM,
String.class)));
} else {
reflectTransceiver = new NettyTransceiver(
new InetSocketAddress("localhost",
Integer.parseInt(System.getProperty(AvroRpcResource.REFLECTIVE_NETTY_TRANSCEIVER_PORT_PARAM))));
ConfigProvider.getConfig().getValue(AvroRpcResource.REFLECTIVE_NETTY_TRANSCEIVER_PORT_PARAM,
Integer.class)));
}
reflectRequestor = new ReflectRequestor(TestReflection.class, reflectTransceiver);
}
Expand All @@ -175,11 +178,13 @@ void initSpecificRequestor() throws IOException {
if (isHttp()) {
specificTransceiver = new HttpTransceiver(
new URL("http://localhost:"
+ System.getProperty(AvroRpcResource.SPECIFIC_HTTP_TRANSCEIVER_PORT_PARAM)));
+ ConfigProvider.getConfig().getValue(AvroRpcResource.SPECIFIC_HTTP_TRANSCEIVER_PORT_PARAM,
String.class)));
} else {
specificTransceiver = new NettyTransceiver(
new InetSocketAddress("localhost",
Integer.parseInt(System.getProperty(AvroRpcResource.SPECIFIC_NETTY_TRANSCEIVER_PORT_PARAM))));
ConfigProvider.getConfig().getValue(AvroRpcResource.SPECIFIC_NETTY_TRANSCEIVER_PORT_PARAM,
Integer.class)));
}
specificRequestor = new SpecificRequestor(KeyValueProtocol.class, specificTransceiver);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.Exchange;
import org.apache.camel.FluentProducerTemplate;
import org.eclipse.microprofile.config.inject.ConfigProperty;

@Path("/cassandraql")
@ApplicationScoped
public class CassandraqlResource {
public static final String DB_URL_PARAMETER = CassandraqlResource.class.getSimpleName() + "_db_url";
public static final String KEYSPACE = "test";
public static final String EMPTY_LIST = "EMPTY";

Expand All @@ -46,6 +46,9 @@ public class CassandraqlResource {
@Inject
ConsumerTemplate consumerTemplate;

@ConfigProperty(name = "db.cassandra.url")
String dbUrl;

@Path("/insertEmployee")
@POST
@Consumes(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -92,8 +95,7 @@ public void deleteEmplyeeById(String id) throws Exception {
}

private String createUrl(String cql) {
String url = System.getProperty(DB_URL_PARAMETER);
return String.format("cql://%s/%s?cql=%s", url, KEYSPACE, cql);
return String.format("cql://%s/%s?cql=%s", dbUrl, KEYSPACE, cql);
}

private String convertBodyToString(Object body) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Map<String, String> start() {
initDB((CassandraContainer) container);

return CollectionHelper.mapOf(
CassandraqlResource.DB_URL_PARAMETER,
"db.cassandra.url",
container.getContainerIpAddress() + ":" + container.getMappedPort(PORT));

} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
Expand Down Expand Up @@ -56,7 +57,7 @@ public void basicProducer(String component) {
@ParameterizedTest
@ValueSource(strings = { "ahc", "http", "netty-http", "vertx-http" })
public void httpsProducer(String component) {
final int port = Integer.getInteger("camel.netty-http.https-test-port");
final int port = ConfigProvider.getConfig().getValue("camel.netty-http.https-test-port", Integer.class);

RestAssured
.given()
Expand All @@ -69,7 +70,7 @@ public void httpsProducer(String component) {

@Test
public void basicNettyHttpServer() throws Exception {
final int port = Integer.getInteger("camel.netty-http.test-port");
final int port = ConfigProvider.getConfig().getValue("camel.netty-http.test-port", Integer.class);

RestAssured
.given()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.inject.Named;

import io.minio.MinioClient;
import org.eclipse.microprofile.config.ConfigProvider;

public class MinioClientProducer {

Expand All @@ -29,8 +30,8 @@ public class MinioClientProducer {
@Named("minioClient")
public MinioClient produceMinioClient() {
return MinioClient.builder()
.endpoint("http://" + System.getProperty(MinioResource.PARAM_SERVER_HOST),
Integer.parseInt(System.getProperty(MinioResource.PARAM_SERVER_PORT)), false)
.endpoint("http://" + ConfigProvider.getConfig().getValue("minio.server.host", String.class),
ConfigProvider.getConfig().getValue("minio.server.port", Integer.class), false)
.credentials(MinioResource.SERVER_ACCESS_KEY, MinioResource.SERVER_SECRET_KEY)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
import java.util.Map;
import java.util.Set;

import javax.enterprise.context.ApplicationScoped;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.eclipse.microprofile.config.spi.ConfigSourceProvider;

@ApplicationScoped
public class MinioConfigProvider implements ConfigSourceProvider {

private final MinioConfig minioConfig = new MinioConfig();
Expand All @@ -35,10 +39,15 @@ public Iterable<ConfigSource> getConfigSources(ClassLoader forClassLoader) {

private static final class MinioConfig implements ConfigSource {

@ConfigProperty(name = "minio.server.host")
String host;

@ConfigProperty(name = "minio.server.port")
String port;

private final Map<String, String> values = new HashMap<String, String>() {
{
put("quarkus.minio.url", String.format("http://%s:%s", System.getProperty(MinioResource.PARAM_SERVER_HOST),
System.getProperty(MinioResource.PARAM_SERVER_PORT)));
put("quarkus.minio.url", String.format("http://%s:%s", host, port));
put("quarkus.minio.access-key", MinioResource.SERVER_ACCESS_KEY);
put("quarkus.minio.secret-key", MinioResource.SERVER_SECRET_KEY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public class MinioResource {

public static final String SERVER_ACCESS_KEY = "testAccessKey";
public static final String SERVER_SECRET_KEY = "testSecretKey";
public static final String PARAM_SERVER_HOST = MinioResource.class.getSimpleName() + "_serverHost";
public static final String PARAM_SERVER_PORT = MinioResource.class.getSimpleName() + "_serverPort";

@Inject
ProducerTemplate producerTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ public class MinioTestResource implements QuarkusTestResourceLifecycleManager {
public Map<String, String> start() {
minioServer.start();

String port = minioServer.getMappedPort(BROKER_PORT) + "";
String host = minioServer.getHost();

return CollectionHelper.mapOf(
MinioResource.PARAM_SERVER_PORT, minioServer.getMappedPort(BROKER_PORT) + "",
MinioResource.PARAM_SERVER_HOST, minioServer.getHost());
"minio.server.host", host,
"minio.server.port", port);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -30,7 +31,7 @@ class SapNetweaverTest {

@Test
public void testSapNetweaverJson() {
final int port = Integer.getInteger("camel.netty.test-port");
final int port = ConfigProvider.getConfig().getValue("camel.netty.test-port", Integer.class);
RestAssured.given()
.queryParam("test-port", port)
.get("/sap-netweaver/json")
Expand All @@ -41,7 +42,7 @@ public void testSapNetweaverJson() {

@Test
public void testSapNetweaverXml() {
final int port = Integer.getInteger("camel.netty.test-port");
final int port = ConfigProvider.getConfig().getValue("camel.netty.test-port", Integer.class);
String body = RestAssured.given()
.queryParam("test-port", port)
.get("/sap-netweaver/xml")
Expand Down

0 comments on commit a22c165

Please sign in to comment.