@Test @SuppressWarnings("CucumberJavaStepDefClassIsPublic") public void shouldInjectEnvVars() { InjectEnvVarsHook hook = new InjectEnvVarsHook() { @Override protected Optional<String> getNamespaceSetting() { return Optional.of("foo"); } @Override protected Optional<String> getClusterWildcardSetting() { return Optional.of("foo.cluster.io"); } }; TestContext context = TestContextFactory.newInstance().getObject(); TestCaseRunner runner = new DefaultTestCaseRunner(context); CitrusAnnotations.injectTestRunner(hook, runner); hook.injectEnvVars(null); Assertions.assertThat(context.getVariable(YaksVariableNames.NAMESPACE.value())).isEqualTo("foo"); Assertions.assertThat(context.getVariable(YaksVariableNames.CLUSTER_WILDCARD_DOMAIN.value())).isEqualTo("foo.cluster.io"); }
@Before public void injectEnvVars(Scenario scenario) { runner.run(new AbstractTestAction() { @Override public void doExecute(TestContext context) { if (scenario != null) { context.setVariable(YaksVariableNames.SCENARIO_ID.value(), scenario.getId()); context.setVariable(YaksVariableNames.SCENARIO_NAME.value(), scenario.getName()); } Optional<String> namespaceEnv = getNamespaceSetting(); Optional<String> domainEnv = getClusterWildcardSetting(); if (namespaceEnv.isPresent()) { context.setVariable(YaksVariableNames.NAMESPACE.value(), namespaceEnv.get()); if (!domainEnv.isPresent()) { context.setVariable(YaksVariableNames.CLUSTER_WILDCARD_DOMAIN.value(), namespaceEnv.get() + "." + YaksSettings.DEFAULT_DOMAIN_SUFFIX); } } domainEnv.ifPresent(var -> context.setVariable(YaksVariableNames.CLUSTER_WILDCARD_DOMAIN.value(), var)); } }); }
InjectEnvVarsHook { @Before public void injectEnvVars(Scenario scenario) { runner.run(new AbstractTestAction() { @Override public void doExecute(TestContext context) { if (scenario != null) { context.setVariable(YaksVariableNames.SCENARIO_ID.value(), scenario.getId()); context.setVariable(YaksVariableNames.SCENARIO_NAME.value(), scenario.getName()); } Optional<String> namespaceEnv = getNamespaceSetting(); Optional<String> domainEnv = getClusterWildcardSetting(); if (namespaceEnv.isPresent()) { context.setVariable(YaksVariableNames.NAMESPACE.value(), namespaceEnv.get()); if (!domainEnv.isPresent()) { context.setVariable(YaksVariableNames.CLUSTER_WILDCARD_DOMAIN.value(), namespaceEnv.get() + "." + YaksSettings.DEFAULT_DOMAIN_SUFFIX); } } domainEnv.ifPresent(var -> context.setVariable(YaksVariableNames.CLUSTER_WILDCARD_DOMAIN.value(), var)); } }); } }
InjectEnvVarsHook { @Before public void injectEnvVars(Scenario scenario) { runner.run(new AbstractTestAction() { @Override public void doExecute(TestContext context) { if (scenario != null) { context.setVariable(YaksVariableNames.SCENARIO_ID.value(), scenario.getId()); context.setVariable(YaksVariableNames.SCENARIO_NAME.value(), scenario.getName()); } Optional<String> namespaceEnv = getNamespaceSetting(); Optional<String> domainEnv = getClusterWildcardSetting(); if (namespaceEnv.isPresent()) { context.setVariable(YaksVariableNames.NAMESPACE.value(), namespaceEnv.get()); if (!domainEnv.isPresent()) { context.setVariable(YaksVariableNames.CLUSTER_WILDCARD_DOMAIN.value(), namespaceEnv.get() + "." + YaksSettings.DEFAULT_DOMAIN_SUFFIX); } } domainEnv.ifPresent(var -> context.setVariable(YaksVariableNames.CLUSTER_WILDCARD_DOMAIN.value(), var)); } }); }  }
InjectEnvVarsHook { @Before public void injectEnvVars(Scenario scenario) { runner.run(new AbstractTestAction() { @Override public void doExecute(TestContext context) { if (scenario != null) { context.setVariable(YaksVariableNames.SCENARIO_ID.value(), scenario.getId()); context.setVariable(YaksVariableNames.SCENARIO_NAME.value(), scenario.getName()); } Optional<String> namespaceEnv = getNamespaceSetting(); Optional<String> domainEnv = getClusterWildcardSetting(); if (namespaceEnv.isPresent()) { context.setVariable(YaksVariableNames.NAMESPACE.value(), namespaceEnv.get()); if (!domainEnv.isPresent()) { context.setVariable(YaksVariableNames.CLUSTER_WILDCARD_DOMAIN.value(), namespaceEnv.get() + "." + YaksSettings.DEFAULT_DOMAIN_SUFFIX); } } domainEnv.ifPresent(var -> context.setVariable(YaksVariableNames.CLUSTER_WILDCARD_DOMAIN.value(), var)); } }); }  @Before void injectEnvVars(Scenario scenario); }
InjectEnvVarsHook { @Before public void injectEnvVars(Scenario scenario) { runner.run(new AbstractTestAction() { @Override public void doExecute(TestContext context) { if (scenario != null) { context.setVariable(YaksVariableNames.SCENARIO_ID.value(), scenario.getId()); context.setVariable(YaksVariableNames.SCENARIO_NAME.value(), scenario.getName()); } Optional<String> namespaceEnv = getNamespaceSetting(); Optional<String> domainEnv = getClusterWildcardSetting(); if (namespaceEnv.isPresent()) { context.setVariable(YaksVariableNames.NAMESPACE.value(), namespaceEnv.get()); if (!domainEnv.isPresent()) { context.setVariable(YaksVariableNames.CLUSTER_WILDCARD_DOMAIN.value(), namespaceEnv.get() + "." + YaksSettings.DEFAULT_DOMAIN_SUFFIX); } } domainEnv.ifPresent(var -> context.setVariable(YaksVariableNames.CLUSTER_WILDCARD_DOMAIN.value(), var)); } }); }  @Before void injectEnvVars(Scenario scenario);  }