Author: vitold
Date: 2009-04-06 11:00:38 -0400 (Mon, 06 Apr 2009)
New Revision: 2321
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/metadata/
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/metadata/XmlBasedMetadataTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/metadata/foo/
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/metadata/foo/AnotherDeploymentType.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/metadata/foo/Order.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/foo/TestDeploymentType.java
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/xml/metadata/
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/xml/metadata/beans.xml
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/xml/metadata/namespace
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/xml/metadata/schema.xsd
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlConstants.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/impl/BeanChildrenCheckerImpl.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/NamespaceAggregationTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/multipleTypes/MultipleTypesInAggregatedNamespacesTest.java
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/multipleTypes/beans.xml
Log:
make some tck tests
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlConstants.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlConstants.java 2009-04-06
14:48:19 UTC (rev 2320)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlConstants.java 2009-04-06
15:00:38 UTC (rev 2321)
@@ -55,4 +55,6 @@
public static final String NAMESPACE_FILE_DELIMETER = " ";
public static final String PRODUCES = "Produces";
+
+ public static final String VALUE = "value";
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java 2009-04-06 14:48:19
UTC (rev 2320)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java 2009-04-06 15:00:38
UTC (rev 2321)
@@ -156,13 +156,13 @@
{
String message = "Can not open stream for " + url;
log.debug(message, e);
- throw new DeploymentException(message, e);
+ throw new DefinitionException(message, e);
}
catch (DocumentException e)
{
String message = "Error during the processing of a DOM4J document for
" + url;
log.debug(message, e);
- throw new DeploymentException(message, e);
+ throw new DefinitionException(message, e);
}
}
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/impl/BeanChildrenCheckerImpl.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/impl/BeanChildrenCheckerImpl.java 2009-04-06
14:48:19 UTC (rev 2320)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/impl/BeanChildrenCheckerImpl.java 2009-04-06
15:00:38 UTC (rev 2321)
@@ -1,6 +1,8 @@
package org.jboss.webbeans.xml.checker.beanchildren.impl;
+import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -18,6 +20,7 @@
import javax.inject.Realizes;
import javax.inject.Specializes;
import javax.interceptor.Interceptor;
+import javax.interceptor.InterceptorBindingType;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;
import javax.xml.ws.WebServiceRef;
@@ -25,6 +28,7 @@
import org.dom4j.Element;
import org.dom4j.Namespace;
import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.xml.ParseXmlHelper;
import org.jboss.webbeans.xml.XmlConstants;
import org.jboss.webbeans.xml.XmlEnvironment;
@@ -36,6 +40,10 @@
private final Map<String, Set<String>> packagesMap;
+ private Set<AnnotatedField<?>> beanFields;
+
+ private List<Method> beanMethods;
+
private boolean haveBeanDeploymentTypeDeclaration = false;
private boolean haveBeanScopeTypeDeclaration = false;
@@ -64,6 +72,9 @@
public void checkChildren(Element beanElement, AnnotatedClass<?> beanClass)
{
+ beanFields = beanClass.getFields();
+ beanMethods = Arrays.asList(beanClass.getRawType().getDeclaredMethods());
+
checkForInterceptorChild(beanElement);
checkForDecoratorChild(beanElement);
@@ -83,7 +94,6 @@
private void checkBeanChild(Element beanChildElement, AnnotatedClass<?>
beanClass)
{
- //TODO: not finished
try
{
AnnotatedClass<?> beanChildClass =
ParseXmlHelper.loadElementClass(beanChildElement, Object.class, environment,
packagesMap);
@@ -153,12 +163,12 @@
checkChildForDecoratorType(beanChildElement);
return;
}
- //TODO: add interceptor binding type
- if(beanChildClass.isAnnotationPresent(BindingType.class) ||
beanChildClass.isAnnotationPresent(Stereotype.class) ||
- beanChildClass.isAnnotationPresent(Named.class) ||
beanChildClass.isAnnotationPresent(Specializes.class) ||
- beanChildClass.isAnnotationPresent(Realizes.class) ||
beanChildClass.isAnnotationPresent(Resource.class) ||
- beanChildClass.isAnnotationPresent(EJB.class) ||
beanChildClass.isAnnotationPresent(WebServiceRef.class) ||
- beanChildClass.isAnnotationPresent(PersistenceContext.class) ||
beanChildClass.isAnnotationPresent(PersistenceUnit.class))
+ if(beanChildClass.isAnnotationPresent(BindingType.class) ||
beanChildClass.isAnnotationPresent(InterceptorBindingType.class) ||
+ beanChildClass.isAnnotationPresent(Stereotype.class) ||
beanChildClass.isAnnotationPresent(Named.class) ||
+ beanChildClass.isAnnotationPresent(Specializes.class) ||
beanChildClass.isAnnotationPresent(Realizes.class) ||
+ beanChildClass.isAnnotationPresent(Resource.class) ||
beanChildClass.isAnnotationPresent(EJB.class) ||
+ beanChildClass.isAnnotationPresent(WebServiceRef.class) ||
beanChildClass.isAnnotationPresent(PersistenceContext.class) ||
+ beanChildClass.isAnnotationPresent(PersistenceUnit.class))
return;
throw new DefinitionException("Can't determine annotation type of
<" + beanChildElement.getName() + "> element in bean '" +
@@ -166,6 +176,58 @@
}
private void checkFieldOrMethodChild(Element beanChildElement, AnnotatedClass<?>
beanClass)
+ { //TODO: not finished
+ boolean isField = false;
+ boolean isMethod = false;
+
+ for(AnnotatedField<?> field : beanFields)
+ {
+ if(beanChildElement.getName().equalsIgnoreCase(field.getName()))
+ {
+ if(isField)
+ throw new DefinitionException("Bean class '" +
beanClass.getName() + "' does not have exactly one field " +
+ "with the specified name '" + beanChildElement.getName() +
"'");
+ isField = true;
+ }
+ }
+
+ for(Method method : beanMethods)
+ {
+ if(beanChildElement.getName().equalsIgnoreCase(method.getName()))
+ isMethod = true;
+ }
+
+ if(isField && isMethod)
+ throw new DefinitionException("The name of the child element <" +
beanChildElement.getName() +
+ "> matches the name of both a method and a field of the bean class
'" + beanClass.getName() + "'");
+
+ if(isField)
+ checkFieldChild(beanChildElement, beanClass);
+
+ if(isMethod)
+ checkMethodChild(beanChildElement, beanClass);
+ }
+
+ private void checkFieldChild(Element beanChildElement, AnnotatedClass<?>
beanClass)
+ {//TODO: not finished
+ Element elementParent = beanChildElement.getParent();
+ String elementName = beanChildElement.getName();
+ String elementPrefix = beanChildElement.getNamespacePrefix();
+ String elementUri = beanChildElement.getNamespaceURI();
+
+ if(ParseXmlHelper.findElements(elementParent, elementName, elementPrefix,
elementUri).size() > 1)
+ throw new DefinitionException("More than one child element of a bean
'" + elementParent.getName() +
+ "' declaration represents the same field'" + elementName
+ "'");
+
+ if(beanChildElement.elements().size() > 1 &&
+ beanChildElement.elements().size() !=
ParseXmlHelper.findElementsInEeNamespace(beanChildElement, XmlConstants.VALUE).size())
+ throw new DefinitionException("Declaration of a field '" +
beanChildElement.getName() + "' has more than one direct child element, " +
+ "and at least one of these elements is something other than a
<value> element in the Java EE namespace");
+
+
+ }
+
+ private void checkMethodChild(Element beanChildElement, AnnotatedClass<?>
beanClass)
{
//TODO: not finished
}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/metadata/XmlBasedMetadataTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/metadata/XmlBasedMetadataTest.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/metadata/XmlBasedMetadataTest.java 2009-04-06
15:00:38 UTC (rev 2321)
@@ -0,0 +1,42 @@
+package org.jboss.jsr299.tck.tests.xml.metadata;
+
+import javax.inject.DefinitionException;
+
+import org.hibernate.tck.annotations.SpecAssertion;
+import org.hibernate.tck.annotations.SpecAssertions;
+import org.jboss.jsr299.tck.AbstractJSR299Test;
+import org.jboss.jsr299.tck.tests.xml.metadata.foo.Order;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.testharness.impl.packaging.ExpectedDeploymentException;
+import org.jboss.testharness.impl.packaging.Resource;
+import org.jboss.testharness.impl.packaging.Resources;
+import org.jboss.testharness.impl.packaging.jsr299.BeansXml;
+import org.testng.annotations.Test;
+
+@Artifact
+@Resources({
+ @Resource(source="namespace",
destination="WEB-INF/classes/org/jboss/jsr299/tck/tests/xml/metadata/namespace"),
+ @Resource(source="schema.xsd",
destination="WEB-INF/classes/org/jboss/jsr299/tck/tests/xml/metadata/namespace")
+})
+(a)Classes({Order.class})
+(a)BeansXml("beans.xml")
+(a)ExpectedDeploymentException(DefinitionException.class)
+public class XmlBasedMetadataTest extends AbstractJSR299Test
+{
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section="9", id="a"),
+ @SpecAssertion(section="9", id="b"),
+ @SpecAssertion(section="9", id="c"),
+ @SpecAssertion(section="9", id="d"),
+ @SpecAssertion(section="9", id="e"),
+ @SpecAssertion(section="9.1", id="b"),
+ @SpecAssertion(section="9.1", id="c"),
+ @SpecAssertion(section="9.1", id="d")
+ })
+ public void testXmlBasedMetadata()
+ {
+ assert true;
+ }
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/metadata/foo/AnotherDeploymentType.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/metadata/foo/AnotherDeploymentType.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/metadata/foo/AnotherDeploymentType.java 2009-04-06
15:00:38 UTC (rev 2321)
@@ -0,0 +1,21 @@
+package org.jboss.jsr299.tck.tests.xml.metadata.foo;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.DeploymentType;
+
+@Target( { TYPE, METHOD, FIELD })
+@Retention(RUNTIME)
+@Documented
+@DeploymentType
+public @interface AnotherDeploymentType
+{
+
+}
\ No newline at end of file
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/metadata/foo/Order.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/metadata/foo/Order.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/metadata/foo/Order.java 2009-04-06
15:00:38 UTC (rev 2321)
@@ -0,0 +1,11 @@
+package org.jboss.jsr299.tck.tests.xml.metadata.foo;
+
+public class Order
+{
+ public String str;
+
+ public String getStr()
+ {
+ return str;
+ }
+}
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/NamespaceAggregationTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/NamespaceAggregationTest.java 2009-04-06
14:48:19 UTC (rev 2320)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/NamespaceAggregationTest.java 2009-04-06
15:00:38 UTC (rev 2321)
@@ -23,9 +23,11 @@
@Test
@SpecAssertions({
+ @SpecAssertion(section="9.1", id="a"),
@SpecAssertion(section="9.2", id="a"),
@SpecAssertion(section="9.2", id="b"),
- @SpecAssertion(section="9.2", id="c")
+ @SpecAssertion(section="9.2", id="c"),
+ @SpecAssertion(section="9.2", id="d")
})
public void testNamespaceAggregation()
{
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/foo/TestDeploymentType.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/foo/TestDeploymentType.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/foo/TestDeploymentType.java 2009-04-06
15:00:38 UTC (rev 2321)
@@ -0,0 +1,9 @@
+package org.jboss.jsr299.tck.tests.xml.namespace.aggregation.foo;
+
+import javax.inject.DeploymentType;
+
+@DeploymentType
+public @interface TestDeploymentType
+{
+
+}
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/multipleTypes/MultipleTypesInAggregatedNamespacesTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/multipleTypes/MultipleTypesInAggregatedNamespacesTest.java 2009-04-06
14:48:19 UTC (rev 2320)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/multipleTypes/MultipleTypesInAggregatedNamespacesTest.java 2009-04-06
15:00:38 UTC (rev 2321)
@@ -1,12 +1,13 @@
package org.jboss.jsr299.tck.tests.xml.namespace.aggregation.multipleTypes;
-
import javax.inject.DefinitionException;
import org.hibernate.tck.annotations.SpecAssertion;
import org.hibernate.tck.annotations.SpecAssertions;
import org.jboss.jsr299.tck.AbstractJSR299Test;
+import org.jboss.jsr299.tck.tests.xml.namespace.aggregation.Cow;
import org.jboss.jsr299.tck.tests.xml.namespace.aggregation.foo.AnotherDeploymentType;
+import org.jboss.jsr299.tck.tests.xml.namespace.aggregation.foo.TestDeploymentType;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.Classes;
import org.jboss.testharness.impl.packaging.ExpectedDeploymentException;
@@ -19,19 +20,19 @@
@Resources({
@Resource(source="namespace",
destination="WEB-INF/classes/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/multipleTypes/namespace")
})
-(a)Classes({AnotherDeploymentType.class,
org.jboss.jsr299.tck.tests.xml.namespace.aggregation.foo.copy.AnotherDeploymentType.class})
+(a)Classes({AnotherDeploymentType.class, TestDeploymentType.class})
@BeansXml("beans.xml")
@ExpectedDeploymentException(DefinitionException.class)
public class MultipleTypesInAggregatedNamespacesTest extends AbstractJSR299Test
-{
-
+{
@Test
@SpecAssertions({
- @SpecAssertion(section="9.2", id="e")
+ @SpecAssertion(section="9.2", id="e"),
+ @SpecAssertion(section="9.2", id="f")
})
public void testNamespaceAggregation()
{
- assert false;
+ assert getCurrentManager().resolveByType(Cow.class).size() == 1;
}
}
Added:
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/xml/metadata/beans.xml
===================================================================
--- tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/xml/metadata/beans.xml
(rev 0)
+++
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/xml/metadata/beans.xml 2009-04-06
15:00:38 UTC (rev 2321)
@@ -0,0 +1,16 @@
+<Beans xmlns="urn:java:ee"
+
xmlns:test="http://www.w3.org/2001/XMLSchema-instance"
+ test:schemaLocation="urn:java:ee
+ urn:java:org.jboss.jsr299.tck.tests.xml.metadata
http://mydomain.com/myapp/schema-1.2.xsd">
+ <Deploy>
+ <Standard />
+ <Production />
+ <test:AnotherDeploymentType />
+ </Deploy>
+ <test:Order>
+ <RequestScoped />
+ <test:str>hello</test:str>
+ <test:getStr />
+ <my:Type />
+ </test:Order>
+</Beans>
\ No newline at end of file
Added:
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/xml/metadata/namespace
===================================================================
--- tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/xml/metadata/namespace
(rev 0)
+++
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/xml/metadata/namespace 2009-04-06
15:00:38 UTC (rev 2321)
@@ -0,0 +1,2 @@
+org.jboss.jsr299.tck.tests.xml.metadata
+org.jboss.jsr299.tck.tests.xml.metadata.foo
\ No newline at end of file
Added:
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/xml/metadata/schema.xsd
===================================================================
Modified:
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/multipleTypes/beans.xml
===================================================================
---
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/multipleTypes/beans.xml 2009-04-06
14:48:19 UTC (rev 2320)
+++
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/xml/namespace/aggregation/multipleTypes/beans.xml 2009-04-06
15:00:38 UTC (rev 2321)
@@ -3,6 +3,7 @@
<Deploy>
<Standard />
<Production />
- <test:AnotherDeploymentType />
+ <test:TestDeploymentType />
+ <test:AnotherDeploymentType />
</Deploy>
</Beans>