[jboss-cvs] JBossAS SVN: r75188 - in projects/aop/branches/joinpoint_graph/aop/src: test/org/jboss/aop/joinpoint/graph and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Jun 29 20:44:50 EDT 2008
Author: flavia.rainone at jboss.com
Date: 2008-06-29 20:44:49 -0400 (Sun, 29 Jun 2008)
New Revision: 75188
Added:
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/AdvisedDataTest.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/AdvisorMock.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/AllTests.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/BehaviorNodeTest.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/ClassNodeTest.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/CompositeDomainDataTest.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/DomainDataTest.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/DummyAnnotation.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/FieldNodeTest.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/GraphInsertionTest.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/InstanceAdvisorMock.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo1.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo2.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo3.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo4.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo5.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Util.java
Modified:
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AdvisableClassNode.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraphFactory.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraphImpl.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/StandardClassNode.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/UnitaryDomainSuperClassNode.java
Log:
[JBAOP-504] Fixed more bugs and added tests for insertion.
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AdvisableClassNode.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AdvisableClassNode.java 2008-06-29 23:34:29 UTC (rev 75187)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AdvisableClassNode.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -120,6 +120,10 @@
public String toString()
{
+ if (clazz == null)
+ {
+ return "[node: null]";
+ }
return "[node: " + clazz.getName() + "]";
}
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraphFactory.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraphFactory.java 2008-06-29 23:34:29 UTC (rev 75187)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraphFactory.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -22,7 +22,9 @@
package org.jboss.aop.joinpoint.graph;
import org.jboss.aop.Domain;
+import org.jboss.aop.InstanceDomain;
import org.jboss.aop.joinpoint.JoinPointRegistry;
+import org.jboss.aop.proxy.container.ProxyAdvisorDomain;
/**
* This factory allows creation and retrieval of joinpoint graphs. The returned
@@ -68,6 +70,14 @@
*/
public static JoinPointGraph create(Domain domain)
{
- throw new UnsupportedOperationException();
+ if (domain instanceof InstanceDomain)
+ {
+ return new UnitaryJoinPointGraph((InstanceDomain) domain);
+ }
+ if (domain instanceof ProxyAdvisorDomain)
+ {
+ return new UnitaryJoinPointGraph((ProxyAdvisorDomain) domain);
+ }
+ return new DomainJoinPointGraph(domain);
}
}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraphImpl.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraphImpl.java 2008-06-29 23:34:29 UTC (rev 75187)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraphImpl.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -93,7 +93,7 @@
{
String defaultKey = ClassNode.getIdentifierKey(superClazz);
N superClassNode = classTree.searchValue(defaultKey);
- if (classNode != null)
+ if (superClassNode != null)
{
superClassNode.addSubtype(classNode);
}
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/StandardClassNode.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/StandardClassNode.java 2008-06-29 23:34:29 UTC (rev 75187)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/StandardClassNode.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -84,6 +84,7 @@
if (advisedData == null)
{
advisedData = new DomainData(advisor);
+ super.setAdvisedData(advisedData);
}
return advisedData;
}
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/UnitaryDomainSuperClassNode.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/UnitaryDomainSuperClassNode.java 2008-06-29 23:34:29 UTC (rev 75187)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/UnitaryDomainSuperClassNode.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -49,7 +49,7 @@
public UnitaryDomainSuperClassNode(Class<?> clazz, ClassNode subClassNode)
{
super(clazz);
- Collection<ClassNode> subClass = new ArrayList<ClassNode>(1);
+ this.subClass = new ArrayList<ClassNode>(1);
subClass.add(subClassNode);
}
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/AdvisedDataTest.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/AdvisedDataTest.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/AdvisedDataTest.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,185 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.advice.annotation.Arg;
+import org.jboss.aop.advice.annotation.Thrown;
+
+/**
+ * Tests {@code AdvisedData}.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class AdvisedDataTest extends TestCase
+{
+ public void testAdvisedDataCreation() throws Exception
+ {
+ AdvisedData advisedData = new AdvisedData(
+ new AdvisorMock("Pojo1Advisor",Pojo1.class));
+ Util.assertCollection(advisedData.searchBehaviors("*"));
+ Util.assertCollection(advisedData.searchFields("*"));
+ }
+
+ public void testAdvisedDataGetField1() throws Exception
+ {
+ AdvisedData advisedData = new AdvisedData(
+ new AdvisorMock("Pojo1Advisor", Pojo1.class));
+ Field field = Pojo1.class.getDeclaredField("field");
+ FieldNode fieldNode = advisedData.getField(field);
+ FieldNodeTest.assertFieldNode(field, fieldNode, "java.lang.String field");
+
+ Util.assertCollection(advisedData.searchFields("*"), fieldNode);
+ Util.assertCollection(advisedData.searchBehaviors("*"));
+ assertSame(fieldNode, advisedData.getField(field));
+ }
+
+ public void testAdvisedDataGetField2() throws Exception
+ {
+ AdvisedData advisedData = new AdvisedData(
+ new AdvisorMock("Pojo3Advisor", Pojo3.class));
+ Field field1 = Pojo3.class.getDeclaredField("field");
+ FieldNode fieldNode1 = advisedData.getField(field1);
+ FieldNodeTest.assertFieldNode(field1, fieldNode1, "java.util.Collection field");
+
+ Field field2 = Pojo3.class.getDeclaredField("ANY_CONSTANT");
+ FieldNode fieldNode2 = advisedData.getField(field2);
+ FieldNodeTest.assertFieldNode(field2, fieldNode2, "long ANY_CONSTANT");
+ Util.assertCollection(advisedData.searchFields("*"), fieldNode1, fieldNode2);
+ }
+
+ public void testAdvisedDataGetFieldWithMetaData() throws Exception
+ {
+ AdvisedData advisedData = new AdvisedData(
+ new AdvisorMock("Pojo1Advisor", Pojo1.class, Arg.class.getName()));
+ Field field = Pojo1.class.getDeclaredField("field");
+ FieldNode fieldNode = advisedData.getField(field);
+ FieldNodeTest.assertFieldNode(field, fieldNode, "java.lang.String field",
+ "java.lang.String @" + Arg.class.getName());
+
+ Util.assertCollection(advisedData.searchFields("*"), fieldNode);
+ Util.assertCollection(advisedData.searchBehaviors("*"));
+ }
+
+ public void testAdvisedDataGetBehavior1() throws Exception
+ {
+ AdvisedData advisedData = new AdvisedData(
+ new AdvisorMock("Pojo1Advisor", Pojo1.class));
+ Method method = Pojo1.class.getDeclaredMethod("method1", String.class, String.class);
+ BehaviorNode behaviorNode = advisedData.getBehavior(method);
+ BehaviorNodeTest.assertBehaviorNode(method, behaviorNode,
+ "void method1(java.lang.String java.lang.String )");
+
+ Util.assertCollection(advisedData.searchFields("*"));
+ Util.assertCollection(advisedData.searchBehaviors("*"), behaviorNode);
+ assertSame(behaviorNode, advisedData.getBehavior(method));
+ }
+
+ public void testAdvisedDataGetBehavior2() throws Exception
+ {
+ AdvisedData advisedData = new AdvisedData(
+ new AdvisorMock("Pojo1Advisor", Pojo1.class));
+ Constructor constructor = Pojo1.class.getDeclaredConstructors()[0];
+ BehaviorNode behaviorNode = advisedData.getBehavior(constructor);
+ BehaviorNodeTest.assertBehaviorNode(constructor, behaviorNode, "new()");
+
+ Util.assertCollection(advisedData.searchFields("*"));
+ Util.assertCollection(advisedData.searchBehaviors("*"),behaviorNode);
+ assertSame(behaviorNode, advisedData.getBehavior(constructor));
+ }
+
+ public void testAdvisedDataGetBehavior3() throws Exception
+ {
+ AdvisedData advisedData = new AdvisedData(
+ new AdvisorMock("Pojo3Advisor", Pojo3.class));
+ Method method1 = Pojo3.class.getDeclaredMethod("voidMethod");
+ BehaviorNode behaviorNode1 = advisedData.getBehavior(method1);
+ BehaviorNodeTest.assertBehaviorNode(method1, behaviorNode1, "void voidMethod()");
+
+ Method method2 = Pojo3.class.getDeclaredMethod("stringMethod");
+ BehaviorNode behaviorNode2 = advisedData.getBehavior(method2);
+ BehaviorNodeTest.assertBehaviorNode(method2, behaviorNode2,
+ "java.lang.String stringMethod()");
+
+ Constructor constructor1 = Pojo3.class.getDeclaredConstructors()[0];
+ BehaviorNode behaviorNode3 = advisedData.getBehavior(constructor1);
+ BehaviorNodeTest.assertBehaviorNode(constructor1, behaviorNode3, "new()");
+
+ Constructor constructor2 = Pojo3.class.getDeclaredConstructors()[1];
+ BehaviorNode behaviorNode4 = advisedData.getBehavior(constructor2);
+ BehaviorNodeTest.assertBehaviorNode(constructor2, behaviorNode4,
+ "new(int long )");
+
+ Util.assertCollection(advisedData.searchFields("*"));
+ Util.assertCollection(advisedData.searchBehaviors("*"), behaviorNode1,
+ behaviorNode2, behaviorNode3, behaviorNode4);
+ }
+
+ public void testAdvisedDataGetBehaviorWithMetaData() throws Exception
+ {
+ AdvisedData advisedData = new AdvisedData(
+ new AdvisorMock("Pojo1Advisor", Pojo1.class, Arg.class.getName()));
+ Method method = Pojo1.class.getDeclaredMethod("privateMethod");
+ BehaviorNode behaviorNode = advisedData.getBehavior(method);
+ BehaviorNodeTest.assertBehaviorNode(method, behaviorNode,
+ "void privateMethod()", "void @" + Arg.class.getName() + "()");
+
+ Util.assertCollection(advisedData.searchFields("*"));
+ Util.assertCollection(advisedData.searchBehaviors("*"), behaviorNode);
+ }
+
+ @SuppressWarnings("deprecation")
+ public void testAdvisedDataGetFieldAndBehaviorWithMetaData() throws Exception
+ {
+ AdvisedData advisedData = new AdvisedData(
+ new AdvisorMock("Pojo2Advisor", Pojo2.class, Thrown.class.getName()));
+
+ Field field = Pojo2.class.getDeclaredField("pojo3");
+ FieldNode fieldNode = advisedData.getField(field);
+ FieldNodeTest.assertFieldNode(field, fieldNode, Pojo3.class.getName() +
+ " pojo3", Pojo3.class.getName() + " @" + Thrown.class.getName());
+
+ Constructor constructor = Pojo2.class.getDeclaredConstructor(String.class);
+ BehaviorNode behaviorNode1 = advisedData.getBehavior(constructor);
+ BehaviorNodeTest.assertBehaviorNode(constructor, behaviorNode1,
+ "new(java.lang.String )",
+ "@" + Thrown.class.getName() + "(java.lang.String )");
+
+ Method method = Pojo2.class.getDeclaredMethod("doSomething", int.class,
+ long.class, Collection.class);
+ BehaviorNode behaviorNode2 = advisedData.getBehavior(method);
+ BehaviorNodeTest.assertBehaviorNode(method, behaviorNode2,
+ Pojo1.class.getName() + " doSomething(int long java.util.Collection )",
+ Pojo1.class.getName() + " @" + Thrown.class.getName() +
+ "(int long java.util.Collection )");
+
+ Util.assertCollection(advisedData.searchFields("*"), fieldNode);
+ Util.assertCollection(advisedData.searchBehaviors("*"), behaviorNode1,
+ behaviorNode2);
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/AdvisorMock.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/AdvisorMock.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/AdvisorMock.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.metadata.ClassMetaDataBinding;
+
+/**
+ * Advisor mock for testing.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class AdvisorMock extends Advisor
+{
+ private Collection<String> metaDataTags;
+
+ public AdvisorMock(String name, Class<?> clazz, String... metaDataTags)
+ {
+ this(name, clazz, AspectManager.instance(), metaDataTags);
+ }
+
+ public AdvisorMock(String name, Class<?> clazz, AspectManager domain,
+ String... metaDataTags)
+ {
+ super(name, domain);
+ super.clazz = clazz;
+ this.metaDataTags = Arrays.asList(metaDataTags);
+ super.constructors = clazz.getDeclaredConstructors();
+ }
+
+ @Override
+ public void addClassMetaData(ClassMetaDataBinding data){}
+
+ @Override
+ protected void rebuildInterceptors(){}
+
+ @Override
+ public void removeClassMetaData(ClassMetaDataBinding data){}
+
+ public Collection<String> getMetaDataTags()
+ {
+ return this.metaDataTags;
+ }
+
+ public Collection<String> getMetaDataTags(Field field)
+ {
+ return this.metaDataTags;
+ }
+
+ public Collection<String> getMetaDataTags(Constructor constructor)
+ {
+ return this.metaDataTags;
+ }
+
+ public Collection<String> getMetaDataTags(Method method)
+ {
+ return this.metaDataTags;
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/AllTests.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/AllTests.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/AllTests.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that contains all test cases of this package.
+ *
+ * @author Flavia Rainone
+ */
+public class AllTests
+{
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("Test for org.jboss.aop.joinpoint.graph.tree");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(FieldNodeTest.class);
+ suite.addTestSuite(BehaviorNodeTest.class);
+ suite.addTestSuite(AdvisedDataTest.class);
+ suite.addTestSuite(DomainDataTest.class);
+ suite.addTestSuite(CompositeDomainDataTest.class);
+ suite.addTestSuite(ClassNodeTest.class);
+ suite.addTestSuite(GraphInsertionTest.class);
+ //suite.addTest(org.jboss.aop.joinpoint.graph.tree.AllTests.suite());
+ //$JUnit-END$
+ return suite;
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/BehaviorNodeTest.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/BehaviorNodeTest.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/BehaviorNodeTest.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,523 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.Aspect;
+import org.jboss.aop.Bind;
+import org.jboss.aop.ConByConInfo;
+import org.jboss.aop.ConByMethodInfo;
+import org.jboss.aop.ConstructionInfo;
+import org.jboss.aop.ConstructorInfo;
+import org.jboss.aop.JoinPointInfo;
+import org.jboss.aop.MethodByConInfo;
+import org.jboss.aop.MethodByMethodInfo;
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.Mixin;
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ * Tests {@code BehaviorNode}..
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class BehaviorNodeTest extends TestCase
+{
+ static Field behaviorTypeField = null;
+
+ static
+ {
+ try
+ {
+ behaviorTypeField = BehaviorNode.class.getDeclaredField("behaviorType");
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ behaviorTypeField.setAccessible(true);
+ }
+
+ public void testConstructorNodeCreation1() throws Exception
+ {
+ Constructor constructor = Pojo1.class.getDeclaredConstructors()[0];
+ BehaviorNode behaviorNode = new BehaviorNode(
+ new AdvisorMock("Pojo1Advisor", Pojo1.class), constructor);
+ assertBehaviorNode(constructor, behaviorNode, "new()");
+ }
+
+ public void testConstructorNodeCreation2() throws Exception
+ {
+ Constructor constructor = Pojo3.class.getDeclaredConstructors()[0];
+ BehaviorNode behaviorNode = new BehaviorNode(
+ new AdvisorMock("Pojo3Advisor", Pojo3.class), constructor);
+ assertBehaviorNode(constructor, behaviorNode, "new()");
+ }
+
+ public void testConstructorNodeCreation3() throws Exception
+ {
+ Constructor constructor = Pojo3.class.getDeclaredConstructors()[1];
+ BehaviorNode behaviorNode = new BehaviorNode(
+ new AdvisorMock("Pojo3Advisor", Pojo3.class), constructor);
+ assertBehaviorNode(constructor, behaviorNode, "new(int long )");
+ }
+
+ public void testConstructorNodeCreation4() throws Exception
+ {
+ Constructor constructor = Pojo3.class.getDeclaredConstructors()[2];
+ BehaviorNode behaviorNode = new BehaviorNode(
+ new AdvisorMock("Pojo3Advisor", Pojo3.class), constructor);
+ assertBehaviorNode(constructor, behaviorNode, "new(int java.lang.String )");
+ }
+
+ public void testConstructorNodeCreationWithMetaData1() throws Exception
+ {
+ Constructor constructor = Pojo1.class.getDeclaredConstructors()[0];
+ BehaviorNode behaviorNode = new BehaviorNode(new AdvisorMock("Pojo1Advisor",
+ Pojo1.class, "one.package.with.Annotation", "markup.Ann",
+ "your.package.Secure"), constructor);
+ assertBehaviorNode(constructor, behaviorNode, "new()",
+ "@one.package.with.Annotation()", "@markup.Ann()",
+ "@your.package.Secure()");
+ }
+
+ public void testConstructorNodeCreationWithMetaData2() throws Exception
+ {
+ Constructor constructor = Pojo3.class.getDeclaredConstructors()[2];
+ BehaviorNode behaviorNode = new BehaviorNode(new AdvisorMock("Pojo1Advisor",
+ Pojo1.class, "JustAnnotation", "any.Ann", "your.markup.Secure"),
+ constructor);
+ assertBehaviorNode(constructor, behaviorNode, "new(int java.lang.String )",
+ "@JustAnnotation(int java.lang.String )",
+ "@any.Ann(int java.lang.String )",
+ "@your.markup.Secure(int java.lang.String )");
+ }
+
+ public void testConstructorNodeWithExecution() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Constructor constructor = Pojo1.class.getDeclaredConstructors()[0];
+ BehaviorNode behaviorNode = new BehaviorNode(advisor, constructor);
+ assertBehaviorNode(constructor, behaviorNode, "new()");
+ ConstructorInfo info = new ConstructorInfo(advisor, constructor, 0);
+ behaviorNode.setExecution(info);
+ assertTrue(behaviorNode.hasExecution());
+ assertSame(info, behaviorNode.getExecution());
+ assertFalse(behaviorNode.hasConstruction());
+ }
+
+ public void testConstructorNodeWithConstruction() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Constructor constructor = Pojo1.class.getDeclaredConstructors()[0];
+ BehaviorNode behaviorNode = new BehaviorNode(advisor, constructor);
+ assertBehaviorNode(constructor, behaviorNode, "new()");
+ ConstructionInfo info = new ConstructionInfo(advisor, constructor, 0);
+ behaviorNode.setConstruction(info);
+ assertTrue(behaviorNode.hasConstruction());
+ assertSame(info, behaviorNode.getConstruction());
+ assertFalse(behaviorNode.hasExecution());
+ }
+
+ public void testConstructorNodeWithExecutionAndConstruction() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Constructor constructor = Pojo1.class.getDeclaredConstructors()[0];
+ BehaviorNode behaviorNode = new BehaviorNode(advisor, constructor);
+ assertBehaviorNode(constructor, behaviorNode, "new()");
+ ConstructorInfo executionInfo = new ConstructorInfo(advisor, constructor, 0);
+ ConstructionInfo constructionInfo = new ConstructionInfo(advisor, constructor, 0);
+ behaviorNode.setExecution(executionInfo);
+ behaviorNode.setConstruction(constructionInfo);
+ assertTrue(behaviorNode.hasExecution());
+ assertSame(executionInfo, behaviorNode.getExecution());
+ assertTrue(behaviorNode.hasConstruction());
+ assertSame(constructionInfo, behaviorNode.getConstruction());
+ }
+
+ public void testConstructorNodeWithCallees() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Constructor constructor = Pojo1.class.getDeclaredConstructor();
+ BehaviorNode behaviorNode = new BehaviorNode(advisor, constructor);
+ assertBehaviorNode(constructor, behaviorNode, "new()");
+
+ Method calleeMethod = Pojo1.class.getDeclaredMethod("privateMethod");
+ // callee
+ MethodByConInfo info1 = new MethodByConInfo(advisor,
+ calleeMethod.getDeclaringClass(), constructor.getDeclaringClass(),
+ 0, calleeMethod, 0L, new Interceptor[0]);
+ behaviorNode.addCallee(info1);
+ Collection<JoinPointInfo> calleesFound = new ArrayList<JoinPointInfo>();
+ behaviorNode.searchCallees(Pojo1.class.getName() + ".void privateMethod()",
+ calleesFound);
+ Util.assertCollection(calleesFound, info1);
+
+ calleesFound.clear();
+ behaviorNode.searchCallees("*", calleesFound);
+ Util.assertCollection(calleesFound, info1);
+
+ // callee
+ Constructor calleeConstructor = Pojo1.class.getDeclaredConstructor(int.class);
+ ConByConInfo info2 = new ConByConInfo(advisor,
+ calleeConstructor.getDeclaringClass(), constructor.getDeclaringClass(), 0,
+ calleeConstructor, 0L, null, new Interceptor[0]);
+ behaviorNode.addCallee(info2);
+ calleesFound.clear();
+ behaviorNode.searchCallees(Pojo1.class.getName() + ".new(int )", calleesFound);
+ Util.assertCollection(calleesFound, info2);
+ calleesFound.clear();
+ behaviorNode.searchCallees("*", calleesFound);
+ Util.assertCollection(calleesFound, info1, info2);
+ calleesFound.clear();
+ behaviorNode.searchCallees("*Pojo1.*", calleesFound);
+ Util.assertCollection(calleesFound, info1, info2);
+ }
+
+ public void testConstructorNodeWithAnnotatedConsCallee() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo4Advisor", Pojo4.class);
+ Constructor callerConstructor = Pojo4.class.getDeclaredConstructor();
+ BehaviorNode behaviorNode = new BehaviorNode(advisor, callerConstructor);
+ assertBehaviorNode(callerConstructor, behaviorNode, "new()");
+ // insert callee
+ Constructor callee= Pojo5.class.getDeclaredConstructor(Collection.class);
+ ConByConInfo info = new ConByConInfo(advisor,
+ callee.getDeclaringClass(), callerConstructor.getDeclaringClass(), 0,
+ callee, 0L, null, new Interceptor[0]);
+ behaviorNode.addCallee(info);
+ // assert search
+ Collection<JoinPointInfo> calleesFound = new HashSet<JoinPointInfo>();
+ behaviorNode.searchCallees(Pojo5.class.getName() + ".new(" +
+ Collection.class.getName() + " )", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees("*", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees("*@*", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees('@' + Aspect.class.getName() + ".new(" +
+ Collection.class.getName() + " )", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees(Pojo5.class.getName() + ".@" +
+ AnyAnnotation.class.getName() + '(' + Collection.class.getName() +
+ " )", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees('@' + Aspect.class.getName() + ".@" +
+ AnyAnnotation.class.getName() + '(' + Collection.class.getName() +
+ " )", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ }
+
+ public void testConstructorNodeWithAnnotatedMethodCallee() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo4Advisor", Pojo4.class);
+ Constructor callerConstructor= Pojo4.class.getDeclaredConstructor(int.class);
+ BehaviorNode behaviorNode = new BehaviorNode(advisor, callerConstructor);
+ assertBehaviorNode(callerConstructor, behaviorNode, "new(int )");
+ Method callee = Pojo5.class.getDeclaredMethod("calledByCon");
+ // insert callee
+ MethodByConInfo info = new MethodByConInfo(advisor,
+ callee.getDeclaringClass(), callerConstructor.getDeclaringClass(),
+ 0, callee, 0L, new Interceptor[0]);
+ behaviorNode.addCallee(info);
+ // assert search
+ Collection<JoinPointInfo> calleesFound = new HashSet<JoinPointInfo>();
+ behaviorNode.searchCallees(Pojo5.class.getName() + ".void calledByCon()",
+ calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees("*", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees('@' + Aspect.class.getName() +
+ ".void calledByCon()", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees(Pojo5.class.getName() + ".void @" +
+ Bind.class.getName() + "()", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees('@' + Aspect.class.getName() + ".void @" +
+ Bind.class.getName() + "()", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ }
+
+
+
+ public void testMethodNodeCreation1() throws Exception
+ {
+ Method method = Pojo1.class.getMethod("method1", String.class, String.class);
+ BehaviorNode behaviorNode = new BehaviorNode(
+ new AdvisorMock("Pojo1Advisor", Pojo1.class), method);
+ assertBehaviorNode(method, behaviorNode,
+ "void method1(java.lang.String java.lang.String )");
+ }
+
+ public void testMethodNodeCreation2() throws Exception
+ {
+ Method method = Pojo3.class.getMethod("voidMethod", new Class[]{});
+ BehaviorNode behaviorNode = new BehaviorNode(
+ new AdvisorMock("Pojo3Advisor", Pojo3.class), method);
+ assertBehaviorNode(method, behaviorNode, "void voidMethod()");
+ }
+
+ public void testMethodNodeCreation3() throws Exception
+ {
+ Method method = Pojo3.class.getMethod("stringMethod", new Class[]{});
+ BehaviorNode behaviorNode = new BehaviorNode(
+ new AdvisorMock("Pojo3Advisor", Pojo3.class), method);
+ assertBehaviorNode(method, behaviorNode, "java.lang.String stringMethod()");
+ }
+
+ public void testMethodNodeCreation4() throws Exception
+ {
+ Method method = Pojo3.class.getMethod("someMethod", new Class[]{int.class, long.class});
+ BehaviorNode behaviorNode = new BehaviorNode(
+ new AdvisorMock("Pojo3Advisor", Pojo3.class), method);
+ assertBehaviorNode(method, behaviorNode, "void someMethod(int long )");
+ }
+
+ public void testMethodNodeCreation5() throws Exception
+ {
+ Method method = Pojo3.class.getMethod("someMethod", new Class[]{String.class, long.class});
+ BehaviorNode behaviorNode = new BehaviorNode(
+ new AdvisorMock("Pojo3Advisor", Pojo3.class), method);
+ assertBehaviorNode(method, behaviorNode,
+ "java.lang.String someMethod(java.lang.String long )");
+ }
+
+ public void testMethodNodeCreationWithMetaData1() throws Exception
+ {
+ Method method = Pojo1.class.getMethod("method1", new Class[]{String.class, String.class});
+ BehaviorNode behaviorNode = new BehaviorNode(
+ new AdvisorMock("Pojo1Advisor", Pojo1.class, "java.lang.Annotation",
+ "other.MetaData", "your.package.Secure"), method);
+ assertBehaviorNode(method, behaviorNode,
+ "void method1(java.lang.String java.lang.String )",
+ "void @java.lang.Annotation(java.lang.String java.lang.String )",
+ "void @other.MetaData(java.lang.String java.lang.String )",
+ "void @your.package.Secure(java.lang.String java.lang.String )");
+ }
+
+ public void testMethodNodeCreationWithMetaData2() throws Exception
+ {
+ Method method = Pojo3.class.getMethod("stringMethod", new Class[]{});
+ BehaviorNode behaviorNode = new BehaviorNode(
+ new AdvisorMock("Pojo3Advisor", Pojo3.class, "java.lang.AnyAnnotation",
+ "other.MetaData", "your.markup.Secure"), method);
+ assertBehaviorNode(method, behaviorNode, "java.lang.String stringMethod()",
+ "java.lang.String @java.lang.AnyAnnotation()",
+ "java.lang.String @other.MetaData()",
+ "java.lang.String @your.markup.Secure()");
+ }
+
+ public void testMethodNodeWithExecution() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Method method = Pojo1.class.getDeclaredMethod("privateMethod", new Class[0]);
+ BehaviorNode behaviorNode = new BehaviorNode(advisor, method);
+ assertBehaviorNode(method, behaviorNode, "void privateMethod()");
+ MethodInfo methodInfo = new MethodInfo(advisor, 0L, method, method);
+ behaviorNode.setExecution(methodInfo);
+ assertTrue(behaviorNode.hasExecution());
+ assertSame(methodInfo, behaviorNode.getExecution());
+ assertFalse(behaviorNode.hasConstruction());
+ }
+
+ public void testMethodNodeWithCallees() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Method callerMethod = Pojo1.class.getMethod("method1", String.class,
+ String.class);
+ BehaviorNode behaviorNode = new BehaviorNode(advisor, callerMethod);
+ assertBehaviorNode(callerMethod, behaviorNode,
+ "void method1(java.lang.String java.lang.String )");
+ Method calleeMethod = Pojo1.class.getDeclaredMethod("privateMethod", new Class[0]);
+ // callee
+ MethodByMethodInfo info1 = new MethodByMethodInfo(advisor,
+ calleeMethod.getDeclaringClass(), calleeMethod, callerMethod, 0L, 0L,
+ new Interceptor[0]);
+ behaviorNode.addCallee(info1);
+ Collection<JoinPointInfo> calleesFound = new ArrayList<JoinPointInfo>();
+ behaviorNode.searchCallees(Pojo1.class.getName() + ".void privateMethod()",
+ calleesFound);
+ Util.assertCollection(calleesFound, info1);
+ calleesFound.clear();
+ behaviorNode.searchCallees("*", calleesFound);
+ Util.assertCollection(calleesFound, info1);
+
+ // callee
+ Constructor constructor = Pojo1.class.getDeclaredConstructor(int.class);
+ ConByMethodInfo info2 = new ConByMethodInfo(advisor,
+ constructor.getDeclaringClass(), callerMethod, 0L, constructor, 0L, null,
+ new Interceptor[0]);
+ behaviorNode.addCallee(info2);
+ calleesFound.clear();
+ behaviorNode.searchCallees(Pojo1.class.getName() + ".new(int )", calleesFound);
+ Util.assertCollection(calleesFound, info2);
+ calleesFound.clear();
+ behaviorNode.searchCallees("*", calleesFound);
+ Util.assertCollection(calleesFound, info1, info2);
+ calleesFound.clear();
+ behaviorNode.searchCallees("org.jboss.aop.joinpoint.*", calleesFound);
+ Util.assertCollection(calleesFound, info1, info2);
+ }
+
+ public void testMethodNodeWithAnnotatedConsCallees() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo4Advisor", Pojo4.class);
+ Method callerMethod = Pojo4.class.getMethod("callConstructor");
+ BehaviorNode behaviorNode = new BehaviorNode(advisor, callerMethod);
+ assertBehaviorNode(callerMethod, behaviorNode, "void callConstructor()");
+ // insert callee
+ Constructor callee= Pojo5.class.getDeclaredConstructor(Pojo3.class);
+ ConByMethodInfo info = new ConByMethodInfo(advisor,
+ callee.getDeclaringClass(), callerMethod, 0L, callee, 0L, null,
+ new Interceptor[0]);
+ behaviorNode.addCallee(info);
+ // assert search
+ Collection<JoinPointInfo> calleesFound = new HashSet<JoinPointInfo>();
+ behaviorNode.searchCallees(Pojo5.class.getName() + ".new(" +
+ Pojo3.class.getName() + " )", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees("*", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees("*@*", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees('@' + Aspect.class.getName() + ".new(" +
+ Pojo3.class.getName() + " )", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees(Pojo5.class.getName() + ".new(" +
+ Pojo3.class.getName() + " )", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees('@' + Aspect.class.getName() + ".@" +
+ Deprecated.class.getName() + '(' + Pojo3.class.getName() + " )",
+ calleesFound);
+ Util.assertCollection(calleesFound, info);
+ }
+
+ public void testMethodNodeWithAnnotatedMethodCallee() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo4Advisor", Pojo4.class);
+ Method callerMethod = Pojo4.class.getMethod("callMethod");
+ BehaviorNode behaviorNode = new BehaviorNode(advisor, callerMethod);
+ assertBehaviorNode(callerMethod, behaviorNode, "void callMethod()");
+ Method callee = Pojo5.class.getDeclaredMethod("calledByMethod");
+ // insert callee
+ MethodByMethodInfo info = new MethodByMethodInfo(advisor,
+ callee.getDeclaringClass(), callee, callerMethod, 0L, 0L,
+ new Interceptor[0]);
+ behaviorNode.addCallee(info);
+ // assert search
+ Collection<JoinPointInfo> calleesFound = new HashSet<JoinPointInfo>();
+ behaviorNode.searchCallees(Pojo5.class.getName() + ".void calledByMethod()",
+ calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees("*", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees('@' + Aspect.class.getName() +
+ ".void calledByMethod()", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees(Pojo5.class.getName() + ".void @" +
+ Mixin.class.getName() + "()", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ calleesFound.clear();
+ behaviorNode.searchCallees('@' + Aspect.class.getName() + ".void @" +
+ Mixin.class.getName() + "()", calleesFound);
+ Util.assertCollection(calleesFound, info);
+ }
+
+ static void assertBehaviorNode(Constructor constructor,
+ BehaviorNode behaviorNode, String defaultKey, String... metaDataKeys)
+ throws Exception
+ {
+ Enum behaviorType = (Enum) behaviorTypeField.get(behaviorNode);
+ assertEquals("CONSTRUCTOR", behaviorType.name());
+ assertSame(constructor, behaviorNode.getBehavior());
+ assertFalse(behaviorNode.hasConstruction());
+ assertNull(behaviorNode.getConstruction());
+ assertFalse(behaviorNode.hasExecution());
+ assertNull(behaviorNode.getExecution());
+ Class<?>[] consExceptionTypes = constructor.getExceptionTypes();
+ Class<?>[] nodeExceptionTypes = behaviorNode.getExceptionTypes();
+ assertEquals(consExceptionTypes.length, nodeExceptionTypes.length);
+ for (int i = 0; i < consExceptionTypes.length; i++)
+ {
+ assertSame(consExceptionTypes[i], nodeExceptionTypes[i]);
+ }
+ assertBehaviorNode(behaviorNode, defaultKey, metaDataKeys);
+ }
+
+ static void assertBehaviorNode(Method method, BehaviorNode behaviorNode,
+ String defaultKey, String... metaDataKeys) throws Exception
+ {
+ Enum behaviorType = (Enum) behaviorTypeField.get(behaviorNode);
+ assertEquals("METHOD", behaviorType.name());
+ assertSame(method, behaviorNode.getBehavior());
+ Class<?>[] methodExceptionTypes = method.getExceptionTypes();
+ Class<?>[] nodeExceptionTypes = behaviorNode.getExceptionTypes();
+ assertEquals(methodExceptionTypes.length, nodeExceptionTypes.length);
+ for (int i = 0; i < methodExceptionTypes.length; i++)
+ {
+ assertSame(methodExceptionTypes[i], nodeExceptionTypes[i]);
+ }
+ assertBehaviorNode(behaviorNode, defaultKey, metaDataKeys);
+ }
+
+ static void assertBehaviorNode(BehaviorNode behaviorNode, String defaultKey,
+ String... expectedMetaDataKeys)
+ {
+ assertFalse(behaviorNode.hasConstruction());
+ assertNull(behaviorNode.getConstruction());
+ assertFalse(behaviorNode.hasExecution());
+ assertNull(behaviorNode.getExecution());
+ Collection<JoinPointInfo> callees = new ArrayList<JoinPointInfo>();
+ behaviorNode.searchCallees("*", callees);
+ Util.assertCollection(callees);
+ assertEquals(defaultKey, behaviorNode.getIdentifierKey());
+ Collection<String> metaDataKeys = new ArrayList<String>();
+ behaviorNode.loadMetaDataKeys(metaDataKeys);
+ Util.assertCollection(metaDataKeys, expectedMetaDataKeys);
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/ClassNodeTest.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/ClassNodeTest.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/ClassNodeTest.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,205 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.ClassAdvisor;
+
+/**
+ * Tests functionality of all types in {@code ClassNode} hierarchy.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class ClassNodeTest extends TestCase
+{
+ Field advisedDataField;
+
+ public void setUp() throws Exception
+ {
+ advisedDataField = AdvisableClassNode.class.getDeclaredField("advisedData");
+ advisedDataField.setAccessible(true);
+ }
+
+ public void testClassNodeCreation1() throws Exception
+ {
+ StandardClassNode classNode = new StandardClassNode(Pojo1.class);
+ assertClassNode(Pojo1.class, classNode, null, Pojo1.class.getName());
+ assertNull(advisedDataField.get(classNode));
+ }
+
+ @SuppressWarnings("deprecation")
+ public void testClassNodeCreation2() throws Exception
+ {
+ StandardClassNode classNode = new StandardClassNode(Pojo2.class);
+ assertClassNode(Pojo2.class, classNode, null, Pojo2.class.getName(),
+ "@" + Deprecated.class.getName());
+ assertNull(advisedDataField.get(classNode));
+ }
+
+ public void testClassNodeGetAdvisedData1() throws Exception
+ {
+ StandardClassNode classNode = new StandardClassNode(Pojo3.class);
+ Advisor advisor = new AdvisorMock("Pojo3Advisor", Pojo3.class,
+ "Annotation1", "Annotation2", "Annotation3", "Annotation4");
+ AdvisedData advisedData = classNode.getAdvisedData(advisor);
+ assertClassNode(Pojo3.class, classNode, advisor, Pojo3.class.getName(),
+ "@Annotation1", "@Annotation2", "@Annotation3", "@Annotation4");
+ assertSame(advisedData, advisedDataField.get(classNode));
+ assertTrue(advisedData instanceof DomainData);
+ assertSame(advisor, advisedData.getAdvisor());
+ }
+
+ public void testClassNodeGetAdvisedData2() throws Exception
+ {
+ StandardClassNode classNode = new StandardClassNode(Pojo3.class);
+ Advisor advisor = new AdvisorMock("Pojo3Advisor", Pojo3.class,"annotation1",
+ "annotation2", "annotation3", "annotation4");
+ Advisor instanceAdvisor = new InstanceAdvisorMock(advisor);
+ AdvisedData advisedData = classNode.getAdvisedData(instanceAdvisor);
+ assertClassNode(Pojo3.class, classNode, advisor, Pojo3.class.getName(),
+ "@annotation1", "@annotation2", "@annotation3", "@annotation4");
+ AdvisedData classAdvisedData = (AdvisedData) advisedDataField.get(classNode);
+ assertNotSame(advisedData, classAdvisedData);
+ assertTrue(advisedData instanceof AdvisedData);
+ assertSame(instanceAdvisor, advisedData.getAdvisor());
+ assertTrue(classAdvisedData instanceof CompositeDomainData);
+ assertSame(advisor, ((CompositeDomainData) classAdvisedData).getAdvisor());
+ assertSame(advisedData, ((CompositeDomainData) classAdvisedData).getAdvisedData(instanceAdvisor));
+ assertSame(classAdvisedData, classNode.getAdvisedData(advisor));
+ }
+
+ public void testClassNodeGetAdvisedData3() throws Exception
+ {
+ StandardClassNode classNode = new StandardClassNode(Pojo3.class);
+ Advisor advisor = new AdvisorMock("Pojo3Advisor", Pojo3.class);
+ Advisor instanceAdvisor = new InstanceAdvisorMock(advisor);
+ AdvisedData classAdvisedData = classNode.getAdvisedData(advisor);
+ AdvisedData instanceAdvisedData = classNode.getAdvisedData(instanceAdvisor);
+ classAdvisedData = classNode.getAdvisedData(advisor);
+ assertClassNode(Pojo3.class, classNode, advisor, Pojo3.class.getName());
+ assertNotSame(instanceAdvisedData, classAdvisedData);
+ assertTrue(instanceAdvisedData instanceof AdvisedData);
+ assertSame(instanceAdvisor, instanceAdvisedData.getAdvisor());
+ assertTrue(classAdvisedData instanceof CompositeDomainData);
+ assertSame(advisor, ((CompositeDomainData) classAdvisedData).getAdvisor());
+ assertSame(instanceAdvisedData, ((CompositeDomainData) classAdvisedData).
+ getAdvisedData(instanceAdvisor));
+ }
+
+ @SuppressWarnings("deprecation")
+ public void testClassNodeAddSubtypes1() throws Exception
+ {
+ ClassNode classNode1 = new StandardClassNode(Pojo1.class);
+ ClassNode classNode2 = new StandardClassNode(Pojo2.class);
+ ClassNode classNode3 = new StandardClassNode(Pojo3.class);
+ classNode1.addSubtype(classNode2);
+ classNode1.addSubtype(classNode3);
+ Util.assertCollection(classNode1.getSubtypes(), classNode2, classNode3);
+ Util.assertCollection(classNode2.getSubtypes());
+ Util.assertCollection(classNode3.getSubtypes());
+ }
+
+ @SuppressWarnings("deprecation")
+ public void testClassNodeAddSubtypes2() throws Exception
+ {
+ ClassNode classNode1 = new StandardClassNode(Pojo1.class);
+ ClassNode classNode2 = new StandardClassNode(Pojo2.class);
+ ClassNode classNode3 = new StandardClassNode(Pojo3.class);
+ classNode1.addSubtype(classNode2);
+ classNode2.addSubtype(classNode3);
+ Util.assertCollection(classNode1.getSubtypes(), classNode2);
+ Util.assertCollection(classNode2.getSubtypes(), classNode3);
+ Util.assertCollection(classNode3.getSubtypes());
+ }
+
+ public void testUnitaryDomainClassNode()
+ {
+ UnitaryDomainClassNode domainClassNode = new UnitaryDomainClassNode(
+ Pojo3.class, null);
+
+ boolean thrown = false;
+ try
+ {
+ domainClassNode.addSubtype(new StandardClassNode(Pojo1.class));
+ }
+ catch (Exception e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+ assertTrue(domainClassNode.getSubtypes().isEmpty());
+ }
+
+ public void testUnitaryDomainSuperClassNode()
+ {
+ UnitaryDomainClassNode domainClassNode = new UnitaryDomainClassNode(
+ Pojo3.class, null);
+ ClassNode classNode = new UnitaryDomainSuperClassNode(Object.class,
+ domainClassNode);
+ boolean thrown = false;
+ try
+ {
+ classNode.addSubtype(new StandardClassNode(Pojo1.class));
+ }
+ catch (Exception e)
+ {
+ thrown = true;
+ }
+ assertTrue(thrown);
+ Util.assertCollection(classNode.getSubtypes(), domainClassNode);
+ Util.assertCollection(classNode.searchFields("*"));
+ Util.assertCollection(classNode.searchBehaviors("*"));
+ }
+
+ private void assertClassNode(Class<?> clazz, StandardClassNode classNode, Advisor advisor,
+ String defaultKey, String... expectedMetaDataKeys)
+ {
+ assertTrue(classNode.getSubtypes().isEmpty());
+ if (advisor == null)
+ {
+ assertTrue(classNode.getMetaDataContainer() instanceof ClassAdvisor);
+ }
+ else
+ {
+ assertSame(classNode.getMetaDataContainer(), advisor);
+ }
+ if (advisor != null)
+ {
+ AdvisedData advisedData = classNode.getAdvisedData(advisor);
+ assertNotNull(advisedData);
+ assertSame(advisor, advisedData.getAdvisor());
+ }
+ assertSame(clazz, classNode.getClazz());
+ assertEquals(defaultKey, classNode.getIdentifierKey());
+ Collection<String> metaDataKeys = new ArrayList<String>();
+ classNode.loadMetaDataKeys(metaDataKeys);
+ Util.assertCollection(metaDataKeys, expectedMetaDataKeys);
+ Util.assertCollection(classNode.searchBehaviors("*"));
+ Util.assertCollection(classNode.searchFields("*"));
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/CompositeDomainDataTest.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/CompositeDomainDataTest.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/CompositeDomainDataTest.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,301 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.Advisor;
+
+/**
+ * Tests {@code CompositeDomainData}.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class CompositeDomainDataTest extends TestCase
+{
+ public void testCompositeDomainDataCreation() throws Exception
+ {
+ Field instanceDataField = CompositeDomainData.class.getDeclaredField("components");
+ instanceDataField.setAccessible(true);
+ CompositeDomainData advisedClassData = new CompositeDomainData(
+ new AdvisorMock("Pojo1Advisor", Pojo1.class));
+ assertTrue(((Map) instanceDataField.get(advisedClassData)).isEmpty());
+ }
+
+ public void testCreateComponent()
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Advisor instanceAdvisor = new InstanceAdvisorMock(advisor);
+ CompositeDomainData compositeData = new CompositeDomainData(
+ advisor);
+ AdvisedData advisedData = compositeData.createComponent(instanceAdvisor);
+ Util.assertCollection(advisedData.searchBehaviors("*"));
+ Util.assertCollection(advisedData.searchFields("*"));
+ assertSame(instanceAdvisor, advisedData.getAdvisor());
+ }
+
+ public void testGetComponent1()
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor",Pojo1.class);
+ Advisor instanceAdvisor = new InstanceAdvisorMock(advisor);
+ CompositeDomainData compositeData = new CompositeDomainData(
+ advisor);
+ // test operation
+ AdvisedData advisedData = compositeData.getComponent(instanceAdvisor);
+ // assert advisedData is in newly created state
+ Util.assertCollection(advisedData.searchBehaviors("*"));
+ Util.assertCollection(advisedData.searchFields("*"));
+ assertSame(instanceAdvisor, advisedData.getAdvisor());
+ }
+
+ public void testGetComponent2()
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Advisor instanceAdvisor = new InstanceAdvisorMock(advisor);
+ CompositeDomainData compositeData = new CompositeDomainData(
+ advisor);
+ // test operation
+ AdvisedData advisedData = compositeData.getComponent(instanceAdvisor);
+ // assert advisedData is always the same.
+ assertSame(advisedData, compositeData.getComponent(instanceAdvisor));
+ }
+
+ public void testGetComponent3()
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Advisor instanceAdvisor = new InstanceAdvisorMock(advisor);
+ CompositeDomainData compositeData = new CompositeDomainData(
+ advisor);
+ // create a component
+ AdvisedData advisedData = compositeData.createComponent(instanceAdvisor);
+ // assert advisedData retrieved is the same as the one previously created
+ assertSame(advisedData, compositeData.getComponent(instanceAdvisor));
+ }
+
+ public void testGetComponent4()
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Advisor instanceAdvisor1 = new InstanceAdvisorMock(advisor);
+ Advisor instanceAdvisor2 = new InstanceAdvisorMock(advisor);
+ CompositeDomainData compositeData = new CompositeDomainData(
+ advisor);
+ // create components
+ AdvisedData advisedData1 = compositeData.getComponent(instanceAdvisor1);
+ AdvisedData advisedData2 = compositeData.getComponent(instanceAdvisor2);
+ // assert advisedData retrieved are different when the advisor is different
+ assertNotSame(advisedData1, advisedData2);
+ }
+
+ public void testSearchFields1() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Advisor instanceAdvisor1 = new InstanceAdvisorMock(advisor);
+ Advisor instanceAdvisor2 = new InstanceAdvisorMock(advisor);
+ CompositeDomainData compositeData = new CompositeDomainData(
+ advisor);
+ // create a components
+ AdvisedData advisedData1 = compositeData.getComponent(instanceAdvisor1);
+ AdvisedData advisedData2 = compositeData.getComponent(instanceAdvisor2);
+ Field field = Pojo1.class.getDeclaredField("field");
+ FieldNode fieldNode1 = advisedData1.getField(field);
+ FieldNode fieldNode2 = advisedData2.getField(field);
+ Util.assertCollection(compositeData.searchFields("*"), fieldNode1, fieldNode2);
+ Util.assertCollection(compositeData.searchBehaviors("*"));
+ }
+
+ public void testSearchFields2() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Advisor instanceAdvisor1 = new InstanceAdvisorMock(advisor);
+ Advisor instanceAdvisor2 = new InstanceAdvisorMock(advisor);
+ CompositeDomainData compositeData = new CompositeDomainData(
+ advisor);
+ // create a components
+ compositeData.getComponent(instanceAdvisor1);
+ compositeData.getComponent(instanceAdvisor2);
+ Field field = Pojo1.class.getDeclaredField("field");
+ FieldNode fieldNode = compositeData.getField(field);
+ Collection<FieldNode> nodesFound = compositeData.searchFields("*");
+ assertEquals(1, nodesFound.size());
+ assertSame(fieldNode, nodesFound.iterator().next());
+ assertTrue(compositeData.searchBehaviors("*").isEmpty());
+ }
+
+ public void testSearchFields3() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo3Advisor", Pojo1.class);
+ Advisor instanceAdvisor1 = new InstanceAdvisorMock(advisor);
+ Advisor instanceAdvisor2 = new InstanceAdvisorMock(advisor);
+ Advisor instanceAdvisor3 = new InstanceAdvisorMock(advisor);
+ Advisor instanceAdvisor4 = new InstanceAdvisorMock(advisor);
+ CompositeDomainData compositeData = new CompositeDomainData(
+ advisor);
+ // create a components
+ AdvisedData advisedData1 = compositeData.getComponent(instanceAdvisor1);
+ AdvisedData advisedData2 = compositeData.getComponent(instanceAdvisor2);
+ AdvisedData advisedData3 = compositeData.getComponent(instanceAdvisor3);
+ AdvisedData advisedData4 = compositeData.getComponent(instanceAdvisor4);
+ // load fields
+ Field intField = Pojo3.class.getDeclaredField("intField");
+ Field dumbField = Pojo3.class.getDeclaredField("dumbField");
+ Field constantField = Pojo3.class.getDeclaredField("ANY_CONSTANT");
+ Field field = Pojo3.class.getDeclaredField("field");
+ // create field nodes
+ FieldNode fieldNode1 = compositeData.getField(intField);
+ FieldNode fieldNode2 = advisedData2.getField(intField);
+ FieldNode fieldNode3 = advisedData4.getField(field);
+ FieldNode fieldNode4 = advisedData1.getField(constantField);
+ FieldNode fieldNode5 = advisedData3.getField(constantField);
+ FieldNode fieldNode6 = advisedData1.getField(dumbField);
+ // search
+ Util.assertCollection(compositeData.searchFields("*"), fieldNode1, fieldNode2,
+ fieldNode3, fieldNode4, fieldNode5, fieldNode6);
+ Util.assertCollection(compositeData.searchFields("java.util.Collection *"),
+ fieldNode3);
+ Util.assertCollection(compositeData.searchFields("* ANY*"), fieldNode4,
+ fieldNode5);
+ Util.assertCollection(compositeData.searchFields("int intField"), fieldNode1,
+ fieldNode2);
+ Util.assertCollection(compositeData.searchBehaviors("*"));
+ }
+
+ public void testSearchBehaviors1() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Advisor instanceAdvisor1 = new InstanceAdvisorMock(advisor);
+ Advisor instanceAdvisor2 = new InstanceAdvisorMock(advisor);
+ CompositeDomainData compositeData = new CompositeDomainData(
+ advisor);
+ // create a components
+ AdvisedData advisedData1 = compositeData.getComponent(instanceAdvisor1);
+ AdvisedData advisedData2 = compositeData.getComponent(instanceAdvisor2);
+ Method method = Pojo1.class.getDeclaredMethod("method1", String.class,
+ String.class);
+ BehaviorNode behaviorNode1 = advisedData1.getBehavior(method);
+ BehaviorNode behaviorNode2 = advisedData2.getBehavior(method);
+ assertTrue(compositeData.searchFields("*").isEmpty());
+ Collection<BehaviorNode> nodesFound = compositeData.searchBehaviors("*");
+ Util.assertCollection(nodesFound, behaviorNode1, behaviorNode2);
+ }
+
+ public void testSearchBehavior2() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Advisor instanceAdvisor1 = new InstanceAdvisorMock(advisor);
+ Advisor instanceAdvisor2 = new InstanceAdvisorMock(advisor);
+ CompositeDomainData compositeData = new CompositeDomainData(
+ advisor);
+ // create a components
+ compositeData.getComponent(instanceAdvisor1);
+ compositeData.getComponent(instanceAdvisor2);
+ Constructor constructor = Pojo1.class.getDeclaredConstructors()[0];
+ BehaviorNode behaviorNode = compositeData.getBehavior(constructor);
+ Util.assertCollection(compositeData.searchFields("*"));
+ Util.assertCollection(compositeData.searchBehaviors("*"), behaviorNode);
+ }
+
+ public void testSearchBehaviors3() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo3Advisor", Pojo1.class);
+ Advisor instanceAdvisor1 = new InstanceAdvisorMock(advisor);
+ Advisor instanceAdvisor2 = new InstanceAdvisorMock(advisor);
+ Advisor instanceAdvisor3 = new InstanceAdvisorMock(advisor);
+ Advisor instanceAdvisor4 = new InstanceAdvisorMock(advisor);
+ CompositeDomainData compositeData = new CompositeDomainData(
+ advisor);
+ // create a components
+ AdvisedData advisedData1 = compositeData.getComponent(instanceAdvisor1);
+ AdvisedData advisedData2 = compositeData.getComponent(instanceAdvisor2);
+ AdvisedData advisedData3 = compositeData.getComponent(instanceAdvisor3);
+ AdvisedData advisedData4 = compositeData.getComponent(instanceAdvisor4);
+ // load fields
+ Constructor constructor1 = Pojo3.class.getDeclaredConstructors()[0];
+ Constructor constructor2 = Pojo3.class.getDeclaredConstructors()[1];
+ Constructor constructor3 = Pojo3.class.getDeclaredConstructors()[2];
+ Method voidMethod = Pojo3.class.getDeclaredMethod("voidMethod");
+ Method stringMethod = Pojo3.class.getDeclaredMethod("stringMethod");
+ Method someMethod1 = Pojo3.class.getDeclaredMethod("someMethod", int.class, long.class);
+ Method someMethod2 = Pojo3.class.getDeclaredMethod("someMethod", String.class, long.class);
+ // create behavior nodes
+ BehaviorNode behaviorNode1 = compositeData.getBehavior(constructor1);
+ BehaviorNode behaviorNode2 = advisedData2.getBehavior(constructor1);
+ BehaviorNode behaviorNode3 = advisedData4.getBehavior(constructor2);
+ BehaviorNode behaviorNode4 = advisedData1.getBehavior(constructor3);
+ BehaviorNode behaviorNode5 = advisedData3.getBehavior(constructor3);
+ BehaviorNode behaviorNode6 = advisedData1.getBehavior(voidMethod);
+ BehaviorNode behaviorNode7 = compositeData.getBehavior(stringMethod);
+ BehaviorNode behaviorNode8 = compositeData.getBehavior(someMethod1);
+ BehaviorNode behaviorNode9 = advisedData1.getBehavior(someMethod1);
+ BehaviorNode behaviorNode10 = advisedData2.getBehavior(someMethod1);
+ BehaviorNode behaviorNode11 = advisedData3.getBehavior(someMethod1);
+ BehaviorNode behaviorNode12 = advisedData4.getBehavior(someMethod1);
+ BehaviorNode behaviorNode13 = advisedData3.getBehavior(someMethod2);
+ BehaviorNode behaviorNode14 = advisedData4.getBehavior(someMethod2);
+
+ // search
+ Util.assertCollection(compositeData.searchFields("*"));
+ Util.assertCollection(compositeData.searchBehaviors("*"), behaviorNode1,
+ behaviorNode2, behaviorNode3, behaviorNode4, behaviorNode5, behaviorNode6,
+ behaviorNode7, behaviorNode8, behaviorNode9, behaviorNode10,
+ behaviorNode11, behaviorNode12, behaviorNode13, behaviorNode14);
+ Util.assertCollection(compositeData.searchBehaviors("*(*)"), behaviorNode1,
+ behaviorNode2, behaviorNode3, behaviorNode4, behaviorNode5, behaviorNode6,
+ behaviorNode7, behaviorNode8, behaviorNode9, behaviorNode10,
+ behaviorNode11, behaviorNode12, behaviorNode13, behaviorNode14);
+ Util.assertCollection(compositeData.searchBehaviors("new(*)"),
+ behaviorNode1, behaviorNode2, behaviorNode3, behaviorNode4, behaviorNode5);
+ Util.assertCollection(compositeData.searchBehaviors("*()"),
+ behaviorNode1, behaviorNode2, behaviorNode6, behaviorNode7);
+ Util.assertCollection(compositeData.searchBehaviors("*int*"),
+ behaviorNode3, behaviorNode4, behaviorNode5, behaviorNode8,
+ behaviorNode9, behaviorNode10, behaviorNode11, behaviorNode12);
+ Util.assertCollection(compositeData.searchBehaviors("void someMethod(*)"),
+ behaviorNode8, behaviorNode9, behaviorNode10, behaviorNode11,
+ behaviorNode12);
+ Util.assertCollection(compositeData.searchBehaviors("* someMethod(*)"),
+ behaviorNode8, behaviorNode9, behaviorNode10, behaviorNode11,
+ behaviorNode12, behaviorNode13, behaviorNode14);
+
+ Util.assertCollection(compositeData.searchBehaviors("new()"),
+ behaviorNode1, behaviorNode2);
+ Util.assertCollection(compositeData.searchBehaviors("new(int long )"),
+ behaviorNode3);
+ Util.assertCollection(compositeData.searchBehaviors("new(int java.lang.String )"),
+ behaviorNode4, behaviorNode5);
+ Util.assertCollection(compositeData.searchBehaviors("void voidMethod()"),
+ behaviorNode6);
+ Util.assertCollection(compositeData.searchBehaviors(
+ "java.lang.String stringMethod()"), behaviorNode7);
+ Util.assertCollection(compositeData.searchBehaviors( "void someMethod(int long )"),
+ behaviorNode8, behaviorNode9, behaviorNode10, behaviorNode11,
+ behaviorNode12);
+ Util.assertCollection(compositeData.searchBehaviors(
+ "java.lang.String someMethod(java.lang.String long )"),
+ behaviorNode13, behaviorNode14);
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/DomainDataTest.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/DomainDataTest.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/DomainDataTest.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.lang.reflect.Field;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.Domain;
+
+/**
+ * Tests {@code DomainData}.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+ at SuppressWarnings("unchecked")
+public class DomainDataTest extends TestCase
+{
+ private Field tagsField;
+
+ public void setUp() throws Exception
+ {
+ tagsField = DomainData.class.getDeclaredField("tags");
+ tagsField.setAccessible(true);
+ }
+
+ public void testAdvisedDomainDataCreation1() throws Exception
+ {
+ DomainData advisedDomainData = new DomainData(
+ new AdvisorMock("Pojo1Advisor", Pojo1.class));
+ assertTrue(((Collection<String>) tagsField.get(advisedDomainData)).isEmpty());
+ }
+
+ public void testAdvisedDomainDataCreation2() throws Exception
+ {
+ Domain domain = new Domain(AspectManager.instance(), "domain1", true);
+ DomainData advisedDomainData = new DomainData(
+ new AdvisorMock("Pojo1Advisor", Pojo1.class, domain));
+ assertEquals(1, ((Collection<String>) tagsField.get(advisedDomainData)).size());
+ assertTrue(advisedDomainData.hasTag("domain1"));
+ }
+
+ public void testAdvisedDomainDataCreation3() throws Exception
+ {
+ Domain domain1 = new Domain(AspectManager.instance(), "domain1", true);
+ Domain domain2 = new Domain(domain1, "domain2", true);
+ Domain domain3 = new Domain(domain2, "domain3", true);
+ Domain domain4 = new Domain(domain3, "domain4", true);
+ DomainData advisedDomainData = new DomainData(
+ new AdvisorMock("Pojo1Advisor", Pojo1.class, domain4));
+ assertEquals(4, ((Collection<String>) tagsField.get(advisedDomainData)).size());
+ assertTrue(advisedDomainData.hasTag("domain1"));
+ assertTrue(advisedDomainData.hasTag("domain2"));
+ assertTrue(advisedDomainData.hasTag("domain3"));
+ assertTrue(advisedDomainData.hasTag("domain4"));
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/DummyAnnotation.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/DummyAnnotation.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/DummyAnnotation.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+/**
+ * Test scenario.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+ at interface DummyAnnotation {}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/FieldNodeTest.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/FieldNodeTest.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/FieldNodeTest.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,159 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.FieldInfo;
+
+/**
+ * Tests {@code FieldNode}.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class FieldNodeTest extends TestCase
+{
+ Field behaviorTypeField = null;
+
+
+ public void setUp() throws Exception
+ {
+ behaviorTypeField = BehaviorNode.class.getDeclaredField("behaviorType");
+ behaviorTypeField.setAccessible(true);
+ }
+
+ public void testFieldNodeCreation1() throws Exception
+ {
+ Field field = Pojo1.class.getDeclaredFields()[0];
+ FieldNode fieldNode = new FieldNode(
+ new AdvisorMock("Pojo1Advisor", Pojo1.class), field);
+ assertFieldNode(field, fieldNode, "java.lang.String field");
+ }
+
+ public void testFieldNodeCreation2() throws Exception
+ {
+ Field field = Pojo3.class.getDeclaredFields()[0];
+ FieldNode fieldNode = new FieldNode(
+ new AdvisorMock("Pojo3Advisor", Pojo3.class), field);
+ assertFieldNode(field, fieldNode, "int intField");
+ }
+
+ public void testFieldNodeCreation3() throws Exception
+ {
+ Field field = Pojo3.class.getDeclaredFields()[1];
+ FieldNode fieldNode = new FieldNode(
+ new AdvisorMock("Pojo3Advisor", Pojo3.class), field);
+ assertFieldNode(field, fieldNode, "java.lang.String dumbField");
+ }
+
+ public void testFieldNodeCreation4() throws Exception
+ {
+ Field field = Pojo3.class.getDeclaredFields()[2];
+ FieldNode fieldNode = new FieldNode(
+ new AdvisorMock("Pojo3Advisor", Pojo3.class), field);
+ assertFieldNode(field, fieldNode, "long ANY_CONSTANT");
+ }
+
+ public void testFieldNodeCreation5() throws Exception
+ {
+ Field field = Pojo3.class.getDeclaredFields()[3];
+ FieldNode fieldNode = new FieldNode(
+ new AdvisorMock("Pojo3Advisor", Pojo3.class), field);
+ assertFieldNode(field, fieldNode, "java.util.Collection field");
+ }
+
+ public void testFieldNodeCreationWithMetaData1() throws Exception
+ {
+ Field field = Pojo1.class.getDeclaredFields()[0];
+ FieldNode fieldNode = new FieldNode(new AdvisorMock("Pojo1Advisor",
+ Pojo1.class, "one.package.with.Annotation", "markup.Ann",
+ "your.package.Secure"), field);
+ assertFieldNode(field, fieldNode, "java.lang.String field",
+ "java.lang.String @one.package.with.Annotation",
+ "java.lang.String @markup.Ann",
+ "java.lang.String @your.package.Secure");
+ }
+
+ public void testFieldNodeWithFieldRead() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Field field = Pojo1.class.getDeclaredFields()[0];
+ FieldNode fieldNode = new FieldNode(advisor, field);
+ assertFieldNode(field, fieldNode, "java.lang.String field");
+
+ FieldInfo info = new FieldInfo(advisor, field, 0, true);
+ fieldNode.setFieldRead(info);
+ assertTrue(fieldNode.hasFieldRead());
+ assertSame(info, fieldNode.getFieldRead());
+ assertFalse(fieldNode.hasFieldWrite());
+ }
+
+ public void testFieldNodeWithFieldWrite() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Field field = Pojo1.class.getDeclaredFields()[0];
+ FieldNode fieldNode = new FieldNode(advisor, field);
+ assertFieldNode(field, fieldNode, "java.lang.String field");
+
+ FieldInfo info = new FieldInfo(advisor, field, 0, false);
+ fieldNode.setFieldWrite(info);
+ assertFalse(fieldNode.hasFieldRead());
+ assertTrue(fieldNode.hasFieldWrite());
+ assertSame(info, fieldNode.getFieldWrite());
+ }
+
+ public void testFieldNodeWithField() throws Exception
+ {
+ Advisor advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ Field field = Pojo1.class.getDeclaredFields()[0];
+ FieldNode fieldNode = new FieldNode(advisor, field);
+ assertFieldNode(field, fieldNode, "java.lang.String field");
+
+ FieldInfo infoRead = new FieldInfo(advisor, field, 0, true);
+ FieldInfo infoWrite = new FieldInfo(advisor, field, 0, false);
+ fieldNode.setFieldRead(infoRead);
+ fieldNode.setFieldWrite(infoWrite);
+ assertTrue(fieldNode.hasFieldRead());
+ assertSame(infoRead, fieldNode.getFieldRead());
+ assertTrue(fieldNode.hasFieldWrite());
+ assertSame(infoWrite, fieldNode.getFieldWrite());
+ }
+
+ static void assertFieldNode(Field field, FieldNode fieldNode,
+ String defaultKey, String... expectedMetaDataKeys) throws Exception
+ {
+ assertSame(field, fieldNode.getField());
+ assertFalse(fieldNode.hasFieldRead());
+ assertNull(fieldNode.getFieldRead());
+ assertFalse(fieldNode.hasFieldWrite());
+ assertNull(fieldNode.getFieldWrite());
+ assertEquals(defaultKey, fieldNode.getIdentifierKey());
+ Collection<String> metaDataKeys = new ArrayList<String>();
+ fieldNode.loadMetaDataKeys(metaDataKeys);
+ Util.assertCollection(metaDataKeys, expectedMetaDataKeys);
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/GraphInsertionTest.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/GraphInsertionTest.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/GraphInsertionTest.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,654 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.ConByConInfo;
+import org.jboss.aop.ConByMethodInfo;
+import org.jboss.aop.ConstructionInfo;
+import org.jboss.aop.ConstructorInfo;
+import org.jboss.aop.Domain;
+import org.jboss.aop.FieldInfo;
+import org.jboss.aop.JoinPointInfo;
+import org.jboss.aop.MethodByConInfo;
+import org.jboss.aop.MethodByMethodInfo;
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.joinpoint.ConstructorCall;
+import org.jboss.aop.joinpoint.JoinPointRegistry;
+import org.jboss.aop.joinpoint.MethodCall;
+import org.jboss.aop.joinpoint.graph.tree.Tree;
+
+/**
+ * Tests the graph insertion mechanism on all implementors of {@code JoinPointGraph}.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class GraphInsertionTest extends TestCase
+{
+ private Advisor advisor = null;
+ private Advisor instanceAdvisor = null;
+ private Field infoRegistryField = null;
+ Tree<ClassNode> classTree = null;
+ private MainJoinPointGraph graph = null;
+ public void setUp() throws Exception
+ {
+ Field classTreeField = JoinPointGraphImpl.class.getDeclaredField("classTree");
+ classTreeField.setAccessible(true);
+ this.graph = MainJoinPointGraph.getInstance();
+ classTree = new Tree<ClassNode>();
+ classTreeField.set(this.graph, classTree);
+
+ advisor = new AdvisorMock("Pojo1Advisor", Pojo1.class);
+ instanceAdvisor = new InstanceAdvisorMock(advisor);
+ infoRegistryField = JoinPointInfo.class.getDeclaredField("registry");
+ infoRegistryField.setAccessible(true);
+ infoRegistryField.set(null, MainJoinPointGraph.getInstance());
+ }
+
+ public void tearDown() throws Exception
+ {
+ infoRegistryField.set(null, new JoinPointRegistry() {
+ public void register(ConstructorInfo info){}
+ public void register(ConstructionInfo info){}
+ public void register(FieldInfo info){}
+ public void register(MethodInfo info){}
+ public void register(ConByConInfo info){}
+ public void register(ConByMethodInfo info){}
+ public void register(MethodByConInfo info){}
+ public void register(MethodByMethodInfo info){}});
+ Field classTreeField = JoinPointGraphImpl.class.getDeclaredField("classTree");
+ classTreeField.setAccessible(true);
+ classTreeField.set(MainJoinPointGraph.getInstance(),
+ new Tree<StandardClassNode>());
+ }
+
+ public void testFieldReadInfo() throws Exception
+ {
+ // create joinpoint
+ Field field = Pojo1.class.getDeclaredField("field");
+ FieldInfo info = new FieldInfo(advisor, field, 0, true);
+ // check if it has been inserted to the graph correctly
+ assertFieldReadInfo(field, info);
+ }
+
+ public void testFieldReadInfoInstanceDomain() throws Exception
+ {
+ // create joinpoint
+ Field field = Pojo1.class.getDeclaredField("field");
+ FieldInfo info = new FieldInfo(instanceAdvisor, field, 0, true);
+ // check if it has been inserted to the graph correctly
+ assertFieldReadInfo(field, info);
+ }
+
+ public void testFieldReadInfoDouble() throws Exception
+ {
+ // create joinpoint
+ Field field = Pojo1.class.getDeclaredField("field");
+ FieldInfo info1 = new FieldInfo(advisor, field, 0, true);
+ FieldInfo info2 = new FieldInfo(instanceAdvisor, field, 0, true);
+ // check if it has been inserted to the graph correctly
+ assertFieldReadInfo(field, info1, info2);
+ }
+
+ public void testFieldWriteInfo() throws Exception
+ {
+ //create joinpoint
+ Field field = Pojo1.class.getDeclaredField("field");
+ FieldInfo info = new FieldInfo(advisor, field, 0, false);
+ // check if it has been inserted to the graph correctly
+ assertFieldWriteInfo(field, info);
+ }
+
+ public void testFieldWriteInfoInstanceDomain() throws Exception
+ {
+ //create joinpoint
+ Field field = Pojo1.class.getDeclaredField("field");
+ FieldInfo info = new FieldInfo(instanceAdvisor, field, 0, false);
+ // check if it has been inserted to the graph correctly
+ assertFieldWriteInfo(field, info);
+ }
+
+ public void testFieldWriteInfoDouble() throws Exception
+ {
+ //create joinpoint
+ Field field = Pojo1.class.getDeclaredField("field");
+ FieldInfo info1 = new FieldInfo(advisor, field, 0, false);
+ FieldInfo info2 = new FieldInfo(instanceAdvisor, field, 0, false);
+ // check if it has been inserted to the graph correctly
+ assertFieldWriteInfo(field, info1, info2);
+ }
+
+ public void testConstructionInfo() throws Exception
+ {
+ // create joinpoint
+ Constructor constructor = Pojo1.class.getDeclaredConstructors()[0];
+ ConstructionInfo info = new ConstructionInfo(advisor, constructor, 0);
+ // check if it has been inserted to the graph correctly
+ assertConstructionInfo(constructor, info);
+ }
+
+ public void testConstructionInfoInstanceDomain() throws Exception
+ {
+ // create joinpoint
+ Constructor constructor = Pojo1.class.getDeclaredConstructors()[0];
+ ConstructionInfo info = new ConstructionInfo(instanceAdvisor, constructor, 0);
+ // check if it has been inserted to the graph correctly
+ assertConstructionInfo(constructor, info);
+ }
+
+ public void testConstructionInfoDouble() throws Exception
+ {
+ // create joinpoint
+ Constructor constructor = Pojo1.class.getDeclaredConstructor();
+ ConstructionInfo info1 = new ConstructionInfo(advisor, constructor, 0);
+ ConstructionInfo info2 = new ConstructionInfo(instanceAdvisor, constructor, 0);
+ // check if it has been inserted to the graph correctly
+ assertConstructionInfo(constructor, info1, info2);
+ }
+
+ public void testConstructorInfo() throws Exception
+ {
+ // create joinpoint
+ Constructor constructor = Pojo1.class.getDeclaredConstructors()[1];
+ ConstructorInfo info = new ConstructorInfo(advisor, constructor, 0);
+ // check if it has been inserted to the graph correctly
+ assertConstructorInfo(constructor, info);
+ }
+
+ public void testConstructorInfoInstanceDomain() throws Exception
+ {
+ // create joinpoint
+ Constructor constructor = Pojo1.class.getDeclaredConstructors()[1];
+ ConstructorInfo info = new ConstructorInfo(instanceAdvisor, constructor, 0);
+ // check if it has been inserted to the graph correctly
+ assertConstructorInfo(constructor, info);
+ }
+
+ public void testConstructorInfoDouble() throws Exception
+ {
+ // create joinpoint
+ Constructor constructor = Pojo1.class.getDeclaredConstructor(int.class);
+ ConstructorInfo info1 = new ConstructorInfo(advisor, constructor, 0);
+ ConstructorInfo info2 = new ConstructorInfo(instanceAdvisor, constructor, 0);
+ // check if it has been inserted to the graph correctly
+ assertConstructorInfo(constructor, info1, info2);
+ }
+
+ public void testMethodInfo() throws Exception
+ {
+ // create joinpoint
+ Method method = Pojo1.class.getMethod("method1", String.class, String.class);
+ MethodInfo info = new MethodInfo(advisor, 0l, method, method);
+ // check if it has been inserted to the graph correctly
+ assertMethodInfo(method, info);
+ }
+
+ public void testMethodInfoInstanceDomain() throws Exception
+ {
+ // create joinpoint
+ Method method = Pojo1.class.getMethod("method1", String.class, String.class);
+ MethodInfo info = new MethodInfo(instanceAdvisor, 0l, method, method);
+ // check if it has been inserted to the graph correctly
+ assertMethodInfo(method, info);
+ }
+
+ public void testMethodInfoDouble() throws Exception
+ {
+ // create joinpoint
+ Method method = Pojo1.class.getMethod("method1", String.class, String.class);
+ MethodInfo info1 = new MethodInfo(advisor, 0l, method, method);
+ MethodInfo info2 = new MethodInfo(instanceAdvisor, 0l, method, method);
+ // check if it has been inserted to the graph correctly
+ assertMethodInfo(method, info1, info2);
+ }
+
+ public void testConByConInfo() throws Exception
+ {
+ // create joinpoint
+ Constructor callerConstructor = Pojo1.class.getDeclaredConstructor();
+ Constructor calleeConstructor = Pojo1.class.getDeclaredConstructor(int.class);
+ ConByConInfo info = new ConByConInfo(advisor, Pojo1.class, Pojo1.class, 0,
+ calleeConstructor, 0l, null, null);
+ // check if it has been inserted to the graph correctly
+ assertConstructorCallInfo(Pojo1.class, BehaviorType.CONSTRUCTOR, callerConstructor,
+ Pojo1.class, calleeConstructor, info);
+ }
+
+ public void testConByConInfoInstanceDomain() throws Exception
+ {
+ advisor = new AdvisorMock("Pojo4Advisor", Pojo4.class);
+ instanceAdvisor = new InstanceAdvisorMock(advisor);
+ // create joinpoint
+ Constructor callerConstructor = Pojo4.class.getDeclaredConstructor();
+ Constructor calleeConstructor = Pojo5.class.getDeclaredConstructor(
+ Collection.class);
+ ConByConInfo info = new ConByConInfo(instanceAdvisor, Pojo5.class, Pojo4.class,
+ 0, calleeConstructor, 0l, null, null);
+ // check if it has been inserted to the graph correctly
+ assertConstructorCallInfo(Pojo4.class, BehaviorType.CONSTRUCTOR, callerConstructor,
+ Pojo5.class, calleeConstructor, info);
+ }
+
+ public void testConByConInfoDouble() throws Exception
+ {
+ // create joinpoint
+ Constructor callerConstructor = Pojo1.class.getDeclaredConstructor();
+ Constructor calleeConstructor = Pojo1.class.getDeclaredConstructor(int.class);
+ ConByConInfo info1 = new ConByConInfo(advisor, Pojo1.class, Pojo1.class, 0,
+ calleeConstructor, 0l, null, null);
+ ConByConInfo info2 = new ConByConInfo(instanceAdvisor, Pojo1.class,
+ Pojo1.class, 0, calleeConstructor, 0l, null, null);
+ // check if it has been inserted to the graph correctly
+ assertConstructorCallInfo(Pojo1.class, BehaviorType.CONSTRUCTOR,
+ callerConstructor, Pojo1.class, calleeConstructor, info1, info2);
+ }
+
+ public void testMethodByConInfo() throws Exception
+ {
+ // create joinpoint
+ Constructor callerConstructor = Pojo1.class.getDeclaredConstructor();
+ Method calleeMethod = Pojo1.class.getDeclaredMethod("privateMethod");
+ MethodByConInfo info = new MethodByConInfo(advisor, Pojo1.class, Pojo1.class,
+ 0, calleeMethod, 0l, null);
+ // check if it has been inserted to the graph correctly
+ assertMethodCallInfo(Pojo1.class, BehaviorType.CONSTRUCTOR, callerConstructor,
+ Pojo1.class, calleeMethod, info);
+ }
+
+ public void testMethodByConInfoInstanceDomain() throws Exception
+ {
+ advisor = new AdvisorMock("Pojo4Advisor", Pojo4.class);
+ instanceAdvisor = new InstanceAdvisorMock(advisor);
+ // create joinpoint
+ Constructor callerConstructor = Pojo4.class.getDeclaredConstructor(int.class);
+ Method calleeMethod = Pojo5.class.getDeclaredMethod("calledByCon");
+ MethodByConInfo info = new MethodByConInfo(instanceAdvisor, Pojo5.class, Pojo4.class,
+ 1, calleeMethod, 0l, null);
+ // check if it has been inserted to the graph correctly
+ assertMethodCallInfo(Pojo4.class, BehaviorType.CONSTRUCTOR, callerConstructor,
+ Pojo5.class, calleeMethod, info);
+ }
+
+ public void testMethodByConInfoDouble() throws Exception
+ {
+ // create joinpoint
+ Constructor callerConstructor = Pojo1.class.getDeclaredConstructor();
+ Method calleeMethod = Pojo1.class.getDeclaredMethod("privateMethod");
+ MethodByConInfo info1 = new MethodByConInfo(advisor, Pojo1.class, Pojo1.class,
+ 0, calleeMethod, 0l, null);
+ MethodByConInfo info2 = new MethodByConInfo(instanceAdvisor, Pojo1.class,
+ Pojo1.class, 0, calleeMethod, 0l, null);
+ // check if it has been inserted to the graph correctly
+ assertMethodCallInfo(Pojo1.class, BehaviorType.CONSTRUCTOR, callerConstructor,
+ Pojo1.class, calleeMethod, info1, info2);
+ }
+
+ public void testConByMethodInfo() throws Exception
+ {
+ // created joinpoint
+ Method callerMethod = Pojo1.class.getMethod("method1", String.class, String.class);
+ Constructor calleeConstructor = Pojo1.class.getDeclaredConstructor(int.class);
+ ConByMethodInfo info = new ConByMethodInfo(advisor, Pojo1.class, callerMethod,
+ 0l, calleeConstructor, 0l, null, null);
+ // check if it has been inserted to the graph correctly
+ assertConstructorCallInfo(Pojo1.class, BehaviorType.METHOD, callerMethod, Pojo1.class,
+ calleeConstructor, info);
+ }
+
+ public void testConByMethodInfoInstanceDomain() throws Exception
+ {
+ advisor = new AdvisorMock("Pojo4Advisor", Pojo4.class);
+ instanceAdvisor = new InstanceAdvisorMock(advisor);
+ // created joinpoint
+ Method callerMethod = Pojo4.class.getMethod("callConstructor");
+ Constructor calleeConstructor = Pojo5.class.getDeclaredConstructor(Pojo3.class);
+ ConByMethodInfo info = new ConByMethodInfo(instanceAdvisor, Pojo5.class,
+ callerMethod, 0l, calleeConstructor, 0l, null, null);
+ // check if it has been inserted to the graph correctly
+ assertConstructorCallInfo(Pojo4.class, BehaviorType.METHOD, callerMethod, Pojo5.class,
+ calleeConstructor, info);
+ }
+
+ public void testConByMethodInfoDouble() throws Exception
+ {
+ // created joinpoint
+ Method callerMethod = Pojo1.class.getMethod("method1", String.class, String.class);
+ Constructor calleeConstructor = Pojo1.class.getDeclaredConstructor(int.class);
+ ConByMethodInfo info1 = new ConByMethodInfo(advisor, Pojo1.class, callerMethod,
+ 0l, calleeConstructor, 0l, null, null);
+ ConByMethodInfo info2 = new ConByMethodInfo(instanceAdvisor, Pojo1.class,
+ callerMethod, 0l, calleeConstructor, 0l, null, null);
+ // check if it has been inserted to the graph correctly
+ assertConstructorCallInfo(Pojo1.class, BehaviorType.METHOD, callerMethod, Pojo1.class,
+ calleeConstructor, info1, info2);
+ }
+
+ public void testMethodbyMethodInfo() throws Exception
+ {
+ // created joinpoint
+ Method callerMethod = Pojo1.class.getMethod("method1", String.class, String.class);
+ Method calleeMethod = Pojo1.class.getDeclaredMethod("privateMethod");
+ MethodByMethodInfo info = new MethodByMethodInfo(advisor, Pojo1.class,
+ calleeMethod, callerMethod, 0l, 0l, null);
+ // check if it has been inserted to the graph correctly
+ assertMethodCallInfo(Pojo1.class, BehaviorType.METHOD, callerMethod, Pojo1.class,
+ calleeMethod, info);
+ }
+
+ public void testMethodbyMethodInfoInstanceDomain() throws Exception
+ {
+ advisor = new AdvisorMock("Pojo4Advisor", Pojo4.class);
+ instanceAdvisor = new InstanceAdvisorMock(advisor);
+ // created joinpoint
+ Method callerMethod = Pojo4.class.getMethod("callMethod");
+ Method calleeMethod = Pojo5.class.getDeclaredMethod("calledByMethod");
+ MethodByMethodInfo info = new MethodByMethodInfo(instanceAdvisor, Pojo5.class,
+ calleeMethod, callerMethod, 0l, 0l, null);
+ // check if it has been inserted to the graph correctly
+ assertMethodCallInfo(Pojo4.class, BehaviorType.METHOD, callerMethod, Pojo5.class,
+ calleeMethod, info);
+ }
+
+ public void testMethodbyMethodInfoDouble() throws Exception
+ {
+ // created joinpoint
+ Method callerMethod = Pojo1.class.getMethod("method1", String.class, String.class);
+ Method calleeMethod = Pojo1.class.getDeclaredMethod("privateMethod");
+ MethodByMethodInfo info1 = new MethodByMethodInfo(advisor, Pojo1.class,
+ calleeMethod, callerMethod, 0l, 0l, null);
+ MethodByMethodInfo info2 = new MethodByMethodInfo(instanceAdvisor, Pojo1.class,
+ calleeMethod, callerMethod, 0l, 0l, null);
+ // check if it has been inserted to the graph correctly
+ assertMethodCallInfo(Pojo1.class, BehaviorType.METHOD, callerMethod, Pojo1.class,
+ calleeMethod, info1, info2);
+ }
+
+ public void testAllPojo1Infos() throws Exception
+ {
+ this.testFieldReadInfoDouble();
+ this.testFieldWriteInfoDouble();
+ this.testConstructionInfoDouble();
+ this.testConstructorInfoDouble();
+ this.testMethodInfoDouble();
+ this.testConByConInfoDouble();
+ this.testMethodByConInfoDouble();
+ this.testConByMethodInfoDouble();
+ this.testMethodbyMethodInfoDouble();
+ }
+
+ // test all infos being added at the same time
+ public void testAllInfos() throws Exception
+ {
+ this.testAllPojo1Infos();
+ // test those later, since they change the value of the advisor/instanceAdvisor
+ this.testConByConInfoInstanceDomain();
+ this.testMethodByConInfoInstanceDomain();
+ this.testConByMethodInfoInstanceDomain();
+ this.testMethodbyMethodInfoInstanceDomain();
+ }
+
+ public void testDomainGraph() throws Exception
+ {
+ Domain domain = new Domain(AspectManager.instance(), "domainName", true);
+ JoinPointGraph domainGraph = JoinPointGraphFactory.create(domain);
+ assertTrue(domainGraph instanceof DomainJoinPointGraph);
+ assertSame(MainJoinPointGraph.getInstance().classTree,
+ ((DomainJoinPointGraph) domainGraph).classTree);
+ }
+
+ public void testUnitaryDomainGraph() throws Exception
+ {
+ this.testAllPojo1Infos();
+ JoinPointGraph domainGraph = JoinPointGraphFactory.create(
+ (Domain) instanceAdvisor.getManager());
+ assertTrue(domainGraph instanceof UnitaryJoinPointGraph);
+ UnitaryJoinPointGraph unitaryGraph = (UnitaryJoinPointGraph) domainGraph;
+ ClassNode objectNode = unitaryGraph.classTree.searchValue(
+ ClassNode.getIdentifierKey(Object.class));
+ ClassNode pojoNode = unitaryGraph.classTree.searchValue(
+ ClassNode.getIdentifierKey(Pojo1.class));
+ Util.assertCollection(unitaryGraph.classTree.search("*"), objectNode, pojoNode);
+ assertUnitaryDomainSuperClassNode(objectNode, pojoNode);
+ Util.assertCollection(pojoNode.getSubtypes());
+ Collection<FieldNode> fieldsFound = pojoNode.searchFields(
+ FieldNode.getIdentifierKey(Pojo1.class.getDeclaredField("field")));
+ assertEquals(1, fieldsFound.size());
+ FieldNode fieldNode = fieldsFound.iterator().next();
+ Util.assertCollection(pojoNode.searchFields("*"), fieldNode);
+ assertTrue(fieldNode.hasFieldRead());
+ assertTrue(fieldNode.hasFieldWrite());
+ Collection<JoinPointInfo> temp = new HashSet<JoinPointInfo>();
+ BehaviorNode cons1 = assertBehaviorNode(pojoNode,
+ Pojo1.class.getDeclaredConstructor(), true, false, 2, temp);
+ BehaviorNode cons2 = assertBehaviorNode(pojoNode,
+ Pojo1.class.getDeclaredConstructor(int.class), false, true, 0, temp);
+ BehaviorNode method = assertBehaviorNode(pojoNode,
+ Pojo1.class.getDeclaredMethod("method1", String.class, String.class),
+ false, true, 2, temp);
+ Util.assertCollection(pojoNode.searchBehaviors("*"), cons1, cons2, method);
+ }
+
+ public void testUnitaryDomainGraph2() throws Exception
+ {
+ this.testAllInfos();
+ JoinPointGraph domainGraph = JoinPointGraphFactory.create(
+ (Domain) instanceAdvisor.getManager());
+ assertTrue(domainGraph instanceof UnitaryJoinPointGraph);
+ UnitaryJoinPointGraph unitaryGraph = (UnitaryJoinPointGraph) domainGraph;
+ ClassNode objectNode = unitaryGraph.classTree.searchValue(
+ ClassNode.getIdentifierKey(Object.class));
+ ClassNode pojoNode = unitaryGraph.classTree.searchValue(
+ ClassNode.getIdentifierKey(Pojo4.class));
+ Util.assertCollection(unitaryGraph.classTree.search("*"), objectNode, pojoNode);
+ assertUnitaryDomainSuperClassNode(objectNode, pojoNode);
+ Util.assertCollection(pojoNode.getSubtypes());
+ Util.assertCollection(pojoNode.searchFields("*"));
+ Collection<JoinPointInfo> temp = new HashSet<JoinPointInfo>();
+ // caller1,2 and 3 won't be present because each test method creates a
+ // new instance domain
+ /*BehaviorNode caller1 = assertBehaviorNode(pojoNode,
+ Pojo4.class.getDeclaredConstructor(), false, false, 1, temp);
+ BehaviorNode caller2 = assertBehaviorNode(pojoNode,
+ Pojo4.class.getDeclaredConstructor(int.class), false, false, 1, temp);*/
+ /*BehaviorNode caller3 = assertBehaviorNode(pojoNode,
+ Pojo4.class.getDeclaredMethod("callConstructor"), false, false, 1, temp);*/
+ BehaviorNode caller4 = assertBehaviorNode(pojoNode,
+ Pojo4.class.getDeclaredMethod("callMethod"), false, false, 1, temp);
+ Util.assertCollection(pojoNode.searchBehaviors("*"), caller4);
+ }
+
+ private void assertFieldReadInfo(Field field, FieldInfo... infos)
+ {
+ Collection<FieldInfo> infoCol = new HashSet<FieldInfo> (Arrays.asList(infos));
+ for (FieldNode fieldNode: assertFieldNodes(field, infos))
+ {
+ assertTrue(fieldNode.hasFieldRead());
+ assertTrue(infoCol.remove(fieldNode.getFieldRead()));
+ }
+ }
+
+ private void assertFieldWriteInfo(Field field, FieldInfo... infos)
+ {
+ Collection<FieldInfo> infoCol = new HashSet<FieldInfo> (Arrays.asList(infos));
+ for (FieldNode fieldNode: assertFieldNodes(field, infos))
+ {
+ assertTrue(fieldNode.hasFieldWrite());
+ assertTrue(infoCol.remove(fieldNode.getFieldWrite()));
+ }
+ }
+
+ private Collection<FieldNode> assertFieldNodes(Field field, FieldInfo... infos)
+ {
+ ClassNode classNode = classTree.searchValue(Pojo1.class.getName());
+ assertNotNull(classNode);
+ Collection<FieldNode> fieldNodesFound = classNode.searchFields(
+ FieldNode.getIdentifierKey(field));
+ assertEquals(infos.length, fieldNodesFound.size());
+ for (FieldNode fieldNode: fieldNodesFound)
+ {
+ assertEquals(field, fieldNode.getField());
+ }
+ return fieldNodesFound;
+ }
+
+ private void assertConstructionInfo(Constructor constructor,
+ ConstructionInfo... infos)
+ {
+ ClassNode classNode = classTree.searchValue(Pojo1.class.getName());
+ assertNotNull(classNode);
+ Collection<BehaviorNode> behaviorNodesFound = classNode.searchBehaviors(
+ BehaviorNode.getIdentifierKey(constructor));
+ assertEquals(infos.length, behaviorNodesFound.size());
+ Collection<ConstructionInfo> infoCol = new HashSet<ConstructionInfo>
+ (Arrays.asList(infos));
+ for (BehaviorNode behaviorNode: behaviorNodesFound)
+ {
+ assertEquals(constructor, behaviorNode.getBehavior());
+ assertTrue(behaviorNode.hasConstruction());
+ assertTrue(infoCol.remove(behaviorNode.getConstruction()));
+ assertFalse(behaviorNode.hasExecution());
+ }
+ }
+
+ private void assertConstructorInfo(Constructor constructor, ConstructorInfo... infos)
+ {
+ assertExecutionInfo(BehaviorType.CONSTRUCTOR, constructor, (JoinPointInfo[]) infos);
+ }
+
+ private void assertMethodInfo(Method method, MethodInfo... infos)
+ {
+ assertExecutionInfo(BehaviorType.METHOD, method, (JoinPointInfo[]) infos);
+ }
+
+ private void assertExecutionInfo(BehaviorType behaviorType, Member behavior,
+ JoinPointInfo... infos)
+ {
+ ClassNode classNode = classTree.searchValue(Pojo1.class.getName());
+ assertNotNull(classNode);
+ Collection<BehaviorNode> behaviorNodesFound = classNode.searchBehaviors(
+ behaviorType.getDefaultKey(behavior));
+ assertEquals(infos.length, behaviorNodesFound.size());
+ Collection<JoinPointInfo> infoCol = new HashSet<JoinPointInfo>(
+ Arrays.asList(infos));
+ for (BehaviorNode behaviorNode: behaviorNodesFound)
+ {
+ assertEquals(behavior, behaviorNode.getBehavior());
+ assertTrue(behaviorNode.hasExecution());
+ assertTrue(infoCol.remove(behaviorNode.getExecution()));
+ }
+ }
+
+ private <T extends JoinPointInfo & ConstructorCall>
+ void assertConstructorCallInfo(Class<?> callerClass,
+ BehaviorType callerType, Member caller, Class<?> calleeClass,
+ Constructor calleeConstructor, T... infos) throws Exception
+ {
+ assertCallInfo(callerClass, callerType, caller, calleeClass,
+ BehaviorType.CONSTRUCTOR, calleeConstructor, infos);
+ }
+
+ private <T extends JoinPointInfo & MethodCall> void assertMethodCallInfo(
+ Class<?> callerClass, BehaviorType callerType, Member caller,
+ Class<?> calleeClass, Method calleeMethod, T... infos) throws Exception
+ {
+ assertCallInfo(callerClass, callerType, caller, calleeClass,
+ BehaviorType.METHOD, calleeMethod, infos);
+ }
+
+ private <T extends JoinPointInfo> void assertCallInfo(Class<?> callerClass,
+ BehaviorType callerType, Member caller, Class<?> calleeClass,
+ BehaviorType calleeType, Member callee, T... infos) throws Exception
+ {
+ ClassNode classNode = classTree.searchValue(ClassNode.
+ getIdentifierKey(callerClass));
+ assertNotNull(classNode);
+ Collection<BehaviorNode> behaviorNodesFound = classNode.
+ searchBehaviors(callerType.getDefaultKey(caller));
+ assertEquals(infos.length, behaviorNodesFound.size());
+ Collection<JoinPointInfo> infoCol = new HashSet<JoinPointInfo>
+ (Arrays.asList(infos));
+ Collection<JoinPointInfo> callees = new HashSet<JoinPointInfo>();
+ for (BehaviorNode behaviorNode: behaviorNodesFound)
+ {
+ assertEquals(caller, behaviorNode.getBehavior());
+ behaviorNode.searchCallees(ClassNode.getIdentifierKey(calleeClass) + '.' +
+ calleeType.getDefaultKey(callee), callees);
+ if (callees.isEmpty())
+ {
+ continue;
+ }
+ assertTrue(infoCol.remove(callees.iterator().next()));
+ callees.clear();
+ }
+ assertTrue(infoCol.isEmpty());
+ }
+ private BehaviorNode assertBehaviorNode(ClassNode classNode,
+ Constructor constructor, boolean construction, boolean execution, int callees,
+ Collection<JoinPointInfo> temp)
+ {
+ return assertBehaviorNode(classNode, BehaviorNode.getIdentifierKey(constructor),
+ construction, execution, callees, temp);
+ }
+
+ private BehaviorNode assertBehaviorNode(ClassNode classNode,
+ Method method, boolean construction, boolean execution, int callees,
+ Collection<JoinPointInfo> temp)
+ {
+ return assertBehaviorNode(classNode, BehaviorNode.getIdentifierKey(method),
+ construction, execution, callees, temp);
+ }
+
+ private BehaviorNode assertBehaviorNode(ClassNode classNode,
+ String idKey, boolean construction, boolean execution, int callees,
+ Collection<JoinPointInfo> temp)
+ {
+ Collection<BehaviorNode> behaviorsFound = classNode.searchBehaviors(idKey);
+ assertEquals(1, behaviorsFound.size());
+ BehaviorNode behaviorNode = behaviorsFound.iterator().next();
+ assertEquals(construction, behaviorNode.hasConstruction());
+ assertEquals(execution, behaviorNode.hasExecution());
+ behaviorNode.searchCallees("*", temp);
+ assertEquals(callees, temp.size());
+ temp.clear();
+ return behaviorNode;
+ }
+
+ private void assertUnitaryDomainSuperClassNode(ClassNode superClassNode,
+ ClassNode classNode)
+ {
+ assertTrue(superClassNode instanceof UnitaryDomainSuperClassNode);
+ Util.assertCollection(superClassNode.getSubtypes(), classNode);
+ Util.assertCollection(superClassNode.searchFields("*"));
+ Util.assertCollection(superClassNode.searchBehaviors("*"));
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/InstanceAdvisorMock.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/InstanceAdvisorMock.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/InstanceAdvisorMock.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import org.jboss.aop.Advised;
+import org.jboss.aop.Advisor;
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.Domain;
+import org.jboss.aop.InstanceAdvisor;
+import org.jboss.aop.InstanceDomain;
+import org.jboss.aop.advice.AspectDefinition;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Joinpoint;
+import org.jboss.aop.metadata.ClassMetaDataBinding;
+import org.jboss.aop.metadata.SimpleMetaData;
+
+/**
+ * Instance advisor mock for testing.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class InstanceAdvisorMock extends Advisor implements InstanceAdvisor
+{
+ private Advised instance;
+
+ public InstanceAdvisorMock(final Advisor advisor)
+ {
+ super("anyName", new InstanceDomain(AspectManager.instance(), "anyName", true));
+ ((InstanceDomain) getManager()).setAdvisor(this);
+ super.clazz = advisor.getClazz();
+ super.constructors = clazz.getDeclaredConstructors();
+ this.instance = new Advised()
+ {
+ public Advisor _getAdvisor()
+ {
+ return advisor;
+ }
+
+ public InstanceAdvisor _getInstanceAdvisor()
+ {
+ return InstanceAdvisorMock.this;
+ }
+
+ public void _setInstanceAdvisor(InstanceAdvisor newAdvisor)
+ {
+ throw new RuntimeException ("This method must not be called.");
+ }
+ };
+ }
+
+ public Object getInstance()
+ {
+ return this.instance;
+ }
+
+ public void insertInterceptor(Interceptor interceptor){}
+ public void insertInterceptor(int index, Interceptor interceptor){}
+ public void insertInterceptorStack(String stackName){}
+ public void appendInterceptor(Interceptor interceptor){}
+ public void appendInterceptor(int index, Interceptor interceptor){}
+ public void appendInterceptorStack(String stackName){}
+ public void removeInterceptor(String name){}
+ public void removeInterceptorStack(String name){}
+
+ public Interceptor[] getInterceptors()
+ {
+ return null;
+ }
+
+ public Interceptor[] getInterceptors(Interceptor[] baseChain)
+ {
+ return null;
+ }
+
+ public SimpleMetaData getMetaData()
+ {
+ return null;
+ }
+
+ public Object getPerInstanceAspect(String aspectName)
+ {
+ return null;
+ }
+
+ public Object getPerInstanceAspect(AspectDefinition def)
+ {
+ return null;
+ }
+
+ public Object getPerInstanceJoinpointAspect(Joinpoint joinpoint, AspectDefinition def)
+ {
+ return null;
+ }
+
+ public boolean hasInterceptors()
+ {
+ return false;
+ }
+
+ public Domain getDomain()
+ {
+ return null;
+ }
+
+ @Override
+ public void addClassMetaData(ClassMetaDataBinding data){}
+
+ @Override
+ protected void rebuildInterceptors(){}
+
+ @Override
+ public void removeClassMetaData(ClassMetaDataBinding data){}
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo1.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo1.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo1.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+/**
+ * Test scenario.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class Pojo1
+{
+ public static String field = "";
+
+ private Pojo1()
+ {
+ (new Pojo1(0)).privateMethod();
+ }
+
+ public Pojo1(int value) {}
+
+ public void method1(String arg1, String arg2)
+ {
+ (new Pojo1(1)).privateMethod();
+ }
+
+ private void privateMethod(){}
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo2.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo2.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo2.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.util.Collection;
+
+/**
+ * Test scenario.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+ at Deprecated
+public class Pojo2
+{
+ private Pojo3 pojo3;
+
+ public Pojo2(Pojo3 pojo3)
+ {
+ this.pojo3 = pojo3;
+ }
+
+ public Pojo2(){}
+
+ public Pojo2(String arg){}
+
+ public static final Pojo2 getPojo2()
+ {
+ return null;
+ }
+
+ public Pojo1 doSomething(int arg1, long arg2, Collection<Pojo1> arg3)
+ {
+ return null;
+ }
+
+ public Pojo3 getPojo3()
+ {
+ return this.pojo3;
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo3.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo3.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo3.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.util.Collection;
+
+/**
+ * Test scenario.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+ at DummyAnnotation
+ at SuppressWarnings("deprecation")
+public class Pojo3 extends Pojo2
+{
+ public int intField;
+ @SuppressWarnings(value="unused")
+ private static String dumbField;
+ public static final long ANY_CONSTANT = 0l;
+ protected Collection<String> field;
+
+ public Pojo3(){}
+ public Pojo3(int arg1, long arg2) {}
+ public Pojo3(int arg1, String arg3) {}
+
+ public void voidMethod() throws Exception{}
+ public String stringMethod() throws ArrayIndexOutOfBoundsException, NullPointerException
+ {
+ return "stringMethod";
+ }
+
+ public void someMethod(int arg1, long arg2) {}
+ public String someMethod(String arg1, long arg2)
+ {
+ return "someMethod(" + arg1 + ", " + arg2 + ")";
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo4.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo4.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo4.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.util.Collections;
+
+/**
+ * Test scenario.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class Pojo4
+{
+ public Pojo4()
+ {
+ new Pojo5(Collections.EMPTY_LIST);
+ }
+
+ public Pojo4(int arg)
+ {
+ new Pojo5().calledByCon();
+ }
+
+ @SuppressWarnings("deprecation")
+ public void callConstructor()
+ {
+ new Pojo5(new Pojo3());
+ }
+
+ public void callMethod()
+ {
+ new Pojo5().calledByMethod();
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo5.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo5.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Pojo5.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.util.Collection;
+
+import org.jboss.aop.Aspect;
+import org.jboss.aop.Bind;
+import org.jboss.aop.Mixin;
+
+/**
+ * Test scenario.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+ at Aspect
+public class Pojo5
+{
+ public Pojo5() {}
+
+ @AnyAnnotation
+ public Pojo5(Collection arg) {}
+
+ @Deprecated
+ public Pojo5(Pojo3 pojo3) {}
+
+ @Bind(pointcut="all(Pojo5)")
+ public void calledByCon(){}
+
+ @Mixin(interfaces={MetaDataKeyLoader.class})
+ public void calledByMethod() {}
+}
+
+ at interface AnyAnnotation {}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Util.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Util.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/Util.java 2008-06-30 00:44:49 UTC (rev 75188)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import junit.framework.TestCase;
+
+/**
+ * Utility class for tests.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class Util
+{
+
+ /**
+ * Asserts that {@code collection} contains all {@code contents}.
+ *
+ * @param <T> type of contents
+ * @param collection a collection
+ * @param contents the contents of {@code collection}
+ */
+ public static <T> void assertCollection(Collection<T> collection, T... contents)
+ {
+ TestCase.assertEquals(contents.length, collection.size());
+ if (contents.length == 1)
+ {
+ TestCase.assertTrue(collection.contains(contents[0]));
+ }
+ else if (contents.length > 0)
+ {
+ Collection<T> expectedNodes = new HashSet<T>();
+ for (T node: contents)
+ {
+ expectedNodes.add(node);
+ }
+ TestCase.assertTrue("Collection " + collection +
+ "does not contain all expected nodes",
+ collection.containsAll(expectedNodes));
+ }
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list