Java Code Examples for org.springframework.tests.sample.beans.ITestBean#getName()
The following examples show how to use
org.springframework.tests.sample.beans.ITestBean#getName() .
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: AbstractTransactionAspectTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void noTransaction() throws Exception { PlatformTransactionManager ptm = mock(PlatformTransactionManager.class); TestBean tb = new TestBean(); TransactionAttributeSource tas = new MapTransactionAttributeSource(); // All the methods in this class use the advised() template method // to obtain a transaction object, configured with the given PlatformTransactionManager // and transaction attribute source ITestBean itb = (ITestBean) advised(tb, ptm, tas); checkTransactionStatus(false); itb.getName(); checkTransactionStatus(false); // expect no calls verifyZeroInteractions(ptm); }
Example 2
Source File: AopNamespaceHandlerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testAdviceInvokedCorrectly() throws Exception { CountingBeforeAdvice getAgeCounter = (CountingBeforeAdvice) this.context.getBean("getAgeCounter"); CountingBeforeAdvice getNameCounter = (CountingBeforeAdvice) this.context.getBean("getNameCounter"); ITestBean bean = getTestBean(); assertEquals("Incorrect initial getAge count", 0, getAgeCounter.getCalls("getAge")); assertEquals("Incorrect initial getName count", 0, getNameCounter.getCalls("getName")); bean.getAge(); assertEquals("Incorrect getAge count on getAge counter", 1, getAgeCounter.getCalls("getAge")); assertEquals("Incorrect getAge count on getName counter", 0, getNameCounter.getCalls("getAge")); bean.getName(); assertEquals("Incorrect getName count on getName counter", 1, getNameCounter.getCalls("getName")); assertEquals("Incorrect getName count on getAge counter", 0, getAgeCounter.getCalls("getName")); }
Example 3
Source File: AopNamespaceHandlerTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testAdviceInvokedCorrectly() throws Exception { CountingBeforeAdvice getAgeCounter = (CountingBeforeAdvice) this.context.getBean("getAgeCounter"); CountingBeforeAdvice getNameCounter = (CountingBeforeAdvice) this.context.getBean("getNameCounter"); ITestBean bean = getTestBean(); assertEquals("Incorrect initial getAge count", 0, getAgeCounter.getCalls("getAge")); assertEquals("Incorrect initial getName count", 0, getNameCounter.getCalls("getName")); bean.getAge(); assertEquals("Incorrect getAge count on getAge counter", 1, getAgeCounter.getCalls("getAge")); assertEquals("Incorrect getAge count on getName counter", 0, getNameCounter.getCalls("getAge")); bean.getName(); assertEquals("Incorrect getName count on getName counter", 1, getNameCounter.getCalls("getName")); assertEquals("Incorrect getName count on getAge counter", 0, getAgeCounter.getCalls("getName")); }
Example 4
Source File: AbstractTransactionAspectTests.java From java-technology-stack with MIT License | 6 votes |
/** * Check that a transaction is created and committed. */ @Test public void transactionShouldSucceedWithNotNew() throws Exception { TransactionAttribute txatt = new DefaultTransactionAttribute(); MapTransactionAttributeSource tas = new MapTransactionAttributeSource(); tas.register(getNameMethod, txatt); TransactionStatus status = mock(TransactionStatus.class); PlatformTransactionManager ptm = mock(PlatformTransactionManager.class); // expect a transaction given(ptm.getTransaction(txatt)).willReturn(status); TestBean tb = new TestBean(); ITestBean itb = (ITestBean) advised(tb, ptm, tas); checkTransactionStatus(false); // verification!? itb.getName(); checkTransactionStatus(false); verify(ptm).commit(status); }
Example 5
Source File: AbstractAopProxyTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testRejectsBogusDynamicIntroductionAdviceWithNoAdapter() throws Throwable { TestBean target = new TestBean(); target.setAge(21); ProxyFactory pc = new ProxyFactory(target); pc.addAdvisor(new DefaultIntroductionAdvisor(new DummyIntroductionAdviceImpl(), Comparable.class)); try { // TODO May fail on either call: may want to tighten up definition ITestBean proxied = (ITestBean) createProxy(pc); proxied.getName(); fail("Bogus introduction"); } catch (Exception ex) { // TODO used to catch UnknownAdviceTypeException, but // with CGLIB some errors are in proxy creation and are wrapped // in aspect exception. Error message is still fine. //assertTrue(ex.getMessage().indexOf("ntroduction") > -1); } }
Example 6
Source File: BenchmarkTests.java From java-technology-stack with MIT License | 6 votes |
private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) { ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS); StopWatch sw = new StopWatch(); sw.start(howmany + " repeated before advice invocations with " + technology); ITestBean adrian = (ITestBean) bf.getBean("adrian"); assertTrue(AopUtils.isAopProxy(adrian)); Advised a = (Advised) adrian; assertTrue(a.getAdvisors().length >= 3); assertEquals("adrian", adrian.getName()); for (int i = 0; i < howmany; i++) { adrian.getName(); } sw.stop(); System.out.println(sw.prettyPrint()); return sw.getLastTaskTimeMillis(); }
Example 7
Source File: ProxyFactoryBeanTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testGetObjectTypeWithNoTargetOrTargetSource() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS)); ITestBean tb = (ITestBean) bf.getBean("noTarget"); try { tb.getName(); fail(); } catch (UnsupportedOperationException ex) { assertEquals("getName", ex.getMessage()); } FactoryBean<?> pfb = (ProxyFactoryBean) bf.getBean("&noTarget"); assertTrue("Has correct object type", ITestBean.class.isAssignableFrom(pfb.getObjectType())); }
Example 8
Source File: AbstractAopProxyTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testTargetCanGetInvocation() throws Throwable { final InvocationCheckExposedInvocationTestBean expectedTarget = new InvocationCheckExposedInvocationTestBean(); AdvisedSupport pc = new AdvisedSupport(ITestBean.class, IOther.class); pc.addAdvice(ExposeInvocationInterceptor.INSTANCE); TrapTargetInterceptor tii = new TrapTargetInterceptor() { @Override public Object invoke(MethodInvocation invocation) throws Throwable { // Assert that target matches BEFORE invocation returns assertEquals("Target is correct", expectedTarget, invocation.getThis()); return super.invoke(invocation); } }; pc.addAdvice(tii); pc.setTarget(expectedTarget); AopProxy aop = createAopProxy(pc); ITestBean tb = (ITestBean) aop.getProxy(); tb.getName(); }
Example 9
Source File: AbstractAopProxyTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testTargetCanGetInvocation() throws Throwable { final InvocationCheckExposedInvocationTestBean expectedTarget = new InvocationCheckExposedInvocationTestBean(); AdvisedSupport pc = new AdvisedSupport(ITestBean.class, IOther.class); pc.addAdvice(ExposeInvocationInterceptor.INSTANCE); TrapTargetInterceptor tii = new TrapTargetInterceptor() { @Override public Object invoke(MethodInvocation invocation) throws Throwable { // Assert that target matches BEFORE invocation returns assertEquals("Target is correct", expectedTarget, invocation.getThis()); return super.invoke(invocation); } }; pc.addAdvice(tii); pc.setTarget(expectedTarget); AopProxy aop = createAopProxy(pc); ITestBean tb = (ITestBean) aop.getProxy(); tb.getName(); }
Example 10
Source File: BenchmarkTests.java From java-technology-stack with MIT License | 5 votes |
private long testMix(String file, int howmany, String technology) { ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS); StopWatch sw = new StopWatch(); sw.start(howmany + " repeated mixed invocations with " + technology); ITestBean adrian = (ITestBean) bf.getBean("adrian"); assertTrue(AopUtils.isAopProxy(adrian)); Advised a = (Advised) adrian; assertTrue(a.getAdvisors().length >= 3); for (int i = 0; i < howmany; i++) { // Hit all 3 joinpoints adrian.getAge(); adrian.getName(); adrian.setAge(i); // Invoke three non-advised methods adrian.getDoctor(); adrian.getLawyer(); adrian.getSpouse(); } sw.stop(); System.out.println(sw.prettyPrint()); return sw.getLastTaskTimeMillis(); }
Example 11
Source File: AdvisorAutoProxyCreatorIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testRegexpApplied() throws Exception { BeanFactory bf = getBeanFactory(); ITestBean test = (ITestBean) bf.getBean("test"); MethodCounter counter = (MethodCounter) bf.getBean("countingAdvice"); assertEquals(0, counter.getCalls()); test.getName(); assertEquals(1, counter.getCalls()); }
Example 12
Source File: AutoProxyCreatorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testAutoProxyCreatorWithFallbackToDynamicProxy() { StaticApplicationContext sac = new StaticApplicationContext(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("proxyFactoryBean", "false"); sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class, pvs); sac.registerSingleton("noInterfaces", NoInterfaces.class); sac.registerSingleton("containerCallbackInterfacesOnly", ContainerCallbackInterfacesOnly.class); sac.registerSingleton("singletonNoInterceptor", CustomProxyFactoryBean.class); sac.registerSingleton("singletonToBeProxied", CustomProxyFactoryBean.class); sac.registerPrototype("prototypeToBeProxied", SpringProxyFactoryBean.class); sac.refresh(); MessageSource messageSource = (MessageSource) sac.getBean("messageSource"); NoInterfaces noInterfaces = (NoInterfaces) sac.getBean("noInterfaces"); ContainerCallbackInterfacesOnly containerCallbackInterfacesOnly = (ContainerCallbackInterfacesOnly) sac.getBean("containerCallbackInterfacesOnly"); ITestBean singletonNoInterceptor = (ITestBean) sac.getBean("singletonNoInterceptor"); ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied"); ITestBean prototypeToBeProxied = (ITestBean) sac.getBean("prototypeToBeProxied"); assertFalse(AopUtils.isCglibProxy(messageSource)); assertTrue(AopUtils.isCglibProxy(noInterfaces)); assertTrue(AopUtils.isCglibProxy(containerCallbackInterfacesOnly)); assertFalse(AopUtils.isCglibProxy(singletonNoInterceptor)); assertFalse(AopUtils.isCglibProxy(singletonToBeProxied)); assertFalse(AopUtils.isCglibProxy(prototypeToBeProxied)); TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator"); assertEquals(0, tapc.testInterceptor.nrOfInvocations); singletonNoInterceptor.getName(); assertEquals(0, tapc.testInterceptor.nrOfInvocations); singletonToBeProxied.getAge(); assertEquals(1, tapc.testInterceptor.nrOfInvocations); prototypeToBeProxied.getSpouse(); assertEquals(2, tapc.testInterceptor.nrOfInvocations); }
Example 13
Source File: AutoProxyCreatorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testAutoProxyCreatorWithFallbackToDynamicProxy() { StaticApplicationContext sac = new StaticApplicationContext(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("proxyFactoryBean", "false"); sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class, pvs); sac.registerSingleton("noInterfaces", NoInterfaces.class); sac.registerSingleton("containerCallbackInterfacesOnly", ContainerCallbackInterfacesOnly.class); sac.registerSingleton("singletonNoInterceptor", CustomProxyFactoryBean.class); sac.registerSingleton("singletonToBeProxied", CustomProxyFactoryBean.class); sac.registerPrototype("prototypeToBeProxied", SpringProxyFactoryBean.class); sac.refresh(); MessageSource messageSource = (MessageSource) sac.getBean("messageSource"); NoInterfaces noInterfaces = (NoInterfaces) sac.getBean("noInterfaces"); ContainerCallbackInterfacesOnly containerCallbackInterfacesOnly = (ContainerCallbackInterfacesOnly) sac.getBean("containerCallbackInterfacesOnly"); ITestBean singletonNoInterceptor = (ITestBean) sac.getBean("singletonNoInterceptor"); ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied"); ITestBean prototypeToBeProxied = (ITestBean) sac.getBean("prototypeToBeProxied"); assertFalse(AopUtils.isCglibProxy(messageSource)); assertTrue(AopUtils.isCglibProxy(noInterfaces)); assertTrue(AopUtils.isCglibProxy(containerCallbackInterfacesOnly)); assertFalse(AopUtils.isCglibProxy(singletonNoInterceptor)); assertFalse(AopUtils.isCglibProxy(singletonToBeProxied)); assertFalse(AopUtils.isCglibProxy(prototypeToBeProxied)); TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator"); assertEquals(0, tapc.testInterceptor.nrOfInvocations); singletonNoInterceptor.getName(); assertEquals(0, tapc.testInterceptor.nrOfInvocations); singletonToBeProxied.getAge(); assertEquals(1, tapc.testInterceptor.nrOfInvocations); prototypeToBeProxied.getSpouse(); assertEquals(2, tapc.testInterceptor.nrOfInvocations); }
Example 14
Source File: BenchmarkTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
private long testMix(String file, int howmany, String technology) { ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS); StopWatch sw = new StopWatch(); sw.start(howmany + " repeated mixed invocations with " + technology); ITestBean adrian = (ITestBean) bf.getBean("adrian"); assertTrue(AopUtils.isAopProxy(adrian)); Advised a = (Advised) adrian; assertTrue(a.getAdvisors().length >= 3); for (int i = 0; i < howmany; i++) { // Hit all 3 joinpoints adrian.getAge(); adrian.getName(); adrian.setAge(i); // Invoke three non-advised methods adrian.getDoctor(); adrian.getLawyer(); adrian.getSpouse(); } sw.stop(); System.out.println(sw.prettyPrint()); return sw.getLastTaskTimeMillis(); }
Example 15
Source File: AutoProxyCreatorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testBeanNameAutoProxyCreatorWithFactoryBeanProxy() { StaticApplicationContext sac = new StaticApplicationContext(); sac.registerSingleton("testInterceptor", TestInterceptor.class); RootBeanDefinition proxyCreator = new RootBeanDefinition(BeanNameAutoProxyCreator.class); proxyCreator.getPropertyValues().add("interceptorNames", "testInterceptor"); proxyCreator.getPropertyValues().add("beanNames", "singletonToBeProxied,&singletonFactoryToBeProxied"); sac.getDefaultListableBeanFactory().registerBeanDefinition("beanNameAutoProxyCreator", proxyCreator); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); sac.getDefaultListableBeanFactory().registerBeanDefinition("singletonToBeProxied", bd); sac.registerSingleton("singletonFactoryToBeProxied", DummyFactory.class); sac.refresh(); ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied"); assertTrue(Proxy.isProxyClass(singletonToBeProxied.getClass())); TestInterceptor ti = (TestInterceptor) sac.getBean("testInterceptor"); int initialNr = ti.nrOfInvocations; singletonToBeProxied.getName(); assertEquals(initialNr + 1, ti.nrOfInvocations); FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied"); assertTrue(Proxy.isProxyClass(factory.getClass())); TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied"); assertFalse(AopUtils.isAopProxy(tb)); assertEquals(initialNr + 3, ti.nrOfInvocations); tb.getAge(); assertEquals(initialNr + 3, ti.nrOfInvocations); }
Example 16
Source File: AutoProxyCreatorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testBeanNameAutoProxyCreatorWithFactoryBeanProxy() { StaticApplicationContext sac = new StaticApplicationContext(); sac.registerSingleton("testInterceptor", TestInterceptor.class); RootBeanDefinition proxyCreator = new RootBeanDefinition(BeanNameAutoProxyCreator.class); proxyCreator.getPropertyValues().add("interceptorNames", "testInterceptor"); proxyCreator.getPropertyValues().add("beanNames", "singletonToBeProxied,&singletonFactoryToBeProxied"); sac.getDefaultListableBeanFactory().registerBeanDefinition("beanNameAutoProxyCreator", proxyCreator); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); sac.getDefaultListableBeanFactory().registerBeanDefinition("singletonToBeProxied", bd); sac.registerSingleton("singletonFactoryToBeProxied", DummyFactory.class); sac.refresh(); ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied"); assertTrue(Proxy.isProxyClass(singletonToBeProxied.getClass())); TestInterceptor ti = (TestInterceptor) sac.getBean("testInterceptor"); int initialNr = ti.nrOfInvocations; singletonToBeProxied.getName(); assertEquals(initialNr + 1, ti.nrOfInvocations); FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied"); assertTrue(Proxy.isProxyClass(factory.getClass())); TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied"); assertFalse(AopUtils.isAopProxy(tb)); assertEquals(initialNr + 3, ti.nrOfInvocations); tb.getAge(); assertEquals(initialNr + 3, ti.nrOfInvocations); }
Example 17
Source File: AdvisorAdapterRegistrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testAdvisorAdapterRegistrationManagerNotPresentInContext() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-without-bpp.xml", getClass()); ITestBean tb = (ITestBean) ctx.getBean("testBean"); // just invoke any method to see if advice fired try { tb.getName(); fail("Should throw UnknownAdviceTypeException"); } catch (UnknownAdviceTypeException ex) { // expected assertEquals(0, getAdviceImpl(tb).getInvocationCounter()); } }
Example 18
Source File: BenchmarkTests.java From spring-analysis-note with MIT License | 5 votes |
private long testMix(String file, int howmany, String technology) { ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS); StopWatch sw = new StopWatch(); sw.start(howmany + " repeated mixed invocations with " + technology); ITestBean adrian = (ITestBean) bf.getBean("adrian"); assertTrue(AopUtils.isAopProxy(adrian)); Advised a = (Advised) adrian; assertTrue(a.getAdvisors().length >= 3); for (int i = 0; i < howmany; i++) { // Hit all 3 joinpoints adrian.getAge(); adrian.getName(); adrian.setAge(i); // Invoke three non-advised methods adrian.getDoctor(); adrian.getLawyer(); adrian.getSpouse(); } sw.stop(); System.out.println(sw.prettyPrint()); return sw.getLastTaskTimeMillis(); }
Example 19
Source File: AopNamespaceHandlerTests.java From java-technology-stack with MIT License | 4 votes |
@Test public void testAspectApplied() throws Exception { ITestBean bean = getTestBean(); CountingAspectJAdvice advice = (CountingAspectJAdvice) this.context.getBean("countingAdvice"); assertEquals("Incorrect before count", 0, advice.getBeforeCount()); assertEquals("Incorrect after count", 0, advice.getAfterCount()); bean.setName("Sally"); assertEquals("Incorrect before count", 1, advice.getBeforeCount()); assertEquals("Incorrect after count", 1, advice.getAfterCount()); bean.getName(); assertEquals("Incorrect before count", 1, advice.getBeforeCount()); assertEquals("Incorrect after count", 1, advice.getAfterCount()); }
Example 20
Source File: AutoProxyCreatorTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void testBeanNameAutoProxyCreator() { StaticApplicationContext sac = new StaticApplicationContext(); sac.registerSingleton("testInterceptor", TestInterceptor.class); RootBeanDefinition proxyCreator = new RootBeanDefinition(BeanNameAutoProxyCreator.class); proxyCreator.getPropertyValues().add("interceptorNames", "testInterceptor"); proxyCreator.getPropertyValues().add("beanNames", "singletonToBeProxied,innerBean,singletonFactoryToBeProxied"); sac.getDefaultListableBeanFactory().registerBeanDefinition("beanNameAutoProxyCreator", proxyCreator); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE); RootBeanDefinition innerBean = new RootBeanDefinition(TestBean.class); bd.getPropertyValues().add("spouse", new BeanDefinitionHolder(innerBean, "innerBean")); sac.getDefaultListableBeanFactory().registerBeanDefinition("singletonToBeProxied", bd); sac.registerSingleton("singletonFactoryToBeProxied", DummyFactory.class); sac.registerSingleton("autowiredIndexedTestBean", IndexedTestBean.class); sac.refresh(); MessageSource messageSource = (MessageSource) sac.getBean("messageSource"); ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied"); assertFalse(Proxy.isProxyClass(messageSource.getClass())); assertTrue(Proxy.isProxyClass(singletonToBeProxied.getClass())); assertTrue(Proxy.isProxyClass(singletonToBeProxied.getSpouse().getClass())); // test whether autowiring succeeded with auto proxy creation assertEquals(sac.getBean("autowiredIndexedTestBean"), singletonToBeProxied.getNestedIndexedBean()); TestInterceptor ti = (TestInterceptor) sac.getBean("testInterceptor"); // already 2: getSpouse + getNestedIndexedBean calls above assertEquals(2, ti.nrOfInvocations); singletonToBeProxied.getName(); singletonToBeProxied.getSpouse().getName(); assertEquals(5, ti.nrOfInvocations); ITestBean tb = (ITestBean) sac.getBean("singletonFactoryToBeProxied"); assertTrue(AopUtils.isJdkDynamicProxy(tb)); assertEquals(5, ti.nrOfInvocations); tb.getAge(); assertEquals(6, ti.nrOfInvocations); ITestBean tb2 = (ITestBean) sac.getBean("singletonFactoryToBeProxied"); assertSame(tb, tb2); assertEquals(6, ti.nrOfInvocations); tb2.getAge(); assertEquals(7, ti.nrOfInvocations); }