Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDITCK-398 and CDITCK-399 - Add tests for @Interceptor, @Decorator, normal scopes, and stereotypes as bean defining annotations #48

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
/**
*
* @author Martin Kouba
* @author Matus Abaffy
*/
@SpecVersion(spec = "cdi", version = "1.1 Final Release")
public class BeanDiscoveryTest extends AbstractTest {

@SuppressWarnings("unchecked")
@Deployment
public static WebArchive createTestArchive() {

Expand All @@ -53,11 +55,13 @@ public static WebArchive createTestArchive() {
.addClass(Charlie.class)
.addAsManifestResource(new StringAsset(Descriptors.create(BeansDescriptor.class).exportAsString()), "beans.xml");
// Bean defining annotation and no beans.xml
JavaArchive delta = ShrinkWrap.create(JavaArchive.class).addClass(Delta.class);
JavaArchive delta = ShrinkWrap.create(JavaArchive.class).addClasses(Delta.class, Golf.class, India.class, Kilo.class,
Mike.class, Interceptor1.class, Decorator1.class);
// Bean defining annotation and 1.1 version beans.xml with bean-discovery-mode of annotated
JavaArchive echo = ShrinkWrap
.create(JavaArchive.class)
.addClasses(Echo.class, EchoNotABean.class)
.addClasses(Echo.class, EchoNotABean.class, Hotel.class, Juliet.class, JulietNotABean.class, Lima.class,
November.class, Interceptor2.class, Decorator2.class)
.addAsManifestResource(
new StringAsset(newBeans11Descriptor().setBeanDiscoveryMode(BeanDiscoveryMode.ANNOTATED)
.exportAsString()), "beans.xml");
Expand All @@ -73,8 +77,10 @@ public static WebArchive createTestArchive() {
JavaArchive legacy = ShrinkWrap.create(JavaArchive.class).addClasses(LegacyExtension.class, LegacyAlpha.class,
LegacyBravo.class).addAsServiceProvider(Extension.class, LegacyExtension.class);

return new WebArchiveBuilder().withTestClass(BeanDiscoveryTest.class).withClasses(VerifyingExtension.class)
.withExtension(VerifyingExtension.class).withLibrary(Ping.class)
return new WebArchiveBuilder().withTestClass(BeanDiscoveryTest.class)
.withClasses(VerifyingExtension.class, ScopesExtension.class, Binding.class, MyNormalScope.class, MyPseudoScope.class,
MyNormalContext.class, MyPseudoContext.class)
.withExtensions(VerifyingExtension.class, ScopesExtension.class).withLibrary(Ping.class)
.withLibraries(alpha, bravo, charlie, delta, echo, foxtrot, legacy).build();
}

Expand Down Expand Up @@ -103,17 +109,71 @@ public void testExplicitBeanArchiveLegacyDescriptor(Charlie charlie) {

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER, groups = INTEGRATION)
@SpecAssertions({ @SpecAssertion(section = BEAN_ARCHIVE, id = "ca"), @SpecAssertion(section = BEAN_DISCOVERY, id = "tb"),
@SpecAssertion(section = BEAN_DEFINING_ANNOTATIONS, id = "b") })
public void testImplicitBeanArchiveNoDescriptor(Delta delta) {
@SpecAssertion(section = BEAN_DEFINING_ANNOTATIONS, id = "ba"),
@SpecAssertion(section = BEAN_DEFINING_ANNOTATIONS, id = "bb") })
public void testNormalScopeImplicitBeanArchiveNoDescriptor(Delta delta, Golf golf) {
assertDiscoveredAndAvailable(delta, Delta.class);
assertDiscoveredAndAvailable(golf, Golf.class);
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER, groups = INTEGRATION)
@SpecAssertions({ @SpecAssertion(section = BEAN_ARCHIVE, id = "ca"), @SpecAssertion(section = BEAN_DISCOVERY, id = "tb"),
@SpecAssertion(section = BEAN_DEFINING_ANNOTATIONS, id = "b") })
public void testImplicitBeanArchiveModeAnnotated(Echo echo) {
@SpecAssertion(section = BEAN_DEFINING_ANNOTATIONS, id = "ba"),
@SpecAssertion(section = BEAN_DEFINING_ANNOTATIONS, id = "bb") })
public void testNormalScopeImplicitBeanArchiveModeAnnotated(Echo echo, Hotel hotel) {
assertDiscoveredAndAvailable(echo, Echo.class);
assertNotDiscoveredAndNotAvailable(EchoNotABean.class);
assertDiscoveredAndAvailable(hotel, Hotel.class);
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER, groups = INTEGRATION)
@SpecAssertions({ @SpecAssertion(section = BEAN_DISCOVERY, id = "tb"),
@SpecAssertion(section = BEAN_DEFINING_ANNOTATIONS, id = "bf") })
public void testDependentScopeImplicitBeanArchiveNoDescriptor(India india) {
assertDiscoveredAndAvailable(india, India.class);
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER, groups = INTEGRATION)
@SpecAssertions({ @SpecAssertion(section = BEAN_DISCOVERY, id = "tb"),
@SpecAssertion(section = BEAN_DEFINING_ANNOTATIONS, id = "bf"),
@SpecAssertion(section = BEAN_DEFINING_ANNOTATIONS, id = "ca") })
public void testPseudoScopeImplicitBeanArchiveModeAnnotated(Juliet juliet) {
assertDiscoveredAndAvailable(juliet, Juliet.class);
assertNotDiscoveredAndNotAvailable(JulietNotABean.class);
}

@Test(groups = INTEGRATION)
@SpecAssertions({ @SpecAssertion(section = BEAN_DEFINING_ANNOTATIONS, id = "bc"),
@SpecAssertion(section = BEAN_DISCOVERY, id = "tb") })
public void testInterceptorIsBeanDefiningAnnotation() {
assertDiscovered(Interceptor1.class);
assertDiscovered(Interceptor2.class);
}

@Test(groups = INTEGRATION)
@SpecAssertions({ @SpecAssertion(section = BEAN_DEFINING_ANNOTATIONS, id = "bd"),
@SpecAssertion(section = BEAN_DISCOVERY, id = "tb") })
public void testDecoratorIsBeanDefiningAnnotation() {
assertDiscovered(Decorator1.class);
assertDiscovered(Decorator2.class);
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER, groups = INTEGRATION)
@SpecAssertions({ @SpecAssertion(section = BEAN_DISCOVERY, id = "tb"),
@SpecAssertion(section = BEAN_DEFINING_ANNOTATIONS, id = "be"),
@SpecAssertion(section = BEAN_DEFINING_ANNOTATIONS, id = "cb") })
public void testStereotypeImplicitBeanArchiveNoDescriptor(Mike mike) {
assertDiscoveredAndAvailable(mike, Mike.class);
assertDiscovered(Kilo.class);
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER, groups = INTEGRATION)
@SpecAssertions({ @SpecAssertion(section = BEAN_DISCOVERY, id = "tb"),
@SpecAssertion(section = BEAN_DEFINING_ANNOTATIONS, id = "be"),
@SpecAssertion(section = BEAN_DEFINING_ANNOTATIONS, id = "cb") })
public void testStereotypeImplicitBeanArchiveModeAnnotatedr(November november) {
assertDiscoveredAndAvailable(november, November.class);
assertDiscovered(Lima.class);
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER, groups = INTEGRATION)
Expand All @@ -130,12 +190,16 @@ public void testNotBeanArchiveExtension(LegacyAlpha legacyAlpha) {
}

private <T extends Ping> void assertDiscoveredAndAvailable(T reference, Class<T> clazz) {
assertTrue(extension.getObservedAnnotatedTypes().contains(clazz));
assertDiscovered(clazz);
assertNotNull(reference);
reference.pong();
getUniqueBean(clazz);
}

private void assertDiscovered(Class<?> clazz) {
assertTrue(extension.getObservedAnnotatedTypes().contains(clazz), clazz.getSimpleName() + " not discovered.");
}

private <T> void assertNotDiscoveredAndNotAvailable(Class<T> clazz) {
assertFalse(extension.getObservedAnnotatedTypes().contains(clazz));
assertTrue(getBeans(clazz).isEmpty());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2014, 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.cdi.tck.tests.deployment.discovery;

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.interceptor.InterceptorBinding;

@Target({ TYPE, METHOD })
@Retention(RUNTIME)
@Documented
@InterceptorBinding
public @interface Binding {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2014, 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.cdi.tck.tests.deployment.discovery;

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

@Decorator
public abstract class Decorator1 implements Ping {

@Inject
@Delegate
Ping ping;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2014, 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.cdi.tck.tests.deployment.discovery;

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

@Decorator
public abstract class Decorator2 implements Ping {

@Inject
@Delegate
Ping ping;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2014, 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.cdi.tck.tests.deployment.discovery;

@MyNormalScope
public class Golf implements Ping {

@Override
public void pong() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2014, 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.cdi.tck.tests.deployment.discovery;

@MyNormalScope
public class Hotel implements Ping {

@Override
public void pong() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2014, 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.cdi.tck.tests.deployment.discovery;

import javax.enterprise.context.Dependent;

@Dependent
public class India implements Ping {

@Override
public void pong() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2014, 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.cdi.tck.tests.deployment.discovery;

import javax.interceptor.Interceptor;

@Interceptor
@Binding
public class Interceptor1 {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2014, 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.cdi.tck.tests.deployment.discovery;

import javax.interceptor.Interceptor;

@Interceptor
@Binding
public class Interceptor2 {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2014, 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.cdi.tck.tests.deployment.discovery;

import javax.enterprise.context.Dependent;

@Dependent
public class Juliet implements Ping {

@Override
public void pong() {
}
}