Added: bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/EJBEnricher.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/EJBEnricher.java?rev=1498347&view=auto ============================================================================== --- bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/EJBEnricher.java (added) +++ bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/EJBEnricher.java Mon Jul 1 10:06:18 2013 @@ -0,0 +1,57 @@ +/* +* JBoss, Home of Professional Open Source +* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual contributors +* by the @authors tag. See the copyright.txt in the distribution for a +* full listing of individual contributors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* http://www.apache.org/licenses/LICENSE-2.0 +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.apache.bval.arquillian; + +import org.jboss.arquillian.test.spi.TestEnricher; + +import javax.annotation.Resource; +import javax.ejb.EJB; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +// mock a very very simple EJB container (in fact only local bean @Resource Validator* injections) +public class EJBEnricher implements TestEnricher { + public void enrich(final Object testCase) { + for (final Field field : testCase.getClass().getDeclaredFields()) { + if (field.getAnnotation(EJB.class) != null) { + try { + final Object instance = field.getType().newInstance(); + for (final Field f : field.getType().getDeclaredFields()) { + if (f.getAnnotation(Resource.class) != null) { + if (f.getType().equals(Validator.class)) { + f.set(instance, Validation.byDefaultProvider().configure().buildValidatorFactory().getValidator()); + } else if (f.getType().equals(ValidatorFactory.class)) { + f.set(instance, Validation.byDefaultProvider().configure().buildValidatorFactory()); + } + } + } + field.setAccessible(true); + field.set(testCase, instance); + } catch (final Exception e) { + // no-op + } + } + } + } + + public Object[] resolve(Method method) { + return new Object[0]; + } +}
Added: bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/jndi/BValJndiFactory.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/jndi/BValJndiFactory.java?rev=1498347&view=auto ============================================================================== --- bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/jndi/BValJndiFactory.java (added) +++ bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/jndi/BValJndiFactory.java Mon Jul 1 10:06:18 2013 @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.bval.arquillian.jndi; + +import javax.naming.Context; +import javax.naming.NamingException; +import javax.naming.spi.InitialContextFactory; +import javax.validation.Validation; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.Hashtable; + +// mock a context to satisfy lookups +public class BValJndiFactory implements InitialContextFactory { + public Context getInitialContext(final Hashtable<?, ?> environment) throws NamingException { + return Context.class.cast(Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), + new Class<?>[] { Context.class }, new InvocationHandler() { + public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { + if (method.getName().equals("lookup") && args != null && args.length == 1 && String.class.isInstance(args[0])) { + if ("java:comp/ValidatorFactory".equals(args[0])) { + return Validation.byDefaultProvider().configure().buildValidatorFactory(); + } + if ("java:comp/Validator".equals(args[0])) { + return Validation.byDefaultProvider().configure().buildValidatorFactory().getValidator(); + } + } + return null; + } + })); + } +} Added: bval/branches/bval-11/bval-tck11/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-tck11/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension?rev=1498347&view=auto ============================================================================== --- bval/branches/bval-11/bval-tck11/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension (added) +++ bval/branches/bval-11/bval-tck11/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension Mon Jul 1 10:06:18 2013 @@ -0,0 +1 @@ +org.apache.bval.arquillian.BValArquillianExtension Added: bval/branches/bval-11/bval-tck11/src/main/resources/jndi.properties URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-tck11/src/main/resources/jndi.properties?rev=1498347&view=auto ============================================================================== --- bval/branches/bval-11/bval-tck11/src/main/resources/jndi.properties (added) +++ bval/branches/bval-11/bval-tck11/src/main/resources/jndi.properties Mon Jul 1 10:06:18 2013 @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +java.naming.factory.initial = org.apache.bval.arquillian.jndi.BValJndiFactory Added: bval/branches/bval-11/bval-tck11/src/test/java/org/apache/webbeans/intercept/InterceptorsManager.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-tck11/src/test/java/org/apache/webbeans/intercept/InterceptorsManager.java?rev=1498347&view=auto ============================================================================== --- bval/branches/bval-11/bval-tck11/src/test/java/org/apache/webbeans/intercept/InterceptorsManager.java (added) +++ bval/branches/bval-11/bval-tck11/src/test/java/org/apache/webbeans/intercept/InterceptorsManager.java Mon Jul 1 10:06:18 2013 @@ -0,0 +1,307 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.webbeans.intercept; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; + +import javax.enterprise.inject.spi.AnnotatedType; +import javax.enterprise.inject.spi.InterceptionType; +import javax.enterprise.inject.spi.Interceptor; +import javax.enterprise.inject.spi.PassivationCapable; + +import org.apache.bval.cdi.BValInterceptor; +import org.apache.webbeans.component.BeanAttributesImpl; +import org.apache.webbeans.component.CdiInterceptorBean; +import org.apache.webbeans.component.OwbBean; +import org.apache.webbeans.component.creation.BeanAttributesBuilder; +import org.apache.webbeans.component.creation.EjbInterceptorBeanBuilder; +import org.apache.webbeans.config.WebBeansContext; +import org.apache.webbeans.container.BeanManagerImpl; +import org.apache.webbeans.exception.WebBeansConfigurationException; +import org.apache.webbeans.util.AnnotationUtil; +import org.apache.webbeans.util.Asserts; + +/** + * see line 86 + * + * + * This class keeps all the enabled interceptor classes information of a certain BeanManager. + */ +public class InterceptorsManager +{ + private final WebBeansContext webBeansContext; + private final BeanManagerImpl beanManager; + + /** + * Interceptor classes which got added via beans.xml + */ + private List<Class<?>> configuredInterceptorClasses = new CopyOnWriteArrayList<Class<?>>(); + + /** + * Active CDI-style interceptors. + */ + private List<Interceptor<?>> cdiInterceptors = new ArrayList<Interceptor<?>>(); + + /** + * EJB-style Interceptor beans. + */ + private ConcurrentHashMap<Class<?>, Interceptor<?>> ejbInterceptors = new ConcurrentHashMap<Class<?>, Interceptor<?>>(); + + /**Additional interceptor class*/ + private List<Class<?>> additionalInterceptorClasses = new ArrayList<Class<?>>(); + + /** + * Additional interceptor binding types we got via Extensions + */ + private Map<Class<? extends Annotation>, Set<Annotation>> additionalInterceptorBindingTypes + = new HashMap<Class<? extends Annotation>, Set<Annotation>>(); + + + public InterceptorsManager(WebBeansContext webBeansContext) + { + this.webBeansContext = webBeansContext; + beanManager = webBeansContext.getBeanManagerImpl(); + configuredInterceptorClasses.add(BValInterceptor.class); // quickly patched + } + + /** + * Clears all info. + * This must only be called by the BeanManager. + */ + public void clear() + { + additionalInterceptorBindingTypes.clear(); + additionalInterceptorClasses.clear(); + configuredInterceptorClasses.clear(); + cdiInterceptors.clear(); + ejbInterceptors.clear(); + } + + + /** + * Add a certain class to the enabled interceptors list. + */ + public void addEnabledInterceptorClass(Class<?> interceptorClazz) + { + Asserts.nullCheckForClass(interceptorClazz, "interceptorClazz can not be null"); + + if (!configuredInterceptorClasses.contains(interceptorClazz)) + { + configuredInterceptorClasses.add(interceptorClazz); + } + } + + /** + * get the EJB-style Interceptor + * @param interceptorClass + * @param <T> + * @return + */ + public <T> Interceptor<T> getEjbInterceptorForClass(Class<T> interceptorClass) + { + Interceptor<T> interceptor = (Interceptor<T>) ejbInterceptors.get(interceptorClass); + if (interceptor == null) + { + AnnotatedType<T> annotatedType = webBeansContext.getBeanManagerImpl().createAnnotatedType(interceptorClass); + BeanAttributesImpl<T> beanAttributes = BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes(annotatedType).build(); + EjbInterceptorBeanBuilder<T> buildr = new EjbInterceptorBeanBuilder<T>(webBeansContext, annotatedType, beanAttributes); + buildr.defineEjbInterceptorRules(); + Interceptor<T> i = buildr.getBean(); + interceptor = (Interceptor<T>) ejbInterceptors.putIfAbsent(interceptorClass, i); + if (interceptor == null) + { + interceptor = i; + } + } + + return interceptor; + } + + /** + * Helper to compare the order of different interceptor classes + */ + public int compareCdiInterceptors(Class<?> src, Class<?> target) + { + Asserts.assertNotNull(src, "src parameter can not be null"); + Asserts.assertNotNull(target, "target parameter can not be null"); + + int srcIndex = configuredInterceptorClasses.indexOf(src); + if (srcIndex == -1) + { + throw new IllegalArgumentException(src.getName() + " is not an enabled interceptor!"); + } + + int targetIndex = configuredInterceptorClasses.indexOf(target); + if (targetIndex == -1) + { + throw new IllegalArgumentException(target.getName() + " is not an enabled interceptor!"); + } + + + if (srcIndex == targetIndex) + { + return 0; + } + else if (srcIndex < targetIndex) + { + return -1; + } + else + { + return 1; + } + } + + /** + * Check if the given interceptor class is in the list of enabled interceptors. + */ + public boolean isInterceptorClassEnabled(Class<?> interceptorClazz) + { + Asserts.nullCheckForClass(interceptorClazz, "interceptorClazz can not be null"); + + return configuredInterceptorClasses.contains(interceptorClazz); + } + + public List<Interceptor<?>> resolveInterceptors(InterceptionType type, Annotation... interceptorBindings) + { + List<Interceptor<?>> interceptorList = new ArrayList<Interceptor<?>>(); + for (Interceptor<?> interceptor : cdiInterceptors) + { + if (interceptor.intercepts(type) && intercepts(interceptor, interceptorBindings)) + { + interceptorList.add(interceptor); + } + } + + Collections.sort(interceptorList, new InterceptorComparator(webBeansContext)); + + return interceptorList; + } + + private boolean intercepts(Interceptor<?> interceptor, Annotation[] requestedInterceptorBindings) + { + for (Annotation interceptorBinding : interceptor.getInterceptorBindings()) + { + // if an interceptor has multiple bindings then all of them must be in the + // requestedInterceptorBindings for a positive match + + if (!inBindingArray(interceptorBinding, requestedInterceptorBindings)) + { + return false; + } + + } + + return true; + } + + private boolean inBindingArray(Annotation interceptorBinding, Annotation[] requestedInterceptorBindings) + { + for (Annotation requestedBinding : requestedInterceptorBindings) + { + if (AnnotationUtil.isCdiAnnotationEqual(requestedBinding, interceptorBinding)) + { + return true; + } + } + return false; + } + + /** + * Add a CDI-style interceptor. + * These are interceptors declared using an {@link javax.interceptor.InterceptorBinding}. + * @param interceptor + */ + public void addCdiInterceptor(Interceptor interceptor) + { + cdiInterceptors.add(interceptor); + if (interceptor instanceof PassivationCapable) + { + OwbBean<?> owbBean = (OwbBean<?>)interceptor; + if(owbBean.isPassivationCapable()) + { + beanManager.addPassivationInfo(interceptor); + } + + } + } + + + public List<Interceptor<?>> getCdiInterceptors() + { + return cdiInterceptors; + } + + public void addCustomInterceptorClass(Class<?> clazz) + { + Asserts.nullCheckForClass(clazz); + additionalInterceptorClasses.add(clazz); + } + + public boolean containsCustomInterceptorClass(Class<?> clazz) + { + Asserts.nullCheckForClass(clazz); + return additionalInterceptorClasses.contains(clazz); + } + + public void addInterceptorBindingType(Class<? extends Annotation> bindingType, Annotation... inheritsArray) + { + Set<Annotation> inherits = additionalInterceptorBindingTypes.get(bindingType); + if (inherits == null) + { + inherits = new HashSet<Annotation>(); + additionalInterceptorBindingTypes.put(bindingType, inherits); + } + for(Annotation ann : inheritsArray) + { + inherits.add(ann); + } + + } + + public boolean hasInterceptorBindingType(Class<? extends Annotation> bindingType) + { + return additionalInterceptorBindingTypes.keySet().contains(bindingType); + } + + + public void validateInterceptorClasses() + { + for(Class<?> interceptorClass : configuredInterceptorClasses) + { + AnnotatedType<?> annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(interceptorClass); + + // Validate decorator classes + if(!annotatedType.isAnnotationPresent(javax.interceptor.Interceptor.class) && + !containsCustomInterceptorClass(interceptorClass)) + { + throw new WebBeansConfigurationException("Given class : " + interceptorClass + " is not a interceptor class"); + } + } + } +} Added: bval/branches/bval-11/bval-tck11/src/test/resources/arquillian.xml URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-tck11/src/test/resources/arquillian.xml?rev=1498347&view=auto ============================================================================== --- bval/branches/bval-11/bval-tck11/src/test/resources/arquillian.xml (added) +++ bval/branches/bval-11/bval-tck11/src/test/resources/arquillian.xml Mon Jul 1 10:06:18 2013 @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://jboss.org/schema/arquillian + http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> + <container qualifier="owb" default="true"> + <configuration> + <property name="useOnlyArchiveResources">true</property> + <property name="useOnlyArchiveResourcesExcludes">META-INF/services/javax.validation.spi.ValidationProvider</property> + </configuration> + </container> +</arquillian> Added: bval/branches/bval-11/bval-tck11/work-tests-suite.xml URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-tck11/work-tests-suite.xml?rev=1498347&view=auto ============================================================================== --- bval/branches/bval-11/bval-tck11/work-tests-suite.xml (added) +++ bval/branches/bval-11/bval-tck11/work-tests-suite.xml Mon Jul 1 10:06:18 2013 @@ -0,0 +1,44 @@ +<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to you under the Apache License, Version + 2.0 (the "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 Unless required by + applicable law or agreed to in writing, software distributed under the + License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. See the License for + the specific language governing permissions and limitations under the + License. +--> +<!-- +JUST HERE TO BE ABLE TO RUN TCK ONE BY ONE WHEN DEVELOPING +think to add -Dvalidation.provider=org.apache.bval.jsr303.ApacheValidationProvider to your runner config +--> +<suite name="tmp" verbose="1"> + <test name="tmp"> + <classes> + <class name="org.hibernate.beanvalidation.tck.tests.constraints.application.ValidationRequirementTest" /> + + <!-- + <class name="org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.ExecutableValidationTest"> + <methods> + + </methods> + </class> + --> + + <!-- + <class name="org.hibernate.beanvalidation.tck.tests.methodvalidation.MethodValidationTest"> + <methods> + <include name="constructorParameterValidationWithRedefinedDefaultGroupSequence"/> + </methods> + </class> + --> + + </classes> + </test> +</suite> Modified: bval/branches/bval-11/pom.xml URL: http://svn.apache.org/viewvc/bval/branches/bval-11/pom.xml?rev=1498347&r1=1498346&r2=1498347&view=diff ============================================================================== --- bval/branches/bval-11/pom.xml (original) +++ bval/branches/bval-11/pom.xml Mon Jul 1 10:06:18 2013 @@ -284,16 +284,18 @@ <dependencyManagement> <dependencies> <!-- Default of Apache Geronimo version of the Spec API --> + <!-- TODO <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-validation_1.0_spec</artifactId> <version>1.1</version> </dependency> + --> <!-- Optional profile to use Spec RI API --> <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> - <version>1.0.0.GA</version> + <version>1.1.0.Final</version> </dependency> <!-- JPA2 spec required for JPA TraversableResolver support --> <dependency> @@ -491,6 +493,7 @@ <exclude>**/*.iml</exclude> <exclude>**/*.ipr</exclude> <exclude>**/*.iws</exclude> + <exclude>**/META-INF/services/*</exclude> <!-- depending service loader it can fail if a comment is added --> </excludes> </configuration> </plugin> @@ -539,7 +542,7 @@ <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>buildnumber-maven-plugin</artifactId> - <version>1.0-beta-4</version> + <version>1.2</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> @@ -626,11 +629,12 @@ <module>bval-core</module> <module>bval-xstream</module> <module>bval-jsr303</module> - <module>bundle</module> + <!--<module>bundle</module>--> <module>bval-json</module> <module>bval-guice</module> <module>bval-tck</module> <module>bval-extras</module> - </modules> + <module>bval-tck11</module> + </modules> </project>
