Skip to content

Commit

Permalink
Test framework for injection points; all tests marked broken till fin…
Browse files Browse the repository at this point in the history
…al integration of feature is done.

git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@753 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
drallen committed Jan 3, 2009
1 parent 638c1db commit 1c67987
Show file tree
Hide file tree
Showing 6 changed files with 349 additions and 9 deletions.
Expand Up @@ -41,9 +41,10 @@ public class InjectionPointBean implements InjectionPoint
private final AbstractAnnotatedMember<?, ? extends Member> memberInjectionPoint;
private final Bean<?> bean;
private final Object beanInstance;

/**
* Creates a new metadata bean for the given injection point information.
*
* @param injectedMember The member of the bean being injected
* @param bean The bean being injected
* @param beanInstance The instance of the bean being injected
Expand All @@ -55,49 +56,41 @@ public InjectionPointBean(AbstractAnnotatedMember<?, ? extends Member> injectedM
this.beanInstance = beanInstance;
}

//@Override
public <T extends Annotation> T getAnnotation(Class<T> annotationType)
{
return this.memberInjectionPoint.getAnnotation(annotationType);
}

//@Override
public Annotation[] getAnnotations()
{
return this.memberInjectionPoint.getAnnotations().toArray(new Annotation[0]);
}

//@Override
public Bean<?> getBean()
{
return this.bean;
}

//@Override
public Set<Annotation> getBindingTypes()
{
return this.memberInjectionPoint.getBindingTypes();
}

//@Override
public Object getInstance()
{
return this.beanInstance;
}

//@Override
public Member getMember()
{
return this.memberInjectionPoint.getDelegate();
}

//@Override
public Type getType()
{
return this.memberInjectionPoint.getType();
}

//@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
{
return this.memberInjectionPoint.isAnnotationPresent(annotationType);
Expand Down
@@ -0,0 +1,211 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, 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.webbeans.test;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.Set;

import javax.webbeans.Current;
import javax.webbeans.Dependent;
import javax.webbeans.InjectionPoint;
import javax.webbeans.Standard;
import javax.webbeans.manager.Bean;

import org.jboss.webbeans.binding.CurrentBinding;
import org.jboss.webbeans.test.beans.ConstructorInjectionPoint;
import org.jboss.webbeans.test.beans.ConstructorInjectionPointBean;
import org.jboss.webbeans.test.beans.FieldInjectionPoint;
import org.jboss.webbeans.test.beans.FieldInjectionPointBean;
import org.jboss.webbeans.test.mock.MockWebBeanDiscovery;
import org.testng.annotations.Test;

/**
* Injection point metadata tests
*
* @author David Allen
*
*/
@SpecVersion("20081222")
public class InjectionPointTest extends AbstractTest
{
@Test(groups = { "broken", "injectionPoint" })
@SpecAssertion(section = "5.11")
public void testGetInstance()
{
webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(FieldInjectionPointBean.class, FieldInjectionPoint.class));
webBeansBootstrap.boot();

// Get an instance of the bean which has another bean injected into it
FieldInjectionPointBean beanWithInjectedBean = manager.getInstanceByType(FieldInjectionPointBean.class, new CurrentBinding());
FieldInjectionPoint beanWithInjectionPoint = beanWithInjectedBean.injectedBean;
assert beanWithInjectionPoint.injectedMetadata != null;
assert beanWithInjectionPoint.injectedMetadata.getInstance().equals(beanWithInjectedBean);
}

@Test(groups = { "broken", "injectionPoint" })
@SpecAssertion(section = "5.11")
public void testGetBean()
{
webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(FieldInjectionPointBean.class, FieldInjectionPoint.class));
webBeansBootstrap.boot();

// Get an instance of the bean which has another bean injected into it
FieldInjectionPointBean beanWithInjectedBean = manager.getInstanceByType(FieldInjectionPointBean.class, new CurrentBinding());
FieldInjectionPoint beanWithInjectionPoint = beanWithInjectedBean.injectedBean;
assert beanWithInjectionPoint.injectedMetadata != null;

Set<Bean<FieldInjectionPointBean>> theBean = manager.resolveByType(FieldInjectionPointBean.class);
assert beanWithInjectionPoint.injectedMetadata.getBean().equals(theBean);
}

@Test(groups = { "broken", "injectionPoint" })
@SpecAssertion(section = "5.11")
public void testGetType()
{
webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(FieldInjectionPointBean.class, FieldInjectionPoint.class));
webBeansBootstrap.boot();

// Get an instance of the bean which has another bean injected into it
FieldInjectionPointBean beanWithInjectedBean = manager.getInstanceByType(FieldInjectionPointBean.class, new CurrentBinding());
FieldInjectionPoint beanWithInjectionPoint = beanWithInjectedBean.injectedBean;
assert beanWithInjectionPoint.injectedMetadata != null;
assert beanWithInjectionPoint.injectedMetadata.getType().equals(FieldInjectionPointBean.class);
}

@Test(groups = { "broken", "injectionPoint" })
@SpecAssertion(section = "5.11")
public void testGetBindingTypes()
{
webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(FieldInjectionPointBean.class, FieldInjectionPoint.class));
webBeansBootstrap.boot();

// Get an instance of the bean which has another bean injected into it
FieldInjectionPointBean beanWithInjectedBean = manager.getInstanceByType(FieldInjectionPointBean.class, new CurrentBinding());
FieldInjectionPoint beanWithInjectionPoint = beanWithInjectedBean.injectedBean;
assert beanWithInjectionPoint.injectedMetadata != null;
Set<Annotation> bindingTypes = beanWithInjectionPoint.injectedMetadata.getBindingTypes();
assert bindingTypes.size() == 1;
assert bindingTypes.iterator().next().equals(Current.class);
}

@Test(groups = { "broken", "injectionPoint" })
@SpecAssertion(section = "5.11")
public void testGetMemberField()
{
webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(FieldInjectionPointBean.class, FieldInjectionPoint.class));
webBeansBootstrap.boot();

// Get an instance of the bean which has another bean injected into it
FieldInjectionPointBean beanWithInjectedBean = manager.getInstanceByType(FieldInjectionPointBean.class, new CurrentBinding());
FieldInjectionPoint beanWithInjectionPoint = beanWithInjectedBean.injectedBean;
assert beanWithInjectionPoint.injectedMetadata != null;
assert Field.class.isAssignableFrom(beanWithInjectionPoint.injectedMetadata.getMember().getClass());
}

@Test(groups = { "stub", "injectionPoint" })
@SpecAssertion(section = "5.11")
public void testGetMemberMethod()
{
assert false;
}

@Test(groups = { "broken", "injectionPoint" })
@SpecAssertion(section = "5.11")
public void testGetMemberConstructor()
{
webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(ConstructorInjectionPointBean.class, ConstructorInjectionPoint.class));
webBeansBootstrap.boot();

// Get an instance of the bean which has another bean injected into it
ConstructorInjectionPointBean beanWithInjectedBean = manager.getInstanceByType(ConstructorInjectionPointBean.class, new CurrentBinding());
ConstructorInjectionPoint beanWithInjectionPoint = beanWithInjectedBean.injectedBean;
assert beanWithInjectionPoint.injectedMetadata != null;
assert Constructor.class.isAssignableFrom(beanWithInjectionPoint.injectedMetadata.getMember().getClass());
}

@Test(groups = { "stub", "injectionPoint" })
@SpecAssertion(section = "5.11")
public void testGetAnnotation()
{
assert false;
}

@Test(groups = { "stub", "injectionPoint" })
@SpecAssertion(section = "5.11")
public void testGetAnnotations()
{
assert false;
}

@Test(groups = { "broken", "injectionPoint" })
@SpecAssertion(section = "5.11")
public void testStandardDeployment()
{
webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(FieldInjectionPointBean.class, FieldInjectionPoint.class));
webBeansBootstrap.boot();

// Get an instance of the bean which has another bean injected into it
FieldInjectionPointBean beanWithInjectedBean = manager.getInstanceByType(FieldInjectionPointBean.class, new CurrentBinding());
FieldInjectionPoint beanWithInjectionPoint = beanWithInjectedBean.injectedBean;
assert beanWithInjectionPoint.injectedMetadata != null;
assert beanWithInjectionPoint.injectedMetadata.getBean().getDeploymentType().equals(Standard.class);
}

@Test(groups = { "broken", "injectionPoint" })
@SpecAssertion(section = "5.11")
public void testDependentScope()
{
webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(FieldInjectionPointBean.class, FieldInjectionPoint.class));
webBeansBootstrap.boot();

// Get an instance of the bean which has another bean injected into it
FieldInjectionPointBean beanWithInjectedBean = manager.getInstanceByType(FieldInjectionPointBean.class, new CurrentBinding());
FieldInjectionPoint beanWithInjectionPoint = beanWithInjectedBean.injectedBean;
assert beanWithInjectionPoint.injectedMetadata != null;
assert beanWithInjectionPoint.injectedMetadata.getBean().getScopeType().equals(Dependent.class);
}

@Test(groups = { "broken", "injectionPoint" })
@SpecAssertion(section = "5.11")
public void testApiTypeInjectionPoint()
{
webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(FieldInjectionPointBean.class, FieldInjectionPoint.class));
webBeansBootstrap.boot();

// Get an instance of the bean which has another bean injected into it
FieldInjectionPointBean beanWithInjectedBean = manager.getInstanceByType(FieldInjectionPointBean.class, new CurrentBinding());
FieldInjectionPoint beanWithInjectionPoint = beanWithInjectedBean.injectedBean;
assert beanWithInjectionPoint.injectedMetadata != null;
assert beanWithInjectionPoint.injectedMetadata.getBean().getTypes().contains(InjectionPoint.class);
}

@Test(groups = { "broken", "injectionPoint" })
@SpecAssertion(section = "5.11")
public void testCurrentBinding()
{
webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(FieldInjectionPointBean.class, FieldInjectionPoint.class));
webBeansBootstrap.boot();

// Get an instance of the bean which has another bean injected into it
FieldInjectionPointBean beanWithInjectedBean = manager.getInstanceByType(FieldInjectionPointBean.class, new CurrentBinding());
FieldInjectionPoint beanWithInjectionPoint = beanWithInjectedBean.injectedBean;
assert beanWithInjectionPoint.injectedMetadata != null;
assert beanWithInjectionPoint.injectedMetadata.getBean().getBindingTypes().contains(Current.class);
}
}
@@ -0,0 +1,35 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, 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.webbeans.test.beans;

import javax.webbeans.InjectionPoint;

/**
* Test bean with injection point on the constructor of the bean
*
* @author David Allen
*
*/
public class ConstructorInjectionPoint
{
public InjectionPoint injectedMetadata;

public ConstructorInjectionPoint(InjectionPoint injectionPoint)
{
injectedMetadata = injectionPoint;
}
}
@@ -0,0 +1,33 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, 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.webbeans.test.beans;

import javax.webbeans.Current;
import javax.webbeans.SessionScoped;

/**
* Test bean to inject another bean which uses injection point metadata on the constructor
*
* @author David Allen
*
*/
@SessionScoped
public class ConstructorInjectionPointBean
{
@Current
public ConstructorInjectionPoint injectedBean;
}
@@ -0,0 +1,34 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, 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.webbeans.test.beans;

import javax.webbeans.Current;
import javax.webbeans.InjectionPoint;

/**
* Test bean with injected metadata in a field about where this bean is injected
* into another bean
*
* @author David Allen
*
*/
public class FieldInjectionPoint
{
@Current
public InjectionPoint injectedMetadata;
}

0 comments on commit 1c67987

Please sign in to comment.