[JBoss AOP] New message: "withincode from JUnit test not working"
by Alan Nisbet
User development,
A new message was posted in the thread "withincode from JUnit test not working":
http://community.jboss.org/message/521123#521123
Author : Alan Nisbet
Profile : http://community.jboss.org/people/nizzy
Message:
--------------------------------------------------------------
Hi Guys,
I have been working on this issue off and on for a while now. Here are my findings, hopefully someone will be able to help me!
Environment
------------------
Standalone Hibernate 3.2.4.GA
Standalone JBoss AOP 2.0.1.GA
Junit 4.4
Log4j
Running via Eclipse 3.3.2
I can successfully do everything I need to use AOP for the purposes of JUnit testing, except using the withincode expression. It will work when I try it from a POJO (non-JUnit class), however nothing I have done so far can get it to intercept a call from within a JUnit test.
I have been using loadtime weaving which made any debugging extremely difficult and so I have updated my project to use compile time weaving, I found this easier to work with.
Initially I suspected the issue may be classpath related, i.e. thought if JUnit archives not on loatime classpath then would the instrumentation of the JUnit class fail, still not sure if this is accurate.
However all I have been able to do this far is repeat the results for both Compile/Load Time Weaving. That is I can intercept call to constructor of class and replace with mock class, etc, however I cannot get withincode to expression to work in conjunction with call expression.
jboss-aop.xml
<?xml version="1.0" encoding="UTF-8"?>
<aop>
<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" scope="PER_CLASS" />
<bind pointcut="call(public void com.ecebs.unittest.aop.ExampleManagerBean->createObject(..))
AND withincode(public void com.ecebs.unittest.aop.ExampleManagerBeanTest->testCreateObject_MultefileException())">
<advice name="throwMultefileException" aspect="com.ecebs.unittest.aop.aspect.ExceptionInjector" />
</bind>
</aop>
Output, including verbose aopc info
> Buildfile: C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\build.xml
> aopclean:
> [echo] cleaning build, aopclasses directory
> [delete] Deleting directory C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\build
> [delete] Deleting directory C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses
> compile:
> [echo] compiling source
> [mkdir] Created dir: C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\build
> [javac] Compiling 17 source files to C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\build
> aop:
> [mkdir] Created dir: C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses
> [copy] Copying 18 files to C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses
> [copy] Copying 2 files to C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses
> [echo] Running AOPC target to instrument classes
> [aopc] [info] Total length of filenames to be compiled is greater than 1000, listing files in --SOURCEPATH: C:\DOCUME~1\ALANN~2.ECE\LOCALS~1\Temp\src6131407091635596476.tmp
> [aopc] log4j:WARN No appenders could be found for logger (org.jboss.aop.instrument.InstrumentorFactory).
> [aopc] log4j:WARN Please initialize the log4j system properly.
> [aopc] [no comp needed] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\MultefileException.class
> [aopc] [no comp needed] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\AbstractJPAHelper.class
> [aopc] [compiled] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\PersistenceHelperTest.class
> [aopc] [no comp needed] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\IPersistenceHelper.class
> [aopc] [no comp needed] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\aspect\ExceptionInjector.class
> [aopc] [no comp needed] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\mock\MockService.class
> [aopc] [no comp needed] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\entitymodel\Application.class
> [aopc] [no comp needed] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\entitymodel\Environment.class
> [aopc] [no comp needed] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\AbstractJPAHelper.class
> [aopc] [compiled] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\PersistenceHelper.class
> [aopc] [compiled] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\PersistenceHelperTest$1.class
> [aopc] [no comp needed] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\ExampleManager.class
> [aopc] [compiled] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\ExampleManagerBean.class
> [aopc] [compiled] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\ExampleManagerBeanTest.class
> [aopc] [no comp needed] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\MultefileRuntimeException.class
> [aopc] [no comp needed] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\interceptor\GenericInterceptor.class
> [aopc] [no comp needed] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\entitymodel\EnvironmentPK.class
> [aopc] [compiled] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\mock\MockPersistenceHelper.class
> [aopc] [no comp needed] C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\aopclasses\com\ecebs\unittest\aop\entitymodel\Revision.class
> [aopc] Build Successful: 484 ms
> do-test-junit:
> [junit] Running com.ecebs.unittest.aop.ExampleManagerBeanTest
> [junit] Tests run: 3, Failures: 2, Errors: 0, Time elapsed: 0.547 sec
> [junit] Test com.ecebs.unittest.aop.ExampleManagerBeanTest FAILED
> [junitreport] Processing C:\workspace\multefile-core-dev\offcard\research\AOPUnitTestPOC\reports\junit\TESTS-TestSuites.xml to C:\DOCUME~1\ALANN~2.ECE\LOCALS~1\Temp\null1590394285
> [junitreport] Loading stylesheet jar:file:/C:/Program%20Files/eclipse/eclipse-j2ee/plugins/org.apache.ant_1.7.0.v200706080842/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
> [junitreport] Transform time: 250ms
> [junitreport] Deleting: C:\DOCUME~1\ALANN~2.ECE\LOCALS~1\Temp\null1590394285
> BUILD SUCCESSFUL
> Total time: 2 seconds
As can be seen from the jboss-aop.xml I'm trying to intercept the call to the ExampleManagerBean->createObject(..) method when called from within the ExamplemanagerBeanTest. I assume that when the aopc output states that a class has been compiled it mean that aop has recognized that instrumentation was required. So from the output I can see that;
> PersistenceHelperTest.class
> PersistenceHelper.class
> PersistenceHelperTest$1.class
> ExampleManagerBean.class
> ExampleManagerBeanTest.class
> MockPersistenceHelper.class
Have been instrumented, is this assumption correct?
I use the following ant targets
<target name="aop" depends="compile">
<property name="classes.dir" value="aopclasses" />
<mkdir dir="${classes.dir}" />
<!-- copy the classes to a aopclasses directory-->
<copy todir="${classes.dir}">
<fileset dir="build" includes="**/*.class"/>
</copy>
<!-- copy the jboss-aop.xml to aopclasses directory so can be located at runtime -->
<copy todir="${classes.dir}">
<fileset dir="test" includes="META-INF/*.*"/>
</copy>
<!-- setup the ant task and the required classpaths -->
<taskdef name="aopc"
classname="org.jboss.aop.ant.AopC"
classpathref="project.class.path"/>
<path id="jboss.aop.classpath">
<pathelement path="${jboss-aop-2.0.1.GA.dir}/jboss-aop-single.jar"/>
</path>
<path id="aop.classpath">
<pathelement path="${classes.dir}"/>
<fileset dir="${log4j.dir}" includes="*.jar"/>
<fileset dir="${JUnit4.dir}" includes="*.jar"/>
</path>
<echo message="Running AOPC target to instrument classes" />
<!-- instrument the classes with the first call to aopc -->
<aopc compilerclasspathref="jboss.aop.classpath" report="false" verbose="true">
<!-- define aop classpath - cp for dependant classes in src -->
<classpath refid="aop.classpath"/>
<!-- define location of classes to be instrumented -->
<src path="${classes.dir}"/>
<include name="**/*.class"/>
<aoppath path="test/META-INF/jboss-aop.xml"/>
</aopc>
</target>
<path id="test.class.path">
<fileset dir="${jboss-aop-2.0.1.GA.dir}" includes="jboss-aop-single.jar" />
<fileset dir="${log4j.dir}" includes="*.jar" />
<fileset dir="${JUnit4.dir}" includes="*.jar"/>
<fileset dir="${hibernate.dir}" includes="*.jar"/>
</path>
<target name="do-test-junit" depends="aopclean, aop">
<mkdir dir="reports/junit/.xml" />
<junit fork="no" printsummary="yes" haltonfailure="no" errorproperty="test.junit.failed">
<classpath>
<path path="${classes.dir}" />
<path refid="test.class.path" />
</classpath>
<formatter type="xml" />
<batchtest todir="reports/junit/.xml">
<fileset dir="${classes.dir}">
<include name="**/ExampleManagerBeanTest.class" />
</fileset>
</batchtest>
</junit>
<junitreport todir="reports/junit">
<fileset dir="reports/junit/.xml">
<include name="*.xml" />
</fileset>
<report format="frames" todir="reports/junit" />
</junitreport>
</target>
<target name="aopclean">
<echo message="cleaning build, aopclasses directory"/>
<delete dir="build"/>
<delete dir="aopclasses"/>
</target>
Please can someone have a look at this issue. Let me know anything I can do that will assist any investigation, i.e. inclusion of code, etc.
It is our intention to use AOP as a tool to improve our unit-testing and so I would really like to be able to solve this issue. I'm at the point I don't have too much more time to spend on it.
--------------------------------------------------------------
To reply to this message visit the message page: http://community.jboss.org/message/521123#521123
16 years, 3 months
[JBoss Tools] Document updated/added: "New KB plug-in and Code Assist in JBoss Tools 3.1.0.M3"
by Alexey Kazakov
User development,
The document "New KB plug-in and Code Assist in JBoss Tools 3.1.0.M3", was updated Jan 20, 2010
by Alexey Kazakov.
To view the document, visit:
http://community.jboss.org/docs/DOC-14027#cf
Document:
--------------------------------------------------------------
Since JBoss Tools 3.1.0 M3 there is a new KB plug-in which is responsible for providing information about JSF components. This information is used by Code Assist, Validators, DnD dialogs, etc in JSP/XHTML editors.
*1. Types of resources that used to provide information about components.*
+- TLDs
- Facelet libs.
- faces-config.xml's
- KB custom schemas.+
This list could be extended by adding new resource types.
*1.1. TLD Resources.*
TLD is the most useful resource for KB plug-in. There is info about tag names and attributes in particular component library. Code assist provides proposals for tag/attributes names which are picked from TLDs.
*1.2. Facelet libs.*
Facelet libs is not as useful as TLD because the is not any info about tag attributes. But in case there is only Facelet lib in class path without corresponded TLD we will able to provide tag names at least.
*1.3 faces-config.xml's*
If faces config file contains info about possible facet names for particular component we will pick this info there.
*1.4 KB custom schemas.*
TLD/Facelet libs/faces-config.xml is not enough to provide Code assist for attributes values. So we use custom XMLs to describe meta information for possible types of proposals for attribute values.
+Here is an example of custom KB schema:+
<tag-lib>
<component name="extendedDataTable">
<attribute name="align">
<proposal type="enumeration">
<param value="left" />
<param value="center" />
<param value="right" />
</proposal>
</attribute>
</component>
<component closeTag="true" name="graphicImage">
<attribute name="url">
<proposal type="file">
<param name="extensions" value="%image%" />
</proposal>
</attribute>
</component>
<component-extension>
<attribute name="reRender">
<proposal type="id"/>
</attribute>
<attribute name="for">
<proposal type="id"/>
</attribute>
</component-extension>
</tag-lib>
+<component>+ tag describes a JSF component.
By default KB plug-in uses info from this tag only if such tag or attribute are described in corresponding TLD or Faces lib. So there is not any need to keep a schema synchronized with TLD. Meta info from a schema supplements TLD/Faces lib. If a schema is the only source where the tag/attribute is described then this tag/attribute info will be ignored by KB. If we want to add some tag/attribute anyway, even if TLD knows nothing about them, we can use +extended="false"+ attribute.
+<component-extension++>+ is used to describes proposal types for particular attributes of any component if such attribute described in corresponded TLD.
In example above we added meta info for all attributes with name "for" and "reRender" of the component library.
For example in editor it will works as: +<any_tag_name_within_lib for="we will propos all component IDs available here" />+
If we want to add proposal types for attributes for all component libs we have some special XML - componentExtension.xml:
<component-extension>
<attribute name="action">
<proposal type="view-actions" />
</attribute>
<attribute name="immediate">
<proposal type="enumeration">
<param value="true" />
<param value="false" />
</proposal>
</attribute>
<attribute name="rendered">
<proposal type="enumeration">
<param value="true" />
<param value="false" />
</proposal>
</attribute>
</component-extension>
Here is a list of possible proposal types for attributes:
+*bundleName*+ - Names of message resource bundles which are available in JSF project (e.g. <f:loadBundle basename="..." />)
+*viewActions*+ - JSF Actions from faces-config.xml (e.g. <h:commandBundle action="..." />)
+*file*+ - Path to a resource. E.g. following proposal type is used in <h:commandButton image="..."/>:
<attribute name="image">
<proposal type="file">
<param name="extensions" value="%image%" /> <!-- *%image%* for "gif", "jpeg", "jpg", "png", "wbmp", "bmp". And *%page%* for "jsp", "htm", "html", "xhtml", "xml" -->
<param name="pathType" value="absolute" /> <!-- *absolute* means relative to WebContent and starts with "/". *relative* means relative to the page -->
</proposal>
</attribute>
+*enumeration*+ - A list of strings. For example
<attribute name="rendered">
<proposal type="enumeration">
<param value="true" />
<param value="false" />
</proposal>
</attribute>
+*faceletsJsfCTags*+ - Used to propos a list of available JSF components for *jsfc* attributes in facelet pages. (e.g. <input jsfc="h:commandButton" />)
+*id*+ - Component ID within the page. (e.g. <a4j:commandButton reRender="...">)
+*converterID*+ - Converter ID
+*validatorID*+ - Validator ID
For more details about KB schema format see https://anonsvn.jboss.org/repos/jbosstools/trunk/jst/plugins/org.jboss.to...
Custom schemas are added to KB plug-in by extension point org.jboss.tools.jst.web.kb.tagLib
+For example plugin.xml:+
<extension
point="org.jboss.tools.jst.web.kb.tagLib">
<tag-lib
location="taglibs/Richfaces.xml"
name="JBoss RichFaces"
uri="http://richfaces.org/rich"/>
<tag-lib
location="taglibs/JBossSeam.xml"
name="JBoss Seam"
uri="http://jboss.com/products/seam/taglib"/>
<component-extension
location="taglibs/componentExtension.xml"/>
</extension>
</plugin>
*2. KB Builder.*
KB builder is used to pick up KB resources (TLD/Facelets/...) from a project. If there is a resource in classpath then it will be loaded and added to KB model. It's important change from previous version of JBoss Tools. Some TLDs are bundled with JBT and will be avaliable even if they are not in project classpath (see https://jira.jboss.org/jira/browse/JBIDE-5650). An user can add any KB resource (TLD or Facelet lib) via XML Catalog if he doesn't want to add them to the project classpath. See http://screencast.com/t/ZjdkODBiZmEt
Old projects which was created by previous JBoss Tools don't have such builder. Imported projects may not have it as well.
JBoss tools checks if there is not KB builder in a project when user invokes Code assist first time.
In this case KB model is built in background thread and stays in static state until the KB-builder is installed and invoked.
A warning about missing KB builder with a quick fix is added to the project as well. So user can fix the problem by couple of clicks.
See https://jira.jboss.org/jira/browse/JBIDE-4762 for details.
Also user can add KB builder/nature in .project manually. See http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4247996#4247996
All our wizards which create projects or add seam/jsf support to a project, add KB builder automatically.
Not all information about tags/attributes which is used in Code Assist picked up by KB builder. KB custom schemas worked without project builders because they don't depend on particular project. So if a project doesn't have KB builder installed then Code assist will show proposals from custom schemas anyway. For example HTML tags/attributes or <ui:* tags from facelets lib will work in JBoss Tools XHTML editor for any projects.
*3. EL resolvers.*
We use system of EL resolvers to provide Code assist for EL in jsp/xhtml editors. Each EL is pluged in by extension point org.jboss.tools.common.el.core.elResolver and should implement org.jboss.tools.common.el.core.resolver.ELResolver interface.
+For example:+
<extension
point="org.jboss.tools.common.el.core.elResolver">
<el-resolver id="seamELResolver">
<project-nature id="org.jboss.tools.seam.core.seamnature"
resolver-class="org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine"/>
</el-resolver>
<el-resolver id="customELResolver">
<factory class="org.jboss.tools.customELResolverfactory"/>
</el-resolver>
</extension>
--------------------------------------------------------------
16 years, 3 months
[JBoss Portal] New message: "How to customize the top navigation bar"
by Venkateswarlu P
User development,
A new message was posted in the thread "How to customize the top navigation bar":
http://community.jboss.org/message/521115#521115
Author : Venkateswarlu P
Profile : http://community.jboss.org/people/paturuv
Message:
--------------------------------------------------------------
Hi -
I would like to understand on how to customize the top navigation using the configuration xml file. Like when I create a portal page under a portal right now that page is visible as a tab in the top navigation. My problem is I definitely need few of the pages to be tabs on the top navigation but remaining page still need to be created in portal but they should not appear on the top navigation as tabs. Is there any parameter that I can set so that the page does not appear as a tab.
Thanks,
Venkat
--------------------------------------------------------------
To reply to this message visit the message page: http://community.jboss.org/message/521115#521115
16 years, 3 months
[JBoss AOP Development] New message: "Help: Error [Instrumentor] AOP Instrumentor failed"
by dfsdf asdas
User development,
A new message was posted in the thread "Help: Error [Instrumentor] AOP Instrumentor failed":
http://community.jboss.org/message/521111#521111
Author : dfsdf asdas
Profile : http://community.jboss.org/people/cuccu83
Message:
--------------------------------------------------------------
Hi, i try to integrate jboss AOP with riftsaw 2.0 M1 for my thesis work at the university.
I tried examples in "injboss" section and they run correctly.
When i try to intercept a method of riftsaw [org.apache.ode.axis2.soapbinding.SoapExternalService-> invoke() ] during the execution of a web services within wotkflowi obtain an exception. Why i obtain that error a runtime ? I'm using jboss 5.1.0 jdk6, jboss AOP 2.1.5 and my aop.xml file is so simple :
15:31:33,251 ERROR [Instrumentor] [warn] AOP Instrumentor failed to transform or
g.apache.ode.axis2.soapbinding.SoapMessageConverter
javassist.CannotCompileException: [source error] no such a constructor
at javassist.CtBehavior.setBody(CtBehavior.java:368)
at javassist.CtBehavior.setBody(CtBehavior.java:334)
<?xml version="1.0" encoding="UTF-8"?>
<aop xmlns="urn:jboss:aop-beans:1.0">
<prepare expr="all(org.apache.ode.axis2.soapbinding.SoapExternalService)" />
<interceptor class="test.aop.Simplex" scope="PER_VM"/>
<bind pointcut="execution(* $instanceof{org.apache.ode.axis2.soapbinding.SoapExternalService}->invoke(..))" >
<interceptor-ref name="test.aop.Simplex" />
</bind>
</aop>
Please to help me !!!
--------------------------------------------------------------
To reply to this message visit the message page: http://community.jboss.org/message/521111#521111
16 years, 3 months