Best Citrus code snippet using com.consol.citrus.dsl.builder.TransformActionBuilder.result
Source:DefaultTestRunner.java
1/*2 * Copyright 2006-2015 the original author or authors.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.consol.citrus.dsl.runner;17import com.consol.citrus.*;18import com.consol.citrus.actions.*;19import com.consol.citrus.container.*;20import com.consol.citrus.context.TestContext;21import com.consol.citrus.dsl.builder.*;22import com.consol.citrus.dsl.container.FinallySequence;23import com.consol.citrus.exceptions.CitrusRuntimeException;24import com.consol.citrus.exceptions.TestCaseFailedException;25import com.consol.citrus.message.MessageType;26import com.consol.citrus.report.TestActionListeners;27import com.consol.citrus.script.GroovyAction;28import com.consol.citrus.server.Server;29import org.slf4j.Logger;30import org.slf4j.LoggerFactory;31import org.springframework.context.ApplicationContext;32import org.springframework.util.CollectionUtils;33import java.util.*;34/**35 * Default test runner implementation. Provides Java DSL methods for test actions. Immediately executes test actions as36 * they were built. This way the test case grows with each test action and changes for instance to the test context (variables) are37 * immediately visible.38 *39 * @author Christoph Deppisch40 * @since 2.341 */42public class DefaultTestRunner implements TestRunner {43 /** Logger */44 private static Logger log = LoggerFactory.getLogger(DefaultTestRunner.class);45 /** This builders test case */46 private final TestCase testCase;47 /** This runners test context */48 private TestContext context;49 /** Spring bean application context */50 private ApplicationContext applicationContext;51 /** Optional stack of containers cached for execution */52 protected Stack<AbstractActionContainer> containers = new Stack<>();53 /** Default constructor */54 public DefaultTestRunner() {55 this(new TestCase());56 testClass(this.getClass());57 name(this.getClass().getSimpleName());58 packageName(this.getClass().getPackage().getName());59 }60 /**61 * Constructor initializing test case.62 * @param testCase63 */64 protected DefaultTestRunner(TestCase testCase) {65 this.testCase = testCase;66 }67 /**68 * Constructor using Spring bean application context.69 * @param applicationContext70 * @param context71 */72 public DefaultTestRunner(ApplicationContext applicationContext, TestContext context) {73 this();74 this.applicationContext = applicationContext;75 this.context = context;76 try {77 initialize();78 } catch (Exception e) {79 throw new CitrusRuntimeException("Failed to setup test runner", e);80 }81 }82 protected void initialize() {83 testCase.setTestRunner(true);84 testCase.setTestActionListeners(applicationContext.getBean(TestActionListeners.class));85 if (!applicationContext.getBeansOfType(SequenceBeforeTest.class).isEmpty()) {86 testCase.setBeforeTest(CollectionUtils.arrayToList(applicationContext.getBeansOfType(SequenceBeforeTest.class).values().toArray()));87 }88 if (!applicationContext.getBeansOfType(SequenceAfterTest.class).isEmpty()) {89 testCase.setAfterTest(CollectionUtils.arrayToList(applicationContext.getBeansOfType(SequenceAfterTest.class).values().toArray()));90 }91 }92 @Override93 public void testClass(Class<?> type) {94 getTestCase().setTestClass(type);95 }96 @Override97 public void name(String name) {98 testCase.setBeanName(name);99 testCase.setName(name);100 }101 @Override102 public void description(String description) {103 getTestCase().setDescription(description);104 }105 @Override106 public void author(String author) {107 getTestCase().getMetaInfo().setAuthor(author);108 }109 @Override110 public void packageName(String packageName) {111 getTestCase().setPackageName(packageName);112 }113 @Override114 public void status(TestCaseMetaInfo.Status status) {115 getTestCase().getMetaInfo().setStatus(status);116 }117 @Override118 public void creationDate(Date date) {119 getTestCase().getMetaInfo().setCreationDate(date);120 }121 @Override122 public void start() {123 testCase.start(context);124 }125 @Override126 public void stop() {127 try {128 if (!CollectionUtils.isEmpty(context.getExceptions())) {129 CitrusRuntimeException ex = context.getExceptions().remove(0);130 testCase.setTestResult(TestResult.failed(testCase.getName(), testCase.getTestClass().getName(), ex));131 throw new TestCaseFailedException(ex);132 }133 } finally {134 testCase.finish(context);135 }136 }137 @Override138 public <T> T variable(String name, T value) {139 testCase.getVariableDefinitions().put(name, value);140 if (value instanceof String) {141 String resolved = context.replaceDynamicContentInString(value.toString());142 context.setVariable(name, resolved);143 return (T) resolved;144 } else {145 context.setVariable(name, value);146 return value;147 }148 }149 @Override150 public <T extends TestAction> T run(T testAction) {151 if (testAction instanceof TestActionContainer) {152 if (containers.lastElement().equals(testAction)) {153 containers.pop();154 } else {155 throw new CitrusRuntimeException("Invalid use of action containers - the container execution is not expected!");156 }157 if (testAction instanceof FinallySequence) {158 testCase.getFinalActions().addAll(((FinallySequence) testAction).getActions());159 return testAction;160 }161 }162 if (!containers.isEmpty()) {163 containers.lastElement().addTestAction(testAction);164 } else {165 testCase.addTestAction(testAction);166 testCase.executeAction(testAction, context);167 }168 return testAction;169 }170 @Override171 public ApplyTestBehaviorAction applyBehavior(TestBehavior behavior) {172 ApplyTestBehaviorAction action = new ApplyTestBehaviorAction(this, behavior);173 behavior.setApplicationContext(applicationContext);174 action.execute(context);175 return action;176 }177 @Override178 public <T extends AbstractActionContainer> AbstractTestContainerBuilder<T> container(T container) {179 AbstractTestContainerBuilder<T> containerBuilder = new AbstractTestContainerBuilder<T>(this, container) {};180 containers.push(containerBuilder.build());181 return containerBuilder;182 }183 @Override184 public CreateVariablesAction createVariable(String variableName, String value) {185 CreateVariablesAction action = new CreateVariablesAction();186 action.getVariables().put(variableName, value);187 return run(action);188 }189 @Override190 public AntRunAction antrun(BuilderSupport<AntRunBuilder> configurer) {191 AntRunBuilder builder = new AntRunBuilder();192 configurer.configure(builder);193 return run(builder.build());194 }195 @Override196 public EchoAction echo(String message) {197 EchoAction action = new EchoAction();198 action.setMessage(message);199 return run(action);200 }201 @Override202 public ExecutePLSQLAction plsql(BuilderSupport<ExecutePLSQLBuilder> configurer) {203 ExecutePLSQLBuilder builder = new ExecutePLSQLBuilder();204 configurer.configure(builder);205 return run(builder.build());206 }207 @Override208 public ExecuteSQLAction sql(BuilderSupport<ExecuteSQLBuilder> configurer) {209 ExecuteSQLBuilder builder = new ExecuteSQLBuilder();210 configurer.configure(builder);211 return run(builder.build());212 }213 @Override214 public ExecuteSQLQueryAction query(BuilderSupport<ExecuteSQLQueryBuilder> configurer) {215 ExecuteSQLQueryBuilder builder = new ExecuteSQLQueryBuilder();216 configurer.configure(builder);217 return run(builder.build());218 }219 @Override220 public FailAction fail(String message) {221 FailAction action = new FailAction();222 action.setMessage(message);223 return run(action);224 }225 @Override226 public InputAction input(BuilderSupport<InputActionBuilder> configurer) {227 InputActionBuilder builder = new InputActionBuilder();228 configurer.configure(builder);229 return run(builder.build());230 }231 @Override232 public ReceiveTimeoutAction receiveTimeout(BuilderSupport<ReceiveTimeoutBuilder> configurer) {233 ReceiveTimeoutBuilder builder = new ReceiveTimeoutBuilder();234 configurer.configure(builder);235 return run(builder.build());236 }237 @Override238 public LoadPropertiesAction load(String filePath) {239 LoadPropertiesAction action = new LoadPropertiesAction();240 action.setFilePath(filePath);241 return run(action);242 }243 @Override244 public TestAction purgeQueues(BuilderSupport<PurgeJmsQueuesBuilder> configurer) {245 PurgeJmsQueuesBuilder builder = new PurgeJmsQueuesBuilder()246 .withApplicationContext(applicationContext);247 configurer.configure(builder);248 return run(builder.build());249 }250 @Override251 public PurgeMessageChannelAction purgeChannels(BuilderSupport<PurgeChannelsBuilder> configurer) {252 PurgeChannelsBuilder builder = new PurgeChannelsBuilder();253 builder.channelResolver(applicationContext);254 configurer.configure(builder);255 return run(builder.build());256 }257 @Override258 public PurgeEndpointAction purgeEndpoints(BuilderSupport<PurgeEndpointsBuilder> configurer) {259 PurgeEndpointsBuilder builder = new PurgeEndpointsBuilder()260 .withApplicationContext(applicationContext);261 configurer.configure(builder);262 return run(builder.build());263 }264 @Override265 public ReceiveMessageAction receive(BuilderSupport<ReceiveMessageBuilder> configurer) {266 ReceiveMessageBuilder<ReceiveMessageAction, ReceiveMessageBuilder> builder = new ReceiveMessageBuilder()267 .messageType(MessageType.XML)268 .withApplicationContext(applicationContext);269 configurer.configure(builder);270 return (ReceiveMessageAction) run(builder.build().getDelegate());271 }272 @Override273 public SendMessageAction send(BuilderSupport<SendMessageBuilder> configurer) {274 SendMessageBuilder<SendMessageAction, SendMessageBuilder> builder = new SendMessageBuilder()275 .withApplicationContext(applicationContext);276 configurer.configure(builder);277 return (SendMessageAction) run(builder.build().getDelegate());278 }279 @Override280 public SleepAction sleep() {281 return run(new SleepAction());282 }283 @Override284 public SleepAction sleep(long milliseconds) {285 SleepAction action = new SleepAction();286 action.setMilliseconds(String.valueOf(milliseconds));287 return run(action);288 }289 @Override290 @Deprecated291 public Wait waitFor(BuilderSupport<WaitBuilder> configurer) {292 WaitBuilder builder = new WaitBuilder(null, new Wait());293 configurer.configure(builder);294 containers.push(builder.build());295 return run(builder.build());296 }297 @Override298 public WaitBuilder waitFor() {299 WaitBuilder builder = new WaitBuilder(this, new Wait());300 containers.push(builder.build());301 return builder;302 }303 @Override304 public StartServerAction start(Server... servers) {305 StartServerAction action = new StartServerAction();306 action.getServerList().addAll(Arrays.asList(servers));307 return run(action);308 }309 @Override310 public StartServerAction start(Server server) {311 StartServerAction action = new StartServerAction();312 action.setServer(server);313 return run(action);314 }315 @Override316 public StopServerAction stop(Server... servers) {317 StopServerAction action = new StopServerAction();318 action.getServerList().addAll(Arrays.asList(servers));319 return run(action);320 }321 @Override322 public StopServerAction stop(Server server) {323 StopServerAction action = new StopServerAction();324 action.setServer(server);325 return run(action);326 }327 @Override328 public StopTimeAction stopTime() {329 return run(new StopTimeAction());330 }331 @Override332 public StopTimeAction stopTime(String id) {333 StopTimeAction action = new StopTimeAction();334 action.setId(id);335 return run(action);336 }337 @Override338 public StopTimeAction stopTime(String id, String suffix) {339 StopTimeAction action = new StopTimeAction();340 action.setId(id);341 action.setSuffix(suffix);342 return run(action);343 }344 @Override345 public TraceVariablesAction traceVariables() {346 return run(new TraceVariablesAction());347 }348 @Override349 public TraceVariablesAction traceVariables(String... variables) {350 TraceVariablesAction action = new TraceVariablesAction();351 action.setVariableNames(Arrays.asList(variables));352 return run(action);353 }354 @Override355 public GroovyAction groovy(BuilderSupport<GroovyActionBuilder> configurer) {356 GroovyActionBuilder builder = new GroovyActionBuilder();357 configurer.configure(builder);358 return run(builder.build());359 }360 @Override361 public TransformAction transform(BuilderSupport<TransformActionBuilder> configurer) {362 TransformActionBuilder builder = new TransformActionBuilder();363 configurer.configure(builder);364 return run(builder.build());365 }366 @Override367 public AssertExceptionBuilder assertException() {368 AssertExceptionBuilder builder = new AssertExceptionBuilder(this);369 containers.push(builder.build());370 return builder;371 }372 @Override373 public CatchExceptionBuilder catchException() {374 CatchExceptionBuilder builder = new CatchExceptionBuilder(this);375 containers.push(builder.build());376 return builder;377 }378 @Override379 public AssertSoapFaultBuilder assertSoapFault() {380 AssertSoapFaultBuilder builder = new AssertSoapFaultBuilder(this)381 .withApplicationContext(applicationContext);382 containers.push(builder.build());383 return builder;384 }385 @Override386 public ConditionalBuilder conditional() {387 ConditionalBuilder builder = new ConditionalBuilder(this);388 containers.push(builder.build());389 return builder;390 }391 @Override392 public IterateBuilder iterate() {393 IterateBuilder builder = new IterateBuilder(this);394 containers.push(builder.build());395 return builder;396 }397 @Override398 public ParallelBuilder parallel() {399 ParallelBuilder builder = new ParallelBuilder(this);400 containers.push(builder.build());401 return builder;402 }403 @Override404 public RepeatOnErrorBuilder repeatOnError() {405 RepeatOnErrorBuilder builder = new RepeatOnErrorBuilder(this);406 containers.push(builder.build());407 return builder;408 }409 @Override410 public RepeatBuilder repeat() {411 RepeatBuilder builder = new RepeatBuilder(this);412 containers.push(builder.build());413 return builder;414 }415 @Override416 public SequenceBuilder sequential() {417 SequenceBuilder builder = new SequenceBuilder(this);418 containers.push(builder.build());419 return builder;420 }421 @Override422 public AsyncBuilder async() {423 AsyncBuilder builder = new AsyncBuilder(this);424 containers.push(builder.build());425 return builder;426 }427 @Override428 public TimerBuilder timer() {429 TimerBuilder builder = new TimerBuilder(this);430 containers.push(builder.build());431 return builder;432 }433 @Override434 public StopTimerAction stopTimer(String timerId) {435 StopTimerAction action = new StopTimerAction();436 action.setTimerId(timerId);437 return run(action);438 }439 @Override440 public StopTimerAction stopTimers() {441 StopTimerAction action = new StopTimerAction();442 return run(action);443 }444 @Override445 public TestAction docker(BuilderSupport<DockerActionBuilder> configurer) {446 DockerActionBuilder builder = new DockerActionBuilder();447 configurer.configure(builder);448 return run(builder.build());449 }450 @Override451 public TestAction kubernetes(BuilderSupport<KubernetesActionBuilder> configurer) {452 KubernetesActionBuilder builder = new KubernetesActionBuilder();453 configurer.configure(builder);454 return run(builder.build());455 }456 @Override457 public TestAction selenium(BuilderSupport<SeleniumActionBuilder> configurer) {458 SeleniumActionBuilder builder = new SeleniumActionBuilder();459 configurer.configure(builder);460 return run(builder.build());461 }462 @Override463 public TestAction http(BuilderSupport<HttpActionBuilder> configurer) {464 HttpActionBuilder builder = new HttpActionBuilder()465 .withApplicationContext(applicationContext);466 configurer.configure(builder);467 return run(builder.build()).getDelegate();468 }469 @Override470 public TestAction soap(BuilderSupport<SoapActionBuilder> configurer) {471 SoapActionBuilder builder = new SoapActionBuilder()472 .withApplicationContext(applicationContext);473 configurer.configure(builder);474 return run(builder.build()).getDelegate();475 }476 @Override477 public TestAction camel(BuilderSupport<CamelRouteActionBuilder> configurer) {478 CamelRouteActionBuilder builder = new CamelRouteActionBuilder()479 .withApplicationContext(applicationContext);480 configurer.configure(builder);481 return run(builder.build()).getDelegate();482 }483 @Override484 public TestAction zookeeper(BuilderSupport<ZooActionBuilder> configurer) {485 ZooActionBuilder builder = new ZooActionBuilder()486 .withApplicationContext(applicationContext);487 configurer.configure(builder);488 return run(builder.build());489 }490 @Override491 public Template applyTemplate(BuilderSupport<TemplateBuilder> configurer) {492 TemplateBuilder builder = new TemplateBuilder();493 configurer.configure(builder);494 builder.load(applicationContext);495 configurer.configure(builder);496 return run(builder.build());497 }498 @Override499 public FinallySequenceBuilder doFinally() {500 FinallySequenceBuilder builder = new FinallySequenceBuilder(this);501 containers.push(builder.build());502 return builder;503 }504 /**505 * Gets the test context.506 * @return507 */508 public TestContext getTestContext() {509 return context;510 }511 /**512 * Sets the test context.513 * @param context514 */515 public void setTestContext(TestContext context) {516 this.context = context;517 }518 /**519 * Gets the value of the applicationContext property.520 *521 * @return the applicationContext522 */523 public ApplicationContext getApplicationContext() {524 return applicationContext;525 }526 /**527 * Sets the application context either from ApplicationContextAware injection or from outside.528 * @param applicationContext529 */530 public void setApplicationContext(ApplicationContext applicationContext) {531 this.applicationContext = applicationContext;532 }533 @Override534 public TestCase getTestCase() {535 return testCase;536 }537}...
Source:TransformTestRunnerTest.java
...42 "</body>%n" +43 "</html>%n" +44 "</xsl:template>%n" +45 "</xsl:stylesheet>"))46 .result("result"));47 }48 };49 TestContext context = builder.getTestContext();50 Assert.assertNotNull(context.getVariable("result"));51 Assert.assertEquals(context.getVariable("result"), String.format("<html>%n" +52 "<body>%n" +53 "<h2>Test Request</h2>%n" +54 "<p>Message: Hello World!</p>%n" +55 "</body>%n" +56 "</html>%n"));57 TestCase test = builder.getTestCase();58 Assert.assertEquals(test.getActionCount(), 1);59 Assert.assertEquals(test.getActions().get(0).getClass(), TransformAction.class);60 TransformAction action = (TransformAction)test.getActions().get(0);61 Assert.assertEquals(action.getName(), "transform");62 Assert.assertTrue(action.getXmlData().startsWith("<TestRequest>"));63 Assert.assertTrue(action.getXsltData().contains("<h2>Test Request</h2>"));64 Assert.assertEquals(action.getTargetVariable(), "result");65 }66 @Test67 public void testTransformBuilderWithResource() throws IOException {68 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {69 @Override70 public void execute() {71 transform(builder -> builder.source(new ClassPathResource("com/consol/citrus/dsl/runner/transform-source.xml"))72 .xslt(new ClassPathResource("com/consol/citrus/dsl/runner/transform.xslt"))73 .result("result"));74 }75 };76 TestContext context = builder.getTestContext();77 Assert.assertNotNull(context.getVariable("result"));78 Assert.assertEquals(context.getVariable("result"), String.format("<html>%n" +79 "<body>%n" +80 "<h2>Test Request</h2>%n" +81 "<p>Message: Hello World!</p>%n" +82 "</body>%n" +83 "</html>%n"));84 TestCase test = builder.getTestCase();85 Assert.assertEquals(test.getActionCount(), 1);86 Assert.assertEquals(test.getActions().get(0).getClass(), TransformAction.class);87 TransformAction action = (TransformAction)test.getActions().get(0);88 Assert.assertEquals(action.getName(), "transform");89 Assert.assertTrue(action.getXmlData().contains("<TestRequest>"));90 Assert.assertTrue(action.getXsltData().contains("<h2>Test Request</h2>"));91 Assert.assertEquals(action.getTargetVariable(), "result");92 }93}...
Source:TransformActionBuilder.java
...22import java.nio.charset.Charset;23/**24 * Action transforms a XML document(specified inline or from external file resource)25 * with a XSLT document(specified inline or from external file resource)26 * and puts the result in the specified variable.27 * 28 * @author Christoph Deppisch29 * @since 2.330 */31public class TransformActionBuilder extends AbstractTestActionBuilder<TransformAction> {32 /**33 * Constructor using action field.34 * @param action35 */36 public TransformActionBuilder(TransformAction action) {37 super(action);38 }39 /**40 * Default constructor.41 */42 public TransformActionBuilder() {43 super(new TransformAction());44 }45 /**46 * Set the target variable for the result47 * @param variable48 */49 public TransformActionBuilder result(String variable) {50 action.setTargetVariable(variable);51 return this;52 }53 54 /**55 * Set the XML document56 * @param xmlData the xmlData to set57 */58 public TransformActionBuilder source(String xmlData) {59 action.setXmlData(xmlData);60 return this;61 }62 63 /**...
result
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import com.consol.citrus.TestAction;3import com.consol.citrus.actions.TransformAction;4import com.consol.citrus.context.TestContext;5import com.consol.citrus.dsl.builder.AbstractTestActionBuilder;6import com.consol.citrus.dsl.builder.TransformActionBuilder;7import com.consol.citrus.dsl.builder.TransformVariablesActionBuilder;8import com.consol.citrus.transform.Transformers;9import org.springframework.util.StringUtils;10import java.util.HashMap;11import java.util.Map;12public class TransformActionBuilder extends AbstractTestActionBuilder<TransformAction> {13 private final TransformAction action;14 private final Transformers transformer;15 private final Map<String, String> variables = new HashMap<>();16 public TransformActionBuilder(TransformAction action) {17 super(action);18 this.action = action;19 this.transformer = action.getTransformer();20 }21 public TransformActionBuilder(Transformers transformer) {22 super(new TransformAction());23 this.action = getAction();24 this.transformer = transformer;25 }26 public TransformActionBuilder transformer(Transformers transformer) {27 action.setTransformer(transformer);28 return this;29 }30 public TransformActionBuilder transformer(String transformer) {31 action.setTransformer(transformer);32 return this;33 }34 public TransformActionBuilder data(String data) {35 action.setData(data);36 return this;37 }38 public TransformActionBuilder data(String data, TestContext context) {39 action.setData(data);40 action.setContext(context);41 return this;42 }
result
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.dsl.builder.AbstractTestContainerBuilder;4import com.consol.citrus.dsl.builder.TransformActionBuilder;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.testng.AbstractTestNGUnitTest;7import org.mockito.Mockito;8import org.testng.Assert;9import org.testng.annotations.Test;10public class TransformActionBuilderTest extends AbstractTestNGUnitTest {11 public void testTransformBuilder() {12 MockTestBuilder builder = new MockTestBuilder(applicationContext, context) {13 public void configure() {14 transform()15 .source("foo")16 .sourceData("bar")17 .sourceData("baz")18 .sourceData("qux")19 .sourceType(MessageType.PLAINTEXT)20 .target("foo")21 .targetType(MessageType.PLAINTEXT)22 .expression("foo")23 .expression("bar")24 .expression("baz")25 .expression("qux")26 .result("foo")27 .result("bar")28 .result("baz")29 .result("qux")30 .resultType(MessageType.PLAINTEXT)31 .validate("foo")32 .validate("bar")33 .validate("baz")34 .validate("qux")35 .validateType(MessageType.PLAINTEXT)36 .extractFromHeader("foo")37 .extractFromHeader("bar")38 .extractFromHeader("baz")39 .extractFromHeader("qux")40 .extractFromHeader("foo", "bar")41 .extractFromHeader("bar", "baz")42 .extractFromHeader("baz", "qux")43 .extractFromHeader("qux", "foo")44 .extractFromHeader("foo", "bar", "baz")45 .extractFromHeader("bar", "baz", "qux")46 .extractFromHeader("baz", "qux", "foo")47 .extractFromHeader("qux", "foo", "bar")48 .extractFromHeader("foo", "bar", "baz", "qux")49 .extractFromHeader("bar", "baz", "qux", "foo")50 .extractFromHeader("baz", "qux", "foo", "bar")51 .extractFromHeader("qux", "foo", "bar", "baz")
result
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import org.springframework.core.io.Resource;3import org.springframework.util.StringUtils;4import com.consol.citrus.actions.TransformAction;5import com.consol.citrus.context.TestContext;6import com.consol.citrus.dsl.design.TestDesigner;7import com.consol.citrus.exceptions.CitrusRuntimeException;8import com.consol.citrus.transformer.AbstractPayloadTransformer;9import com.consol.citrus.transformer.PayloadTransformer;10public class TransformActionBuilder extends AbstractTestContainerBuilder<TransformAction, TransformActionBuilder> {11 public TransformActionBuilder(TransformAction action) {12 super(action);13 }14 public TransformActionBuilder(TestDesigner designer, TransformAction action, String name) {15 super(designer, action, name);16 }17 public TransformActionBuilder transformer(PayloadTransformer transformer) {18 action.setTransformer(transformer);19 return this;20 }21 public TransformActionBuilder transformer(String transformer) {22 action.setTransformer(transformer);23 return this;24 }25 public TransformActionBuilder transformer(Resource transformer) {26 action.setTransformer(transformer);27 return this;28 }29 public TransformActionBuilder transformer(Class<? extends PayloadTransformer> transformer) {30 action.setTransformer(transformer);31 return this;32 }33 public TransformActionBuilder transformerName(String transformerName) {34 action.setTransformerName(transformerName);35 return this;36 }37 public TransformActionBuilder source(String sourceData) {38 action.setSourceData(sourceData);39 return this;40 }
result
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import com.consol.citrus.dsl.runner.TestRunner;3import com.consol.citrus.message.Message;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.message.builder.ScriptMessageBuilder;6import com.consol.citrus.testng.AbstractTestNGUnitTest;7import org.testng.annotations.Test;8import java.util.HashMap;9import java.util.Map;10import static com.consol.citrus.dsl.builder.BuilderSupport.transform;11import static com.consol.citrus.dsl.builder.BuilderSupport.variable;12import static com.consol.citrus.dsl.builder.BuilderSupport.xpath;13import static com.consol.citrus.dsl.builder.BuilderSupport.xslt;14public class TransformActionBuilderTest extends AbstractTestNGUnitTest {15 public void testTransformBuilder() {16 Map<String, Object> headers = new HashMap<>();17 headers.put("operation", "foo");18 headers.put("id", 1234L);19 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {20 public void execute() {21 transform(builder -> builder22 .source("<TestRequest><Message>Hello World!</Message></TestRequest>")23 .xslt("classpath:com/consol/citrus/dsl/builder/transform.xsl")24 .result("transformedResult")25 .validateScript("assertThat(transformedResult).isEqualTo(\"<TestResponse><Message>Hello World!</Message></TestResponse>\")"));26 transform(builder -> builder27 .source("<TestRequest><Message>Hello World!</Message></TestRequest>")28 .xslt("classpath:com/consol/citrus/dsl/builder/transform.xsl")29 .result("transformedResult")30 .validateScript("assertThat(transformedResult).isEqualTo(\"<TestResponse><Message>Hello World!</Message></TestResponse>\")"));31 transform(builder -> builder32 .source("<TestRequest><Message>Hello World!</Message></TestRequest>")33 .xslt("classpath:com/consol/citrus/dsl/builder/transform.xsl")34 .result("transformedResult")35 .validateScript("assertThat(transformedResult).isEqualTo(\"<TestResponse><Message>Hello World!</Message></TestResponse>\")"));36 transform(builder -> builder37 .source("<TestRequest><Message>Hello World!</Message></TestRequest>")38 .xslt("classpath
result
Using AI Code Generation
1package com.consol.citrus.dsl;2import com.consol.citrus.dsl.builder.TransformActionBuilder;3import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;4import org.testng.annotations.Test;5public class TransformActionBuilderTest extends TestNGCitrusTestDesigner {6 public void transformActionBuilder() {7 variable("var1", "value1");8 variable("var2", "value2");9 variable("var3", "value3");10 $(transformAction()11 .source("<testMessage><text>Hello Citrus!</text></testMessage>")12 .xslt("classpath:com/consol/citrus/dsl/transform.xsl")13 .result("<testMessage><text>Hello Citrus!</text><text>Hello Citrus!</text></testMessage>"));14 }15}16package com.consol.citrus.dsl;17import com.consol.citrus.dsl.builder.TransformActionBuilder;18import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;19import org.testng.annotations.Test;20public class TransformActionBuilderTest extends TestNGCitrusTestDesigner {21 public void transformActionBuilder() {22 variable("var1", "value1");23 variable("var2", "value2");24 variable("var3", "value3");25 $(transformAction()26 .source("<testMessage><text>Hello Citrus!</text></testMessage>")27 .xslt("classpath:com/consol/citrus/dsl/transform.xsl")28 .result("<testMessage><text>Hello Citrus!</text><text>Hello Citrus!</text></testMessage>")29 .description("Transform message using XSLT"));30 }31}32package com.consol.citrus.dsl;33import com.consol.citrus.dsl.builder.TransformActionBuilder;34import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;35import org.testng.annotations.Test;36public class TransformActionBuilderTest extends TestNGCitrusTestDesigner {37 public void transformActionBuilder() {38 variable("var1", "value1");39 variable("var2", "value2");
result
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import com.consol.citrus.dsl.builder.TransformActionBuilder;3import com.consol.citrus.dsl.builder.TransformActionBuilder.TransformActionBuilderSupport;4import com.consol.citrus.message.MessageType;5public class TransformActionBuilder extends TransformActionBuilderSupport<TransformActionBuilder> {6 public TransformActionBuilder() {7 super(new com.consol.citrus.actions.TransformAction());8 }9 public com.consol.citrus.actions.TransformAction getAction() {10 return (com.consol.citrus.actions.TransformAction) action;11 }12 public static TransformActionBuilder transform() {13 return new TransformActionBuilder();14 }15 public static TransformActionBuilder transform(com.consol.citrus.actions.TransformAction action) {16 return new TransformActionBuilder().action(action);17 }18 public TransformActionBuilder message(String message) {19 getAction().setMessage(message);20 return this;21 }22 public TransformActionBuilder message(com.consol.citrus.message.Message message) {23 getAction().setMessage(message);24 return this;25 }26 public TransformActionBuilder message(com.consol.citrus.message.MessageBuilder messageBuilder) {27 getAction().setMessage(messageBuilder.build());28 return this;29 }30 public TransformActionBuilder dataDictionary(com.consol.citrus.dictionary.DataDictionary<?> dataDictionary) {31 getAction().setDataDictionary(dataDictionary);32 return this;33 }34 public TransformActionBuilder messageType(MessageType messageType) {35 getAction().setMessageType(messageType);
result
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import com.consol.citrus.dsl.runner.TestRunner;3import org.testng.annotations.Test;4public class TransformActionBuilderTest {5 public void testTransformActionBuilder() {6 TestRunner runner = new TestRunner();7 runner.transform(builder -> builder8 .source("com.consol.citrus.dsl.builder.TransformActionBuilderTest$Source")9 .result("com.consol.citrus.dsl.builder.TransformActionBuilderTest$Result")10 .expression("payload.firstName + ' ' + payload.lastName")11 );12 }13 public static class Source {14 private String firstName;15 private String lastName;16 public String getFirstName() {17 return firstName;18 }19 public void setFirstName(String firstName) {20 this.firstName = firstName;21 }22 public String getLastName() {23 return lastName;24 }25 public void setLastName(String lastName) {26 this.lastName = lastName;27 }28 }29 public static class Result {30 private String fullName;31 public String getFullName() {32 return fullName;33 }34 public void setFullName(String fullName) {35 this.fullName = fullName;36 }37 }38}39package com.consol.citrus.dsl.builder;40import com.consol.citrus.dsl.runner.TestRunner;41import org.testng.annotations.Test;42public class TransformActionBuilderTest {43 public void testTransformActionBuilder() {44 TestRunner runner = new TestRunner();45 runner.transform(builder -> builder46 .source("com.consol.citrus.dsl.builder.TransformActionBuilderTest$Source")47 .result("com.consol.citrus.dsl.builder.TransformActionBuilderTest$Result")48 .expression("payload.firstName + ' ' + payload.lastName")49 .resultType("json")50 );51 }52 public static class Source {53 private String firstName;54 private String lastName;55 public String getFirstName() {56 return firstName;57 }58 public void setFirstName(String firstName) {59 this.firstName = firstName;60 }61 public String getLastName() {62 return lastName;63 }64 public void setLastName(String lastName) {65 this.lastName = lastName;66 }67 }68 public static class Result {69 private String fullName;70 public String getFullName() {71 return fullName;72 }
result
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import javax.xml.transform.Result;3import org.springframework.core.io.Resource;4import com.consol.citrus.dsl.builder.AbstractTestBuilder;5import com.consol.citrus.dsl.builder.TransformActionBuilder;6import com.consol.citrus.message.MessageType;7public interface TransformActionBuilder extends AbstractTestBuilder<TransformActionBuilder> {8 TransformActionBuilder payload(Object data);9 TransformActionBuilder payload(Resource resource);10 TransformActionBuilder payload(String resourcePath);11 TransformActionBuilder payload(Resource resource, String charset);12 TransformActionBuilder payload(String resourcePath, String charset);13 TransformActionBuilder xmlPayload(Object source);14 TransformActionBuilder xmlPayload(Object source, String charset);15 TransformActionBuilder xmlPayload(Resource resource);16 TransformActionBuilder xmlPayload(String resourcePath);17 TransformActionBuilder xmlPayload(Resource resource, String charset);18 TransformActionBuilder xmlPayload(String
result
Using AI Code Generation
1package com.consol.citrus.dsl.samples;2import com.consol.citrus.dsl.junit.JUnit4CitrusTest;3import org.springframework.http.HttpStatus;4import org.testng.annotations.Test;5public class TransformActionBuilder_3 extends JUnit4CitrusTest {6 public void transformActionBuilder_3() {7 variable("id", "citrus:randomNumber(10)");8 variable("name", "citrus:concat('Name_', citrus:randomNumber(3))");9 variable("description", "citrus:concat('Description_', citrus:randomNumber(3))");10 http().client("httpClient")11 .send()12 .post("/services/rest/bookstore/books")13 .contentType("application/xml")14 .payload("<book>" +15 " <id>${id}</id>" +16 " <name>${name}</name>" +17 " <description>${description}</description>" +18 "</book>");19 http().client("httpClient")20 .receive()21 .response(HttpStatus.CREATED);22 http().client("httpClient")23 .send()24 .get("/services/rest/bookstore/books/${id}");25 http().client("httpClient")26 .receive()27 .response(HttpStatus.OK)28 .payload("<book>" +29 " <id>${id}</id>" +30 " <name>${name}</name>" +31 " <description>${description}</description>" +32 "</book>");33 transform()34 .xslt()35 .source("<book>" +36 " <id>${id}</id>" +37 " <name>${name}</name>" +38 " <description>${description}</description>" +39 .xslt("classpath:com/consol/citrus/dsl/samples/TransformActionBuilder_3.xsl")40 .result("transformedResult");41 echo("Transformed result is: '${transformedResult}'");42 validate()43 .xpath()44 .expression("/Book/Id", "${id}")45 .expression("/Book/Name", "${name}")46 .expression("/Book/Description", "${description}")47 .message(transformedResult);48 }49}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!