use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.
the class TestUtils method createLightweightSynapseMessageContext.
public static MessageContext createLightweightSynapseMessageContext(String payload, SynapseConfiguration config) throws Exception {
org.apache.axis2.context.MessageContext mc = new org.apache.axis2.context.MessageContext();
SynapseEnvironment env = new Axis2SynapseEnvironment(config);
MessageContext synMc = new Axis2MessageContext(mc, config, env);
SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
omDoc.addChild(envelope);
envelope.getBody().addChild(createOMElement(payload));
synMc.setEnvelope(envelope);
return synMc;
}
use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.
the class EJBMediatorTest method testInitAndMediate.
/**
* Initializing EJBMediator and Mediating a messageContext
*/
@Test
public void testInitAndMediate() throws Exception {
SynapseEnvironment synapseEnvironment = Mockito.mock(SynapseEnvironment.class);
ServerConfigurationInformation configurationInformation = new ServerConfigurationInformation();
ServerContextInformation contextInformation = new ServerContextInformation(configurationInformation);
Mockito.when(synapseEnvironment.getServerContextInformation()).thenReturn(contextInformation);
try {
ejbMediator.init(synapseEnvironment);
Assert.fail("executed successfully when exception is expected");
} catch (Exception ex) {
Assert.assertEquals("assert exception class", SynapseException.class, ex.getClass());
Assert.assertEquals("assert exception message", "Initialization failed. BeanstalkManager not found.", ex.getMessage());
}
ejbMediator.setBeanstalkName(BEANSTALK_NAME);
EnterpriseBeanstalkManager beanstalkManager = Mockito.mock(EnterpriseBeanstalkManager.class);
contextInformation.addProperty(EnterpriseBeanstalkConstants.BEANSTALK_MANAGER_PROP_NAME, beanstalkManager);
try {
ejbMediator.init(synapseEnvironment);
Assert.fail("executed successfully when exception is expected");
} catch (Exception ex) {
Assert.assertEquals("assert exception class", SynapseException.class, ex.getClass());
Assert.assertEquals("assert exception message", "Initialization failed. '" + BEANSTALK_NAME + "' " + "beanstalk not found.", ex.getMessage());
}
beanstalk = PowerMockito.mock(EnterpriseBeanstalk.class);
Value beanId = new Value(VALUE);
ejbMediator.setBeanId(beanId);
Object obj = new Object();
PowerMockito.when(beanstalk.getEnterpriseBean(any(String.class), any(String.class), any(String.class))).thenReturn(obj);
PowerMockito.when(beanstalkManager.getBeanstalk(BEANSTALK_NAME)).thenReturn(beanstalk);
PowerMockito.mockStatic(BeanUtils.class);
PowerMockito.when(BeanUtils.invokeInstanceMethod(any(Object.class), any(Method.class), any(Object[].class))).thenReturn(new Object());
ejbMediator.init(synapseEnvironment);
String samplePayload = "<test>value</test>";
Map<String, Entry> properties = new HashMap<>();
Axis2MessageContext messageContext = TestUtils.getAxis2MessageContext(samplePayload, properties);
ejbMediator.setClassName(CLASS_NAME);
ejbMediator.setJndiName(JNDI_NAME);
Assert.assertTrue("mediation must be successful", ejbMediator.mediate(messageContext));
}
use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.
the class XpathExtensionUtil method resolveVariableContext.
/**
* Returns an object resolved by Variable Context extension registered for given
* QName/namespaceURI+prefix+localName combination
*
* @param ctxt Synapse Message Context
* @param namespaceURI binding namespace in xpath expression
* @param prefix binding prefix string in xpath expression
* @param localName binding localname string in xpath expression
* @return Object variable resolved by corresponding extension
*/
public static Object resolveVariableContext(MessageContext ctxt, String namespaceURI, String prefix, String localName) {
SynapseEnvironment environment = ctxt.getEnvironment();
if (environment != null) {
Map<QName, SynapseXpathVariableResolver> extensions = environment.getXpathVariableExtensions();
SynapseXpathVariableResolver variableResolver = getMatchingExtensionProvider(extensions, namespaceURI, prefix, localName);
if (variableResolver != null) {
return resolveXpathVariable(variableResolver, ctxt);
}
}
return null;
}
use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.
the class HessianMessageBuilderTest method testProcessDocumentWithSynEnv.
public void testProcessDocumentWithSynEnv() throws IOException {
SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), new SynapseConfiguration());
testProcessDocument(synEnv);
}
use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.
the class HessianMessageBuilderTest method testProcessDocumentFaultWithSynEnv.
public void testProcessDocumentFaultWithSynEnv() throws IOException {
SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), new SynapseConfiguration());
testProcessDocumentFault(synEnv);
}
Aggregations