[jboss-cvs] container/src/tests/org/jboss/test/annotation/factory/test ...
Kabir Khan
kkhan at jboss.com
Tue Jul 18 07:23:50 EDT 2006
User: kkhan
Date: 06/07/18 07:23:50
Added: src/tests/org/jboss/test/annotation/factory/test
JavassistAnnotationCreatorTestCase.java
NoJavassistAnnotationCreatorTestCase.java
AnnotationCreatorTest.java
Log:
Move annotation creator into container from aop module
Use jboss retro to create a JDK 1.4 dist and test under JDK 1,4.
Revision Changes Path
1.1 date: 2006/07/18 11:23:50; author: kkhan; state: Exp;container/src/tests/org/jboss/test/annotation/factory/test/JavassistAnnotationCreatorTestCase.java
Index: JavassistAnnotationCreatorTestCase.java
===================================================================
/*
* 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.test.annotation.factory.test;
import java.lang.annotation.Annotation;
import junit.framework.Test;
import org.jboss.annotation.factory.AnnotationCreator;
import org.jboss.test.annotation.factory.support.ComplexWithDefault;
import org.jboss.test.annotation.factory.support.MyEnum;
/**
*
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
* @version $Revision: 1.1 $
*/
public class JavassistAnnotationCreatorTestCase extends AnnotationCreatorTest
{
public static Test suite()
{
return suite(JavassistAnnotationCreatorTestCase.class);
}
public JavassistAnnotationCreatorTestCase(String name)
{
super(name);
}
public void testDefaultValues() throws Exception
{
String expr = "@org.jboss.test.annotation.factory.support.ComplexWithDefault";
Annotation annotation = (Annotation)AnnotationCreator.createAnnotation(expr, ComplexWithDefault.class);
assertEquals(ComplexWithDefault.class, annotation.annotationType());
ComplexWithDefault complex = (ComplexWithDefault)annotation;
assertEquals('d', complex.ch());
assertEquals("default", complex.string());
assertEquals(1.0, complex.flt());
assertEquals(2.3, complex.dbl());
assertEquals(2, complex.shrt());
assertEquals(123456789, complex.lng());
assertEquals(123, complex.integer());
assertEquals(true, complex.bool());
assertEquals(String.class, complex.clazz());
assertEquals(MyEnum.ONE, complex.enumVal());
assertEquals("default", complex.annotation().value());
assertEquals(new String[]{"The", "defaults"}, complex.array());
int[] expectedIntArray = new int[] {1,2,3};
int[] actualIntArray = complex.intArray();
assertEquals(expectedIntArray.length, actualIntArray.length);
for (int i = 0 ; i < expectedIntArray.length ; i++)
{
assertEquals(expectedIntArray[i], actualIntArray[i]);
}
}
}
1.1 date: 2006/07/18 11:23:50; author: kkhan; state: Exp;container/src/tests/org/jboss/test/annotation/factory/test/NoJavassistAnnotationCreatorTestCase.java
Index: NoJavassistAnnotationCreatorTestCase.java
===================================================================
/*
* 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.test.annotation.factory.test;
import java.lang.annotation.Annotation;
import junit.framework.Test;
import org.jboss.annotation.factory.AnnotationCreator;
import org.jboss.annotation.factory.AnnotationValidationException;
import org.jboss.test.annotation.factory.support.ComplexWithDefault;
import org.jboss.test.annotation.factory.support.MyEnum;
/**
*
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
* @version $Revision: 1.1 $
*/
public class NoJavassistAnnotationCreatorTestCase extends AnnotationCreatorTest
{
public static Test suite()
{
return suite(NoJavassistAnnotationCreatorTestCase.class);
}
public NoJavassistAnnotationCreatorTestCase(String name)
{
super(name);
}
public void testDefaultValues() throws Exception
{
try
{
String expr = "@org.jboss.test.annotation.factory.support.ComplexWithDefault";
Annotation annotation = (Annotation)AnnotationCreator.createAnnotation(expr, ComplexWithDefault.class);
fail("Should have had a validation exception");
}
catch (AnnotationValidationException expected)
{
}
}
}
1.1 date: 2006/07/18 11:23:50; author: kkhan; state: Exp;container/src/tests/org/jboss/test/annotation/factory/test/AnnotationCreatorTest.java
Index: AnnotationCreatorTest.java
===================================================================
/*
* 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.test.annotation.factory.test;
import java.lang.annotation.Annotation;
import org.jboss.annotation.factory.AnnotationCreator;
import org.jboss.annotation.factory.AnnotationValidationException;
import org.jboss.test.ContainerTest;
import org.jboss.test.annotation.factory.support.Complex;
import org.jboss.test.annotation.factory.support.MyEnum;
import org.jboss.test.annotation.factory.support.Simple;
import org.jboss.test.annotation.factory.support.SimpleValue;
/**
*
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
* @version $Revision: 1.1 $
*/
public abstract class AnnotationCreatorTest extends ContainerTest
{
public AnnotationCreatorTest(String name)
{
super(name);
}
public void testSimple() throws Exception
{
String expr = "@org.jboss.test.annotation.factory.support.Simple";
Annotation annotation = (Annotation)AnnotationCreator.createAnnotation(expr, Simple.class);
assertEquals(Simple.class, annotation.annotationType());
}
public void testSimpleValue() throws Exception
{
String expr = "@org.jboss.test.annotation.factory.support.SimpleValue(\"Test\")";
Annotation annotation = (Annotation)AnnotationCreator.createAnnotation(expr, SimpleValue.class);
assertEquals(SimpleValue.class, annotation.annotationType());
assertEquals("Test", ((SimpleValue)annotation).value());
}
public void testComplex() throws Exception
{
String expr = "@org.jboss.test.annotation.factory.support.Complex(ch='a', string=\"Test123\", flt=9.9, dbl=123456789.99, shrt=1, lng=987654321, integer=123, bool=true, annotation=@org.jboss.test.annotation.factory.support.SimpleValue(\"Yes\"), array={\"Test\", \"123\"}, clazz=java.lang.Long.class, enumVal=org.jboss.test.annotation.factory.support.MyEnum.TWO)";
Annotation annotation = (Annotation)AnnotationCreator.createAnnotation(expr, Complex.class);
assertEquals(Complex.class, annotation.annotationType());
Complex complex = (Complex)annotation;
assertEquals('a', complex.ch());
assertEquals("Test123", complex.string());
assertEquals(9,9, complex.flt());
assertEquals(123456789.99, complex.dbl());
assertEquals(1, complex.shrt());
assertEquals(987654321, complex.lng());
assertEquals(123, complex.integer());
assertEquals(true, complex.bool());
assertEquals(Long.class, complex.clazz());
assertEquals("Yes", complex.annotation().value());
assertEquals(new String[]{"Test", "123"}, complex.array());
assertEquals(MyEnum.TWO, complex.enumVal());
}
public void testMissingAttributeAndNoDefault() throws Exception
{
try
{
String expr = "@org.jboss.test.annotation.factory.support.SimpleValue";
Annotation annotation = (Annotation)AnnotationCreator.createAnnotation(expr, SimpleValue.class);
fail("Should have picked up on missing attribute");
}
catch (AnnotationValidationException expected)
{
}
}
}
More information about the jboss-cvs-commits
mailing list