How to use getReferenceResolver method of com.consol.citrus.context.TestContext class

Best Citrus code snippet using com.consol.citrus.context.TestContext.getReferenceResolver

Source:KafkaSteps.java Github

copy

Full Screen

...55 private long timeout = KafkaSettings.getConsumerTimeout();56 @Before57 public void before(Scenario scenario) {58 if (kafkaEndpoint == null) {59 if (citrus.getCitrusContext().getReferenceResolver().resolveAll(KafkaEndpoint.class).size() == 1L) {60 kafkaEndpoint = citrus.getCitrusContext().getReferenceResolver().resolve(KafkaEndpoint.class);61 } else if (citrus.getCitrusContext().getReferenceResolver().isResolvable(endpointName)) {62 kafkaEndpoint = citrus.getCitrusContext().getReferenceResolver().resolve(endpointName, KafkaEndpoint.class);63 } else {64 kafkaEndpoint = new KafkaEndpointBuilder().build();65 citrus.getCitrusContext().getReferenceResolver().bind(endpointName, kafkaEndpoint);66 }67 }68 headers = new HashMap<>();69 body = null;70 messageKey = null;71 partition = null;72 }73 @Given("^(?:Kafka|kafka) connection$")74 public void setConnection(DataTable properties) {75 Map<String, String> connectionProps = properties.asMap(String.class, String.class);76 String url = connectionProps.getOrDefault("url", "localhost:9092");77 String topicName = connectionProps.getOrDefault("topic", this.topic);78 String consumerGroup = connectionProps.getOrDefault("consumerGroup", KafkaMessageHeaders.KAFKA_PREFIX + "group");79 String offsetReset = connectionProps.getOrDefault("offsetReset", "earliest");80 setTopic(context.replaceDynamicContentInString(topicName));81 kafkaEndpoint.getEndpointConfiguration().setServer(context.replaceDynamicContentInString(url));82 kafkaEndpoint.getEndpointConfiguration().setOffsetReset(context.replaceDynamicContentInString(offsetReset));83 kafkaEndpoint.getEndpointConfiguration().setConsumerGroup(context.replaceDynamicContentInString(consumerGroup));84 }85 @Given("^(?:Kafka|kafka) producer configuration$")86 public void setProducerConfig(DataTable properties) {87 Map<String, Object> producerProperties = properties.asMap(String.class, Object.class);88 kafkaEndpoint.getEndpointConfiguration().setProducerProperties(producerProperties);89 }90 @Given("^(?:Kafka|kafka) consumer configuration$")91 public void setConsumerConfig(DataTable properties) {92 Map<String, Object> consumerProperties = properties.asMap(String.class, Object.class);93 kafkaEndpoint.getEndpointConfiguration().setConsumerProperties(consumerProperties);94 }95 @Given("^(?:Kafka|kafka) endpoint \"([^\"\\s]+)\"$")96 public void setServer(String name) {97 this.endpointName = name;98 if (citrus.getCitrusContext().getReferenceResolver().isResolvable(name)) {99 kafkaEndpoint = citrus.getCitrusContext().getReferenceResolver().resolve(name, KafkaEndpoint.class);100 } else if (kafkaEndpoint != null) {101 citrus.getCitrusContext().getReferenceResolver().bind(endpointName, kafkaEndpoint);102 kafkaEndpoint.setName(endpointName);103 }104 }105 @Given("^(?:Kafka|kafka) message key: (.+)$")106 public void setMessageKey(String key) {107 this.messageKey = key;108 }109 @Given("^(?:Kafka|kafka) consumer timeout is (\\d+)(?: ms| milliseconds)$")110 public void setConsumerTimeout(int milliseconds) {111 this.timeout = milliseconds;112 }113 @Given("^(?:Kafka|kafka) topic partition: (\\d+)$")114 public void setPartition(int partition) {115 this.partition = partition;...

Full Screen

Full Screen

Source:JmsSteps.java Github

copy

Full Screen

...55 private long timeout = JmsSettings.getTimeout();56 @Before57 public void before(Scenario scenario) {58 if (jmsEndpoint == null) {59 if (citrus.getCitrusContext().getReferenceResolver().resolveAll(JmsEndpoint.class).size() == 1L) {60 jmsEndpoint = citrus.getCitrusContext().getReferenceResolver().resolve(JmsEndpoint.class);61 } else if (citrus.getCitrusContext().getReferenceResolver().isResolvable(endpointName)) {62 jmsEndpoint = citrus.getCitrusContext().getReferenceResolver().resolve(endpointName, JmsEndpoint.class);63 } else {64 jmsEndpoint = new JmsEndpointBuilder()65 .timeout(timeout)66 .build();67 citrus.getCitrusContext().getReferenceResolver().bind(endpointName, jmsEndpoint);68 }69 }70 if (connectionFactory == null71 && citrus.getCitrusContext().getReferenceResolver().resolveAll(ConnectionFactory.class).size() == 1L) {72 connectionFactory = citrus.getCitrusContext().getReferenceResolver().resolve(ConnectionFactory.class);73 if (jmsEndpoint.getEndpointConfiguration().getConnectionFactory() == null) {74 jmsEndpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);75 }76 }77 headers = new HashMap<>();78 body = null;79 }80 @Given("^(?:JMS|jms) connection factory ([^\\s]+)$")81 public void setConnectionFactory(String name) {82 if (citrus.getCitrusContext().getReferenceResolver().isResolvable(name)) {83 connectionFactory = citrus.getCitrusContext().getReferenceResolver().resolve(name, ConnectionFactory.class);84 jmsEndpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);85 } else {86 throw new CitrusRuntimeException(String.format("Unable to find connection factory '%s'", name));87 }88 }89 @Given("^(?:JMS|jms) connection factory$")90 public void setConnection(DataTable properties) throws ClassNotFoundException {91 List<List<String>> cells = properties.cells();92 Map<String, String> connectionSettings = new LinkedHashMap<>();93 cells.forEach(row -> connectionSettings.put(row.get(0), context.replaceDynamicContentInString(row.get(1))));94 connectionFactory = ConnectionFactoryCreator.lookup(connectionSettings.get("type"))95 .create(connectionSettings);96 citrus.getCitrusContext().getReferenceResolver().bind("connectionFactory", connectionFactory);97 jmsEndpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);98 }99 @Given("^(?:JMS|jms) destination: ([^\\s]+)$")100 public void setDestination(String destination) {101 jmsEndpoint.getEndpointConfiguration().setDestinationName(destination);102 }103 @Given("^(?:JMS|jms) endpoint \"([^\"\\s]+)\"$")104 public void setEndpoint(String name) {105 this.endpointName = name;106 if (citrus.getCitrusContext().getReferenceResolver().isResolvable(name)) {107 jmsEndpoint = citrus.getCitrusContext().getReferenceResolver().resolve(name, JmsEndpoint.class);108 } else if (jmsEndpoint != null) {109 citrus.getCitrusContext().getReferenceResolver().bind(endpointName, jmsEndpoint);110 jmsEndpoint.setName(endpointName);111 }112 }113 @Given("^(?:JMS|jms) selector: (.+)$")114 public void selector(String selector) {115 this.selector = selector;116 }117 @Given("^(?:JMS|jms) consumer timeout is (\\d+)(?: ms| milliseconds)$")118 public void configureTimeout(long timeout) {119 this.timeout = timeout;120 }121 @Given("^(?:JMS|jms) message header ([^\\s]+)(?:=| is )\"(.+)\"$")122 @Then("^(?:expect|verify) (?:JMS|jms) message header ([^\\s]+)(?:=| is )\"(.+)\"$")123 public void addMessageHeader(String name, Object value) {...

Full Screen

Full Screen

Source:ScenarioRunner.java Github

copy

Full Screen

...63 *64 * @return65 */66 public HttpScenarioRunnerActionBuilder http() {67 return new HttpScenarioRunnerActionBuilder(this, scenarioEndpoint).withReferenceResolver(getTestContext().getReferenceResolver());68 }69 /**70 * Special scenario endpoint http operation.71 *72 * @return73 */74 public SoapScenarioRunnerActionBuilder soap() {75 return new SoapScenarioRunnerActionBuilder(this, scenarioEndpoint).withReferenceResolver(getTestContext().getReferenceResolver());76 }77 /**78 * Sends SOAP fault as scenario response.79 *80 * @return81 */82 public SendSoapFaultAction sendFault(BuilderSupport<SendSoapFaultActionBuilder> configurer) {83 84 SendSoapFaultActionBuilder sendFaultActionBuilder = new SoapActionBuilder().withReferenceResolver(getTestContext().getReferenceResolver())85 .server(scenarioEndpoint.getName()).sendFault();86 87 configurer.configure(sendFaultActionBuilder);88 run(sendFaultActionBuilder);89 90 return (SendSoapFaultAction) sendFaultActionBuilder.build();91 }92 /**93 * Gets the scenario inbound endpoint.94 *95 * @return96 */97 public ScenarioEndpoint scenarioEndpoint() {98 return scenarioEndpoint;...

Full Screen

Full Screen

getReferenceResolver

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import org.testng.annotations.Test;3import org.testng.Assert;4import org.testng.AssertJUnit;5import org.testng.annotations.Test;6import org.testng.annotations.BeforeMethod;7import org.testng.annotations.AfterMethod;8import org.testng.annotations.BeforeClass;9import org.testng.annotations.AfterClass;10import org.testng.annotations.BeforeTest;11import org.testng.annotations.AfterTest;12import org.testng.annotations.BeforeSuite;13import org.testng.annotations.AfterSuite;14import org.testng.annotations.DataProvider;15import org.testng.annotations.Parameters;16import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;17import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;18public class 4 extends TestNGCitrusTestRunner {19 @Parameters({"context"})20 public void 4(String context) {21 echo("Hello World!");22 }23}24package com.consol.citrus;25import org.testng.annotations.Test;26import org.testng.Assert;27import org.testng.AssertJUnit;28import org.testng.annotations.Test;29import org.testng.annotations.BeforeMethod;30import org.testng.annotations.AfterMethod;31import org.testng.annotations.BeforeClass;32import org.testng.annotations.AfterClass;33import org.testng.annotations.BeforeTest;34import org.testng.annotations.AfterTest;35import org.testng.annotations.BeforeSuite;36import org.testng.annotations.AfterSuite;37import org.testng.annotations.DataProvider;38import org.testng.annotations.Parameters;39import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;40import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;41public class 5 extends TestNGCitrusTestRunner {42 @Parameters({"context"})43 public void 5(String context) {44 echo("Hello World!");45 }46}47package com.consol.citrus;48import org.testng.annotations.Test;49import org.testng.Assert;50import org.testng.AssertJUnit;51import org.testng.annotations.Test;52import org.testng.annotations.BeforeMethod;53import org.testng.annotations.AfterMethod;54import org.testng.annotations.BeforeClass;55import org.testng.annotations.AfterClass;56import org.testng.annotations.BeforeTest;57import org.testng.annotations.AfterTest;58import org.testng.annotations.BeforeSuite;59import org.testng.annotations.AfterSuite;60import org.testng.annotations.DataProvider;61import org.testng.annotations.Parameters;

Full Screen

Full Screen

getReferenceResolver

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import org.testng.annotations.Test;3import org.testng.Assert;4import org.testng.annotations.BeforeClass;5import org.testng.annotations.AfterClass;6import org.springframework.context.ApplicationContext;7import org.springframework.context.support.ClassPathXmlApplicationContext;8import org.springframework.beans.f

Full Screen

Full Screen

getReferenceResolver

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.context.TestContextFactory;4import com.consol.citrus.context.TestContextReferenceResolver;5import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;6import org.testng.annotations.Test;7import java.util.HashMap;8import java.util.Map;9public class Path4 extends TestNGCitrusTestDesigner {10 public void test() {11 TestContext context = TestContextFactory.create();12 Map<String, Object> variables = new HashMap<>();13 variables.put("var1", "value1");14 variables.put("var2", "value2");15 context.setVariables(variables);16 TestContextReferenceResolver resolver = context.getReferenceResolver();17 System.out.println(resolver.resolve("var1"));18 }19}20package com.consol.citrus;21import com.consol.citrus.context.TestContext;22import com.consol.citrus.context.TestContextFactory;23import com.consol.citrus.context.TestContextReferenceResolver;24import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;25import org.testng.annotations.Test;26import java.util.HashMap;27import java.util.Map;28public class Path5 extends TestNGCitrusTestDesigner {29 public void test() {30 TestContext context = TestContextFactory.create();31 Map<String, Object> variables = new HashMap<>();32 variables.put("var1", "value1");33 variables.put("var2", "value2");34 context.setVariables(variables);35 TestContextReferenceResolver resolver = context.getReferenceResolver();36 System.out.println(resolver.resolve("var1"));37 }38}39package com.consol.citrus;40import com.consol.citrus.context.TestContext;41import com.consol.citrus.context.TestContextFactory;42import com.consol.citrus.context.TestContextReferenceResolver;43import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;44import org.testng.annotations.Test;45import java.util.HashMap;46import java.util.Map

Full Screen

Full Screen

getReferenceResolver

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import org.testng.annotations.Test;3import org.testng.Assert;4import org.testng.AssertJUnit;5import java.util.HashMap;6import java.util.Map;7import java.util.Properties;8import org.springframework.context.ApplicationContext;9import org.springframework.context.support.ClassPathXmlApplicationContext;10public class Test4 {11 public void test1() {12 ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");13 TestContext testContext = new TestContext(applicationContext);14 Map<String, Object> variables = new HashMap<String, Object>();15 variables.put("key", "value");16 testContext.setVariables(variables);17 Properties properties = new Properties();18 properties.setProperty("key", "value");19 testContext.setProperties(properties);20 AssertJUnit.assertEquals(testContext.getReferenceResolver(), new TestContext(applicationContext).getReferenceResolver());21 }22}23package com.consol.citrus;24import org.testng.annotations.Test;25import org.testng.Assert;26import org.testng.AssertJUnit;27import java.util.HashMap;28import java.util.Map;29import java.util.Properties;30import org.springframework.context.ApplicationContext;31import org.springframework.context.support.ClassPathXmlApplicationContext;32public class Test5 {33 public void test1() {34 ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");35 TestContext testContext = new TestContext(applicationContext);36 Map<String, Object> variables = new HashMap<String, Object>();37 variables.put("key", "value");38 testContext.setVariables(variables);39 Properties properties = new Properties();40 properties.setProperty("key", "value");41 testContext.setProperties(properties);42 AssertJUnit.assertEquals(testContext.getReferenceResolver(), new TestContext(applicationContext).getReferenceResolver());43 }44}45package com.consol.citrus;46import org.testng.annotations.Test;47import org.testng.Assert;48import org.testng.AssertJUnit;49import java.util.HashMap;50import java.util.Map;51import java.util.Properties;52import org.springframework.context.ApplicationContext;53import org.springframework.context.support.ClassPathXmlApplicationContext;54public class Test6 {55 public void test1() {56 ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");

Full Screen

Full Screen

getReferenceResolver

Using AI Code Generation

copy

Full Screen

1public class Test {2 public static void main(String[] args) {3 TestContext context = new TestContext();4 context.setVariable("var", "value");5 System.out.println(context.getReferenceResolver().resolve("var"));6 }7}

Full Screen

Full Screen

getReferenceResolver

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;4import com.consol.citrus.dsl.builder.SendActionBuilder;5import com.consol.citrus.dsl.runner.TestRunner;6import com.consol.citrus.dsl.runner.TestRunnerSupport;7import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;8import com.consol.citrus.message.DefaultMessage;9import com.consol.citrus.message.MessageType;10import com.consol.citrus.testng.CitrusParameters;11import org.springframework.core.io.ClassPathResource;12import org.springframework.core.io.Resource;13import org.springframework.util.StringUtils;14import org.testng.annotations.Test;15import java.util.Map;16import static com.consol.citrus.actions.EchoAction.Builder.echo;17import static com.consol.citrus.actions.SendMessageAction.Builder.send;18import static com.consol.citrus.container.Sequence.Builder.sequential;19import static com.consol.citrus.dsl.builder.Builder.*;20import static com.consol.citrus.dsl.builder.Builder.applyBehavior;21import static com.consol.citrus.dsl.builder.Builder.extractFromHeader;22import static com.consol.citrus.dsl.builder.Builder.http;23import static com.consol.citrus.dsl.builder.Builder.httpAction;24import static com.consol.citrus.dsl.builder.Builder.httpServer;25import static com.consol.citrus.dsl.builder.Builder.readVariable;26import static com.consol.citrus.dsl.builder.Builder.receive;27import static com.consol.citrus.dsl.builder.Builder.send;28import static com.consol.citrus.dsl.builder.Builder.server;29import static com.consol.citrus.dsl.builder.Builder.setVariable;30import static com.consol.citrus.dsl.builder.Builder.soap;31import static com.consol.citrus.dsl.builder.Builder.soapClient;32import static com.consol.citrus.dsl.builder.Builder.soapServer;33import static com.consol.citrus.dsl.builder.Builder.sql;34import static com.consol.citrus.dsl.builder.Builder.sqlAction;35import static com.consol.citrus.dsl.builder.Builder.sqlServer;36import static com.consol.citrus.dsl.builder.Builder.waitFor;37import static com.consol.citrus.dsl.builder.Builder.waitForBuilder;38import static com.consol.citrus.dsl.builder.Builder.ws;39import static com.consol.citrus.dsl.builder.Builder.wsClient;40import static com.consol.c

Full Screen

Full Screen

getReferenceResolver

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.context;2import java.util.HashMap;3import java.util.Map;4import org.springframework.context.support.ClassPathXmlApplicationContext;5import org.testng.Assert;6import org.testng.annotations.Test;7import com.consol.citrus.context.TestContext;8import com.consol.citrus.exceptions.CitrusRuntimeException;9import com.consol.citrus.testng.AbstractTestNGUnitTest;10public class GetReferenceResolverTest extends AbstractTestNGUnitTest {11public void testGetReferenceResolver() throws Exception {12ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(13new String[] { "com/consol/citrus/config/citrus-context.xml" });14TestContext context = new TestContext();15context.setApplicationContext(applicationContext);16Map<String, Object> variables = new HashMap<String, Object>();17variables.put("foo", "bar");18context.setVariables(variables);19Object referenceResolver = context.getReferenceResolver();20Assert.assertNotNull(referenceResolver);21Assert.assertTrue(referenceResolver instanceof ReferenceResolver);22}23@Test(expectedExceptions = CitrusRuntimeException.class)24public void testGetReferenceResolverWithoutApplicationContext() throws Exception {25TestContext context = new TestContext();26Object referenceResolver = context.getReferenceResolver();27}28}29package com.consol.citrus.context;30import java.util.HashMap;31import java.util.Map;32import org.springframework.context.support.ClassPathXmlApplicationContext;33import org.testng.Assert;34import org.testng.annotations.Test;35import com.consol.citrus.context.TestContext;36import com.consol.citrus.exceptions.CitrusRuntimeException;37import com.consol.citrus.testng.AbstractTestNGUnitTest;38public class GetReferenceResolverTest extends AbstractTestNGUnitTest {39public void testGetReferenceResolver() throws Exception {40ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(41new String[] { "com/consol/citrus/config/citrus-context.xml" });42TestContext context = new TestContext();43context.setApplicationContext(applicationContext);

Full Screen

Full Screen

getReferenceResolver

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import org.springframework.context.support.ClassPathXmlApplicationContext;3import com.consol.citrus.context.TestContext;4import com.consol.citrus.context.TestContextFactory;5public class 4 {6 public static void main(String[] args) {7 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");8 TestContextFactory factory = context.getBean(TestContextFactory.class);9 TestContext testContext = factory.getObject();10 String value = testContext.getReferenceResolver().resolve("variable");11 System.out.println(value);12 }13}

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