org.springframework.tests.aop.interceptor.TimestampIntroductionInterceptor Java Examples

The following examples show how to use org.springframework.tests.aop.interceptor.TimestampIntroductionInterceptor. 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
/**
 * Simple test that if we set values we can get them out again.
 */
@Test
public void testValuesStick() {
	int age1 = 33;
	int age2 = 37;
	String name = "tony";

	TestBean target1 = new TestBean();
	target1.setAge(age1);
	ProxyFactory pf1 = new ProxyFactory(target1);
	pf1.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()));
	pf1.addAdvisor(new DefaultPointcutAdvisor(new TimestampIntroductionInterceptor()));
	ITestBean tb = (ITestBean) pf1.getProxy();

	assertEquals(age1, tb.getAge());
	tb.setAge(age2);
	assertEquals(age2, tb.getAge());
	assertNull(tb.getName());
	tb.setName(name);
	assertEquals(name, tb.getName());
}
 
Example #2
Source File: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Check that the introduction advice isn't allowed to introduce interfaces
 * that are unsupported by the IntroductionInterceptor.
 */
@Test
public void testCannotAddIntroductionAdviceWithUnimplementedInterface() throws Throwable {
	TestBean target = new TestBean();
	target.setAge(21);
	ProxyFactory pc = new ProxyFactory(target);
	try {
		pc.addAdvisor(0, new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor(), ITestBean.class));
		fail("Shouldn't be able to add introduction advice introducing an unimplemented interface");
	}
	catch (IllegalArgumentException ex) {
		//assertTrue(ex.getMessage().indexOf("ntroduction") > -1);
	}
	// Check it still works: proxy factory state shouldn't have been corrupted
	ITestBean proxied = (ITestBean) createProxy(pc);
	assertEquals(target.getAge(), proxied.getAge());
}
 
Example #3
Source File: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Should only be able to introduce interfaces, not classes.
 */
@Test
public void testCannotAddIntroductionAdviceToIntroduceClass() throws Throwable {
	TestBean target = new TestBean();
	target.setAge(21);
	ProxyFactory pc = new ProxyFactory(target);
	try {
		pc.addAdvisor(0, new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor(), TestBean.class));
		fail("Shouldn't be able to add introduction advice that introduces a class, rather than an interface");
	}
	catch (IllegalArgumentException ex) {
		assertTrue(ex.getMessage().contains("interface"));
	}
	// Check it still works: proxy factory state shouldn't have been corrupted
	ITestBean proxied = (ITestBean) createProxy(pc);
	assertEquals(target.getAge(), proxied.getAge());
}
 
Example #4
Source File: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testUseAsHashKey() {
	TestBean target1 = new TestBean();
	ProxyFactory pf1 = new ProxyFactory(target1);
	pf1.addAdvice(new NopInterceptor());
	ITestBean proxy1 = (ITestBean) createProxy(pf1);

	TestBean target2 = new TestBean();
	ProxyFactory pf2 = new ProxyFactory(target2);
	pf2.addAdvisor(new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor()));
	ITestBean proxy2 = (ITestBean) createProxy(pf2);

	HashMap<ITestBean, Object> h = new HashMap<>();
	Object value1 = "foo";
	Object value2 = "bar";
	assertNull(h.get(proxy1));
	h.put(proxy1, value1);
	h.put(proxy2, value2);
	assertEquals(h.get(proxy1), value1);
	assertEquals(h.get(proxy2), value2);
}
 
Example #5
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Simple test that if we set values we can get them out again.
 */
@Test
public void testValuesStick() {
	int age1 = 33;
	int age2 = 37;
	String name = "tony";

	TestBean target1 = new TestBean();
	target1.setAge(age1);
	ProxyFactory pf1 = new ProxyFactory(target1);
	pf1.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()));
	pf1.addAdvisor(new DefaultPointcutAdvisor(new TimestampIntroductionInterceptor()));
	ITestBean tb = (ITestBean) pf1.getProxy();

	assertEquals(age1, tb.getAge());
	tb.setAge(age2);
	assertEquals(age2, tb.getAge());
	assertNull(tb.getName());
	tb.setName(name);
	assertEquals(name, tb.getName());
}
 
Example #6
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Check that the introduction advice isn't allowed to introduce interfaces
 * that are unsupported by the IntroductionInterceptor.
 */
@Test
public void testCannotAddIntroductionAdviceWithUnimplementedInterface() throws Throwable {
	TestBean target = new TestBean();
	target.setAge(21);
	ProxyFactory pc = new ProxyFactory(target);
	try {
		pc.addAdvisor(0, new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor(), ITestBean.class));
		fail("Shouldn't be able to add introduction advice introducing an unimplemented interface");
	}
	catch (IllegalArgumentException ex) {
		//assertTrue(ex.getMessage().indexOf("ntroduction") > -1);
	}
	// Check it still works: proxy factory state shouldn't have been corrupted
	ITestBean proxied = (ITestBean) createProxy(pc);
	assertEquals(target.getAge(), proxied.getAge());
}
 
Example #7
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Should only be able to introduce interfaces, not classes.
 */
@Test
public void testCannotAddIntroductionAdviceToIntroduceClass() throws Throwable {
	TestBean target = new TestBean();
	target.setAge(21);
	ProxyFactory pc = new ProxyFactory(target);
	try {
		pc.addAdvisor(0, new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor(), TestBean.class));
		fail("Shouldn't be able to add introduction advice that introduces a class, rather than an interface");
	}
	catch (IllegalArgumentException ex) {
		assertTrue(ex.getMessage().contains("interface"));
	}
	// Check it still works: proxy factory state shouldn't have been corrupted
	ITestBean proxied = (ITestBean) createProxy(pc);
	assertEquals(target.getAge(), proxied.getAge());
}
 
Example #8
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testUseAsHashKey() {
	TestBean target1 = new TestBean();
	ProxyFactory pf1 = new ProxyFactory(target1);
	pf1.addAdvice(new NopInterceptor());
	ITestBean proxy1 = (ITestBean) createProxy(pf1);

	TestBean target2 = new TestBean();
	ProxyFactory pf2 = new ProxyFactory(target2);
	pf2.addAdvisor(new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor()));
	ITestBean proxy2 = (ITestBean) createProxy(pf2);

	HashMap<ITestBean, Object> h = new HashMap<>();
	Object value1 = "foo";
	Object value2 = "bar";
	assertNull(h.get(proxy1));
	h.put(proxy1, value1);
	h.put(proxy2, value2);
	assertEquals(h.get(proxy1), value1);
	assertEquals(h.get(proxy2), value2);
}
 
Example #9
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Simple test that if we set values we can get them out again.
 */
@Test
public void testValuesStick() {
	int age1 = 33;
	int age2 = 37;
	String name = "tony";

	TestBean target1 = new TestBean();
	target1.setAge(age1);
	ProxyFactory pf1 = new ProxyFactory(target1);
	pf1.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()));
	pf1.addAdvisor(new DefaultPointcutAdvisor(new TimestampIntroductionInterceptor()));
	ITestBean tb = (ITestBean) pf1.getProxy();

	assertEquals(age1, tb.getAge());
	tb.setAge(age2);
	assertEquals(age2, tb.getAge());
	assertNull(tb.getName());
	tb.setName(name);
	assertEquals(name, tb.getName());
}
 
Example #10
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Check that the introduction advice isn't allowed to introduce interfaces
 * that are unsupported by the IntroductionInterceptor.
 */
@Test
public void testCannotAddIntroductionAdviceWithUnimplementedInterface() throws Throwable {
	TestBean target = new TestBean();
	target.setAge(21);
	ProxyFactory pc = new ProxyFactory(target);
	try {
		pc.addAdvisor(0, new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor(), ITestBean.class));
		fail("Shouldn't be able to add introduction advice introducing an unimplemented interface");
	}
	catch (IllegalArgumentException ex) {
		//assertTrue(ex.getMessage().indexOf("ntroduction") > -1);
	}
	// Check it still works: proxy factory state shouldn't have been corrupted
	ITestBean proxied = (ITestBean) createProxy(pc);
	assertEquals(target.getAge(), proxied.getAge());
}
 
Example #11
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Should only be able to introduce interfaces, not classes.
 */
@Test
public void testCannotAddIntroductionAdviceToIntroduceClass() throws Throwable {
	TestBean target = new TestBean();
	target.setAge(21);
	ProxyFactory pc = new ProxyFactory(target);
	try {
		pc.addAdvisor(0, new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor(), TestBean.class));
		fail("Shouldn't be able to add introduction advice that introduces a class, rather than an interface");
	}
	catch (IllegalArgumentException ex) {
		assertTrue(ex.getMessage().indexOf("interface") > -1);
	}
	// Check it still works: proxy factory state shouldn't have been corrupted
	ITestBean proxied = (ITestBean) createProxy(pc);
	assertEquals(target.getAge(), proxied.getAge());
}
 
Example #12
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseAsHashKey() {
	TestBean target1 = new TestBean();
	ProxyFactory pf1 = new ProxyFactory(target1);
	pf1.addAdvice(new NopInterceptor());
	ITestBean proxy1 = (ITestBean) createProxy(pf1);

	TestBean target2 = new TestBean();
	ProxyFactory pf2 = new ProxyFactory(target2);
	pf2.addAdvisor(new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor()));
	ITestBean proxy2 = (ITestBean) createProxy(pf2);

	HashMap<ITestBean, Object> h = new HashMap<ITestBean, Object>();
	Object value1 = "foo";
	Object value2 = "bar";
	assertNull(h.get(proxy1));
	h.put(proxy1, value1);
	h.put(proxy2, value2);
	assertEquals(h.get(proxy1), value1);
	assertEquals(h.get(proxy2), value2);
}
 
Example #13
Source File: TimestampIntroductionAdvisor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public TimestampIntroductionAdvisor() {
	super(new DelegatingIntroductionInterceptor(new TimestampIntroductionInterceptor()));
}
 
Example #14
Source File: TimestampIntroductionAdvisor.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * @param dii
 */
public TimestampIntroductionAdvisor() {
	super(new DelegatingIntroductionInterceptor(new TimestampIntroductionInterceptor()));
}
 
Example #15
Source File: TimestampIntroductionAdvisor.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * @param dii
 */
public TimestampIntroductionAdvisor() {
	super(new DelegatingIntroductionInterceptor(new TimestampIntroductionInterceptor()));
}