本文整理汇总了Java中org.apache.axis2.context.MessageContext.setCurrentMessageContext方法的典型用法代码示例。如果您正苦于以下问题:Java MessageContext.setCurrentMessageContext方法的具体用法?Java MessageContext.setCurrentMessageContext怎么用?Java MessageContext.setCurrentMessageContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.axis2.context.MessageContext
的用法示例。
在下文中一共展示了MessageContext.setCurrentMessageContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetUserRegistryUsingInvalidRegistry
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
public void testGetUserRegistryUsingInvalidRegistry() throws Exception {
RegistryService registryService = mock(RegistryService.class);
MessageContext messageContext = mock(MessageContext.class);
HttpServletRequest httpServletRequest = mock(HttpServletRequest.class);
HttpSession httpSession = mock(HttpSession.class);
MessageContext.setCurrentMessageContext(messageContext);
when(messageContext.getProperty("transport.http.servletRequest")).thenReturn(httpServletRequest);
when(httpServletRequest.getSession()).thenReturn(httpSession);
httpSession.setAttribute(RegistryConstants.USER_REGISTRY, null);
when(httpSession.getAttribute(RegistryConstants.USER_REGISTRY)).thenReturn(null);
try {
CommonUtil.getUserRegistry(registryService);
fail("Exception expected");
} catch (RegistryException e) {
assertEquals("User's Registry instance is not found. Users have to login to retrieve a registry instance. ",
e.getMessage());
}
}
示例2: simulate
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
@Test
public void simulate() throws Exception {
MessageContext messageContext = new MessageContext();
HttpServletRequest servletRequest = mock(HttpServletRequest.class);
HttpSession session = mock(HttpSession.class);
when(session.getAttribute(RegistryConstants.ROOT_REGISTRY_INSTANCE)).thenReturn(registry);
when(servletRequest.getSession()).thenReturn(session);
messageContext.setProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST, servletRequest);
AxisService axisService = new AxisService();
axisService.addParameter(new Parameter(CarbonConstants.ADMIN_SERVICE_PARAM_NAME, "true"));
messageContext.setAxisService(axisService);
MessageContext.setCurrentMessageContext(messageContext);
final SimulationRequest simulationRequest = new SimulationRequest();
simulationRequest.setOperation("resourceexists");
simulationRequest.setPath("/test/2017/10/18");
CommonUtil.setSimulationService(new RegistryCoreServiceComponent.DefaultSimulationService());
HandlerManagementService managementService = new HandlerManagementService();
managementService.simulate(simulationRequest);
assertNotNull(CommonUtil.getSimulationResponse().getStatus());
assertEquals(3, CommonUtil.getSimulationResponse().getStatus().length);
}
示例3: setUp
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
objectSupplier = new DefaultObjectSupplier();
omFactory = OMAbstractFactory.getSOAP12Factory();
xsiNamespace = omFactory.createOMNamespace(Constants.XSI_NAMESPACE, "xsi");
omElement = omFactory.createOMElement(new QName("hello"));
MessageContext msgContext = new MessageContext();
msgContext.setEnvelope(omFactory.createSOAPEnvelope());
MessageContext.setCurrentMessageContext(msgContext);
}
示例4: testGetSessionResourcePathErrorCase
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
public void testGetSessionResourcePathErrorCase() throws Exception {
MessageContext.setCurrentMessageContext(null);
try {
RegistryUtil.getSessionResourcePath();
} catch (RegistryException e) {
assertEquals("Could not get the user's Registry session. Message context not found.", e.getMessage());
}
}
示例5: testSetSessionResourcePath
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
public void testSetSessionResourcePath() throws Exception {
MessageContext messageContext = mock(MessageContext.class);
HttpServletRequest httpServletRequest = mock(HttpServletRequest.class);
String path = "/_system/governance/soapservces";
HttpSession httpSession = mock(HttpSession.class);
MessageContext.setCurrentMessageContext(messageContext);
when(messageContext.getProperty("transport.http.servletRequest")).thenReturn(httpServletRequest);
when(httpServletRequest.getSession()).thenReturn(httpSession);
when(httpSession.getAttribute(RegistryConstants.SESSION_RESOURCE_PATH)).thenReturn(path);
RegistryUtil.setSessionResourcePath(path);
MessageContext.setCurrentMessageContext(null);
}
示例6: testSetSessionResourcePathErrorCase
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
public void testSetSessionResourcePathErrorCase() throws Exception {
MessageContext.setCurrentMessageContext(null);
try {
String path = "/_system/governance/soapservces";
RegistryUtil.setSessionResourcePath(path);
} catch (RegistryException e) {
assertEquals("Could not get the user's Registry session. Message context not found.", e.getMessage());
}
}
示例7: testGetResourcePath
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
public void testGetResourcePath() throws Exception {
MessageContext messageContext = mock(MessageContext.class);
HttpServletRequest httpServletRequest = mock(HttpServletRequest.class);
String path = "/_system/governance/service1";
HttpSession httpSession = mock(HttpSession.class);
MessageContext.setCurrentMessageContext(messageContext);
when(messageContext.getProperty("transport.http.servletRequest")).thenReturn(httpServletRequest);
when(httpServletRequest.getSession()).thenReturn(httpSession);
when(httpSession.getAttribute(RegistryConstants.SESSION_RESOURCE_PATH)).thenReturn(path);
String userRegistryReturned = RegistryUtil.getResourcePath();
assertEquals(path, userRegistryReturned);
MessageContext.setCurrentMessageContext(null);
}
示例8: testGetResourcePathErrorCase
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
public void testGetResourcePathErrorCase() throws Exception {
MessageContext.setCurrentMessageContext(null);
try {
RegistryUtil.getResourcePath();
} catch (RegistryException e) {
assertEquals("Could not get the user's Registry session. Message context not found.", e.getMessage());
}
}
示例9: testGetUserRegistryEmptyMessageContext
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
public void testGetUserRegistryEmptyMessageContext() throws Exception {
try {
MessageContext.setCurrentMessageContext(null);
RegistryService registryService = mock(RegistryService.class);
CommonUtil.getUserRegistry(registryService);
fail("Exception expected");
} catch (RegistryException e) {
assertEquals("Could not get the user's Registry session. Message context not found.", e.getMessage());
}
}
示例10: testGetUserRegistryUsingRegistryService
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
public void testGetUserRegistryUsingRegistryService() throws Exception {
RegistryService registryService = mock(RegistryService.class);
MessageContext messageContext = mock(MessageContext.class);
HttpServletRequest httpServletRequest = mock(HttpServletRequest.class);
UserRegistry userRegistry = mock(UserRegistry.class);
HttpSession httpSession = mock(HttpSession.class);
MessageContext.setCurrentMessageContext(messageContext);
when(messageContext.getProperty("transport.http.servletRequest")).thenReturn(httpServletRequest);
when(httpServletRequest.getSession()).thenReturn(httpSession);
httpSession.setAttribute(RegistryConstants.USER_REGISTRY, userRegistry);
when(httpSession.getAttribute(RegistryConstants.USER_REGISTRY)).thenReturn(userRegistry);
UserRegistry userRegistryReturned = CommonUtil.getUserRegistry(registryService);
assertEquals(userRegistry, userRegistryReturned);
}
示例11: testGetRegistry
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
@Test
public void testGetRegistry() throws Exception {
MessageContext context = new MessageContext();
MessageContext.setCurrentMessageContext(context);
HttpServletRequest httpRequest = mock(HttpServletRequest.class);
HttpSession httpSession = mock(HttpSession.class);
when(httpSession.getAttribute(RegistryConstants.USER_REGISTRY)).thenReturn(userRegistry);
when(httpRequest.getSession()).thenReturn(httpSession);
context.setProperty("transport.http.servletRequest", httpRequest);
assertEquals(userRegistry, Utils.getRegistry());
}
示例12: testGetRegistryFromService
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
@Test
public void testGetRegistryFromService() throws Exception {
MessageContext context = new MessageContext();
MessageContext.setCurrentMessageContext(context);
HttpServletRequest httpRequest = mock(HttpServletRequest.class);
HttpSession httpSession = mock(HttpSession.class);
when(httpSession.getAttribute(RegistryConstants.USER_REGISTRY)).thenReturn(null);
when(httpRequest.getSession()).thenReturn(httpSession);
context.setProperty("transport.http.servletRequest", httpRequest);
assertEquals(userRegistry, Utils.getRegistry());
}
示例13: testGetRegistry
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
@Test
public void testGetRegistry() throws RegistryException {
MessageContext context = new MessageContext();
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpSession session = Mockito.mock(HttpSession.class);
when(session.getAttribute(RegistryConstants.USER_REGISTRY)).thenReturn(null);
when(request.getSession()).thenReturn(session);
context.setProperty("transport.http.servletRequest", request);
MessageContext.setCurrentMessageContext(context);
RegistryService service = Mockito.mock(RegistryService.class);
UserRegistry registry = Mockito.mock(UserRegistry.class);
when(service.getUserRegistry()).thenReturn(registry);
final Registry[] registries = {null};
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
registries[0] = (Registry) args[1];
return null;
}
}).when(session).setAttribute(eq(RegistryConstants.USER_REGISTRY), (Registry)anyObject());
Utils.setRegistryService(service);
Registry registry1 = Utils.getRegistry();
assertEquals(registry, registry1);
assertEquals(registry, registries[0]);
}
示例14: testGetRegistryWithoutRegistryService
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
@Test(expected = RegistryException.class)
public void testGetRegistryWithoutRegistryService() throws RegistryException {
MessageContext context = new MessageContext();
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpSession session = Mockito.mock(HttpSession.class);
when(session.getAttribute(RegistryConstants.USER_REGISTRY)).thenReturn(null);
when(request.getSession()).thenReturn(session);
context.setProperty("transport.http.servletRequest", request);
MessageContext.setCurrentMessageContext(context);
Utils.getRegistry();
}
示例15: getRegistryWithoutSession
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
@Test
public void getRegistryWithoutSession() throws Exception {
UserRegistry userRegistry = mock(UserRegistry.class);
MessageContext messageContext = new MessageContext();
HttpServletRequest servletRequest = mock(HttpServletRequest.class);
HttpSession session = mock(HttpSession.class);
when(session.getAttribute(RegistryConstants.USER_REGISTRY)).thenReturn(userRegistry);
when(servletRequest.getSession()).thenReturn(session);
messageContext.setProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST, servletRequest);
MessageContext.setCurrentMessageContext(messageContext);
assertEquals(userRegistry, CommonUtil.getRegistry(null));
}