[jboss-user] [JBoss AOP] - Different jboss-aop.xml files for unit testing
nizzy
do-not-reply at jboss.com
Fri Mar 13 07:10:32 EDT 2009
Hi All,
As mentioned in my previous post I'm reviewing AOP for use with unit testing.
I define my jboss-aop.xml in test/META-INF folder in my eclipse project. I have noticed that it is going to be quite probable that poincut definitions are going to cause undesired side-effects.
For instance - if you consider the test code
| @Test
| public void testCreateObject() {
| try {
| man.createObject(ap);
| } catch (Exception e) {
| fail("Test failed since exception was thrown: " + e);
| }
| }
|
| @Test
| public void testCreateObject_MultefileException() {
| try {
| man.createObject(ap);
| fail("Should have thrown MultefileException");
| } catch (Exception e) {
|
| if (!(e instanceof MultefileException)) {
| fail("Test failed since exception was not MultefileException: " + e);
| }
| }
| }
then the jboss-aop.xml
| <bind pointcut="execution(public $typedef{persistenceHelperTypeDef}->new(java.lang.String))">
| <interceptor class="com.ecebs.unittest.aop.interceptor.GenericInterceptor">
| <attribute name="mockObjectName">MockPersistenceHelper</attribute>
| </interceptor>
| </bind>
|
| <typedef name="persistenceHelperTypeDef"
| expr="class($instanceof{com.ecebs.unittest.aop.IPersistenceHelper})
| AND !class(com.ecebs.unittest.aop.mock.*)" />
|
| <aspect class="com.ecebs.unittest.aop.aspect.ExceptionInjector" />
| <bind pointcut="execution(public void com.ecebs.unittest.aop.AOPUnitTestManagerBean->createObject(..))">
| <advice name="throwMultefileException" aspect="com.ecebs.unittest.aop.aspect.ExceptionInjector" />
| </bind>
The first entry in the jboss-aop.xml file mocks-out a persistence helper.
The createObject test would then pass. When I add the subsequent aspect and bind to inject an Exception - every time createObject is called - the first test obviously then fails - which I appreciate is exactly what I would expect to happen given the way I have set this up!!
Is there a way; via the pointcut definitions or by changing which jboss-aop.xml file is used, to overcome such an issue?
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4217811#4217811
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4217811
More information about the jboss-user
mailing list