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

The following examples show how to use org.springframework.tests.sample.beans.ITestBean#unreliableFileOperation() . 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: AtAspectJAfterThrowingTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testAccessThrowable() throws Exception {
	ClassPathXmlApplicationContext ctx =
		new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());

	ITestBean bean = (ITestBean) ctx.getBean("testBean");
	ExceptionHandlingAspect aspect = (ExceptionHandlingAspect) ctx.getBean("aspect");

	assertTrue(AopUtils.isAopProxy(bean));
	try {
		bean.unreliableFileOperation();
	}
	catch (IOException e) {
		//
	}

	assertEquals(1, aspect.handled);
	assertNotNull(aspect.lastException);
}
 
Example 2
Source File: AtAspectJAfterThrowingTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testAccessThrowable() throws Exception {
	ClassPathXmlApplicationContext ctx =
		new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());

	ITestBean bean = (ITestBean) ctx.getBean("testBean");
	ExceptionHandlingAspect aspect = (ExceptionHandlingAspect) ctx.getBean("aspect");

	assertTrue(AopUtils.isAopProxy(bean));
	try {
		bean.unreliableFileOperation();
	}
	catch (IOException e) {
		//
	}

	assertEquals(1, aspect.handled);
	assertNotNull(aspect.lastException);
}
 
Example 3
Source File: AtAspectJAfterThrowingTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testAccessThrowable() throws Exception {
	ClassPathXmlApplicationContext ctx =
		new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());

	ITestBean bean = (ITestBean) ctx.getBean("testBean");
	ExceptionHandlingAspect aspect = (ExceptionHandlingAspect) ctx.getBean("aspect");

	assertTrue(AopUtils.isAopProxy(bean));
	try {
		bean.unreliableFileOperation();
	}
	catch (IOException e) {
		//
	}

	assertEquals(1, aspect.handled);
	assertNotNull(aspect.lastException);
}
 
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: 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 6
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...
	}
}