Java Code Examples for org.springframework.tests.sample.beans.ITestBean#setSpouse()

The following examples show how to use org.springframework.tests.sample.beans.ITestBean#setSpouse() . 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 spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testReentrance() {
	int age1 = 33;

	TestBean target1 = new TestBean();
	ProxyFactory pf1 = new ProxyFactory(target1);
	NopInterceptor di1 = new NopInterceptor();
	pf1.addAdvice(0, di1);
	ITestBean advised1 = (ITestBean) createProxy(pf1);
	advised1.setAge(age1); // = 1 invocation
	advised1.setSpouse(advised1); // = 2 invocations

	assertEquals("one was invoked correct number of times", 2, di1.getCount());

	assertEquals("Advised one has correct age", age1, advised1.getAge()); // = 3 invocations
	assertEquals("one was invoked correct number of times", 3, di1.getCount());

	// = 5 invocations, as reentrant call to spouse is advised also
	assertEquals("Advised spouse has correct age", age1, advised1.getSpouse().getAge());

	assertEquals("one was invoked correct number of times", 5, di1.getCount());
}
 
Example 2
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testReentrance() {
	int age1 = 33;

	TestBean target1 = new TestBean();
	ProxyFactory pf1 = new ProxyFactory(target1);
	NopInterceptor di1 = new NopInterceptor();
	pf1.addAdvice(0, di1);
	ITestBean advised1 = (ITestBean) createProxy(pf1);
	advised1.setAge(age1); // = 1 invocation
	advised1.setSpouse(advised1); // = 2 invocations

	assertEquals("one was invoked correct number of times", 2, di1.getCount());

	assertEquals("Advised one has correct age", age1, advised1.getAge()); // = 3 invocations
	assertEquals("one was invoked correct number of times", 3, di1.getCount());

	// = 5 invocations, as reentrant call to spouse is advised also
	assertEquals("Advised spouse has correct age", age1, advised1.getSpouse().getAge());

	assertEquals("one was invoked correct number of times", 5, di1.getCount());
}
 
Example 3
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testReentrance() {
	int age1 = 33;

	TestBean target1 = new TestBean();
	ProxyFactory pf1 = new ProxyFactory(target1);
	NopInterceptor di1 = new NopInterceptor();
	pf1.addAdvice(0, di1);
	ITestBean advised1 = (ITestBean) createProxy(pf1);
	advised1.setAge(age1); // = 1 invocation
	advised1.setSpouse(advised1); // = 2 invocations

	assertEquals("one was invoked correct number of times", 2, di1.getCount());

	assertEquals("Advised one has correct age", age1, advised1.getAge()); // = 3 invocations
	assertEquals("one was invoked correct number of times", 3, di1.getCount());

	// = 5 invocations, as reentrant call to spouse is advised also
	assertEquals("Advised spouse has correct age", age1, advised1.getSpouse().getAge());

	assertEquals("one was invoked correct number of times", 5, di1.getCount());
}
 
Example 4
Source File: MethodInvocationProceedingJoinPointTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void toShortAndLongStringFormedCorrectly() throws Exception {
	final Object raw = new TestBean();
	ProxyFactory pf = new ProxyFactory(raw);
	pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
	pf.addAdvice(new MethodBeforeAdvice() {
		@Override
		public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
			// makeEncSJP, although meant for computing the enclosing join point,
			// it serves our purpose here
			JoinPoint.StaticPart aspectJVersionJp = Factory.makeEncSJP(method);
			JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();

			assertEquals(aspectJVersionJp.getSignature().toLongString(), jp.getSignature().toLongString());
			assertEquals(aspectJVersionJp.getSignature().toShortString(), jp.getSignature().toShortString());
			assertEquals(aspectJVersionJp.getSignature().toString(), jp.getSignature().toString());

			assertEquals(aspectJVersionJp.toLongString(), jp.toLongString());
			assertEquals(aspectJVersionJp.toShortString(), jp.toShortString());
			assertEquals(aspectJVersionJp.toString(), jp.toString());
		}
	});
	ITestBean itb = (ITestBean) pf.getProxy();
	itb.getAge();
	itb.setName("foo");
	itb.getDoctor();
	itb.getStringArray();
	itb.getSpouse();
	itb.setSpouse(new TestBean());
	try {
		itb.unreliableFileOperation();
	}
	catch (IOException ex) {
		// we don't really care...
	}
}
 
Example 5
Source File: AbstractPropertyAccessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void getAnotherNestedDeepProperty() {
	ITestBean target = new TestBean("rod", 31);
	ITestBean kerry = new TestBean("kerry", 35);
	target.setSpouse(kerry);
	kerry.setSpouse(target);
	AbstractPropertyAccessor accessor = createAccessor(target);
	Integer KA = (Integer) accessor.getPropertyValue("spouse.age");
	assertTrue("kerry is 35", KA == 35);
	Integer RA = (Integer) accessor.getPropertyValue("spouse.spouse.age");
	assertTrue("rod is 31, not" + RA, RA == 31);
	ITestBean spousesSpouse = (ITestBean) accessor.getPropertyValue("spouse.spouse");
	assertTrue("spousesSpouse = initial point", target == spousesSpouse);
}
 
Example 6
Source File: AbstractPropertyAccessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testErrorMessageOfNestedProperty() {
	ITestBean target = new TestBean();
	ITestBean child = new DifferentTestBean();
	child.setName("test");
	target.setSpouse(child);
	AbstractPropertyAccessor accessor = createAccessor(target);
	try {
		accessor.getPropertyValue("spouse.bla");
	}
	catch (NotReadablePropertyException ex) {
		assertTrue(ex.getMessage().contains(TestBean.class.getName()));
	}
}
 
Example 7
Source File: MethodInvocationProceedingJoinPointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void toShortAndLongStringFormedCorrectly() throws Exception {
	final Object raw = new TestBean();
	ProxyFactory pf = new ProxyFactory(raw);
	pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
	pf.addAdvice(new MethodBeforeAdvice() {
		@Override
		public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
			// makeEncSJP, although meant for computing the enclosing join point,
			// it serves our purpose here
			JoinPoint.StaticPart aspectJVersionJp = Factory.makeEncSJP(method);
			JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();

			assertEquals(aspectJVersionJp.getSignature().toLongString(), jp.getSignature().toLongString());
			assertEquals(aspectJVersionJp.getSignature().toShortString(), jp.getSignature().toShortString());
			assertEquals(aspectJVersionJp.getSignature().toString(), jp.getSignature().toString());

			assertEquals(aspectJVersionJp.toLongString(), jp.toLongString());
			assertEquals(aspectJVersionJp.toShortString(), jp.toShortString());
			assertEquals(aspectJVersionJp.toString(), jp.toString());
		}
	});
	ITestBean itb = (ITestBean) pf.getProxy();
	itb.getAge();
	itb.setName("foo");
	itb.getDoctor();
	itb.getStringArray();
	itb.getSpouse();
	itb.setSpouse(new TestBean());
	try {
		itb.unreliableFileOperation();
	}
	catch (IOException ex) {
		// we don't really care...
	}
}
 
Example 8
Source File: AbstractPropertyAccessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void getAnotherNestedDeepProperty() {
	ITestBean target = new TestBean("rod", 31);
	ITestBean kerry = new TestBean("kerry", 35);
	target.setSpouse(kerry);
	kerry.setSpouse(target);
	AbstractPropertyAccessor accessor = createAccessor(target);
	Integer KA = (Integer) accessor.getPropertyValue("spouse.age");
	assertTrue("kerry is 35", KA == 35);
	Integer RA = (Integer) accessor.getPropertyValue("spouse.spouse.age");
	assertTrue("rod is 31, not" + RA, RA == 31);
	ITestBean spousesSpouse = (ITestBean) accessor.getPropertyValue("spouse.spouse");
	assertTrue("spousesSpouse = initial point", target == spousesSpouse);
}
 
Example 9
Source File: AbstractPropertyAccessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testErrorMessageOfNestedProperty() {
	ITestBean target = new TestBean();
	ITestBean child = new DifferentTestBean();
	child.setName("test");
	target.setSpouse(child);
	AbstractPropertyAccessor accessor = createAccessor(target);
	try {
		accessor.getPropertyValue("spouse.bla");
	}
	catch (NotReadablePropertyException ex) {
		assertTrue(ex.getMessage().contains(TestBean.class.getName()));
	}
}
 
Example 10
Source File: MethodInvocationProceedingJoinPointTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void toShortAndLongStringFormedCorrectly() throws Exception {
	final Object raw = new TestBean();
	ProxyFactory pf = new ProxyFactory(raw);
	pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
	pf.addAdvice(new MethodBeforeAdvice() {
		@Override
		public void before(Method method, Object[] args, Object target) throws Throwable {
			// makeEncSJP, although meant for computing the enclosing join point,
			// it serves our purpose here
			JoinPoint.StaticPart aspectJVersionJp = Factory.makeEncSJP(method);
			JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();

			assertEquals(aspectJVersionJp.getSignature().toLongString(), jp.getSignature().toLongString());
			assertEquals(aspectJVersionJp.getSignature().toShortString(), jp.getSignature().toShortString());
			assertEquals(aspectJVersionJp.getSignature().toString(), jp.getSignature().toString());

			assertEquals(aspectJVersionJp.toLongString(), jp.toLongString());
			assertEquals(aspectJVersionJp.toShortString(), jp.toShortString());
			assertEquals(aspectJVersionJp.toString(), jp.toString());
		}
	});
	ITestBean itb = (ITestBean) pf.getProxy();
	itb.getAge();
	itb.setName("foo");
	itb.getDoctor();
	itb.getStringArray();
	itb.getSpouse();
	itb.setSpouse(new TestBean());
	try {
		itb.unreliableFileOperation();
	} catch (IOException ex) {
		// we don't realy care...
	}
}
 
Example 11
Source File: AbstractPropertyAccessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void getAnotherNestedDeepProperty() {
	ITestBean target = new TestBean("rod", 31);
	ITestBean kerry = new TestBean("kerry", 35);
	target.setSpouse(kerry);
	kerry.setSpouse(target);
	AbstractPropertyAccessor accessor = createAccessor(target);
	Integer KA = (Integer) accessor.getPropertyValue("spouse.age");
	assertTrue("kerry is 35", KA == 35);
	Integer RA = (Integer) accessor.getPropertyValue("spouse.spouse.age");
	assertTrue("rod is 31, not" + RA, RA == 31);
	ITestBean spousesSpouse = (ITestBean) accessor.getPropertyValue("spouse.spouse");
	assertTrue("spousesSpouse = initial point", target == spousesSpouse);
}
 
Example 12
Source File: AbstractPropertyAccessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testErrorMessageOfNestedProperty() {
	ITestBean target = new TestBean();
	ITestBean child = new DifferentTestBean();
	child.setName("test");
	target.setSpouse(child);
	AbstractPropertyAccessor accessor = createAccessor(target);
	try {
		accessor.getPropertyValue("spouse.bla");
	}
	catch (NotReadablePropertyException ex) {
		assertTrue(ex.getMessage().contains(TestBean.class.getName()));
	}
}
 
Example 13
Source File: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Check that the two MethodInvocations necessary are independent and
 * don't conflict.
 * Check also proxy exposure.
 */
@Test
public void testOneAdvisedObjectCallsAnother() {
	int age1 = 33;
	int age2 = 37;

	TestBean target1 = new TestBean();
	ProxyFactory pf1 = new ProxyFactory(target1);
	// Permit proxy and invocation checkers to get context from AopContext
	pf1.setExposeProxy(true);
	NopInterceptor di1 = new NopInterceptor();
	pf1.addAdvice(0, di1);
	pf1.addAdvice(1, new ProxyMatcherInterceptor());
	pf1.addAdvice(2, new CheckMethodInvocationIsSameInAndOutInterceptor());
	pf1.addAdvice(1, new CheckMethodInvocationViaThreadLocalIsSameInAndOutInterceptor());
	// Must be first
	pf1.addAdvice(0, ExposeInvocationInterceptor.INSTANCE);
	ITestBean advised1 = (ITestBean) pf1.getProxy();
	advised1.setAge(age1); // = 1 invocation

	TestBean target2 = new TestBean();
	ProxyFactory pf2 = new ProxyFactory(target2);
	pf2.setExposeProxy(true);
	NopInterceptor di2 = new NopInterceptor();
	pf2.addAdvice(0, di2);
	pf2.addAdvice(1, new ProxyMatcherInterceptor());
	pf2.addAdvice(2, new CheckMethodInvocationIsSameInAndOutInterceptor());
	pf2.addAdvice(1, new CheckMethodInvocationViaThreadLocalIsSameInAndOutInterceptor());
	pf2.addAdvice(0, ExposeInvocationInterceptor.INSTANCE);
	ITestBean advised2 = (ITestBean) createProxy(pf2);
	advised2.setAge(age2);
	advised1.setSpouse(advised2); // = 2 invocations

	assertEquals("Advised one has correct age", age1, advised1.getAge()); // = 3 invocations
	assertEquals("Advised two has correct age", age2, advised2.getAge());
	// Means extra call on advised 2
	assertEquals("Advised one spouse has correct age", age2, advised1.getSpouse().getAge()); // = 4 invocations on 1 and another one on 2

	assertEquals("one was invoked correct number of times", 4, di1.getCount());
	// Got hit by call to advised1.getSpouse().getAge()
	assertEquals("one was invoked correct number of times", 3, di2.getCount());
}
 
Example 14
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Check that the two MethodInvocations necessary are independent and
 * don't conflict.
 * Check also proxy exposure.
 */
@Test
public void testOneAdvisedObjectCallsAnother() {
	int age1 = 33;
	int age2 = 37;

	TestBean target1 = new TestBean();
	ProxyFactory pf1 = new ProxyFactory(target1);
	// Permit proxy and invocation checkers to get context from AopContext
	pf1.setExposeProxy(true);
	NopInterceptor di1 = new NopInterceptor();
	pf1.addAdvice(0, di1);
	pf1.addAdvice(1, new ProxyMatcherInterceptor());
	pf1.addAdvice(2, new CheckMethodInvocationIsSameInAndOutInterceptor());
	pf1.addAdvice(1, new CheckMethodInvocationViaThreadLocalIsSameInAndOutInterceptor());
	// Must be first
	pf1.addAdvice(0, ExposeInvocationInterceptor.INSTANCE);
	ITestBean advised1 = (ITestBean) pf1.getProxy();
	advised1.setAge(age1); // = 1 invocation

	TestBean target2 = new TestBean();
	ProxyFactory pf2 = new ProxyFactory(target2);
	pf2.setExposeProxy(true);
	NopInterceptor di2 = new NopInterceptor();
	pf2.addAdvice(0, di2);
	pf2.addAdvice(1, new ProxyMatcherInterceptor());
	pf2.addAdvice(2, new CheckMethodInvocationIsSameInAndOutInterceptor());
	pf2.addAdvice(1, new CheckMethodInvocationViaThreadLocalIsSameInAndOutInterceptor());
	pf2.addAdvice(0, ExposeInvocationInterceptor.INSTANCE);
	ITestBean advised2 = (ITestBean) createProxy(pf2);
	advised2.setAge(age2);
	advised1.setSpouse(advised2); // = 2 invocations

	assertEquals("Advised one has correct age", age1, advised1.getAge()); // = 3 invocations
	assertEquals("Advised two has correct age", age2, advised2.getAge());
	// Means extra call on advised 2
	assertEquals("Advised one spouse has correct age", age2, advised1.getSpouse().getAge()); // = 4 invocations on 1 and another one on 2

	assertEquals("one was invoked correct number of times", 4, di1.getCount());
	// Got hit by call to advised1.getSpouse().getAge()
	assertEquals("one was invoked correct number of times", 3, di2.getCount());
}
 
Example 15
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Check that the two MethodInvocations necessary are independent and
 * don't conflict.
 * Check also proxy exposure.
 */
@Test
public void testOneAdvisedObjectCallsAnother() {
	int age1 = 33;
	int age2 = 37;

	TestBean target1 = new TestBean();
	ProxyFactory pf1 = new ProxyFactory(target1);
	// Permit proxy and invocation checkers to get context from AopContext
	pf1.setExposeProxy(true);
	NopInterceptor di1 = new NopInterceptor();
	pf1.addAdvice(0, di1);
	pf1.addAdvice(1, new ProxyMatcherInterceptor());
	pf1.addAdvice(2, new CheckMethodInvocationIsSameInAndOutInterceptor());
	pf1.addAdvice(1, new CheckMethodInvocationViaThreadLocalIsSameInAndOutInterceptor());
	// Must be first
	pf1.addAdvice(0, ExposeInvocationInterceptor.INSTANCE);
	ITestBean advised1 = (ITestBean) pf1.getProxy();
	advised1.setAge(age1); // = 1 invocation

	TestBean target2 = new TestBean();
	ProxyFactory pf2 = new ProxyFactory(target2);
	pf2.setExposeProxy(true);
	NopInterceptor di2 = new NopInterceptor();
	pf2.addAdvice(0, di2);
	pf2.addAdvice(1, new ProxyMatcherInterceptor());
	pf2.addAdvice(2, new CheckMethodInvocationIsSameInAndOutInterceptor());
	pf2.addAdvice(1, new CheckMethodInvocationViaThreadLocalIsSameInAndOutInterceptor());
	pf2.addAdvice(0, ExposeInvocationInterceptor.INSTANCE);
	ITestBean advised2 = (ITestBean) createProxy(pf2);
	advised2.setAge(age2);
	advised1.setSpouse(advised2); // = 2 invocations

	assertEquals("Advised one has correct age", age1, advised1.getAge()); // = 3 invocations
	assertEquals("Advised two has correct age", age2, advised2.getAge());
	// Means extra call on advised 2
	assertEquals("Advised one spouse has correct age", age2, advised1.getSpouse().getAge()); // = 4 invocations on 1 and another one on 2

	assertEquals("one was invoked correct number of times", 4, di1.getCount());
	// Got hit by call to advised1.getSpouse().getAge()
	assertEquals("one was invoked correct number of times", 3, di2.getCount());
}