List of usage examples for org.springframework.web.context WebApplicationContext ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
String ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
To view the source code for org.springframework.web.context WebApplicationContext ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE.
Click Source Link
From source file:com.betfair.tornjak.monitor.overlay.AuthUtilsTest.java
@Test public void testCreateRolePerms() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); ServletContext context = mock(ServletContext.class); ApplicationContext appContext = mock(ApplicationContext.class); Principal p = mock(Principal.class); when(context.getAttribute("com.betfair.tornjak.monitor.overlay.RolePerms")).thenReturn(null); when(context.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) .thenReturn(appContext);//from w ww .j a va 2 s . co m when(context.getInitParameter("contextAuthConfigLocation")).thenReturn("somewhere"); when(appContext.getResource("somewhere")).thenReturn( new DefaultResourceLoader().getResource("com/betfair/tornjak/monitor/overlay/auth.properties")); when(request.getUserPrincipal()).thenReturn(p); when(request.isUserInRole("jmxadmin")).thenReturn(true); Auth auth = AuthUtils.checkAuthorised(request, response, context); assertThat(auth, notNullValue()); assertThat("User should be authorised", auth.check(), equalTo(AUTHORISED)); }
From source file:test.pl.chilldev.facelets.taglib.spring.web.MessageTagTest.java
@Test public void applyInterpolateCollection() throws FacesException { String message = "Foo {0}"; String var = "bar"; List<String> args = new ArrayList<>(); args.add("baz"); Map<String, Object> config = new HashMap<>(); config.put(MessageTag.ATTRIBUTE_MESSAGE, message); config.put(MessageTag.ATTRIBUTE_VAR, var); config.put(MessageTag.ATTRIBUTE_ARGS, args); MessageTag tag = new MessageTag(MockTagConfig.factory(config)); // set up context FaceletContext context = new MockFaceletContext(); context.getFacesContext().getExternalContext().getApplicationMap() .put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.applicationContext); // run the tag tag.apply(context, this.parent); assertEquals("MessageTag.apply() should use collection given as arguments for interpolation.", "Foo baz", context.getAttribute(var)); }
From source file:net.sourceforge.vulcan.web.struts.MockApplicationContextStrutsTestCase.java
@Override public void setUp() throws Exception { super.setUp(); context = new ServletContextSimulator() { @Override/*from w ww . jav a2s . c o m*/ public Set<String> getResourcePaths(String path) { return Collections.emptySet(); } }; config = new ServletConfigSimulator() { @Override public ServletContext getServletContext() { return context; } }; request = new HttpServletRequestSimulator(config.getServletContext()); response = new HttpServletResponseSimulator(); request.setServerName("localhost"); request.setServerPort(80); context.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); multipartElements.clear(); setContextDirectory(TestUtils.resolveRelativeFile("source/main/docroot")); setRequestProcessor(new RequestProcessor() { @Override protected ActionForward processException(HttpServletRequest request, HttpServletResponse response, Exception exception, ActionForm form, ActionMapping mapping) throws IOException, ServletException { throw new UncaughtExceptionError(exception); } @Override protected void processForwardConfig(HttpServletRequest request, HttpServletResponse response, ForwardConfig forward) throws IOException, ServletException { resultForward = (ActionForward) forward; super.processForwardConfig(request, response, forward); } @Override protected boolean processValidate(HttpServletRequest request, HttpServletResponse response, ActionForm form, ActionMapping mapping) throws IOException, ServletException, InvalidCancelException { boolean result = super.processValidate(request, response, form, mapping); if (result == false) { // validation failed, use ActionMapping "input" param as forward resultForward = mapping.getInputForward(); } return result; } }); context.setAttribute(Keys.STATE_MANAGER, manager); context.setAttribute("javax.servlet.context.tempdir", new File(System.getProperty("java.io.tmpdir"))); }
From source file:com.tcloud.bee.key.server.jetty.config.JettyConfiguration.java
@Bean public WebAppContext webAppContext() throws IOException { WebAppContext ctx = new WebAppContext(); ctx.setContextPath(contextPath);/*from w w w. j ava2 s .co m*/ String warPath = new ClassPathResource("webapp").getURI().toString(); logger.info("warPath:{}", warPath); ctx.setWar(warPath); // http://www.eclipse.org/jetty/documentation/current/configuring-jsp.html /* Disable directory listings if no index.html is found. */ ctx.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); ctx.setInitParameter("development", "true"); ctx.setInitParameter("checkInterval", "10"); ctx.setInitParameter("compilerTargetVM", "1.7"); ctx.setInitParameter("compilerSourceVM", "1.7"); /* * Create the root web application context and set * it as a servlet * attribute so the dispatcher servlet can find it. */ GenericWebApplicationContext webApplicationContext = new GenericWebApplicationContext(); webApplicationContext.setParent(applicationContext); webApplicationContext.refresh(); ctx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext); ctx.addEventListener(new WebAppInitializer()); return ctx; }
From source file:test.pl.chilldev.facelets.taglib.spring.web.MessageTagTest.java
@Test public void applyCustomObject() throws FacesException { String message = "Foo {0}"; String var = "bar"; Map<String, Object> config = new HashMap<>(); config.put(MessageTag.ATTRIBUTE_MESSAGE, message); config.put(MessageTag.ATTRIBUTE_VAR, var); config.put(MessageTag.ATTRIBUTE_ARGS, Locale.US); MessageTag tag = new MessageTag(MockTagConfig.factory(config)); // set up context FaceletContext context = new MockFaceletContext(); context.getFacesContext().getExternalContext().getApplicationMap() .put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.applicationContext); // run the tag tag.apply(context, this.parent); assertEquals("MessageTag.apply() should use single object as argument for interpolation.", "Foo en_US", context.getAttribute(var)); }
From source file:test.pl.chilldev.facelets.taglib.spring.web.MessageTagTest.java
@Test public void applyEmptyArguments() throws FacesException { String message = "Foo {0}"; String var = "bar"; Map<String, Object> config = new HashMap<>(); config.put(MessageTag.ATTRIBUTE_MESSAGE, message); config.put(MessageTag.ATTRIBUTE_VAR, var); config.put(MessageTag.ATTRIBUTE_ARGS, null); MessageTag tag = new MessageTag(MockTagConfig.factory(config)); // set up context FaceletContext context = new MockFaceletContext(); context.getFacesContext().getExternalContext().getApplicationMap() .put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.applicationContext); // run the tag tag.apply(context, this.parent); assertEquals("MessageTag.apply() should not interpolate any argument if NULL is passed as arguments.", message, context.getAttribute(var)); }
From source file:com.github.nblair.web.ProfileConditionalDelegatingFilterProxyTest.java
/** * Set up a {@link ServletContext} to contain a {@link WebApplicationContext} with the provided {@link Environment}. * //from www . j a v a 2s . c o m * @param environment * @return a mock {@link ServletContext} ready for use in the delegate filter proxy */ protected ServletContext mockServletContextWithEnvironment(Environment environment) { ServletContext servletContext = mock(ServletContext.class); WebApplicationContext wac = mock(WebApplicationContext.class); when(wac.getEnvironment()).thenReturn(environment); when(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) .thenReturn(wac); return servletContext; }
From source file:com.sourcesense.alfresco.opensso.AlfrescoOpenSSOFilterTest.java
private AlfrescoFacade mockAlfrescoFacade() { GenericWebApplicationContext webApplicationContext = new MockAlfrescoApplicationContext(); MockServletContext mockServletContext = new MockServletContext(); mockServletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext);//www . j a va 2 s . co m AlfrescoFacade mockAlfrescoFacade = new AlfrescoFacade(mockServletContext) { public ArrayList<String> users = new ArrayList<String>(); public HashMap<String, List<String>> groups = new HashMap<String, List<String>>(); @Override public void createUser(String username, String email, String firstName, String lastName) { users.add(username); } @Override public Boolean existUser(String username) { return users.contains(username); } public ArrayList<String> getUserGroups(String username) { return (ArrayList<String>) groups.get(username); } @Override protected void setLocale(HttpSession session) { // TODO Auto-generated method stub } @Override public void createOrUpdateGroups(String principal, List<String> openSSOGroups) { groups.remove(principal); groups.put(principal, openSSOGroups); } @Override protected void setAuthenticatedUser(HttpServletRequest req, HttpServletResponse res, HttpSession httpSess, String userName) { NodeRef nodeRef = new NodeRef("workspace://SpacesStore/386f7ece-4127-42b5-8543-3de2e2a20d7e"); User user = new User(userName, "ticket", nodeRef); populateSession(httpSess, user); } @Override public void authenticateAsGuest(HttpSession session) { } }; return mockAlfrescoFacade; }