How to use TemplateBuilder class of com.consol.citrus.dsl.builder package

Best Citrus code snippet using com.consol.citrus.dsl.builder.TemplateBuilder

Source:TemplateTestRunnerTest.java Github

copy

Full Screen

...20import com.consol.citrus.actions.TraceVariablesAction;21import com.consol.citrus.container.*;22import com.consol.citrus.context.TestContext;23import com.consol.citrus.dsl.builder.BuilderSupport;24import com.consol.citrus.dsl.builder.TemplateBuilder;25import com.consol.citrus.report.TestActionListeners;26import com.consol.citrus.testng.AbstractTestNGUnitTest;27import org.mockito.Mockito;28import org.springframework.context.ApplicationContext;29import org.testng.Assert;30import org.testng.annotations.Test;31import java.util.*;32import static org.mockito.Mockito.*;33public class TemplateTestRunnerTest extends AbstractTestNGUnitTest {34 35 private ApplicationContext applicationContextMock = Mockito.mock(ApplicationContext.class);36 37 @Test38 public void testTemplateBuilder() {39 Template rootTemplate = new Template();40 rootTemplate.setName("fooTemplate");41 42 List<TestAction> actions = new ArrayList<TestAction>();43 actions.add(new EchoAction());44 actions.add(new TraceVariablesAction());45 rootTemplate.setActions(actions);46 47 reset(applicationContextMock);48 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));49 when(applicationContextMock.getBean("fooTemplate", Template.class)).thenReturn(rootTemplate);50 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());51 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());52 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());53 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {54 @Override55 public void execute() {56 applyTemplate(builder -> builder.name("fooTemplate")57 .parameter("param", "foo")58 .parameter("text", "Citrus rocks!"));59 }60 };61 TestCase test = builder.getTestCase();62 Assert.assertEquals(test.getActions().size(), 1);63 Assert.assertEquals(test.getActions().get(0).getClass(), Template.class);64 Assert.assertEquals(test.getActions().get(0).getName(), "fooTemplate");65 66 Template container = (Template)test.getActions().get(0);67 Assert.assertEquals(container.isGlobalContext(), true);68 Assert.assertEquals(container.getParameter().toString(), "{param=foo, text=Citrus rocks!}");69 Assert.assertEquals(container.getActions().size(), 2);70 Assert.assertEquals(container.getActions().get(0).getClass(), EchoAction.class);71 Assert.assertEquals(container.getActions().get(1).getClass(), TraceVariablesAction.class);72 }73 74 @Test75 public void testTemplateBuilderGlobalContext() {76 Template rootTemplate = new Template();77 rootTemplate.setName("fooTemplate");78 79 List<TestAction> actions = new ArrayList<TestAction>();80 actions.add(new EchoAction());81 rootTemplate.setActions(actions);82 83 reset(applicationContextMock);84 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));85 when(applicationContextMock.getBean("fooTemplate", Template.class)).thenReturn(rootTemplate);86 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());87 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());88 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());89 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {...

Full Screen

Full Screen

Source:TemplateBuilder.java Github

copy

Full Screen

...22 * 23 * @author Christoph Deppisch24 * @since 2.325 */26public class TemplateBuilder extends AbstractTestActionBuilder<Template> {27 /**28 * Constructor using action field.29 * @param action30 */31 public TemplateBuilder(Template action) {32 super(action);33 }34 /**35 * Default constructor.36 */37 public TemplateBuilder() {38 super(new Template());39 }40 /**41 * Sets the template name.42 * @param name43 * @return44 */45 public TemplateBuilder name(String name) {46 action.setName(name);47 return this;48 }49 /**50 * Loads template bean from Spring bean application context and sets attributes.51 * @param applicationContext52 * @return53 */54 public TemplateBuilder load(ApplicationContext applicationContext) {55 Template rootTemplate = applicationContext.getBean(action.getName(), Template.class);56 action.setGlobalContext(rootTemplate.isGlobalContext());57 action.setActor(rootTemplate.getActor());58 action.setActions(rootTemplate.getActions());59 action.setParameter(rootTemplate.getParameter());60 return this;61 }62 63 /**64 * Boolean flag marking the template variables should also affect65 * variables in test case.66 * @param globalContext the globalContext to set67 */68 public TemplateBuilder globalContext(boolean globalContext) {69 action.setGlobalContext(globalContext);70 return this;71 }72 /**73 * Set parameter before execution.74 * @param parameters the parameter to set75 */76 public TemplateBuilder parameters(Map<String, String> parameters) {77 action.getParameter().putAll(parameters);78 return this;79 }80 81 /**82 * Set parameter before execution.83 * @param name84 * @param value85 */86 public TemplateBuilder parameter(String name, String value) {87 action.getParameter().put(name, value);88 return this;89 }90}...

Full Screen

Full Screen

Source:XmlSteps.java Github

copy

Full Screen

...16package com.consol.citrus.cucumber.step.xml;17import com.consol.citrus.annotations.CitrusResource;18import com.consol.citrus.container.Template;19import com.consol.citrus.cucumber.container.StepTemplate;20import com.consol.citrus.dsl.builder.TemplateBuilder;21import com.consol.citrus.dsl.design.TestDesigner;22import com.consol.citrus.dsl.runner.TestRunner;23import com.consol.citrus.exceptions.CitrusRuntimeException;24/**25 * Step executes a XML template on test designer. The template is provided with step arguments as test template parameters.26 * @author Christoph Deppisch27 * @since 2.628 */29public class XmlSteps {30 @CitrusResource31 private TestDesigner designer;32 @CitrusResource33 private TestRunner runner;34 /**35 * Run template within designer.36 * @param stepTemplate37 * @param args38 */39 public void execute(StepTemplate stepTemplate, Object[] args) {40 Template steps = new Template();41 steps.setActions(stepTemplate.getActions());42 steps.setActor(stepTemplate.getActor());43 TemplateBuilder templateBuilder = new TemplateBuilder(steps)44 .name(stepTemplate.getName())45 .globalContext(stepTemplate.isGlobalContext());46 if (stepTemplate.getParameterNames().size() != args.length) {47 throw new CitrusRuntimeException(String.format("Step argument mismatch for template '%s', expected %s arguments but found %s",48 stepTemplate.getName(), stepTemplate.getParameterNames().size(), args.length));49 }50 for (int i = 0; i < args.length; i++) {51 templateBuilder.parameter(stepTemplate.getParameterNames().get(i), args[i].toString());52 }53 if (designer != null) {54 designer.action(templateBuilder);55 }56 if (runner != null) {57 runner.run(templateBuilder.build());...

Full Screen

Full Screen

TemplateBuilder

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.builder.TemplateBuilder;2import com.consol.citrus.dsl.junit.JUnit4CitrusTestRunner;3import org.testng.annotations.Test;4public class 3 extends JUnit4CitrusTestRunner {5public void test() {6TemplateBuilder template = new TemplateBuilder();7template.echo("Hello World!");8template.echo("Hello Wo

Full Screen

Full Screen

TemplateBuilder

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.builder;2import org.springframework.context.ApplicationContext;3import org.springframework.context.support.ClassPathXmlApplicationContext;4import org.testng.annotations.Test;5import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;6public class TemplateBuilderTest extends TestNGCitrusTestRunner {7ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");8public void TemplateBuilderTest() {9TemplateBuilder templateBuilder = new TemplateBuilder(context);10templateBuilder.templateName("templateName")11.templateData("templateData")12.templateFile("templateFile")

Full Screen

Full Screen

TemplateBuilder

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.builder;2import org.springframework.context.ApplicationContext;3import org.springframework.context.support.ClassPathXmlApplicationContext;4import com.consol.citrus.dsl.builder.TemplateBuilder;5import com.consol.citrus.dsl.builder.TemplateBuilderSupport;6public class TemplateBuilder extends TemplateBuilderSupport<TemplateBuilder> {7 public TemplateBuilder(ApplicationContext applicationContext) {8 super(applicationContext, new TemplateBuilderSupport<TemplateBuilder>() {9 public void configure() {

Full Screen

Full Screen

TemplateBuilder

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.runner;2import com.consol.citrus.dsl.builder.TemplateBuilder;3import com.consol.citrus.dsl.builder.TemplateBuilderSupport;4public class TemplateBuilderTestRunner extends AbstractTestRunner<TemplateBuilderSupport<TemplateBuilderTestRunner>> {5 public TemplateBuilderTestRunner(TemplateBuilderSupport<TemplateBuilderTestRunner> builder) {6 super(builder);7 }8 public TemplateBuilderTestRunner() {9 this(new TemplateBuilder());10 }11}12package com.consol.citrus.dsl.builder;13import com.consol.citrus.dsl.runner.TemplateBuilderTestRunner;14import com.consol.citrus.template.Template;15import com.consol.citrus.variable.VariableExtractor;16import java.util.Map;17public class TemplateBuilder extends AbstractTestContainerBuilder<TemplateBuilderTestRunner> {18 private Template template = new Template();19 public TemplateBuilder() {20 super(new TemplateBuilderTestRunner(this));21 }22 public TemplateBuilder name(String name) {23 template.setName(name);24 return this;25 }26 public TemplateBuilder resource(String resource) {27 template.setResource(resource);28 return this;29 }30 public TemplateBuilder variables(Map<String, Object> variables) {31 template.setVariables(variables);32 return this;33 }34 public TemplateBuilder variable(String name, Object value) {35 template.getVariables().put(name, value);36 return this;37 }38 public TemplateBuilder extractVariables(Map<String, String> extractVariables) {39 template.setExtractVariables(extractVariables);40 return this;41 }42 public TemplateBuilder extractVariable(String name, String value) {43 template.getExtractVariables().put(name, value);44 return this;45 }46 public TemplateBuilder extractVariablesFromPayload(Map<String, String> extractVariablesFromPayload) {47 template.setExtractVariablesFromPayload(extractVariablesFromPayload);48 return this;49 }50 public TemplateBuilder extractVariableFromPayload(String name, String value) {51 template.getExtractVariablesFromPayload().put(name, value);52 return this;53 }54 public TemplateBuilder extractVariablesFromHeader(Map<String, String> extractVariablesFromHeader) {55 template.setExtractVariablesFromHeader(extractVariablesFromHeader);56 return this;57 }58 public TemplateBuilder extractVariableFromHeader(String name, String value) {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in TemplateBuilder

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful