use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class SALSessionsTest method testUpdateWithOldSessionSameName.
/**
* Test updating session with session id and old session where the old session id is same as current session id
* @throws Exception
*/
@Test
public void testUpdateWithOldSessionSameName() throws Exception {
BasicConfigurator.configure();
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
MessageContext messageContext = axis2MessageContext;
Endpoint endpoint = new AddressEndpoint();
List<Endpoint> endpoints = new ArrayList<>();
endpoints.add(endpoint);
messageContext.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_ENDPOINT_LIST, endpoints);
SALSessions salSessions = SALSessions.getInstance();
salSessions.initialize(false, cfgCtx);
SessionInformation oldSessionInfo = new SessionInformation("testSession3", endpoints, 30000);
messageContext.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, oldSessionInfo);
salSessions.updateSession(messageContext, "testSession3");
SessionInformation sessionInformation = salSessions.getSession("testSession3");
Assert.assertEquals("Session not updated!", "testSession3", sessionInformation.getId());
}
use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class SALSessionsTest method testUpdateWithOldSession.
/**
* Test updating session with session id and old session
* @throws Exception
*/
@Test
public void testUpdateWithOldSession() throws Exception {
BasicConfigurator.configure();
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
MessageContext messageContext = axis2MessageContext;
Endpoint endpoint = new AddressEndpoint();
List<Endpoint> endpoints = new ArrayList<>();
endpoints.add(endpoint);
SALSessions salSessions = SALSessions.getInstance();
salSessions.initialize(false, cfgCtx);
SessionInformation oldSessionInfo = new SessionInformation("oldTestSession", endpoints, 30000);
messageContext.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, oldSessionInfo);
salSessions.updateSession(messageContext, "testSession2");
SessionInformation sessionInformation = salSessions.getSession("testSession2");
Assert.assertEquals("Session not updated!", "testSession2", sessionInformation.getId());
}
use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class SALSessionsTest method testUpdateWithId.
/**
* Test updating session with session id
* @throws Exception
*/
@Test
public void testUpdateWithId() throws Exception {
BasicConfigurator.configure();
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
MessageContext messageContext = axis2MessageContext;
Endpoint endpoint = new AddressEndpoint();
List<Endpoint> endpoints = new ArrayList<>();
endpoints.add(endpoint);
messageContext.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_ENDPOINT_LIST, endpoints);
SALSessions salSessions = SALSessions.getInstance();
salSessions.initialize(false, cfgCtx);
salSessions.updateSession(messageContext, "testSession");
SessionInformation sessionInformation = salSessions.getSession("testSession");
Assert.assertEquals("Session not updated!", "testSession", sessionInformation.getId());
}
use of org.apache.synapse.core.axis2.Axis2MessageContext 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.axis2.Axis2MessageContext 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));
}
Aggregations