Skip to content

Commit

Permalink
chore: Support test variables in integration properties
Browse files Browse the repository at this point in the history
  • Loading branch information
christophd committed Nov 9, 2021
1 parent 57a2678 commit 2655f3b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -29,6 +30,7 @@
import com.consol.citrus.exceptions.ActionTimeoutException;
import com.consol.citrus.exceptions.CitrusRuntimeException;
import com.consol.citrus.util.FileUtils;
import io.cucumber.datatable.DataTable;
import io.cucumber.java.Before;
import io.cucumber.java.Scenario;
import io.cucumber.java.en.Given;
Expand Down Expand Up @@ -57,6 +59,7 @@ public class CamelKSteps {
private long delayBetweenAttempts = CamelKSettings.getDelayBetweenAttempts();

private List<String> propertyFiles;
private Map<String, String> properties;

private boolean supportVariablesInSources = CamelKSettings.isSupportVariablesInSources();

Expand All @@ -67,6 +70,7 @@ public void before(Scenario scenario) {
}

propertyFiles = new ArrayList<>();
properties = new LinkedHashMap<>();
}

@Given("^Disable auto removal of Camel-K resources$")
Expand Down Expand Up @@ -100,6 +104,17 @@ public void addPropertyFile(String filePath) {
propertyFiles.add(filePath);
}

@Given("^Camel-K integration property ([^\\s]+)=\"([^\"]*)\"$")
@Given("^Camel-K integration property ([^\\s]+) (?:is|=) \"([^\"]*)\"$")
public void addProperty(String name, String value) {
properties.put(name, value);
}

@Given("^Camel-K integration properties$")
public void addProperties(DataTable propertyTable) {
properties.putAll(propertyTable.asMap(String.class, String.class));
}

@Given("^(?:create|new) Camel-K integration ([a-z0-9][a-z0-9-\\.]+[a-z0-9])\\.([a-z0-9-]+) with configuration:?$")
public void createIntegration(String name, String language, Map<String, String> configuration) {
if (configuration.get("source") == null) {
Expand Down Expand Up @@ -203,6 +218,7 @@ private void createIntegration(String name, String language, String source, Map<
.source(name + "." + language, source)
.dependencies(configuration.getOrDefault("dependencies", "").trim())
.properties(configuration.getOrDefault("properties", "").trim())
.properties(properties)
.propertyFiles(propertyFiles)
.supportVariables(Boolean.parseBoolean(
configuration.getOrDefault("supportVariables", String.valueOf(supportVariablesInSources))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private void addPropertyConfigurationSpec(Integration.Builder integrationBuilder
}
final String[] property = p.split("=",2);
configurationList.add(
new IntegrationSpec.Configuration("property", createPropertySpec(property[0], property[1])));
new IntegrationSpec.Configuration("property", createPropertySpec(property[0], property[1], context)));
}
}

Expand All @@ -158,7 +158,7 @@ private void addPropertyConfigurationSpec(Integration.Builder integrationBuilder
Properties props = new Properties();
props.load(FileUtils.getFileResource(pf, context).getInputStream());
props.forEach((key, value) -> configurationList.add(
new IntegrationSpec.Configuration("property", createPropertySpec(key.toString(), value.toString()))));
new IntegrationSpec.Configuration("property", createPropertySpec(key.toString(), value.toString(), context))));
} catch (IOException e) {
throw new CitrusRuntimeException("Failed to load property file", e);
}
Expand All @@ -170,8 +170,8 @@ private void addPropertyConfigurationSpec(Integration.Builder integrationBuilder
}
}

private String createPropertySpec(String key, String value) {
return escapePropertyItem(key) + "=" + escapePropertyItem(value);
private String createPropertySpec(String key, String value, TestContext context) {
return escapePropertyItem(key) + "=" + escapePropertyItem(context.replaceDynamicContentInString(value));
}

private String escapePropertyItem(String item) {
Expand Down Expand Up @@ -285,6 +285,11 @@ public Builder properties(List<String> properties) {
return this;
}

public Builder properties(Map<String, String> properties) {
properties.forEach(this::property);
return this;
}

public Builder dependencies(List<String> dependencies) {
this.dependencies.addAll(dependencies);
return this;
Expand Down

0 comments on commit 2655f3b

Please sign in to comment.