List of usage examples for org.springframework.web.context.support GenericWebApplicationContext getBeanFactory
@Override public final ConfigurableListableBeanFactory getBeanFactory()
From source file:com.autentia.wuija.spring.RegisterWebSessionScopeTestContextLoader.java
@Override protected void customizeContext(GenericWebApplicationContext context) { final MockServletContext servlet = new MockServletContext(); context.setServletContext(servlet);/*w w w . j a v a 2 s . co m*/ final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpSession session = new MockHttpSession(); request.setSession(session); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); context.getBeanFactory().registerScope("session", new SessionScope()); }
From source file:de.uni_koeln.spinfo.maalr.services.editor.TestEditorService.java
@Before public void beforeTest() throws Exception { Database.getInstance().deleteAllEntries(); loginManager.logout();/*from w w w. jav a 2s. c o m*/ GenericWebApplicationContext context = new GenericWebApplicationContext(); MockServletContext servlet = new MockServletContext(); context.setServletContext(servlet); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpSession session = new MockHttpSession(); request.setSession(session); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); context.refresh(); context.getBeanFactory().registerScope("session", new SessionScope()); loginManager.login("admin", "admin"); File file = File.createTempFile("maalr", "test"); File indexDir = new File(file.getParentFile(), "maalr_test" + UUID.randomUUID().toString() + "_idx"); Assert.assertFalse(indexDir.exists()); indexDir.mkdir(); file.deleteOnExit(); LuceneConfiguration environment = new LuceneConfiguration(); environment.setBaseDirectory(indexDir.getAbsolutePath()); Dictionary d = new Dictionary(); d.setEnvironment(environment); }
From source file:de.uni_koeln.spinfo.maalr.mongo.integration.ITSpringMongoBackend.java
License:asdf
@Before public void beforeTest() throws Exception { Database.getInstance().deleteAllEntries(); loginManager.logout();/*from ww w . j av a 2s .c o m*/ GenericWebApplicationContext context = new GenericWebApplicationContext(); MockServletContext servlet = new MockServletContext(); context.setServletContext(servlet); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpSession session = new MockHttpSession(); request.setSession(session); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); context.refresh(); context.getBeanFactory().registerScope("session", new SessionScope()); }
From source file:org.dataconservancy.ui.stripes.AddCollectionActionBeanTest.java
@Test public void testPollExpirationOnDepositReturnsCorrectHttpErrorCodeAndMessage() throws Exception { // Construct our own ArchiveService instance; this is because Spring will return a Proxied instance // of ArchiveService, which Mockito won't be able to spy(...) on. final ArchiveService notProxiedArchiveService = new InMemoryArchiveServiceImpl(mockDatasetMapper, dataItemProfile, mockCollectionMapper, mockMetadataFileMapper, mockDatafileMapper, metadataFormatRegistryEntryMapper, mockDepositDocumentResolver, mockArchiveUtil, uiIdService, false, mockArchiveDepositInfoDAO);/*from w w w. j a v a 2 s. co m*/ // Create a mock ArchiveService that behaves like the real ArchiveService, except we override the // pollArchive() method to do nothing. Effectively this means that deposit status will never be updated. final ArchiveService pollsForever = spy(notProxiedArchiveService); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { log.debug("Invoking a mock ArchiveService.pollArchive(); impl is a no-op, so deposit statuses will " + "never be updated."); return null; } }).when(pollsForever).pollArchive(); // Inject the mocked archiveService into the spring context GenericWebApplicationContext springContext = (GenericWebApplicationContext) servletCtx .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); springContext.getBeanFactory().registerSingleton("archiveService", pollsForever); servletCtx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, springContext); // Fix up the collaborating Project Project project = new Project(); project.setId("project:/2341"); project.setStartDate(DateTime.now()); project.setEndDate(DateTime.now()); projectDao.insertProject(project); adminSession.setAttribute("projectId", project.getId()); MockRoundtrip rt = new MockRoundtrip(servletCtx, AddCollectionActionBean.class, adminSession); rt.addParameter("collection.title", modifiedCollection.getTitle()); rt.addParameter("collection.summary", modifiedCollection.getSummary()); rt.addParameter("collection.citableLocator", modifiedCollection.getCitableLocator()); rt.addParameter("collection.publicationDate", modifiedCollection.getPublicationDate().toString()); rt.addParameter("collection.alternateIds[0]", (String) modifiedCollection.getAlternateIds().toArray()[0]); rt.addParameter("collection.alternateIds[1]", (String) modifiedCollection.getAlternateIds().toArray()[1]); rt.addParameter("collection.creators[0].prefixes", modifiedCollection.getCreators().get(0).getPrefixes()); rt.addParameter("collection.creators[0].givenNames", modifiedCollection.getCreators().get(0).getGivenNames()); rt.addParameter("collection.creators[0].middleNames", modifiedCollection.getCreators().get(0).getMiddleNames()); rt.addParameter("collection.creators[0].familyNames", modifiedCollection.getCreators().get(0).getFamilyNames()); rt.addParameter("collection.creators[0].suffixes", modifiedCollection.getCreators().get(0).getSuffixes()); // Attempt to deposit the collection; this should fail because the pollForever archive service will never // update the deposit status. rt.execute("addCollection"); final MockHttpServletResponse response = rt.getResponse(); assertEquals(302, response.getStatus()); }
From source file:ubic.gemma.util.SpringContextUtil.java
/** * Adds the resource to the application context and sets the parentContext as the parent of the resource * //from w w w. j a v a2 s. c o m * @param parentContext * @param resource * @return {@link ApplicationContext} */ public static ApplicationContext addResourceToContext(ApplicationContext parentContext, ClassPathResource resource) { GenericWebApplicationContext spacesBeans = new GenericWebApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(spacesBeans); xmlReader.loadBeanDefinitions(resource); spacesBeans.setParent(parentContext); CommonsConfigurationPropertyPlaceholderConfigurer configurationPropertyConfigurer = (CommonsConfigurationPropertyPlaceholderConfigurer) spacesBeans .getBean("configurationPropertyConfigurer"); configurationPropertyConfigurer.postProcessBeanFactory(spacesBeans.getBeanFactory()); spacesBeans.refresh(); return spacesBeans; }