org.springframework.tests.sample.beans.TestBean Java Examples
The following examples show how to use
org.springframework.tests.sample.beans.TestBean.
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: AutowiredAnnotationBeanPostProcessorTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testFieldInjectionWithMap() { RootBeanDefinition bd = new RootBeanDefinition(MapFieldInjectionBean.class); bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); TestBean tb1 = new TestBean("tb1"); TestBean tb2 = new TestBean("tb2"); bf.registerSingleton("testBean1", tb1); bf.registerSingleton("testBean2", tb2); MapFieldInjectionBean bean = (MapFieldInjectionBean) bf.getBean("annotatedBean"); assertEquals(2, bean.getTestBeanMap().size()); assertTrue(bean.getTestBeanMap().keySet().contains("testBean1")); assertTrue(bean.getTestBeanMap().keySet().contains("testBean2")); assertTrue(bean.getTestBeanMap().values().contains(tb1)); assertTrue(bean.getTestBeanMap().values().contains(tb2)); bean = (MapFieldInjectionBean) bf.getBean("annotatedBean"); assertEquals(2, bean.getTestBeanMap().size()); assertTrue(bean.getTestBeanMap().keySet().contains("testBean1")); assertTrue(bean.getTestBeanMap().keySet().contains("testBean2")); assertTrue(bean.getTestBeanMap().values().contains(tb1)); assertTrue(bean.getTestBeanMap().values().contains(tb2)); }
Example #2
Source File: ErrorsTagTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void withExplicitEmptyWhitespaceBodyContent() throws Exception { this.tag.setBodyContent(new MockBodyContent("", getWriter())); // construct an errors instance of the tag TestBean target = new TestBean(); target.setName("Rob Harrop"); Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME); errors.rejectValue("name", "some.code", "Default Message"); exposeBindingResult(errors); int result = this.tag.doStartTag(); assertEquals(BodyTag.EVAL_BODY_BUFFERED, result); result = this.tag.doEndTag(); assertEquals(Tag.EVAL_PAGE, result); String output = getOutput(); assertElementTagOpened(output); assertElementTagClosed(output); assertContainsAttribute(output, "id", "name.errors"); assertBlockTagContains(output, "Default Message"); }
Example #3
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testCustomEditor() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); lbf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() { @Override public void registerCustomEditors(PropertyEditorRegistry registry) { NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN); registry.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, true)); } }); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("myFloat", "1,1"); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.setPropertyValues(pvs); lbf.registerBeanDefinition("testBean", bd); TestBean testBean = (TestBean) lbf.getBean("testBean"); assertTrue(testBean.getMyFloat().floatValue() == 1.1f); }
Example #4
Source File: MBeanExporterTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testOnlyBonaFideMBeanIsExportedWhenAutodetectIsMBeanOnly() throws Exception { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(Person.class); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.registerBeanDefinition(OBJECT_NAME, builder.getBeanDefinition()); String exportedBeanName = "spring:type=TestBean"; factory.registerSingleton(exportedBeanName, new TestBean()); MBeanExporter exporter = new MBeanExporter(); exporter.setServer(getServer()); exporter.setAssembler(new NamedBeanAutodetectCapableMBeanInfoAssemblerStub(exportedBeanName)); exporter.setBeanFactory(factory); exporter.setAutodetectMode(MBeanExporter.AUTODETECT_MBEAN); start(exporter); assertIsRegistered("Bona fide MBean not autodetected in AUTODETECT_MBEAN mode", ObjectNameManager.getInstance(OBJECT_NAME)); assertIsNotRegistered("Bean autodetected and (only) AUTODETECT_MBEAN mode is on", ObjectNameManager.getInstance(exportedBeanName)); }
Example #5
Source File: PropertySourcesPlaceholderConfigurerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void explicitPropertySources() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class) .addPropertyValue("name", "${my.name}") .getBeanDefinition()); MutablePropertySources propertySources = new MutablePropertySources(); propertySources.addLast(new MockPropertySource().withProperty("my.name", "foo")); PropertySourcesPlaceholderConfigurer pc = new PropertySourcesPlaceholderConfigurer(); pc.setPropertySources(propertySources); pc.postProcessBeanFactory(bf); assertThat(bf.getBean(TestBean.class).getName(), equalTo("foo")); assertEquals(pc.getAppliedPropertySources().iterator().next(), propertySources.iterator().next()); }
Example #6
Source File: OptionsTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override protected void extendRequest(MockHttpServletRequest request) { TestBean bean = new TestBean(); bean.setName("foo"); bean.setCountry("UK"); bean.setMyFloat(new Float("12.34")); request.setAttribute(COMMAND_NAME, bean); List floats = new ArrayList(); floats.add(new Float("12.30")); floats.add(new Float("12.31")); floats.add(new Float("12.32")); floats.add(new Float("12.33")); floats.add(new Float("12.34")); floats.add(new Float("12.35")); request.setAttribute("floats", floats); }
Example #7
Source File: BeanUtilsTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testCopyPropertiesWithIgnore() throws Exception { TestBean tb = new TestBean(); assertTrue("Name empty", tb.getName() == null); tb.setAge(32); tb.setTouchy("bla"); TestBean tb2 = new TestBean(); tb2.setName("rod"); assertTrue("Age empty", tb2.getAge() == 0); assertTrue("Touchy empty", tb2.getTouchy() == null); // "spouse", "touchy", "age" should not be copied BeanUtils.copyProperties(tb, tb2, "spouse", "touchy", "age"); assertTrue("Name copied", tb2.getName() == null); assertTrue("Age still empty", tb2.getAge() == 0); assertTrue("Touchy still empty", tb2.getTouchy() == null); }
Example #8
Source File: MBeanExporterTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testBonaFideMBeanIsNotExportedWithAutodetectAssembler() throws Exception { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(Person.class); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.registerBeanDefinition(OBJECT_NAME, builder.getBeanDefinition()); String exportedBeanName = "spring:type=TestBean"; factory.registerSingleton(exportedBeanName, new TestBean()); MBeanExporter exporter = new MBeanExporter(); exporter.setServer(getServer()); exporter.setAssembler(new NamedBeanAutodetectCapableMBeanInfoAssemblerStub(exportedBeanName)); exporter.setBeanFactory(factory); exporter.setAutodetectMode(MBeanExporter.AUTODETECT_ASSEMBLER); start(exporter); assertIsNotRegistered("Bona fide MBean was autodetected in AUTODETECT_ASSEMBLER mode - must not have been", ObjectNameManager.getInstance(OBJECT_NAME)); assertIsRegistered("Bean not autodetected in AUTODETECT_ASSEMBLER mode", ObjectNameManager.getInstance(exportedBeanName)); }
Example #9
Source File: CustomEditorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testComplexObject() { TestBean tb = new TestBean(); String newName = "Rod"; String tbString = "Kerry_34"; BeanWrapper bw = new BeanWrapperImpl(tb); bw.registerCustomEditor(ITestBean.class, new TestBeanEditor()); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValue(new PropertyValue("age", new Integer(55))); pvs.addPropertyValue(new PropertyValue("name", newName)); pvs.addPropertyValue(new PropertyValue("touchy", "valid")); pvs.addPropertyValue(new PropertyValue("spouse", tbString)); bw.setPropertyValues(pvs); assertTrue("spouse is non-null", tb.getSpouse() != null); assertTrue("spouse name is Kerry and age is 34", tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34); }
Example #10
Source File: AutowiredAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testCustomAnnotationOptionalMethodResourceInjection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setAutowiredAnnotationType(MyAutowired.class); bpp.setRequiredParameterName("optional"); bpp.setRequiredParameterValue(false); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); bf.registerBeanDefinition("customBean", new RootBeanDefinition( CustomAnnotationOptionalMethodResourceInjectionBean.class)); TestBean tb = new TestBean(); bf.registerSingleton("testBean", tb); CustomAnnotationOptionalMethodResourceInjectionBean bean = (CustomAnnotationOptionalMethodResourceInjectionBean) bf.getBean("customBean"); assertSame(tb, bean.getTestBean3()); assertNull(bean.getTestBean()); assertNull(bean.getTestBean2()); bf.destroySingletons(); }
Example #11
Source File: AbstractAopProxyTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testStaticMethodPointcut() throws Throwable { TestBean tb = new TestBean(); ProxyFactory pc = new ProxyFactory(); pc.addInterface(ITestBean.class); NopInterceptor di = new NopInterceptor(); TestStaticPointcutAdvice sp = new TestStaticPointcutAdvice(di, "getAge"); pc.addAdvisor(sp); pc.setTarget(tb); ITestBean it = (ITestBean) createProxy(pc); assertEquals(di.getCount(), 0); it.getAge(); assertEquals(di.getCount(), 1); it.setAge(11); assertEquals(it.getAge(), 11); assertEquals(di.getCount(), 2); }
Example #12
Source File: RequestScopedProxyTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testGetFromScopeThroughDynamicProxy() throws Exception { String name = "requestScopedProxy"; ITestBean bean = (ITestBean) this.beanFactory.getBean(name); assertTrue(AopUtils.isJdkDynamicProxy(bean)); MockHttpServletRequest request = new MockHttpServletRequest(); RequestAttributes requestAttributes = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(requestAttributes); try { assertNull(request.getAttribute("scopedTarget." + name)); assertEquals("scoped", bean.getName()); assertNotNull(request.getAttribute("scopedTarget." + name)); TestBean target = (TestBean) request.getAttribute("scopedTarget." + name); assertEquals(TestBean.class, target.getClass()); assertEquals("scoped", target.getName()); assertSame(bean, this.beanFactory.getBean(name)); assertEquals(bean.toString(), target.toString()); } finally { RequestContextHolder.setRequestAttributes(null); } }
Example #13
Source File: XmlBeanCollectionTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testRefSubelementsBuildCollection() throws Exception { TestBean jen = (TestBean) this.beanFactory.getBean("jenny"); TestBean dave = (TestBean) this.beanFactory.getBean("david"); TestBean rod = (TestBean) this.beanFactory.getBean("rod"); // Must be a list to support ordering // Our bean doesn't modify the collection: // of course it could be a different copy in a real object. Object[] friends = rod.getFriends().toArray(); assertTrue(friends.length == 2); assertTrue("First friend must be jen, not " + friends[0], friends[0] == jen); assertTrue(friends[1] == dave); // Should be ordered }
Example #14
Source File: AutowiredAnnotationBeanPostProcessorTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testExtendedResourceInjectionWithSkippedOverriddenMethods() { RootBeanDefinition annotatedBd = new RootBeanDefinition(OverriddenExtendedResourceInjectionBean.class); bf.registerBeanDefinition("annotatedBean", annotatedBd); TestBean tb = new TestBean(); bf.registerSingleton("testBean", tb); NestedTestBean ntb = new NestedTestBean(); bf.registerSingleton("nestedTestBean", ntb); OverriddenExtendedResourceInjectionBean bean = (OverriddenExtendedResourceInjectionBean) bf.getBean("annotatedBean"); assertSame(tb, bean.getTestBean()); assertNull(bean.getTestBean2()); assertSame(tb, bean.getTestBean3()); assertSame(tb, bean.getTestBean4()); assertSame(ntb, bean.getNestedTestBean()); assertNull(bean.getBeanFactory()); assertTrue(bean.baseInjected); assertTrue(bean.subInjected); }
Example #15
Source File: MBeanExporterTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testIgnoreBeanName() throws MalformedObjectNameException { DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); String firstBeanName = "spring:type=TestBean"; factory.registerSingleton(firstBeanName, new TestBean("test")); String secondBeanName = "spring:type=TestBean2"; factory.registerSingleton(secondBeanName, new TestBean("test2")); MBeanExporter exporter = new MBeanExporter(); exporter.setServer(getServer()); exporter.setAssembler(new NamedBeanAutodetectCapableMBeanInfoAssemblerStub(firstBeanName, secondBeanName)); exporter.setBeanFactory(factory); exporter.setAutodetectMode(MBeanExporter.AUTODETECT_ALL); exporter.addExcludedBean(secondBeanName); start(exporter); assertIsRegistered("Bean not autodetected in (AUTODETECT_ALL) mode", ObjectNameManager.getInstance(firstBeanName)); assertIsNotRegistered("Bean should have been excluded", ObjectNameManager.getInstance(secondBeanName)); }
Example #16
Source File: AutowiredAnnotationBeanPostProcessorTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testConstructorResourceInjectionWithNullFromFactoryBean() { RootBeanDefinition bd = new RootBeanDefinition(ConstructorResourceInjectionBean.class); bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); TestBean tb = new TestBean(); bf.registerSingleton("testBean", tb); bf.registerBeanDefinition("nestedTestBean", new RootBeanDefinition(NullNestedTestBeanFactoryBean.class)); bf.registerSingleton("nestedTestBean2", new NestedTestBean()); ConstructorResourceInjectionBean bean = (ConstructorResourceInjectionBean) bf.getBean("annotatedBean"); assertSame(tb, bean.getTestBean()); assertSame(tb, bean.getTestBean2()); assertSame(tb, bean.getTestBean3()); assertSame(tb, bean.getTestBean4()); assertNull(bean.getNestedTestBean()); assertSame(bf, bean.getBeanFactory()); bean = (ConstructorResourceInjectionBean) bf.getBean("annotatedBean"); assertSame(tb, bean.getTestBean()); assertSame(tb, bean.getTestBean2()); assertSame(tb, bean.getTestBean3()); assertSame(tb, bean.getTestBean4()); assertNull(bean.getNestedTestBean()); assertSame(bf, bean.getBeanFactory()); }
Example #17
Source File: AutowireWithExclusionTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void byTypeAutowireWithPrimaryInParentAndChild() throws Exception { CountingFactory.reset(); DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml"); parent.getBeanDefinition("props1").setPrimary(true); parent.preInstantiateSingletons(); DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class); robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE); robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally")); child.registerBeanDefinition("rob2", robDef); RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class); propsDef.getPropertyValues().add("properties", "name=props3"); propsDef.setPrimary(true); child.registerBeanDefinition("props3", propsDef); TestBean rob = (TestBean) child.getBean("rob2"); assertEquals("props3", rob.getSomeProperties().getProperty("name")); assertEquals(1, CountingFactory.getFactoryBeanInstanceCount()); }
Example #18
Source File: BindTagTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void bindTagWithMappedProperties() throws JspException { PageContext pc = createPageContext(); IndexedTestBean tb = new IndexedTestBean(); Errors errors = new ServletRequestDataBinder(tb, "tb").getBindingResult(); errors.rejectValue("map[key1]", "code1", "message1"); errors.rejectValue("map[key1]", "code2", "message2"); pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors); BindTag tag = new BindTag(); tag.setPageContext(pc); tag.setPath("tb.map[key1]"); assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE); BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE); assertTrue("Has status variable", status != null); assertTrue("Correct expression", "map[key1]".equals(status.getExpression())); assertTrue("Value is TestBean", status.getValue() instanceof TestBean); assertTrue("Correct value", "name4".equals(((TestBean) status.getValue()).getName())); assertTrue("Correct isError", status.isError()); assertTrue("Correct errorCodes", status.getErrorCodes().length == 2); assertTrue("Correct errorMessages", status.getErrorMessages().length == 2); assertTrue("Correct errorCode", "code1".equals(status.getErrorCodes()[0])); assertTrue("Correct errorCode", "code2".equals(status.getErrorCodes()[1])); assertTrue("Correct errorMessage", "message1".equals(status.getErrorMessages()[0])); assertTrue("Correct errorMessage", "message2".equals(status.getErrorMessages()[1])); }
Example #19
Source File: AbstractAopProxyTests.java From spring-analysis-note with MIT License | 6 votes |
/** * Check that casting to Advised can't get around advice freeze. */ @Test public void testCannotAddAdvisorWhenFrozenUsingCast() throws Throwable { TestBean target = new TestBean(); target.setAge(21); ProxyFactory pc = new ProxyFactory(target); assertFalse(pc.isFrozen()); pc.addAdvice(new NopInterceptor()); ITestBean proxied = (ITestBean) createProxy(pc); pc.setFrozen(true); Advised advised = (Advised) proxied; assertTrue(pc.isFrozen()); try { advised.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor())); fail("Shouldn't be able to add Advisor when frozen"); } catch (AopConfigException ex) { assertTrue(ex.getMessage().contains("frozen")); } // Check it still works: proxy factory state shouldn't have been corrupted assertEquals(target.getAge(), proxied.getAge()); assertEquals(1, advised.getAdvisors().length); }
Example #20
Source File: ProxyFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testProxyTargetClassWithConcreteClassAsTarget() { ProxyFactory pf = new ProxyFactory(); pf.setTargetClass(TestBean.class); Object proxy = pf.getProxy(); assertTrue("Proxy is a CGLIB proxy", AopUtils.isCglibProxy(proxy)); assertTrue(proxy instanceof TestBean); assertEquals(TestBean.class, AopProxyUtils.ultimateTargetClass(proxy)); ProxyFactory pf2 = new ProxyFactory(proxy); pf2.setProxyTargetClass(true); Object proxy2 = pf2.getProxy(); assertTrue("Proxy is a CGLIB proxy", AopUtils.isCglibProxy(proxy2)); assertTrue(proxy2 instanceof TestBean); assertEquals(TestBean.class, AopProxyUtils.ultimateTargetClass(proxy2)); }
Example #21
Source File: RequestScopeTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void requestScopedInnerBeanDestroyedWhileContainedBySingleton() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(requestAttributes); String outerBeanName = "singletonOuterBean"; TestBean outer1 = (TestBean) this.beanFactory.getBean(outerBeanName); assertNull(request.getAttribute(outerBeanName)); TestBean inner1 = (TestBean) outer1.getSpouse(); TestBean outer2 = (TestBean) this.beanFactory.getBean(outerBeanName); assertSame(outer1, outer2); assertSame(inner1, outer2.getSpouse()); requestAttributes.requestCompleted(); assertTrue(inner1.wasDestroyed()); assertFalse(outer1.wasDestroyed()); }
Example #22
Source File: CommonAnnotationBeanPostProcessorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testExtendedEjbInjection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); bf.registerResolvableDependency(BeanFactory.class, bf); bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ExtendedEjbInjectionBean.class)); TestBean tb = new TestBean(); bf.registerSingleton("testBean", tb); TestBean tb2 = new TestBean(); bf.registerSingleton("testBean2", tb2); TestBean tb3 = new TestBean(); bf.registerSingleton("testBean3", tb3); TestBean tb4 = new TestBean(); bf.registerSingleton("testBean4", tb4); NestedTestBean tb6 = new NestedTestBean(); bf.registerSingleton("xy", tb6); bf.registerAlias("xy", "testBean9"); ExtendedEjbInjectionBean bean = (ExtendedEjbInjectionBean) bf.getBean("annotatedBean"); assertTrue(bean.initCalled); assertTrue(bean.init2Called); assertSame(tb, bean.getTestBean()); assertSame(tb2, bean.getTestBean2()); assertSame(tb4, bean.getTestBean3()); assertSame(tb3, bean.getTestBean4()); assertSame(tb6, bean.testBean5); assertSame(tb6, bean.testBean6); assertSame(bf, bean.beanFactory); bf.destroySingletons(); assertTrue(bean.destroyCalled); assertTrue(bean.destroy2Called); }
Example #23
Source File: StaticApplicationContextMulticasterTests.java From spring-analysis-note with MIT License | 5 votes |
@Override protected ConfigurableApplicationContext createContext() throws Exception { StaticApplicationContext parent = new StaticApplicationContext(); Map<String, String> m = new HashMap<>(); m.put("name", "Roderick"); parent.registerPrototype("rod", TestBean.class, new MutablePropertyValues(m)); m.put("name", "Albert"); parent.registerPrototype("father", TestBean.class, new MutablePropertyValues(m)); parent.registerSingleton(StaticApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME, TestApplicationEventMulticaster.class, null); parent.refresh(); parent.addApplicationListener(parentListener) ; parent.getStaticMessageSource().addMessage("code1", Locale.getDefault(), "message1"); this.sac = new StaticApplicationContext(parent); sac.registerSingleton("beanThatListens", BeanThatListens.class, new MutablePropertyValues()); sac.registerSingleton("aca", ACATester.class, new MutablePropertyValues()); sac.registerPrototype("aca-prototype", ACATester.class, new MutablePropertyValues()); PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(sac.getDefaultListableBeanFactory()); Resource resource = new ClassPathResource("testBeans.properties", getClass()); reader.loadBeanDefinitions(new EncodedResource(resource, "ISO-8859-1")); sac.refresh(); sac.addApplicationListener(listener); sac.getStaticMessageSource().addMessage("code2", Locale.getDefault(), "message2"); return sac; }
Example #24
Source File: SelectTagTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void withNullValue() throws Exception { TestBean tb = getTestBean(); tb.setCountry(null); this.tag.setPath("country"); this.tag.setItems(Country.getCountries()); assertList(false); }
Example #25
Source File: PropertySourceAnnotationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void withResolvablePlaceholderAndFactoryBean() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ConfigWithResolvablePlaceholderAndFactoryBean.class); System.setProperty("path.to.properties", "org/springframework/context/annotation"); ctx.refresh(); assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p1TestBean")); System.clearProperty("path.to.properties"); }
Example #26
Source File: SelectTagTests.java From java-technology-stack with MIT License | 5 votes |
@Override protected TestBean createTestBean() { this.bean = new TestBeanWithRealCountry(); this.bean.setName("Rob"); this.bean.setCountry("UK"); this.bean.setSex("M"); this.bean.setMyFloat(new Float("12.34")); this.bean.setSomeIntegerArray(new Integer[]{new Integer(12), new Integer(34)}); return this.bean; }
Example #27
Source File: ClassFiltersTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testIntersection() { assertTrue(exceptionFilter.matches(RuntimeException.class)); assertTrue(hasRootCauseFilter.matches(NestedRuntimeException.class)); ClassFilter intersection = ClassFilters.intersection(exceptionFilter, hasRootCauseFilter); assertFalse(intersection.matches(RuntimeException.class)); assertFalse(intersection.matches(TestBean.class)); assertTrue(intersection.matches(NestedRuntimeException.class)); }
Example #28
Source File: DefaultListableBeanFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testAutowireBeanByTypePrimaryTakesPrecedenceOverPriority() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); lbf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE); RootBeanDefinition bd = new RootBeanDefinition(HighPriorityTestBean.class); RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class); bd2.setPrimary(true); lbf.registerBeanDefinition("test", bd); lbf.registerBeanDefinition("spouse", bd2); DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); assertThat(bean.getSpouse(), equalTo(lbf.getBean("spouse"))); }
Example #29
Source File: DefaultListableBeanFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testConfigureBean() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("age", "99"); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.setPropertyValues(pvs); lbf.registerBeanDefinition("test", bd); TestBean tb = new TestBean(); assertEquals(0, tb.getAge()); lbf.configureBean(tb, "test"); assertEquals(99, tb.getAge()); assertSame(lbf, tb.getBeanFactory()); assertNull(tb.getSpouse()); }
Example #30
Source File: HibernateTemplateTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testEvict() throws HibernateException { TestBean tb = new TestBean(); hibernateTemplate.evict(tb); verify(session).evict(tb); verify(session).flush(); verify(session).close(); }