Java Code Examples for org.springframework.tests.sample.beans.ITestBean#setName()
The following examples show how to use
org.springframework.tests.sample.beans.ITestBean#setName() .
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: AbstractAopProxyTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testDynamicMethodPointcutThatAppliesStaticallyOnlyToSetters() throws Throwable { TestBean tb = new TestBean(); ProxyFactory pc = new ProxyFactory(); pc.addInterface(ITestBean.class); // Could apply dynamically to getAge/setAge but not to getName TestDynamicPointcutForSettersOnly dp = new TestDynamicPointcutForSettersOnly(new NopInterceptor(), "Age"); pc.addAdvisor(dp); this.mockTargetSource.setTarget(tb); pc.setTargetSource(mockTargetSource); ITestBean it = (ITestBean) createProxy(pc); assertEquals(0, dp.count); it.getAge(); // Statically vetoed assertEquals(0, dp.count); it.setAge(11); assertEquals(11, it.getAge()); assertEquals(1, dp.count); // Applies statically but not dynamically it.setName("joe"); assertEquals(1, dp.count); }
Example 2
Source File: AbstractAopProxyTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testReplaceArgument() throws Throwable { TestBean tb = new TestBean(); ProxyFactory pc = new ProxyFactory(); pc.addInterface(ITestBean.class); pc.setTarget(tb); pc.addAdvisor(new StringSetterNullReplacementAdvice()); ITestBean t = (ITestBean) pc.getProxy(); int newAge = 5; t.setAge(newAge); assertEquals(newAge, t.getAge()); String newName = "greg"; t.setName(newName); assertEquals(newName, t.getName()); t.setName(null); // Null replacement magic should work assertEquals("", t.getName()); }
Example 3
Source File: CauchoRemotingTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void burlapProxyFactoryBeanWithAuthenticationAndAccessError() throws Exception { BurlapProxyFactoryBean factory = new BurlapProxyFactoryBean(); factory.setServiceInterface(ITestBean.class); factory.setServiceUrl("http://localhosta/testbean"); factory.setUsername("test"); factory.setPassword("bean"); factory.setOverloadEnabled(true); factory.afterPropertiesSet(); assertTrue("Correct singleton value", factory.isSingleton()); assertTrue(factory.getObject() instanceof ITestBean); ITestBean bean = (ITestBean) factory.getObject(); exception.expect(RemoteAccessException.class); bean.setName("test"); }
Example 4
Source File: AbstractAopProxyTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testReplaceArgument() throws Throwable { TestBean tb = new TestBean(); ProxyFactory pc = new ProxyFactory(new Class<?>[] {ITestBean.class}); pc.setTarget(tb); pc.addAdvisor(new StringSetterNullReplacementAdvice()); ITestBean t = (ITestBean) pc.getProxy(); int newAge = 5; t.setAge(newAge); assertEquals(newAge, t.getAge()); String newName = "greg"; t.setName(newName); assertEquals(newName, t.getName()); t.setName(null); // Null replacement magic should work assertEquals("", t.getName()); }
Example 5
Source File: AbstractAspectJAdvisorFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testTwoAdvicesOnOneAspect() { TestBean target = new TestBean(); TwoAdviceAspect twoAdviceAspect = new TwoAdviceAspect(); List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(twoAdviceAspect,"someBean")); assertEquals("Two advice methods found", 2, advisors.size()); ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class); itb.setName(""); assertEquals(0, itb.getAge()); int newAge = 32; itb.setAge(newAge); assertEquals(1, itb.getAge()); }
Example 6
Source File: AbstractAopProxyTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testReplaceArgument() throws Throwable { TestBean tb = new TestBean(); ProxyFactory pc = new ProxyFactory(); pc.addInterface(ITestBean.class); pc.setTarget(tb); pc.addAdvisor(new StringSetterNullReplacementAdvice()); ITestBean t = (ITestBean) pc.getProxy(); int newAge = 5; t.setAge(newAge); assertEquals(newAge, t.getAge()); String newName = "greg"; t.setName(newName); assertEquals(newName, t.getName()); t.setName(null); // Null replacement magic should work assertEquals("", t.getName()); }
Example 7
Source File: CauchoRemotingTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void hessianProxyFactoryBeanWithAuthenticationAndAccessError() throws Exception { HessianProxyFactoryBean factory = new HessianProxyFactoryBean(); factory.setServiceInterface(ITestBean.class); factory.setServiceUrl("http://localhosta/testbean"); factory.setUsername("test"); factory.setPassword("bean"); factory.setOverloadEnabled(true); factory.afterPropertiesSet(); assertTrue("Correct singleton value", factory.isSingleton()); assertTrue(factory.getObject() instanceof ITestBean); ITestBean bean = (ITestBean) factory.getObject(); exception.expect(RemoteAccessException.class); bean.setName("test"); }
Example 8
Source File: ProxyFactoryBeanTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testMethodPointcuts() { ITestBean tb = (ITestBean) factory.getBean("pointcuts"); PointcutForVoid.reset(); assertTrue("No methods intercepted", PointcutForVoid.methodNames.isEmpty()); tb.getAge(); assertTrue("Not void: shouldn't have intercepted", PointcutForVoid.methodNames.isEmpty()); tb.setAge(1); tb.getAge(); tb.setName("Tristan"); tb.toString(); assertEquals("Recorded wrong number of invocations", 2, PointcutForVoid.methodNames.size()); assertTrue(PointcutForVoid.methodNames.get(0).equals("setAge")); assertTrue(PointcutForVoid.methodNames.get(1).equals("setName")); }
Example 9
Source File: AopNamespaceHandlerScopeIntegrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testRequestScoping() throws Exception { MockHttpServletRequest oldRequest = new MockHttpServletRequest(); MockHttpServletRequest newRequest = new MockHttpServletRequest(); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(oldRequest)); ITestBean scoped = (ITestBean) this.context.getBean("requestScoped"); assertTrue("Should be AOP proxy", AopUtils.isAopProxy(scoped)); assertTrue("Should be target class proxy", scoped instanceof TestBean); ITestBean testBean = (ITestBean) this.context.getBean("testBean"); assertTrue("Should be AOP proxy", AopUtils.isAopProxy(testBean)); assertFalse("Regular bean should be JDK proxy", testBean instanceof TestBean); String rob = "Rob Harrop"; String bram = "Bram Smeets"; assertEquals(rob, scoped.getName()); scoped.setName(bram); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(newRequest)); assertEquals(rob, scoped.getName()); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(oldRequest)); assertEquals(bram, scoped.getName()); assertTrue("Should have advisors", ((Advised) scoped).getAdvisors().length > 0); }
Example 10
Source File: CauchoRemotingTests.java From spring-analysis-note with MIT License | 5 votes |
@Test @SuppressWarnings("deprecation") public void simpleHessianServiceExporter() throws IOException { final int port = SocketUtils.findAvailableTcpPort(); TestBean tb = new TestBean("tb"); SimpleHessianServiceExporter exporter = new SimpleHessianServiceExporter(); exporter.setService(tb); exporter.setServiceInterface(ITestBean.class); exporter.setDebug(true); exporter.prepare(); HttpServer server = HttpServer.create(new InetSocketAddress(port), -1); server.createContext("/hessian", exporter); server.start(); try { HessianClientInterceptor client = new HessianClientInterceptor(); client.setServiceUrl("http://localhost:" + port + "/hessian"); client.setServiceInterface(ITestBean.class); //client.setHessian2(true); client.prepare(); ITestBean proxy = ProxyFactory.getProxy(ITestBean.class, client); assertEquals("tb", proxy.getName()); proxy.setName("test"); assertEquals("test", proxy.getName()); } finally { server.stop(Integer.MAX_VALUE); } }
Example 11
Source File: AbstractTransactionAspectTests.java From spring-analysis-note with MIT License | 5 votes |
/** * Simulate failure of the underlying transaction infrastructure to commit. * Check that the target method was invoked, but that the transaction * infrastructure exception was thrown to the client */ @Test public void cannotCommitTransaction() throws Exception { TransactionAttribute txatt = new DefaultTransactionAttribute(); Method m = setNameMethod; MapTransactionAttributeSource tas = new MapTransactionAttributeSource(); tas.register(m, txatt); // Method m2 = getNameMethod; // No attributes for m2 PlatformTransactionManager ptm = mock(PlatformTransactionManager.class); TransactionStatus status = mock(TransactionStatus.class); given(ptm.getTransaction(txatt)).willReturn(status); UnexpectedRollbackException ex = new UnexpectedRollbackException("foobar", null); willThrow(ex).given(ptm).commit(status); TestBean tb = new TestBean(); ITestBean itb = (ITestBean) advised(tb, ptm, tas); String name = "new name"; try { itb.setName(name); fail("Shouldn't have succeeded"); } catch (UnexpectedRollbackException thrown) { assertTrue(thrown == ex); } // Should have invoked target and changed name assertTrue(itb.getName() == name); }
Example 12
Source File: AbstractTransactionAspectTests.java From java-technology-stack with MIT License | 5 votes |
/** * Simulate failure of the underlying transaction infrastructure to commit. * Check that the target method was invoked, but that the transaction * infrastructure exception was thrown to the client */ @Test public void cannotCommitTransaction() throws Exception { TransactionAttribute txatt = new DefaultTransactionAttribute(); Method m = setNameMethod; MapTransactionAttributeSource tas = new MapTransactionAttributeSource(); tas.register(m, txatt); // Method m2 = getNameMethod; // No attributes for m2 PlatformTransactionManager ptm = mock(PlatformTransactionManager.class); TransactionStatus status = mock(TransactionStatus.class); given(ptm.getTransaction(txatt)).willReturn(status); UnexpectedRollbackException ex = new UnexpectedRollbackException("foobar", null); willThrow(ex).given(ptm).commit(status); TestBean tb = new TestBean(); ITestBean itb = (ITestBean) advised(tb, ptm, tas); String name = "new name"; try { itb.setName(name); fail("Shouldn't have succeeded"); } catch (UnexpectedRollbackException thrown) { assertTrue(thrown == ex); } // Should have invoked target and changed name assertTrue(itb.getName() == name); }
Example 13
Source File: AspectJAutoProxyCreatorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testPerTargetAspect() throws SecurityException, NoSuchMethodException { ClassPathXmlApplicationContext bf = newContext("pertarget.xml"); ITestBean adrian1 = (ITestBean) bf.getBean("adrian"); assertTrue(AopUtils.isAopProxy(adrian1)); // Does not trigger advice or count int explicitlySetAge = 25; adrian1.setAge(explicitlySetAge); assertEquals("Setter does not initiate advice", explicitlySetAge, adrian1.getAge()); // Fire aspect AspectMetadata am = new AspectMetadata(PerTargetAspect.class, "someBean"); assertTrue(am.getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)); adrian1.getSpouse(); assertEquals("Advice has now been instantiated", 0, adrian1.getAge()); adrian1.setAge(11); assertEquals("Any int setter increments", 2, adrian1.getAge()); adrian1.setName("Adrian"); //assertEquals("Any other setter does not increment", 2, adrian1.getAge()); ITestBean adrian2 = (ITestBean) bf.getBean("adrian"); assertNotSame(adrian1, adrian2); assertTrue(AopUtils.isAopProxy(adrian1)); assertEquals(34, adrian2.getAge()); adrian2.getSpouse(); assertEquals("Aspect now fired", 0, adrian2.getAge()); assertEquals(1, adrian2.getAge()); assertEquals(2, adrian2.getAge()); assertEquals(3, adrian1.getAge()); }
Example 14
Source File: AspectJAutoProxyCreatorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testPerTargetAspect() throws SecurityException, NoSuchMethodException { ClassPathXmlApplicationContext bf = newContext("pertarget.xml"); ITestBean adrian1 = (ITestBean) bf.getBean("adrian"); assertTrue(AopUtils.isAopProxy(adrian1)); // Does not trigger advice or count int explicitlySetAge = 25; adrian1.setAge(explicitlySetAge); assertEquals("Setter does not initiate advice", explicitlySetAge, adrian1.getAge()); // Fire aspect AspectMetadata am = new AspectMetadata(PerTargetAspect.class, "someBean"); assertTrue(am.getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)); adrian1.getSpouse(); assertEquals("Advice has now been instantiated", 0, adrian1.getAge()); adrian1.setAge(11); assertEquals("Any int setter increments", 2, adrian1.getAge()); adrian1.setName("Adrian"); //assertEquals("Any other setter does not increment", 2, adrian1.getAge()); ITestBean adrian2 = (ITestBean) bf.getBean("adrian"); assertNotSame(adrian1, adrian2); assertTrue(AopUtils.isAopProxy(adrian1)); assertEquals(34, adrian2.getAge()); adrian2.getSpouse(); assertEquals("Aspect now fired", 0, adrian2.getAge()); assertEquals(1, adrian2.getAge()); assertEquals(2, adrian2.getAge()); assertEquals(3, adrian1.getAge()); }
Example 15
Source File: AopNamespaceHandlerScopeIntegrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testSingletonScoping() throws Exception { ITestBean scoped = (ITestBean) this.context.getBean("singletonScoped"); assertTrue("Should be AOP proxy", AopUtils.isAopProxy(scoped)); assertTrue("Should be target class proxy", scoped instanceof TestBean); String rob = "Rob Harrop"; String bram = "Bram Smeets"; assertEquals(rob, scoped.getName()); scoped.setName(bram); assertEquals(bram, scoped.getName()); ITestBean deserialized = (ITestBean) SerializationTestUtils.serializeAndDeserialize(scoped); assertEquals(bram, deserialized.getName()); }
Example 16
Source File: AopNamespaceHandlerScopeIntegrationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testRequestScoping() throws Exception { MockHttpServletRequest oldRequest = new MockHttpServletRequest(); MockHttpServletRequest newRequest = new MockHttpServletRequest(); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(oldRequest)); ITestBean scoped = (ITestBean) this.context.getBean("requestScoped"); assertTrue("Should be AOP proxy", AopUtils.isAopProxy(scoped)); assertTrue("Should be target class proxy", scoped instanceof TestBean); ITestBean testBean = (ITestBean) this.context.getBean("testBean"); assertTrue("Should be AOP proxy", AopUtils.isAopProxy(testBean)); assertFalse("Regular bean should be JDK proxy", testBean instanceof TestBean); String rob = "Rob Harrop"; String bram = "Bram Smeets"; assertEquals(rob, scoped.getName()); scoped.setName(bram); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(newRequest)); assertEquals(rob, scoped.getName()); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(oldRequest)); assertEquals(bram, scoped.getName()); assertTrue("Should have advisors", ((Advised) scoped).getAdvisors().length > 0); }
Example 17
Source File: ArgumentBindingTests.java From spring-analysis-note with MIT License | 5 votes |
@Test(expected = IllegalArgumentException.class) public void testBindingInPointcutUsedByAdvice() { TestBean tb = new TestBean(); AspectJProxyFactory proxyFactory = new AspectJProxyFactory(tb); proxyFactory.addAspect(NamedPointcutWithArgs.class); ITestBean proxiedTestBean = proxyFactory.getProxy(); proxiedTestBean.setName("Supercalifragalisticexpialidocious"); }
Example 18
Source File: ExposeInvocationInterceptorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testXmlConfig() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT); ITestBean tb = (ITestBean) bf.getBean("proxy"); String name = "tony"; tb.setName(name); // Fires context checks assertEquals(name, tb.getName()); }
Example 19
Source File: AopNamespaceHandlerTests.java From java-technology-stack with MIT License | 4 votes |
@Test public void testAspectAppliedForInitializeBeanWithNullName() { ITestBean bean = (ITestBean) this.context.getAutowireCapableBeanFactory().initializeBean(new TestBean(), null); 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: AopNamespaceHandlerTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void testAspectAppliedForInitializeBeanWithEmptyName() { ITestBean bean = (ITestBean) this.context.getAutowireCapableBeanFactory().initializeBean(new TestBean(), ""); 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()); }