@Before public void setUp() throws Exception { TestMockServletContext servletContext = new TestMockServletContext(); appContext = new XmlWebApplicationContext(); appContext.setServletContext(servletContext); LocaleContextHolder.setLocale(Locale.US); String attributeName = WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE; appContext.getServletContext().setAttribute(attributeName, appContext); handler = new TestController(); handlerMethod = new InvocableHandlerMethod(handler, TestController.class.getMethod("testBind", Date.class, Double.class, TestBean.class, BindingResult.class)); }
@Test public void changePassword_do_with_clientid_and_redirecturi() throws Exception { String code = getExpiringCode("app", "http://localhost:8080/app/"); String email = user.getUserName(); MockHttpServletRequestBuilder get = get("/reset_password") .param("code", code) .param("email", email); MvcResult result = getMockMvc().perform(get) .andExpect(status().isOk()) .andExpect(content().string(containsString(String.format("<input type=\"hidden\" name=\"email\" value=\"%s\"/>", email)))) .andReturn(); String resultingCodeString = getCodeFromPage(result); MockHttpServletRequestBuilder post = post("/reset_password.do") .param("code", resultingCodeString) .param("email", email) .param("password", "newpass") .param("password_confirmation", "newpass") .with(cookieCsrf()); getMockMvc().perform(post) .andExpect(status().is3xxRedirection()) .andExpect(redirectedUrl(getWebApplicationContext().getServletContext().getContextPath() +"/login?success=password_reset&form_redirect_uri=http://localhost:8080/app/")); post = post("/login.do") .param("username", user.getUserName()) .param("password", "newpass") .param("form_redirect_uri", "http://localhost:8080/app/") .with(cookieCsrf()); getMockMvc().perform(post) .andExpect(status().is3xxRedirection()) .andExpect(redirectedUrl("http://localhost:8080/app/")); }
@Test public void shouldUpgradeModule() { Module module = ModuleFactory.getModuleById(MODULE3_ID); assertTrue(module.getVersion().equals("1.0-SNAPSHOT")); URL url = OpenmrsClassLoader.getInstance().getResource("org/openmrs/module/include/test3-2.0-SNAPSHOT.omod"); module.setDownloadURL("file:" + url.getFile()); createWebInfFolderIfNotExist(); ModuleFactory.stopModule(module, false, true); // stop the module with these parameters so that mandatory modules can be upgraded WebModuleUtil.stopModule(module, ((XmlWebApplicationContext) applicationContext).getServletContext()); Module newModule = ModuleFactory.updateModule(module); WebModuleUtil.startModule(newModule, ((XmlWebApplicationContext) applicationContext).getServletContext(), false); //module3 should have upgraded from version 1.0 to 2.0 module = ModuleFactory.getModuleById(MODULE3_ID); assertTrue(module.getVersion().equals("2.0-SNAPSHOT")); }
WebModuleUtil.stopModule(module, ((XmlWebApplicationContext) applicationContext).getServletContext()); WebModuleUtil.startModule(newModule, ((XmlWebApplicationContext) applicationContext).getServletContext(), false);
WebModuleUtil.stopModule(module, ((XmlWebApplicationContext) applicationContext).getServletContext()); ModuleFactory.unloadModule(module); module = ModuleFactory.loadModule(file); ModuleFactory.startModule(module); WebModuleUtil.startModule(module, ((XmlWebApplicationContext) applicationContext).getServletContext(), false);
/** * Calls {@link AbstractApplicationContext#setParent(org.springframework.context.ApplicationContext)}, * {@link AbstractRefreshableWebApplicationContext#setServletContext(javax.servlet.ServletContext)}, * {@link AbstractRefreshableWebApplicationContext#setNamespace(java.lang.String)} then * {@link AbstractRefreshableWebApplicationContext#refresh()}. * * @param namespace * @param parentContext * @see XmlWebApplicationContext#XmlWebApplicationContext() */ public ContextResolvingXmlWebApplicationContext(String namespace, XmlWebApplicationContext parentContext) { super(); this.setParent(parentContext); this.setServletContext(parentContext.getServletContext()); this.setNamespace(namespace); super.refresh(); }
@Test public void shouldRefreshContextForAllStartedModulesOnWebStartup() throws Throwable { //At OpenMRS start up: // willRefreshContext(), contextRefreshed(), willStart() and started() methods get called for all started modules' activators Listener.performWebStartOfModules(((XmlWebApplicationContext) applicationContext).getServletContext()); assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE1_ID) == 1); assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE2_ID) == 1); assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE3_ID) == 1); assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE1_ID) == 1); assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE2_ID) == 1); assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE3_ID) == 1); assertTrue(moduleTestData.getWillStartCallCount(MODULE1_ID) == 1); assertTrue(moduleTestData.getWillStartCallCount(MODULE2_ID) == 1); assertTrue(moduleTestData.getWillStartCallCount(MODULE3_ID) == 1); assertTrue(moduleTestData.getStartedCallCount(MODULE1_ID) == 1); assertTrue(moduleTestData.getStartedCallCount(MODULE2_ID) == 1); assertTrue(moduleTestData.getStartedCallCount(MODULE3_ID) == 1); }
WebModuleUtil.stopModule(module, ((XmlWebApplicationContext) applicationContext).getServletContext());
WebModuleUtil.startModule(module, ((XmlWebApplicationContext) applicationContext).getServletContext(), false);