-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#90): Inject environment variables as test variables before scenario
- Loading branch information
1 parent
1c7853f
commit 7cbed0b
Showing
5 changed files
with
77 additions
and
13 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
3 changes: 2 additions & 1 deletion
3
java/steps/yaks-http/src/test/resources/org/citrusframework/yaks/http/http.client.feature
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
64 changes: 64 additions & 0 deletions
64
java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/hooks/InjectEnvVarsHook.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,64 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.citrusframework.yaks.hooks; | ||
|
||
import com.consol.citrus.TestCaseRunner; | ||
import com.consol.citrus.actions.AbstractTestAction; | ||
import com.consol.citrus.annotations.CitrusResource; | ||
import com.consol.citrus.context.TestContext; | ||
import io.cucumber.java.Before; | ||
import io.cucumber.java.Scenario; | ||
|
||
/** | ||
* Cucumber hook injects environment variables as test variables before the scenario is executed. | ||
* @author Christoph Deppisch | ||
*/ | ||
public class InjectEnvVarsHook { | ||
|
||
@CitrusResource | ||
private TestCaseRunner runner; | ||
|
||
@Before | ||
public void injectEnvVars(Scenario scenario) { | ||
runner.run(new AbstractTestAction() { | ||
@Override | ||
public void doExecute(TestContext context) { | ||
context.setVariable("SCENARIO_NAME", scenario.getName()); | ||
context.setVariable("SCENARIO_ID", scenario.getId()); | ||
|
||
injectEnvVar(context, "CLUSTER_WILDCARD_DOMAIN", "ns.svc.cluster.local"); | ||
injectEnvVar(context, "YAKS_NAMESPACE", null); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Read System environment variable and set value as test variable using the very same variable name. In case variable | ||
* is not present use default value if given. | ||
* @param context | ||
* @param env | ||
* @param defaultValue | ||
*/ | ||
private void injectEnvVar(TestContext context, String env, String defaultValue) { | ||
if (System.getenv(env) != null) { | ||
context.setVariable(env, System.getenv(env)); | ||
} else if (defaultValue != null) { | ||
context.setVariable(env, defaultValue); | ||
} | ||
} | ||
} |
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