How to use loadEndpointParserProperties method of com.consol.citrus.endpoint.DefaultEndpointFactory class

Best Citrus code snippet using com.consol.citrus.endpoint.DefaultEndpointFactory.loadEndpointParserProperties

Source:DefaultEndpointFactory.java Github

copy

Full Screen

...56 * Default constructor.57 */58 public DefaultEndpointFactory() {59 loadEndpointComponentProperties();60 loadEndpointParserProperties();61 }62 @Override63 public Endpoint create(String endpointName, Annotation endpointConfig, TestContext context) {64 String qualifier = endpointConfig.annotationType().getAnnotation(CitrusEndpointConfig.class).qualifier();65 AnnotationConfigParser parser = getAnnotationParser(context.getApplicationContext()).get(qualifier);66 if (parser == null) {67 // try to get parser from default Citrus modules68 parser = resolveDefaultAnnotationParser(qualifier);69 }70 if (parser == null) {71 throw new CitrusRuntimeException(String.format("Unable to create endpoint annotation parser with name '%s'", qualifier));72 }73 Endpoint endpoint = parser.parse(endpointConfig);74 endpoint.setName(endpointName);75 return endpoint;76 }77 @Override78 public Endpoint create(String uri, TestContext context) {79 String endpointUri = context.replaceDynamicContentInString(uri);80 if (!endpointUri.contains(":")) {81 return context.getApplicationContext().getBean(endpointUri, Endpoint.class);82 }83 StringTokenizer tok = new StringTokenizer(endpointUri, ":");84 if (tok.countTokens() < 2) {85 throw new CitrusRuntimeException(String.format("Invalid endpoint uri '%s'", endpointUri));86 }87 String componentName = tok.nextToken();88 EndpointComponent component = getEndpointComponents(context.getApplicationContext()).get(componentName);89 if (component == null) {90 // try to get component from default Citrus modules91 component = resolveDefaultComponent(componentName);92 }93 if (component == null) {94 throw new CitrusRuntimeException(String.format("Unable to create endpoint component with name '%s'", componentName));95 }96 Map<String, String> parameters = component.getParameters(endpointUri);97 String cachedEndpointName;98 if (parameters.containsKey(AbstractEndpointComponent.ENDPOINT_NAME)) {99 cachedEndpointName = parameters.remove(AbstractEndpointComponent.ENDPOINT_NAME);100 } else {101 cachedEndpointName = endpointUri;102 }103 synchronized (endpointCache) {104 if (endpointCache.containsKey(cachedEndpointName)) {105 if (log.isDebugEnabled()) {106 log.debug(String.format("Found cached endpoint for uri '%s'", cachedEndpointName));107 }108 return endpointCache.get(cachedEndpointName);109 } else {110 Endpoint endpoint = component.createEndpoint(endpointUri, context);111 endpointCache.put(cachedEndpointName, endpoint);112 return endpoint;113 }114 }115 }116 private Map<String, EndpointComponent> getEndpointComponents(ApplicationContext applicationContext) {117 return applicationContext.getBeansOfType(EndpointComponent.class);118 }119 private EndpointComponent resolveDefaultComponent(String componentName) {120 String endpointComponentClassName = endpointComponentProperties.getProperty(componentName);121 try {122 if (endpointComponentClassName != null) {123 Class<EndpointComponent> endpointComponentClass = (Class<EndpointComponent>) Class.forName(endpointComponentClassName);124 EndpointComponent endpointComponent = endpointComponentClass.newInstance();125 endpointComponent.setName(componentName);126 return endpointComponent;127 }128 } catch (ClassNotFoundException e) {129 log.warn(String.format("Unable to find default Citrus endpoint component '%s' in classpath", endpointComponentClassName), e);130 } catch (InstantiationException e) {131 log.warn(String.format("Unable to instantiate Citrus endpoint component '%s'", endpointComponentClassName), e);132 } catch (IllegalAccessException e) {133 log.warn(String.format("Unable to access Citrus endpoint component '%s'", endpointComponentClassName), e);134 }135 return null;136 }137 private Map<String, AnnotationConfigParser> getAnnotationParser(ApplicationContext applicationContext) {138 return applicationContext.getBeansOfType(AnnotationConfigParser.class);139 }140 private AnnotationConfigParser resolveDefaultAnnotationParser(String qualifier) {141 String annotationParserClassName = endpointParserProperties.getProperty(qualifier);142 try {143 if (annotationParserClassName != null) {144 Class<AnnotationConfigParser> annotationParserClass = (Class<AnnotationConfigParser>) Class.forName(annotationParserClassName);145 AnnotationConfigParser annotationParser = annotationParserClass.getConstructor(ReferenceResolver.class).newInstance(referenceResolver);146 return annotationParser;147 }148 } catch (ClassNotFoundException e) {149 log.warn(String.format("Unable to find default Citrus endpoint parser '%s' in classpath", annotationParserClassName), e);150 } catch (InstantiationException e) {151 log.warn(String.format("Unable to instantiate Citrus endpoint parser '%s'", annotationParserClassName), e);152 } catch (IllegalAccessException e) {153 log.warn(String.format("Unable to access Citrus endpoint parser '%s'", annotationParserClassName), e);154 } catch (NoSuchMethodException | InvocationTargetException e) {155 log.warn(String.format("Unable to instantiate Citrus endpoint parser '%s'", annotationParserClassName), e);156 }157 return null;158 }159 /**160 * Loads property file from classpath holding default endpoint component definitions in Citrus.161 */162 private void loadEndpointComponentProperties() {163 try {164 endpointComponentProperties = PropertiesLoaderUtils.loadProperties(new ClassPathResource("com/consol/citrus/endpoint/endpoint.components"));165 } catch (IOException e) {166 log.warn("Unable to laod default endpoint components from resource '%s'", e);167 }168 }169 /**170 * Loads property file from classpath holding default endpoint annotation parser definitions in Citrus.171 */172 private void loadEndpointParserProperties() {173 try {174 endpointParserProperties = PropertiesLoaderUtils.loadProperties(new ClassPathResource("com/consol/citrus/endpoint/endpoint.parser"));175 } catch (IOException e) {176 log.warn("Unable to laod default endpoint annotation parsers from resource '%s'", e);177 }178 }179}...

Full Screen

Full Screen

loadEndpointParserProperties

Using AI Code Generation

copy

Full Screen

1import java.io.File;2import java.util.Properties;3import org.testng.Assert;4import org.testng.annotations.Test;5import com.consol.citrus.endpoint.DefaultEndpointFactory;6public class DefaultEndpointFactoryTest {7 public void testLoadEndpointParserProperties() {8 DefaultEndpointFactory endpointFactory = new DefaultEndpointFactory();9 endpointFactory.loadEndpointParserProperties(new File("src/test/resources/endpoint.properties"));10 Assert.assertEquals(endpointFactory.getEndpointParserProperties().getProperty("foo"), "bar");11 }12 public void testSetEndpointParserProperties() {13 DefaultEndpointFactory endpointFactory = new DefaultEndpointFactory();14 Properties properties = new Properties();15 properties.setProperty("foo", "bar");16 endpointFactory.setEndpointParserProperties(properties);17 Assert.assertEquals(endpointFactory.getEndpointParserProperties().getProperty("foo"), "bar");18 }19 public void testGetEndpointParserProperties() {20 DefaultEndpointFactory endpointFactory = new DefaultEndpointFactory();21 Properties properties = new Properties();22 properties.setProperty("foo", "bar");23 endpointFactory.setEndpointParserProperties(properties);24 Assert.assertEquals(endpointFactory.getEndpointParserProperties().getProperty("foo"), "bar");25 }26}27package com.consol.citrus.endpoint;28import java.util.Properties;29import com.consol.citrus.context.TestContext;30import com.consol.citrus.endpoint.resolver.EndpointUriResolver;31public class DefaultEndpointFactory implements EndpointFactory {32 private EndpointUriResolver endpointUriResolver = new DefaultEndpointUriResolver();33 private EndpointUriParser endpointUriParser = new DefaultEndpointUriParser();34 private Properties endpointParserProperties = new Properties();35 public DefaultEndpointFactory() {36 super();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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful