Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I bring the context for processing the template to the executor #30

Open
zian92 opened this issue Jan 26, 2023 · 1 comment
Open

Comments

@zian92
Copy link

zian92 commented Jan 26, 2023

Hey,

I currently struggle with creating the variables hat should be used to fill the templates from the surrounding java JUnit code.
I know I can do it from within the thtest-file but that is not a viable solution as the context contains multiple aggregated objects.
Is there an intended way to do so? If not, i would like to request it.

I already asked this on stackoverflow some time ago but did no receive any response or solution to it.

@zian92
Copy link
Author

zian92 commented May 12, 2023

I found this solution:

`public class WebProcessingContextBuilderWithJavaVariables extends WebProcessingContextBuilder {

private final Map<String, Object> vars;

public WebProcessingContextBuilderWithJavaVariables(Map<String, Object> variables) {
	vars = variables;
}

@Override
protected void doAdditionalVariableProcessing(
		final ITest test,
		final HttpServletRequest request, final HttpServletResponse response, final ServletContext servletContext,
		final Locale locale, final Map<String, Object> variables) {

	variables.putAll(vars);
}

}

@test
void someTest() {
HashMap<String, Object> vars = new HashMap<>();
vars.put("key", validations);
executor.setProcessingContextBuilder(new WebProcessingContextBuilderWithJavaVariables(vars));
executor.execute("classpath:template.thtest");

Assertions.assertTrue(executor.isAllOK());

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant