How to use CitrusSpringObjectFactory method of cucumber.runtime.java.spring.CitrusSpringObjectFactory class

Best Citrus code snippet using cucumber.runtime.java.spring.CitrusSpringObjectFactory.CitrusSpringObjectFactory

Source:CitrusBackend.java Github

copy

Full Screen

...24import cucumber.api.java.*;25import cucumber.runtime.*;26import cucumber.runtime.io.ResourceLoader;27import cucumber.runtime.io.ResourceLoaderClassFinder;28import cucumber.runtime.java.spring.CitrusSpringObjectFactory;29import cucumber.runtime.snippets.FunctionNameGenerator;30import gherkin.pickles.PickleStep;31import io.cucumber.stepexpression.TypeRegistry;32import org.slf4j.Logger;33import org.slf4j.LoggerFactory;34import org.springframework.context.ApplicationContext;35import org.springframework.context.ConfigurableApplicationContext;36import org.springframework.context.support.ClassPathXmlApplicationContext;37import java.lang.reflect.Method;38import java.util.List;39import java.util.Map;40/**41 * @author Christoph Deppisch42 * @since 2.643 */44public class CitrusBackend implements Backend {45 /** Citrus instance used by all scenarios */46 private static Citrus citrus;47 /** Logger */48 private static Logger log = LoggerFactory.getLogger(CitrusBackend.class);49 /** Basic resource loader */50 private ResourceLoader resourceLoader;51 private TypeRegistry typeRegistry;52 /**53 * Constructor using resource loader.54 * @param resourceLoader55 */56 public CitrusBackend(ResourceLoader resourceLoader, TypeRegistry typeRegistry) {57 this.resourceLoader = resourceLoader;58 this.typeRegistry = typeRegistry;59 Citrus.CitrusInstanceManager.addInstanceProcessor(instance -> instance.beforeSuite(CitrusReporter.SUITE_NAME));60 }61 @Override62 public void loadGlue(Glue glue, List<String> gluePaths) {63 try {64 Citrus.CitrusInstanceManager.addInstanceProcessor(new XmlStepInstanceProcessor(glue, gluePaths, getObjectFactory(), typeRegistry));65 } catch (IllegalAccessException e) {66 throw new CitrusRuntimeException("Failed to add XML step definition", e);67 }68 try {69 if (!gluePaths.contains(CitrusLifecycleHooks.class.getPackage().getName()) && getObjectFactory().addClass(CitrusLifecycleHooks.class)) {70 Method beforeMethod = CitrusLifecycleHooks.class.getMethod("before", Scenario.class);71 Before beforeAnnotation = beforeMethod.getAnnotation(Before.class);72 glue.addBeforeHook(new JavaHookDefinition(beforeMethod, beforeAnnotation.value(), beforeAnnotation.order(), beforeAnnotation.timeout(), getObjectFactory()));73 Method afterMethod = CitrusLifecycleHooks.class.getMethod("after", Scenario.class);74 After afterAnnotation = afterMethod.getAnnotation(After.class);75 glue.addAfterHook(new JavaHookDefinition(afterMethod, afterAnnotation.value(), afterAnnotation.order(), afterAnnotation.timeout(), getObjectFactory()));76 }77 } catch (NoSuchMethodException | IllegalAccessException e) {78 throw new CucumberException("Unable to add Citrus lifecylce hooks");79 }80 }81 @Override82 public void buildWorld() {83 }84 @Override85 public void disposeWorld() {86 }87 @Override88 public String getSnippet(PickleStep step, String keyword, FunctionNameGenerator functionNameGenerator) {89 return "";90 }91 /**92 * Gets the object factory instance that is configured in environment.93 * @return94 */95 private ObjectFactory getObjectFactory() throws IllegalAccessException {96 if (Env.INSTANCE.get(ObjectFactory.class.getName()).equals(CitrusObjectFactory.class.getName())) {97 return CitrusObjectFactory.instance();98 } else if (Env.INSTANCE.get(ObjectFactory.class.getName()).equals(CitrusSpringObjectFactory.class.getName())) {99 return CitrusSpringObjectFactory.instance();100 }101 return ObjectFactoryLoader.loadObjectFactory(new ResourceLoaderClassFinder(resourceLoader, Thread.currentThread().getContextClassLoader()),102 Env.INSTANCE.get(ObjectFactory.class.getName()));103 }104 /**105 * Provide access to the Citrus instance.106 * @return107 */108 public static Citrus getCitrus() {109 if (citrus == null) {110 citrus = Citrus.newInstance();111 }112 return citrus;113 }...

Full Screen

Full Screen

Source:CitrusSpringObjectFactory.java Github

copy

Full Screen

...29/**30 * @author Christoph Deppisch31 * @since 2.632 */33public class CitrusSpringObjectFactory extends SpringFactory {34 /** Logger */35 private static Logger log = LoggerFactory.getLogger(CitrusSpringObjectFactory.class);36 /** Test designer */37 private TestDesigner designer;38 /** Test runner */39 private TestRunner runner;40 /** Test context */41 private TestContext context;42 /** Static self reference */43 private static CitrusSpringObjectFactory selfReference;44 /** Mode to use for injection */45 private InjectionMode mode = null;46 /**47 * Default constructor with static self reference initialization.48 */49 public CitrusSpringObjectFactory() {50 selfReference = this;51 }52 @Override53 public boolean addClass(Class<?> clazz) {54 InjectionMode fallback;55 if (mode == null) {56 log.info("Initializing injection mode for Citrus " + Citrus.getVersion());57 fallback = InjectionMode.valueOf(System.getProperty(CitrusObjectFactory.INJECTION_MODE_PROPERTY, System.getenv(CitrusObjectFactory.INJECTION_MODE_ENV) != null ?58 System.getenv(CitrusObjectFactory.INJECTION_MODE_ENV) : InjectionMode.DESIGNER.name()));59 } else {60 fallback = mode;61 }62 InjectionMode requiredMode = InjectionMode.analyseMode(clazz, fallback);63 if (mode == null) {64 mode = requiredMode;65 } else if (!mode.equals(requiredMode)) {66 log.warn(String.format("Ignoring class of injection type '%s' as current injection mode is '%s'", requiredMode, mode));67 return false;68 }69 return super.addClass(clazz);70 }71 @Override72 public void start() {73 super.start();74 context = getInstance(TestContext.class);75 if (mode == null) {76 mode = InjectionMode.valueOf(System.getProperty(CitrusObjectFactory.INJECTION_MODE_PROPERTY, System.getenv(CitrusObjectFactory.INJECTION_MODE_ENV) != null ?77 System.getenv(CitrusObjectFactory.INJECTION_MODE_ENV) : InjectionMode.DESIGNER.name()));78 }79 if (InjectionMode.DESIGNER.equals(mode)) {80 designer = new DefaultTestDesigner(CitrusBackend.getCitrus().getApplicationContext(), context);81 }82 if (InjectionMode.RUNNER.equals(mode)) {83 runner = new DefaultTestRunner(CitrusBackend.getCitrus().getApplicationContext(), context);84 }85 }86 @Override87 public <T> T getInstance(Class<T> type) {88 if (context == null) {89 try {90 context = super.getInstance(TestContext.class);91 CitrusBackend.initializeCitrus(context.getApplicationContext());92 } catch (CucumberException e) {93 log.warn("Failed to get proper TestContext from Cucumber Spring application context: " + e.getMessage());94 context = CitrusBackend.getCitrus().createTestContext();95 }96 }97 if (TestContext.class.isAssignableFrom(type)) {98 return (T) context;99 }100 if (CitrusSpringObjectFactory.class.isAssignableFrom(type)) {101 return (T) this;102 }103 T instance = super.getInstance(type);104 CitrusAnnotations.injectAll(instance, CitrusBackend.getCitrus());105 if (InjectionMode.DESIGNER.equals(mode)) {106 CitrusDslAnnotations.injectTestDesigner(instance, designer);107 }108 if (InjectionMode.RUNNER.equals(mode)) {109 CitrusDslAnnotations.injectTestRunner(instance, runner);110 }111 return instance;112 }113 /**114 * Static access to self reference.115 * @return116 */117 public static CitrusSpringObjectFactory instance() throws IllegalAccessException {118 if (selfReference == null) {119 throw new IllegalAccessException("Illegal access to self reference - not available yet");120 }121 return selfReference;122 }123}...

Full Screen

Full Screen

Source:CitrusSpringObjectFactoryTest.java Github

copy

Full Screen

...20/**21 * @author Christoph Deppisch22 * @since 2.623 */24public class CitrusSpringObjectFactoryTest {25 @AfterMethod(alwaysRun = true)26 public void resetCitrus() {27 CitrusBackend.resetCitrus();28 }29 @Test30 public void testDesignerInject() throws Exception {31 CitrusSpringObjectFactory factory = new CitrusSpringObjectFactory();32 factory.addClass(SpringDesignerSteps.class);33 // Scenario 134 factory.start();35 final SpringDesignerSteps steps = factory.getInstance(SpringDesignerSteps.class);36 Assert.assertNotNull(steps.getTestDesigner());37 factory.stop();38 }39 @Test40 public void testDesignerInjectWithDefaultContext() throws Exception {41 CitrusSpringObjectFactory factory = new CitrusSpringObjectFactory();42 factory.addClass(DefaultSpringDesignerSteps.class);43 // Scenario 144 factory.start();45 final DefaultSpringDesignerSteps steps = factory.getInstance(DefaultSpringDesignerSteps.class);46 Assert.assertNotNull(steps.getTestDesigner());47 factory.stop();48 }49 @Test50 public void testRunnerInject() throws Exception {51 CitrusSpringObjectFactory factory = new CitrusSpringObjectFactory();52 factory.addClass(SpringRunnerSteps.class);53 // Scenario 154 factory.start();55 final SpringRunnerSteps steps = factory.getInstance(SpringRunnerSteps.class);56 Assert.assertNotNull(steps.getTestRunner());57 factory.stop();58 }59 @Test60 public void testRunnerInjectWithDefaultContext() throws Exception {61 CitrusSpringObjectFactory factory = new CitrusSpringObjectFactory();62 factory.addClass(DefaultSpringRunnerSteps.class);63 // Scenario 164 factory.start();65 final DefaultSpringRunnerSteps steps = factory.getInstance(DefaultSpringRunnerSteps.class);66 Assert.assertNotNull(steps.getTestRunner());67 factory.stop();68 }69}...

Full Screen

Full Screen

CitrusSpringObjectFactory

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.cucumber.spring;2import cucumber.api.CucumberOptions;3import cucumber.api.junit.Cucumber;4import org.junit.runner.RunWith;5@RunWith(Cucumber.class)6@CucumberOptions(features = "classpath:com/consol/citrus/cucumber/spring/features",7 plugin = { "pretty", "html:target/cucumber-html-report", "json:target/cucumber-json-report.json" },8public class CitrusSpringTestRunner {9}10package com.consol.citrus.cucumber.spring;11import cucumber.api.CucumberOptions;12import cucumber.api.junit.Cucumber;13import org.junit.runner.RunWith;14@RunWith(Cucumber.class)15@CucumberOptions(features = "classpath:com/consol/citrus/cucumber/spring/features",16 plugin = { "pretty", "html:target/cucumber-html-report", "json:target/cucumber-json-report.json" },17public class CitrusSpringTestRunner {18}19package com.consol.citrus.cucumber.spring;20import cucumber.api.CucumberOptions;21import cucumber.api.junit.Cucumber;22import org.junit.runner.RunWith;23@RunWith(Cucumber.class)24@CucumberOptions(features = "classpath:com/consol/citrus/cucumber/spring/features",25 plugin = { "pretty", "html:target/cucumber-html-report", "json:target/cucumber-json-report.json" },26public class CitrusSpringTestRunner {27}28package com.consol.citrus.cucumber.spring;29import cucumber.api.CucumberOptions;30import cucumber.api.junit.Cucumber;31import org.junit.runner.RunWith;32@RunWith(Cucumber.class)33@CucumberOptions(features =

Full Screen

Full Screen

CitrusSpringObjectFactory

Using AI Code Generation

copy

Full Screen

1package com.cucumberFramework.stepDefinitions;2import org.springframework.beans.factory.annotation.Autowired;3import org.springframework.test.context.ContextConfiguration;4import com.consol.citrus.context.TestContext;5import com.consol.citrus.dsl.junit.JUnit4CitrusTestRunner;6import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;7import com.consol.citrus.http.client.HttpClient;8import com.consol.citrus.message.MessageType;9import com.consol.citrus.testng.CitrusParameters;10import com.consol.citrus.validation.json.JsonTextMessageValidator;11import com.consol.citrus.ws.client.WebServiceClient;12import com.consol.citrus.ws.client.WebServiceEndpointConfiguration;13import com.consol.citrus.ws.message.converter.SoapAttachmentMessageConverter;14import com.consol.citrus.ws.message.converter.SoapMessageConverter;15import cucumber.api.java.en.Given;16import cucumber.api.java.en.Then;17import cucumber.api.java.en.When;18@ContextConfiguration(classes = { com.cucumberFramework.stepDefinitions.CitrusSpringObjectFactory.class })19public class StepDefinition extends TestNGCitrusTestRunner {20 private HttpClient httpClient;21 private WebServiceClient webServiceClient;22 @Given("^User is on Home Page$")23 public void user_is_on_Home_Page() throws Throwable {24 http(httpClient).receive().response(HttpStatus.OK).messageType(MessageType.PLAINTEXT)25 }26 @When("^User Navigate to LogIn Page$")27 public void user_Navigate_to_LogIn_Page() throws Throwable {28 webService(webServiceClient).receive().response(HttpStatus.OK).messageType(MessageType.XML)29 .payload("<ns2:HelloResponse xmlns:

Full Screen

Full Screen

CitrusSpringObjectFactory

Using AI Code Generation

copy

Full Screen

1import cucumber.runtime.java.spring.CitrusSpringObjectFactory;2import org.springframework.beans.factory.annotation.Autowired;3import org.springframework.context.ApplicationContext;4import org.springframework.context.ApplicationContextAware;5import org.springframework.stereotype.Component;6public class SpringBean extends CitrusSpringObjectFactory implements ApplicationContextAware {7 private ApplicationContext applicationContext;8 public void setApplicationContext(ApplicationContext applicationContext) {9 this.applicationContext = applicationContext;10 }11 public Object getInstance(Class<?> clazz) {12 return applicationContext.getBean(clazz);13 }14}15package step;16import cucumber.api.java.en.Given;17import org.springframework.context.ApplicationContext;18import org.springframework.context.ApplicationContextAware;19import org.springframework.stereotype.Component;20public class SpringBean implements ApplicationContextAware {21 private ApplicationContext applicationContext;22 public void setApplicationContext(ApplicationContext applicationContext) {23 this.applicationContext = applicationContext;24 }25 @Given("^I use a spring bean$")26 public void i_use_a_spring_bean() throws Throwable {27 SpringBean springBean = (SpringBean) applicationContext.getBean("springBean");28 springBean.sayHello();29 }30}31package step;32import org.springframework.stereotype.Component;33public class SpringBean {34 public void sayHello() {35 System.out.println("Hello");36 }37}

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 method in CitrusSpringObjectFactory

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful