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

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

Source:CitrusBackend.java Github

copy

Full Screen

...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 }114 /**115 * Initializes Citrus instance with given application context.116 * @param applicationContext117 * @return118 */119 public static void initializeCitrus(ApplicationContext applicationContext) {120 if (citrus != null) {121 if (!citrus.getApplicationContext().equals(applicationContext)) {122 log.warn("Citrus instance has already been initialized - creating new instance and shutting down current instance");123 if (citrus.getApplicationContext() instanceof ConfigurableApplicationContext) {124 ((ConfigurableApplicationContext) citrus.getApplicationContext()).stop();125 }126 } else {127 return;128 }129 }130 citrus = Citrus.newInstance(applicationContext);131 }132 /**133 * Reset Citrus instance. Use this method with special care. Usually Citrus instance should only be instantiated134 * once throughout the whole test suite run.135 */136 public static void resetCitrus() {137 citrus = null;138 }139 /**140 * Initialization hook performs before suite actions and XML step initialization. Called as soon as citrus instance is requested141 * from outside for the first time. Performs only once.142 */143 private static class XmlStepInstanceProcessor implements Citrus.InstanceProcessor {144 private final Glue glue;145 private final List<String> gluePaths;146 private final ObjectFactory objectFactory;147 private TypeRegistry typeRegistry;148 XmlStepInstanceProcessor(Glue glue, List<String> gluePaths, ObjectFactory objectFactory, TypeRegistry typeRegistry) {149 this.glue = glue;150 this.gluePaths = gluePaths;151 this.objectFactory = objectFactory;152 this.typeRegistry = typeRegistry;153 }154 @Override155 public void process(Citrus instance) {156 for (String gluePath : gluePaths) {157 String xmlStepConfigLocation = "classpath*:" + gluePath.replaceAll("\\.", "/").replaceAll("^classpath:", "") + "/**/*Steps.xml";158 log.info(String.format("Loading XML step definitions %s", xmlStepConfigLocation));159 ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{ xmlStepConfigLocation }, true, instance.getApplicationContext());160 Map<String, StepTemplate> xmlSteps = ctx.getBeansOfType(StepTemplate.class);161 for (StepTemplate stepTemplate : xmlSteps.values()) {162 if (log.isDebugEnabled()) {163 log.debug(String.format("Found XML step definition: %s %s", stepTemplate.getName(), stepTemplate.getPattern().pattern()));164 }165 glue.addStepDefinition(new XmlStepDefinition(stepTemplate, objectFactory, typeRegistry));166 }167 }168 }169 }170}...

Full Screen

Full Screen

Source:CitrusSpringObjectFactory.java Github

copy

Full Screen

...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

1/*2 * Copyright 2006-2016 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 cucumber.runtime.java.spring;17import cucumber.runtime.java.CitrusBackend;18import org.testng.Assert;19import org.testng.annotations.*;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

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