Java Code Examples for org.springframework.context.support.GenericApplicationContext#close()
The following examples show how to use
org.springframework.context.support.GenericApplicationContext#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeanValidationPostProcessorTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testSizeConstraint() { GenericApplicationContext ac = new GenericApplicationContext(); ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class)); RootBeanDefinition bd = new RootBeanDefinition(NotNullConstrainedBean.class); bd.getPropertyValues().add("testBean", new TestBean()); bd.getPropertyValues().add("stringValue", "s"); ac.registerBeanDefinition("bean", bd); try { ac.refresh(); fail("Should have thrown BeanCreationException"); } catch (BeanCreationException ex) { assertTrue(ex.getRootCause().getMessage().contains("stringValue")); assertTrue(ex.getRootCause().getMessage().contains("invalid")); } ac.close(); }
Example 2
Source File: AsyncExecutionTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void asyncClassListener() throws Exception { // Arrange originalThreadName = Thread.currentThread().getName(); listenerCalled = 0; listenerConstructed = 0; GenericApplicationContext context = new GenericApplicationContext(); context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassListener.class)); context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class)); // Act context.refresh(); context.close(); // Assert Awaitility.await() .atMost(1, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> listenerCalled == 2); assertEquals(1, listenerConstructed); }
Example 3
Source File: BeanValidationPostProcessorTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testNotNullConstraint() { GenericApplicationContext ac = new GenericApplicationContext(); ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class)); ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class)); ac.registerBeanDefinition("bean", new RootBeanDefinition(NotNullConstrainedBean.class)); try { ac.refresh(); fail("Should have thrown BeanCreationException"); } catch (BeanCreationException ex) { assertTrue(ex.getRootCause().getMessage().contains("testBean")); assertTrue(ex.getRootCause().getMessage().contains("invalid")); } ac.close(); }
Example 4
Source File: BeanValidationPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testSizeConstraint() { GenericApplicationContext ac = new GenericApplicationContext(); ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class)); RootBeanDefinition bd = new RootBeanDefinition(NotNullConstrainedBean.class); bd.getPropertyValues().add("testBean", new TestBean()); bd.getPropertyValues().add("stringValue", "s"); ac.registerBeanDefinition("bean", bd); try { ac.refresh(); fail("Should have thrown BeanCreationException"); } catch (BeanCreationException ex) { assertTrue(ex.getRootCause().getMessage().contains("stringValue")); assertTrue(ex.getRootCause().getMessage().contains("invalid")); } ac.close(); }
Example 5
Source File: BeanValidationPostProcessorTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testNotNullConstraint() { GenericApplicationContext ac = new GenericApplicationContext(); ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class)); ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class)); ac.registerBeanDefinition("bean", new RootBeanDefinition(NotNullConstrainedBean.class)); try { ac.refresh(); fail("Should have thrown BeanCreationException"); } catch (BeanCreationException ex) { assertTrue(ex.getRootCause().getMessage().contains("testBean")); assertTrue(ex.getRootCause().getMessage().contains("invalid")); } ac.close(); }
Example 6
Source File: AsyncExecutionTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void asyncMethodListener() throws Exception { // Arrange originalThreadName = Thread.currentThread().getName(); listenerCalled = 0; GenericApplicationContext context = new GenericApplicationContext(); context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodListener.class)); context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class)); // Act context.refresh(); // Assert Awaitility.await() .atMost(1, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> listenerCalled == 1); context.close(); }
Example 7
Source File: AsyncExecutionTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void asyncPrototypeClassListener() throws Exception { originalThreadName = Thread.currentThread().getName(); listenerCalled = 0; listenerConstructed = 0; GenericApplicationContext context = new GenericApplicationContext(); RootBeanDefinition listenerDef = new RootBeanDefinition(AsyncClassListener.class); listenerDef.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); context.registerBeanDefinition("asyncTest", listenerDef); context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class)); context.refresh(); context.close(); Thread.sleep(1000); assertEquals(2, listenerCalled); assertEquals(2, listenerConstructed); }
Example 8
Source File: ComponentScanParserBeanDefinitionDefaultsTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testDefaultInitAndDestroyMethodsDefined() { GenericApplicationContext context = new GenericApplicationContext(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultInitAndDestroyMethodsTests.xml"); context.refresh(); DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME); assertTrue("bean should have been initialized", bean.isInitialized()); context.close(); assertTrue("bean should have been destroyed", bean.isDestroyed()); }
Example 9
Source File: ComponentScanParserBeanDefinitionDefaultsTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testDefaultInitAndDestroyMethodsNotDefined() { GenericApplicationContext context = new GenericApplicationContext(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml"); context.refresh(); DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME); assertFalse("bean should not have been initialized", bean.isInitialized()); context.close(); assertFalse("bean should not have been destroyed", bean.isDestroyed()); }
Example 10
Source File: BeanValidationPostProcessorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testNotNullConstraintAfterInitialization() { GenericApplicationContext ac = new GenericApplicationContext(); RootBeanDefinition bvpp = new RootBeanDefinition(BeanValidationPostProcessor.class); bvpp.getPropertyValues().add("afterInitialization", true); ac.registerBeanDefinition("bvpp", bvpp); ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class)); ac.registerBeanDefinition("bean", new RootBeanDefinition(AfterInitConstraintBean.class)); ac.refresh(); ac.close(); }
Example 11
Source File: BeanValidationPostProcessorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testNotNullConstraintSatisfied() { GenericApplicationContext ac = new GenericApplicationContext(); ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class)); ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class)); RootBeanDefinition bd = new RootBeanDefinition(NotNullConstrainedBean.class); bd.getPropertyValues().add("testBean", new TestBean()); ac.registerBeanDefinition("bean", bd); ac.refresh(); ac.close(); }
Example 12
Source File: PropertyPlaceholderConfigurerEnvironmentIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test @SuppressWarnings("deprecation") public void test() { GenericApplicationContext ctx = new GenericApplicationContext(); ctx.registerBeanDefinition("ppc", rootBeanDefinition(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.class) .addPropertyValue("searchSystemEnvironment", false) .getBeanDefinition()); ctx.refresh(); ctx.getBean("ppc"); ctx.close(); }
Example 13
Source File: BeanValidationPostProcessorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testNotNullConstraintAfterInitialization() { GenericApplicationContext ac = new GenericApplicationContext(); RootBeanDefinition bvpp = new RootBeanDefinition(BeanValidationPostProcessor.class); bvpp.getPropertyValues().add("afterInitialization", true); ac.registerBeanDefinition("bvpp", bvpp); ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class)); ac.registerBeanDefinition("bean", new RootBeanDefinition(AfterInitConstraintBean.class)); ac.refresh(); ac.close(); }
Example 14
Source File: BeanValidationPostProcessorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testNotNullConstraintAfterInitializationWithProxy() { GenericApplicationContext ac = new GenericApplicationContext(); RootBeanDefinition bvpp = new RootBeanDefinition(BeanValidationPostProcessor.class); bvpp.getPropertyValues().add("afterInitialization", true); ac.registerBeanDefinition("bvpp", bvpp); ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class)); ac.registerBeanDefinition("bean", new RootBeanDefinition(AfterInitConstraintBean.class)); ac.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); ac.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class)); ac.refresh(); ac.close(); }
Example 15
Source File: BeanValidationPostProcessorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testSizeConstraintSatisfied() { GenericApplicationContext ac = new GenericApplicationContext(); ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class)); RootBeanDefinition bd = new RootBeanDefinition(NotNullConstrainedBean.class); bd.getPropertyValues().add("testBean", new TestBean()); bd.getPropertyValues().add("stringValue", "ss"); ac.registerBeanDefinition("bean", bd); ac.refresh(); ac.close(); }
Example 16
Source File: BeanValidationPostProcessorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testSizeConstraintSatisfied() { GenericApplicationContext ac = new GenericApplicationContext(); ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class)); RootBeanDefinition bd = new RootBeanDefinition(NotNullConstrainedBean.class); bd.getPropertyValues().add("testBean", new TestBean()); bd.getPropertyValues().add("stringValue", "ss"); ac.registerBeanDefinition("bean", bd); ac.refresh(); ac.close(); }
Example 17
Source File: ComponentScanParserBeanDefinitionDefaultsTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testDefaultInitAndDestroyMethodsNotDefined() { GenericApplicationContext context = new GenericApplicationContext(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml"); context.refresh(); DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME); assertFalse("bean should not have been initialized", bean.isInitialized()); context.close(); assertFalse("bean should not have been destroyed", bean.isDestroyed()); }
Example 18
Source File: BeanValidationPostProcessorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testNotNullConstraintAfterInitializationWithProxy() { GenericApplicationContext ac = new GenericApplicationContext(); RootBeanDefinition bvpp = new RootBeanDefinition(BeanValidationPostProcessor.class); bvpp.getPropertyValues().add("afterInitialization", true); ac.registerBeanDefinition("bvpp", bvpp); ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class)); ac.registerBeanDefinition("bean", new RootBeanDefinition(AfterInitConstraintBean.class)); ac.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); ac.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class)); ac.refresh(); ac.close(); }
Example 19
Source File: BeanValidationPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testNotNullConstraintAfterInitialization() { GenericApplicationContext ac = new GenericApplicationContext(); RootBeanDefinition bvpp = new RootBeanDefinition(BeanValidationPostProcessor.class); bvpp.getPropertyValues().add("afterInitialization", true); ac.registerBeanDefinition("bvpp", bvpp); ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class)); ac.registerBeanDefinition("bean", new RootBeanDefinition(AfterInitConstraintBean.class)); ac.refresh(); ac.close(); }
Example 20
Source File: ApplicationContextEventTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void beanPostProcessorPublishesEvents() { GenericApplicationContext context = new GenericApplicationContext(); context.registerBeanDefinition("listener", new RootBeanDefinition(BeanThatListens.class)); context.registerBeanDefinition("messageSource", new RootBeanDefinition(StaticMessageSource.class)); context.registerBeanDefinition("postProcessor", new RootBeanDefinition(EventPublishingBeanPostProcessor.class)); context.refresh(); context.publishEvent(new MyEvent(this)); BeanThatListens listener = context.getBean(BeanThatListens.class); assertEquals(4, listener.getEventCount()); context.close(); }