Skip to content

Commit

Permalink
WELD-742 including tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbogoevici authored and pmuir committed Oct 31, 2010
1 parent fa05b2a commit 6399c51
Show file tree
Hide file tree
Showing 8 changed files with 247 additions and 8 deletions.
4 changes: 2 additions & 2 deletions impl/src/main/java/org/jboss/weld/bean/DecoratorImpl.java
Expand Up @@ -129,8 +129,8 @@ public void initialize(BeanDeployerEnvironment environment)

protected void initDecoratedTypes()
{
this.decoratedTypes = new HashSet<Type>();
this.decoratedTypes.addAll(getWeldAnnotated().getInterfaceClosure());
this.decoratedTypes = new HashSet(getWeldAnnotated().getInterfaceClosure());
decoratedTypes.retainAll(getTypes());
this.decoratedTypes.remove(Serializable.class);
this.decoratorMethods = Decorators.getDecoratorMethods(beanManager, decoratedTypes, getWeldAnnotated());
}
Expand Down
Expand Up @@ -87,8 +87,6 @@ public interface WeldAnnotated<T, S> extends Annotated
/**
* Get the type hierarchy of any interfaces implemented by this class.
*
* Interface hierarchies from super classes are not included.
*
* The returned types should have any type parameters resolved to their
* actual types.
*
Expand Down
Expand Up @@ -42,6 +42,7 @@
import org.jboss.weld.util.collections.ArraySetMultimap;
import org.jboss.weld.util.collections.Arrays2;
import org.jboss.weld.util.reflection.HierarchyDiscovery;
import org.jboss.weld.util.reflection.Reflections;

/**
* Represents functionality common for all annotated items, mainly different
Expand Down Expand Up @@ -226,12 +227,15 @@ public Type[] getActualTypeArguments()

public Set<Type> getInterfaceClosure()
{
Set<Type> types = new HashSet<Type>();
for (Type t : rawType.getGenericInterfaces())
Set<Type> interfaces = new HashSet<Type>();
for (Type t: getTypeClosure())
{
types.addAll(new HierarchyDiscovery(t).getTypeClosure());
if (Reflections.getRawType(t).isInterface())
{
interfaces.add(t);
}
}
return types;
return Collections.unmodifiableSet(interfaces);
}

public abstract S getDelegate();
Expand Down
@@ -0,0 +1,52 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., 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.jboss.weld.tests.decorators.decoratedTypes;

import javax.decorator.Decorator;
import javax.decorator.Delegate;
import javax.inject.Inject;

/**
*
* @author Marius Bogoevici
*/
@Decorator
public class ExtendingDecorator extends ParentDecorator
{

@Inject @Delegate TestBean delegate;

static boolean decoratedInvoked;

static boolean notDecoratedInvoked;

public void decoratedMethod()
{
decoratedInvoked = true;
delegate.decoratedMethod();
}

/**
* Should not be invoked
*/
public void notDecoratedMethod()
{
notDecoratedInvoked = true;
delegate.decoratedMethod();
}
}
@@ -0,0 +1,53 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., 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.jboss.weld.tests.decorators.decoratedTypes;

import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.BeanArchive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* @author Marius Bogoevici
*/
@RunWith(Arquillian.class)
public class ExtendingDecoratorTest
{
@Deployment
public static Archive<?> deploy()
{
return ShrinkWrap.create(BeanArchive.class)
.decorate(ExtendingDecorator.class)
.addPackage(ExtendingDecoratorTest.class.getPackage());
}

@Test
public void testDecoratorDoesNotDecorateOutsideDecoratedTypes(TestBean testBean)
{
testBean.decoratedMethod();
testBean.notDecoratedMethod();

Assert.assertTrue(ExtendingDecorator.decoratedInvoked);
Assert.assertFalse(ExtendingDecorator.notDecoratedInvoked);
Assert.assertTrue(TestBean.decoratedInvoked);
Assert.assertTrue(TestBean.notDecoratedInvoked);
}
}
@@ -0,0 +1,26 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., 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.jboss.weld.tests.decorators.decoratedTypes;

/**
*
* @author Marius Bogoevici
*/
public abstract class ParentDecorator implements Decorated
{

}
@@ -0,0 +1,53 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., 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.jboss.weld.tests.decorators.decoratedTypes;

import javax.decorator.Decorator;
import javax.decorator.Delegate;
import javax.enterprise.inject.Typed;
import javax.inject.Inject;

/**
*
* @author Marius Bogoevici
*/
@Decorator @Typed(Decorated.class)
public class TypedDecorator implements Decorated, NotDecorated
{

@Inject @Delegate TestBean delegate;

static boolean decoratedInvoked;

static boolean notDecoratedInvoked;

public void decoratedMethod()
{
decoratedInvoked = true;
delegate.decoratedMethod();
}

/**
* Should not be invoked
*/
public void notDecoratedMethod()
{
notDecoratedInvoked = true;
delegate.decoratedMethod();
}
}
@@ -0,0 +1,53 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., 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.jboss.weld.tests.decorators.decoratedTypes;

import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.BeanArchive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* @author Marius Bogoevici
*/
@RunWith(Arquillian.class)
public class TypedDecoratorTest
{
@Deployment
public static Archive<?> deploy()
{
return ShrinkWrap.create(BeanArchive.class)
.decorate(TypedDecorator.class)
.addPackage(TypedDecoratorTest.class.getPackage());
}

@Test
public void testDecoratorDoesNotDecorateOutsideDecoratedTypes(TestBean testBean)
{
testBean.decoratedMethod();
testBean.notDecoratedMethod();

Assert.assertTrue(TypedDecorator.decoratedInvoked);
Assert.assertFalse(TypedDecorator.notDecoratedInvoked);
Assert.assertTrue(TestBean.decoratedInvoked);
Assert.assertTrue(TestBean.notDecoratedInvoked);
}
}

0 comments on commit 6399c51

Please sign in to comment.