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

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

Source:WebHookToFtp_IT.java Github

copy

Full Screen

1/*2 * Copyright (C) 2016 Red Hat, Inc.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 io.syndesis.test.itest.ftp;17import java.io.File;18import java.io.IOException;19import java.nio.file.Path;20import com.consol.citrus.actions.AbstractTestAction;21import com.consol.citrus.annotations.CitrusResource;22import com.consol.citrus.annotations.CitrusTest;23import com.consol.citrus.context.TestContext;24import com.consol.citrus.dsl.endpoint.CitrusEndpoints;25import com.consol.citrus.dsl.runner.TestRunner;26import com.consol.citrus.exceptions.CitrusRuntimeException;27import com.consol.citrus.ftp.message.FtpMessage;28import com.consol.citrus.http.client.HttpClient;29import com.consol.citrus.message.DefaultMessage;30import com.consol.citrus.util.FileUtils;31import com.consol.citrus.validation.json.JsonMessageValidationContext;32import com.consol.citrus.validation.json.JsonTextMessageValidator;33import io.syndesis.test.SyndesisTestEnvironment;34import io.syndesis.test.container.integration.SyndesisIntegrationRuntimeContainer;35import org.apache.commons.net.ftp.FTPCmd;36import org.apache.ftpserver.DataConnectionConfiguration;37import org.apache.ftpserver.DataConnectionConfigurationFactory;38import org.junit.Assert;39import org.junit.ClassRule;40import org.junit.Test;41import org.springframework.beans.factory.annotation.Autowired;42import org.springframework.context.annotation.Bean;43import org.springframework.context.annotation.Configuration;44import org.springframework.http.HttpStatus;45import org.springframework.test.annotation.DirtiesContext;46import org.springframework.test.context.ContextConfiguration;47import org.testcontainers.containers.GenericContainer;48/**49 * @author Christoph Deppisch50 */51@ContextConfiguration(classes = WebHookToFtp_IT.EndpointConfig.class)52@DirtiesContext53public class WebHookToFtp_IT extends FtpTestSupport {54 @Autowired55 private HttpClient webHookClient;56 /**57 * Integration receives a WebHook trigger with contact information as Json object. The contact is transformed to a csv like58 * comma delimited String and pushed to Ftp server as new file.59 */60 @ClassRule61 public static SyndesisIntegrationRuntimeContainer integrationContainer = new SyndesisIntegrationRuntimeContainer.Builder()62 .name("webhook-to-ftp")63 .fromExport(WebHookToFtp_IT.class.getResource("WebhookToFtp-export"))64 .customize("$..configuredProperties.contextPath", "contact")65 .customize("$..configuredProperties.directoryName", "public")66 .customize("$..configuredProperties.host", GenericContainer.INTERNAL_HOST_HOSTNAME)67 .customize("$..configuredProperties.port", FTP_TEST_SERVER_PORT)68 .build()69 .withExposedPorts(SyndesisTestEnvironment.getServerPort());70 @Test71 @CitrusTest72 public void testWebHookToFtp(@CitrusResource TestRunner runner) {73 runner.variable("first_name", "Joanne");74 runner.variable("company", "Red Hat");75 runner.variable("email", "joanne@syndesis.org");76 runner.http(builder -> builder.client(webHookClient)77 .send()78 .post()79 .fork(true)80 .payload("{\"first_name\":\"${first_name}\",\"company\":\"${company}\",\"mail\":\"${email}\"}"));81 runner.receive(receiveMessageBuilder -> receiveMessageBuilder82 .endpoint(ftpTestServer)83 .message(FtpMessage.command(FTPCmd.STOR).arguments("tmp_contacts.csv")));84 runner.send(sendMessageBuilder -> sendMessageBuilder85 .endpoint(ftpTestServer)86 .message(FtpMessage.success()));87 runner.receive(receiveMessageBuilder -> receiveMessageBuilder88 .endpoint(ftpTestServer)89 .message(FtpMessage.command(FTPCmd.RNFR).arguments("public/tmp_contacts.csv")));90 runner.send(sendMessageBuilder -> sendMessageBuilder91 .endpoint(ftpTestServer)92 .message(FtpMessage.success()));93 runner.http(builder -> builder.client(webHookClient)94 .receive()95 .response(HttpStatus.NO_CONTENT));96 runner.run(new VerifyFtpUploadTestAction());97 }98 @Configuration99 public static class EndpointConfig {100 @Bean101 public HttpClient webHookClient() {102 return CitrusEndpoints.http().client()103 .requestUrl(String.format("http://localhost:%s/webhook/contact", integrationContainer.getServerPort()))104 .build();105 }106 @Bean107 public DataConnectionConfiguration dataConnectionConfiguration() {108 DataConnectionConfigurationFactory dataConnectionFactory = new DataConnectionConfigurationFactory();109 dataConnectionFactory.setPassiveExternalAddress(integrationContainer.getInternalHostIp());110 dataConnectionFactory.setPassivePorts(String.valueOf(PASSIVE_PORT));111 return dataConnectionFactory.createDataConnectionConfiguration();112 }113 }114 /*115 * Helper test action ready the uploaded ftp file from user home directory and verifies116 * the content with Json message validator.117 */118 private static class VerifyFtpUploadTestAction extends AbstractTestAction {119 private static final String UPLOAD_FILENAME = "contacts.csv";120 @Override121 public void doExecute(TestContext testContext) {122 Path publicUserDir = getFtpUserHome().resolve("public");123 Assert.assertTrue( "Missing ftp user home directory", publicUserDir.toFile().exists());124 File ftpUploadFile = publicUserDir.resolve(UPLOAD_FILENAME).toFile();125 Assert.assertTrue(String.format("Missing ftp upload file '%s'", UPLOAD_FILENAME), ftpUploadFile.exists());126 try {127 JsonTextMessageValidator validator = new JsonTextMessageValidator();128 validator.validateMessage(new DefaultMessage(FileUtils.readToString(ftpUploadFile)),129 new DefaultMessage("{\"message\" : \"${first_name},${company},${email}\"}"),130 testContext,131 new JsonMessageValidationContext());132 } catch (IOException e) {133 throw new CitrusRuntimeException(String.format("Failed to verify ftp upload file '%s'", UPLOAD_FILENAME), e);134 }135 }136 }137}...

Full Screen

Full Screen

Source:ScenarioDesigner.java Github

copy

Full Screen

...14 * limitations under the License.15 */16package com.consol.citrus.simulator.scenario;17import com.consol.citrus.context.TestContext;18import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;19import com.consol.citrus.dsl.builder.SendMessageBuilder;20import com.consol.citrus.dsl.design.DefaultTestDesigner;21import com.consol.citrus.simulator.correlation.CorrelationHandlerBuilder;22import com.consol.citrus.simulator.correlation.CorrelationManager;23import com.consol.citrus.simulator.http.HttpScenarioActionBuilder;24import com.consol.citrus.simulator.ws.SoapScenarioActionBuilder;25import org.springframework.context.ApplicationContext;26/**27 * @author Christoph Deppisch28 */29public class ScenarioDesigner extends DefaultTestDesigner {30 /**31 * Scenario direct endpoint32 */33 private final ScenarioEndpoint scenarioEndpoint;34 /**35 * Default constructor using fields.36 *37 * @param scenarioEndpoint38 * @param applicationContext39 * @param context40 */41 public ScenarioDesigner(ScenarioEndpoint scenarioEndpoint, ApplicationContext applicationContext, TestContext context) {42 super(applicationContext, context);43 this.scenarioEndpoint = scenarioEndpoint;44 }45 /**46 * Start new message correlation so scenario is provided with additional inbound messages.47 *48 * @return49 */50 public CorrelationManager correlation() {51 return () -> {52 CorrelationHandlerBuilder builder = new CorrelationHandlerBuilder(scenarioEndpoint, getApplicationContext());53 action(builder);54 doFinally().actions(builder.stop());55 return builder;56 };57 }58 /**59 * Receive message from scenario endpoint.60 *61 * @return62 */63 public ReceiveMessageBuilder receive() {64 return (ReceiveMessageBuilder) receive(scenarioEndpoint)65 .description("Receive scenario request");66 }67 /**68 * Send message from scenario endpoint.69 *70 * @return71 */72 public SendMessageBuilder send() {73 return (SendMessageBuilder) send(scenarioEndpoint)74 .description("Send scenario response");75 }76 @Override77 public HttpScenarioActionBuilder http() {78 HttpScenarioActionBuilder builder = new HttpScenarioActionBuilder(scenarioEndpoint)...

Full Screen

Full Screen

ReceiveMessageBuilder

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;2import com.consol.citrus.dsl.runner.TestRunner;3public class ReceiveMessageBuilderDemo {4 public static void main(String[] args) {5 TestRunner runner = new TestRunner();6 ReceiveMessageBuilder receiveMessageBuilder = runner.receive();7 receiveMessageBuilder.message();8 receiveMessageBuilder.endpoint("myEndpoint");9 receiveMessageBuilder.selector("selector");10 receiveMessageBuilder.timeout(1000L);11 receiveMessageBuilder.extractFromHeader("headerName", "variableName");12 receiveMessageBuilder.extractFromPayload("/bookstore/book[1]/title", "variableName");13 receiveMessageBuilder.extractFromPayload("/bookstore/book[1]/title", "variableName");14 receiveMessageBuilder.extractFromPayload("/bookstore/book[1]/title", "variableName");15 receiveMessageBuilder.extractFromPayload("/bookstore/book[1]/title", "variableName");16 receiveMessageBuilder.extractFromPayload("/bookstore/book[1]/title", "variableName");17 receiveMessageBuilder.validateScript("groovy", "payload.size() == 3");18 receiveMessageBuilder.validateScript("javascript", "payload.size() == 3");19 receiveMessageBuilder.validateScript("python", "payload.size() == 3");20 receiveMessageBuilder.validateScript("ruby", "payload.size() == 3");21 receiveMessageBuilder.validateScript("xpath", "payload.size() == 3");22 receiveMessageBuilder.validateScript("xquery", "payload.size() == 3");23 receiveMessageBuilder.validateScript("xslt", "payload.size(

Full Screen

Full Screen

ReceiveMessageBuilder

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;2public class ReceiveMessageBuilderDemo {3public static void main(String[] args) {4ReceiveMessageBuilder receiveMessageBuilder = new ReceiveMessageBuilder();5receiveMessageBuilder.endpoint("myEndpoint");6receiveMessageBuilder.message("Hello World");7receiveMessageBuilder.validateMessage();8receiveMessageBuilder.validateMessage("Hello World");9}10}

Full Screen

Full Screen

ReceiveMessageBuilder

Using AI Code Generation

copy

Full Screen

1ReceiveMessageBuilder receiveMessageBuilder = new ReceiveMessageBuilder();2receiveMessageBuilder.endpoint(messageEndpoint);3receiveMessageBuilder.message(message);4receiveMessageBuilder.timeout(10000);5receiveMessageBuilder.selector("operation = 'sayHello'");6receiveMessageBuilder.selector("name

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful