[jboss-cvs] JBossAS SVN: r68680 - in projects/microcontainer/trunk/container/src: tests/org/jboss/test/metadata and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jan 8 11:59:33 EST 2008
Author: alesj
Date: 2008-01-08 11:59:33 -0500 (Tue, 08 Jan 2008)
New Revision: 68680
Added:
projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/SignatureMetaDataTest.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/loader/memory/test/MemoryLoaderComponentMutableUnitTestCase.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/shared/support/SignatureTester.java
Modified:
projects/microcontainer/trunk/container/src/main/org/jboss/metadata/spi/signature/MethodParametersSignature.java
Log:
JBMICROCONT-222.
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/metadata/spi/signature/MethodParametersSignature.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/metadata/spi/signature/MethodParametersSignature.java 2008-01-08 16:29:00 UTC (rev 68679)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/metadata/spi/signature/MethodParametersSignature.java 2008-01-08 16:59:33 UTC (rev 68680)
@@ -23,6 +23,8 @@
import java.lang.reflect.Method;
+import org.jboss.reflect.spi.MethodInfo;
+
/**
* Method parameters Signature.
*
@@ -76,6 +78,19 @@
}
/**
+ * Create a new Signature.
+ *
+ * @param method the method info
+ * @param param the parameter number
+ */
+ public MethodParametersSignature(MethodInfo method, int param)
+ {
+ super(method.getName(), convertParameterTypes(method.getParameterTypes()));
+ this.param = param;
+ checkParam();
+ }
+
+ /**
* Get the param.
*
* @return the param.
Added: projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/SignatureMetaDataTest.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/SignatureMetaDataTest.java (rev 0)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/SignatureMetaDataTest.java 2008-01-08 16:59:33 UTC (rev 68680)
@@ -0,0 +1,228 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.test.metadata;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+import org.jboss.config.plugins.property.PropertyConfiguration;
+import org.jboss.config.spi.Configuration;
+import org.jboss.metadata.spi.signature.ConstructorSignature;
+import org.jboss.metadata.spi.signature.FieldSignature;
+import org.jboss.metadata.spi.signature.MethodParametersSignature;
+import org.jboss.metadata.spi.signature.MethodSignature;
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.ConstructorInfo;
+import org.jboss.reflect.spi.FieldInfo;
+import org.jboss.reflect.spi.MethodInfo;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.test.metadata.shared.support.SignatureTester;
+
+/**
+ * SignatureMetaDataTest.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class SignatureMetaDataTest extends AbstractMetaDataTest
+{
+ private static final Configuration configuration = new PropertyConfiguration();
+
+ public SignatureMetaDataTest(String name)
+ {
+ super(name);
+ }
+
+ protected ConstructorSignature getStringParameterConstructorSignature()
+ {
+ return new ConstructorSignature(new String[]{Calendar.class.getName()});
+ }
+
+ protected ConstructorSignature getDefaultConstructorSignature()
+ {
+ return new ConstructorSignature();
+ }
+
+ protected ConstructorSignature getClassParameterConstructorSignature() throws Exception
+ {
+ return new ConstructorSignature(getConstructor());
+ }
+
+ protected ConstructorSignature getClassInfoParameterConstructorSignature() throws Exception
+ {
+ return new ConstructorSignature(getConstructorInfo());
+ }
+
+ protected MethodSignature getStringMethodSignature() throws Exception
+ {
+ return new MethodSignature("applyTimeZone", new String[]{Calendar.class.getName(), TimeZone.class.getName()});
+ }
+
+ protected MethodSignature getClassMethodSignature() throws Exception
+ {
+ return new MethodSignature("applyTimeZone", Calendar.class, TimeZone.class);
+ }
+
+ protected MethodSignature getMethodSignature() throws Exception
+ {
+ return new MethodSignature(getMethod());
+ }
+
+ protected MethodSignature getMethodInfoSignature() throws Exception
+ {
+ return new MethodSignature(getMethodInfo());
+ }
+
+ protected FieldSignature getStringFieldSignature()
+ {
+ return new FieldSignature("calendar");
+ }
+
+ protected FieldSignature getFieldSignature() throws Exception
+ {
+ return new FieldSignature(getField());
+ }
+
+ protected FieldSignature getFieldInfoSignature()
+ {
+ return new FieldSignature(getFieldInfo());
+ }
+
+ protected MethodParametersSignature getStringMethodParametersSignature()
+ {
+ return new MethodParametersSignature("applyTimeZone", new String[]{Calendar.class.getName(), TimeZone.class.getName()}, 0);
+ }
+
+ protected MethodParametersSignature getClassMethodParametersSignature() throws Exception
+ {
+ return new MethodParametersSignature("applyTimeZone", 0, Calendar.class, TimeZone.class);
+ }
+
+ protected MethodParametersSignature getMethodParametersSignature() throws Exception
+ {
+ return new MethodParametersSignature(getMethod(), 0);
+ }
+
+ protected MethodParametersSignature getMethodInfoParametersSignature() throws Exception
+ {
+ return new MethodParametersSignature(getMethodInfo(), 0);
+ }
+
+ protected Constructor getConstructor() throws Exception
+ {
+ return SignatureTester.class.getDeclaredConstructor(Calendar.class);
+ }
+
+ protected ConstructorInfo getConstructorInfo()
+ {
+ ClassInfo classInfo = configuration.getClassInfo(SignatureTester.class);
+ TypeInfo calendarTypeInfo = configuration.getTypeInfo(Calendar.class);
+ return classInfo.getDeclaredConstructor(new TypeInfo[]{calendarTypeInfo});
+ }
+
+ protected Method getMethod() throws Exception
+ {
+ return SignatureTester.class.getDeclaredMethod("applyTimeZone", Calendar.class, TimeZone.class);
+ }
+
+ protected MethodInfo getMethodInfo()
+ {
+ ClassInfo classInfo = configuration.getClassInfo(SignatureTester.class);
+ TypeInfo calendarTypeInfo = configuration.getTypeInfo(Calendar.class);
+ TypeInfo timeZoneTypeInfo = configuration.getTypeInfo(TimeZone.class);
+ return classInfo.getDeclaredMethod("applyTimeZone", new TypeInfo[]{calendarTypeInfo, timeZoneTypeInfo});
+ }
+
+ protected Field getField() throws Exception
+ {
+ return SignatureTester.class.getDeclaredField("calendar");
+ }
+
+ protected FieldInfo getFieldInfo()
+ {
+ ClassInfo classInfo = configuration.getClassInfo(SignatureTester.class);
+ return classInfo.getDeclaredField("calendar");
+ }
+
+ protected Signature[] getSignatures() throws Exception
+ {
+ Signature[] signatures = new Signature[15];
+ signatures[0] = getDefaultConstructorSignature();
+ signatures[1] = getStringParameterConstructorSignature();
+ signatures[2] = getClassParameterConstructorSignature();
+ signatures[3] = getClassInfoParameterConstructorSignature();
+ signatures[4] = getStringMethodSignature();
+ signatures[5] = getClassMethodSignature();
+ signatures[6] = getMethodSignature();
+ signatures[7] = getMethodInfoSignature();
+ signatures[8] = getStringFieldSignature();
+ signatures[9] = getFieldSignature();
+ signatures[10] = getFieldInfoSignature();
+ signatures[11] = getClassMethodParametersSignature();
+ signatures[12] = getStringMethodParametersSignature();
+ signatures[13] = getMethodParametersSignature();
+ signatures[14] = getMethodInfoParametersSignature();
+ return signatures;
+ }
+
+ protected ConstructorSignature[] getConstructorSignatures() throws Exception
+ {
+ ConstructorSignature[] signatures = new ConstructorSignature[4];
+ signatures[0] = getDefaultConstructorSignature();
+ signatures[1] = getStringParameterConstructorSignature();
+ signatures[2] = getClassParameterConstructorSignature();
+ signatures[3] = getClassInfoParameterConstructorSignature();
+ return signatures;
+ }
+
+ protected MethodSignature[] getMethodSignatures() throws Exception
+ {
+ MethodSignature[] signatures = new MethodSignature[4];
+ signatures[0] = getStringMethodSignature();
+ signatures[1] = getClassMethodSignature();
+ signatures[2] = getMethodSignature();
+ signatures[3] = getMethodInfoSignature();
+ return signatures;
+ }
+
+ protected FieldSignature[] getFieldSignatures() throws Exception
+ {
+ FieldSignature[] signatures = new FieldSignature[3];
+ signatures[1] = getStringFieldSignature();
+ signatures[2] = getFieldSignature();
+ signatures[3] = getFieldInfoSignature();
+ return signatures;
+ }
+
+ protected MethodParametersSignature[] getMethodParametersSignatures() throws Exception
+ {
+ MethodParametersSignature[] signatures = new MethodParametersSignature[4];
+ signatures[0] = getClassMethodParametersSignature();
+ signatures[1] = getStringMethodParametersSignature();
+ signatures[2] = getMethodParametersSignature();
+ signatures[3] = getMethodInfoParametersSignature();
+ return signatures;
+ }
+}
Added: projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/loader/memory/test/MemoryLoaderComponentMutableUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/loader/memory/test/MemoryLoaderComponentMutableUnitTestCase.java (rev 0)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/loader/memory/test/MemoryLoaderComponentMutableUnitTestCase.java 2008-01-08 16:59:33 UTC (rev 68680)
@@ -0,0 +1,172 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.test.metadata.loader.memory.test;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+
+import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
+import org.jboss.metadata.plugins.loader.thread.ThreadLocalMetaDataLoader;
+import org.jboss.metadata.spi.ComponentMutableMetaData;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.signature.ConstructorSignature;
+import org.jboss.metadata.spi.signature.FieldSignature;
+import org.jboss.metadata.spi.signature.MethodSignature;
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.reflect.spi.ConstructorInfo;
+import org.jboss.reflect.spi.FieldInfo;
+import org.jboss.reflect.spi.MemberInfo;
+import org.jboss.reflect.spi.MethodInfo;
+import org.jboss.test.metadata.SignatureMetaDataTest;
+import org.jboss.test.metadata.shared.support.TestAnnotation;
+import org.jboss.test.metadata.shared.support.TestAnnotationImpl;
+
+/**
+ * MemoryLoaderComponentMutableUnitTestCase.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class MemoryLoaderComponentMutableUnitTestCase extends SignatureMetaDataTest
+{
+ public MemoryLoaderComponentMutableUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ protected ComponentMutableMetaData[] getArray()
+ {
+ ComponentMutableMetaData[] array = new ComponentMutableMetaData[10];
+ array[0] = new MemoryMetaDataLoader();
+ array[1] = new MemoryMetaDataLoader(true, true);
+ array[2] = new MemoryMetaDataLoader(true, false);
+ array[3] = new MemoryMetaDataLoader(false, true);
+ array[4] = new MemoryMetaDataLoader(false, false);
+ ScopeKey key = new ScopeKey(CommonLevels.APPLICATION, "SignatureTester");
+ array[5] = new MemoryMetaDataLoader(key);
+ array[6] = new MemoryMetaDataLoader(key, true, true);
+ array[7] = new MemoryMetaDataLoader(key, true, false);
+ array[8] = new MemoryMetaDataLoader(key, false, true);
+ array[9] = new MemoryMetaDataLoader(key, false, false);
+ return array;
+ }
+
+ public void testComponentMetaDataRetrieval() throws Exception
+ {
+ ComponentMutableMetaData[] array = getArray();
+ Signature[] signatures = getSignatures();
+ MetaDataRetrieval retrieval = ThreadLocalMetaDataLoader.INSTANCE;
+ for(ComponentMutableMetaData cmmd : array)
+ {
+ for(Signature sig : signatures)
+ {
+ assertNull(cmmd.addComponentMetaDataRetrieval(sig, retrieval));
+ MetaDataRetrieval mdr = cmmd.removeComponentMetaDataRetrieval(sig);
+ assertSame(retrieval, mdr);
+ }
+ }
+ }
+
+ public void testAnnotations() throws Exception
+ {
+ ComponentMutableMetaData[] array = getArray();
+ Signature[] signatures = getSignatures();
+ TestAnnotation annotation = new TestAnnotationImpl();
+ for(ComponentMutableMetaData cmmd : array)
+ {
+ for(Signature sig : signatures)
+ {
+ assertNull(cmmd.addAnnotation(sig, annotation));
+ assertSame(annotation, cmmd.removeAnnotation(sig, TestAnnotation.class));
+ }
+ }
+ Constructor c = getConstructor();
+ ConstructorInfo ci = getConstructorInfo();
+ Signature sc = new ConstructorSignature(c);
+ checkAnnotationCycle(sc, c, ci);
+ Method m = getMethod();
+ MethodInfo mi = getMethodInfo();
+ Signature sm = new MethodSignature(m);
+ checkAnnotationCycle(sm, m, mi);
+ Field f = getField();
+ FieldInfo fi = getFieldInfo();
+ Signature sf = new FieldSignature(f);
+ checkAnnotationCycle(sf, f, fi);
+ }
+
+ public void testMetaData() throws Exception
+ {
+ ComponentMutableMetaData[] array = getArray();
+ Signature[] signatures = getSignatures();
+ Object metadata = new Object();
+ for(ComponentMutableMetaData cmmd : array)
+ {
+ for(Signature sig : signatures)
+ {
+ assertNull(cmmd.addMetaData(sig, metadata, Object.class));
+ Object object = cmmd.removeMetaData(sig, Object.class);
+ assertSame(metadata, object);
+ }
+ }
+ Constructor c = getConstructor();
+ ConstructorInfo ci = getConstructorInfo();
+ Signature sc = new ConstructorSignature(c);
+ checkMetaDataCycle(sc, c, ci);
+ Method m = getMethod();
+ MethodInfo mi = getMethodInfo();
+ Signature sm = new MethodSignature(m);
+ checkMetaDataCycle(sm, m, mi);
+ Field f = getField();
+ FieldInfo fi = getFieldInfo();
+ Signature sf = new FieldSignature(f);
+ checkMetaDataCycle(sf, f, fi);
+ }
+
+ protected void checkAnnotationCycle(Signature signature, Member member, MemberInfo memberInfo) throws Exception
+ {
+ TestAnnotation annotation = new TestAnnotationImpl();
+ ComponentMutableMetaData[] array = getArray();
+ for(ComponentMutableMetaData cmmd : array)
+ {
+ assertNull(cmmd.addAnnotation(signature, annotation));
+ assertSame(annotation, cmmd.removeAnnotation(member, annotation.annotationType()));
+ assertNull(cmmd.addAnnotation(memberInfo, annotation));
+ assertSame(annotation, cmmd.removeAnnotation(signature, annotation.annotationType()));
+ }
+ }
+
+ protected void checkMetaDataCycle(Signature signature, Member member, MemberInfo memberInfo) throws Exception
+ {
+ Object metadata = new Object();
+ ComponentMutableMetaData[] array = getArray();
+ for(ComponentMutableMetaData cmmd : array)
+ {
+ assertNull(cmmd.addMetaData(signature, metadata, Object.class));
+ assertSame(metadata, cmmd.removeMetaData(member, Object.class));
+ assertNull(cmmd.addMetaData(memberInfo, metadata, Object.class));
+ assertSame(metadata, cmmd.removeMetaData(signature, Object.class));
+ }
+ }
+}
Added: projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/shared/support/SignatureTester.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/shared/support/SignatureTester.java (rev 0)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/shared/support/SignatureTester.java 2008-01-08 16:59:33 UTC (rev 68680)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.test.metadata.shared.support;
+
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * Signature test class.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SignatureTester
+{
+ public Calendar calendar;
+
+ public SignatureTester()
+ {
+ }
+
+ public SignatureTester(Calendar calendar)
+ {
+ }
+
+ // meaningless method ;-)
+ public boolean applyTimeZone(Calendar calendar, TimeZone timeZone)
+ {
+ calendar.setTimeZone(timeZone);
+ return Locale.getDefault().equals(timeZone);
+ }
+}
More information about the jboss-cvs-commits
mailing list