Skip to content

Commit

Permalink
System.properties not recognized if set in Test Resource apache#2572
Browse files Browse the repository at this point in the history
  • Loading branch information
zbendhiba authored and ppalaga committed May 24, 2021
1 parent 43d6d45 commit 8d4aad6
Show file tree
Hide file tree
Showing 42 changed files with 207 additions and 124 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Empty partial for a Camel bit unsupported by Camel Quarkus to avoid warnings when this file is included from a Camel page
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
import org.apache.camel.quarkus.test.mock.backend.MockBackendUtils;
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;

import static com.github.tomakehurst.wiremock.client.WireMock.recordSpec;
Expand Down Expand Up @@ -175,8 +176,7 @@ protected boolean envVarsPresent(String... envVarNames) {
* Get the value of a given environment variable or a default value if it does not exist
*/
protected String envOrDefault(String envVarName, String defaultValue) {
String value = System.getenv(envVarName);
return value != null ? value : defaultValue;
return ConfigProvider.getConfig().getOptionalValue(envVarName, String.class).orElse(defaultValue);
}

/**
Expand Down
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 @@ -21,6 +21,7 @@
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.Exchange;
import org.apache.camel.component.debezium.DebeziumConstants;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.inject.ConfigProperty;

/**
Expand All @@ -37,6 +38,9 @@ public abstract class AbstractDebeziumResource {
@Inject
ConsumerTemplate consumerTemplate;

@Inject
Config config;

public AbstractDebeziumResource(Type type) {
this.type = type;
}
Expand Down Expand Up @@ -87,12 +91,12 @@ public String receiveEmptyMessages() {

private Exchange receiveAsExchange() {
String endpoint = getEndpoinUrl(
System.getProperty(type.getPropertyHostname()),
System.getProperty(type.getPropertyPort()),
System.getProperty(type.getPropertyUsername()),
System.getProperty(type.getPropertyPassword()),
config.getValue(type.getPropertyHostname(), String.class),
config.getValue(type.getPropertyPort(), String.class),
config.getValue(type.getPropertyUsername(), String.class),
config.getValue(type.getPropertyPassword(), String.class),
"qa",
System.getProperty(type.getPropertyOffsetFileName()));
config.getValue(type.getPropertyOffsetFileName(), String.class));
return consumerTemplate.receive(endpoint, TIMEOUT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@
package org.apache.camel.quarkus.component.debezium.common.it;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.config.Config;

@Path("/debezium-mongodb")
@ApplicationScoped
public class DebeziumMongodbResource extends AbstractDebeziumResource {

@Inject
Config config;

public DebeziumMongodbResource() {
super(Type.mongodb);
}
Expand Down Expand Up @@ -61,8 +67,8 @@ String getEndpoinUrl(String hostname, String port, String username, String passw
String offsetStorageFileName) {
return Type.mongodb.getComponent() + ":localhost?"
+ "offsetStorageFileName=" + offsetStorageFileName
+ "&mongodbUser=" + System.getProperty(Type.mongodb.getPropertyUsername())
+ "&mongodbPassword=" + System.getProperty(Type.mongodb.getPropertyPassword())
+ "&mongodbUser=" + config.getValue(Type.mongodb.getPropertyUsername(), String.class)
+ "&mongodbPassword=" + config.getValue(Type.mongodb.getPropertyPassword(), String.class)
+ "&mongodbName=docker-rs"
+ "&mongodbHosts=" + hostname + ":" + port;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
package org.apache.camel.quarkus.component.debezium.common.it;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.config.Config;

@Path("/debezium-mysql")
@ApplicationScoped
public class DebeziumMysqlResource extends AbstractDebeziumResource {
Expand All @@ -32,6 +35,9 @@ public class DebeziumMysqlResource extends AbstractDebeziumResource {
//debezium on mysql needs more privileges, therefore it will use root user
public static final String DB_ROOT_USERNAME = "root";

@Inject
Config config;

public DebeziumMysqlResource() {
super(Type.mysql);
}
Expand All @@ -58,6 +64,6 @@ String getEndpoinUrl(String hostname, String port, String username, String passw
return super.getEndpoinUrl(hostname, port, DB_ROOT_USERNAME, password, databaseServerName, offsetStorageFileName)
//and add specific parameters
+ "&databaseServerId=223344"
+ "&databaseHistoryFileFilename=" + System.getProperty(PROPERTY_DB_HISTORY_FILE);
+ "&databaseHistoryFileFilename=" + config.getValue(PROPERTY_DB_HISTORY_FILE, String.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
package org.apache.camel.quarkus.component.debezium.common.it;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.config.Config;

@Path("/debezium-sqlserver")
@ApplicationScoped
public class DebeziumSqlserverResource extends AbstractDebeziumResource {
Expand All @@ -31,6 +34,9 @@ public class DebeziumSqlserverResource extends AbstractDebeziumResource {

public static final String DB_NAME = "testDB";

@Inject
Config config;

public DebeziumSqlserverResource() {
super(Type.sqlserver);
}
Expand Down Expand Up @@ -59,6 +65,6 @@ String getEndpoinUrl(String hostname, String port, String username, String passw
String offsetStorageFileName) {
return super.getEndpoinUrl(hostname, port, username, password, databaseServerName, offsetStorageFileName)
+ "&databaseDbname=" + DB_NAME
+ "&databaseHistoryFileFilename=" + System.getProperty(PROPERTY_DB_HISTORY_FILE);
+ "&databaseHistoryFileFilename=" + config.getValue(PROPERTY_DB_HISTORY_FILE, String.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
## ---------------------------------------------------------------------------

#sql docker container's security is enabled
quarkus.ssl.native=true
quarkus.ssl.native=true
quarkus.test.flat-class-path=true
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Optional;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
Expand All @@ -29,6 +30,8 @@
import org.apache.camel.quarkus.component.debezium.common.it.AbstractDebeziumTest;
import org.apache.camel.quarkus.component.debezium.common.it.Type;
import org.bson.Document;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -62,10 +65,12 @@ public DebeziumMongodbTest() {

@BeforeAll
public static void setUp() throws SQLException {
final String mongoUrl = System.getProperty(Type.mongodb.getPropertyJdbc());
Config config = ConfigProvider.getConfig();

if (mongoUrl != null) {
mongoClient = MongoClients.create(mongoUrl);
final Optional<String> mongoUrl = config.getOptionalValue(Type.mongodb.getPropertyJdbc(), String.class);

if (mongoUrl.isPresent()) {
mongoClient = MongoClients.create(mongoUrl.get());
} else {
LOG.warn("Container is not running. Connection is not created.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Optional;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import org.apache.camel.quarkus.component.debezium.common.it.AbstractDebeziumTest;
import org.apache.camel.quarkus.component.debezium.common.it.Type;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -49,10 +52,11 @@ public DebeziumMysqlTest() {

@BeforeAll
public static void setUp() throws SQLException {
final String jdbcUrl = System.getProperty(PROPERTY_JDBC);
Config config = ConfigProvider.getConfig();
Optional<String> jdbcUrl = config.getOptionalValue(PROPERTY_JDBC, String.class);

if (jdbcUrl != null) {
connection = DriverManager.getConnection(jdbcUrl);
if (jdbcUrl.isPresent()) {
connection = DriverManager.getConnection(jdbcUrl.get());
} else {
LOG.warn("Container is not running. Connection is not created.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import io.quarkus.test.junit.QuarkusTest;
import org.apache.camel.quarkus.component.debezium.common.it.AbstractDebeziumTest;
import org.apache.camel.quarkus.component.debezium.common.it.Type;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -44,8 +46,8 @@ public DebeziumPostgresTest() {

@BeforeAll
public static void setUp() throws SQLException {
final String jdbcUrl = System.getProperty(Type.postgres.getPropertyJdbc());

Config config = ConfigProvider.getConfig();
final String jdbcUrl = config.getValue(Type.postgres.getPropertyJdbc(), String.class);
connection = DriverManager.getConnection(jdbcUrl);
}

Expand Down

0 comments on commit 8d4aad6

Please sign in to comment.