Skip to content

Commit

Permalink
SOLDER-95 migrate tests to compatibility module
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Mar 25, 2011
1 parent c4fc440 commit 2f3aab0
Show file tree
Hide file tree
Showing 32 changed files with 1,060 additions and 20 deletions.
8 changes: 8 additions & 0 deletions pom.xml
Expand Up @@ -118,6 +118,14 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<!-- FIXME version/scope to seam-parent -->
<version>1.3.RC2</version>
<scope>test</scope>
</dependency>

</dependencies>

<profiles>
Expand Down
@@ -0,0 +1,65 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.jboss.seam.compat.alternative;

import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
import static org.junit.Assert.assertEquals;

import javax.enterprise.inject.spi.Extension;
import javax.inject.Inject;

import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.descriptor.api.Descriptors;
import org.jboss.shrinkwrap.descriptor.api.spec.cdi.beans.BeansDescriptor;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* This test verifies that alternatives work correctly in BDAs that contain at least one extension.
*
* @see <a href="http://java.net/jira/browse/GLASSFISH-15791">GLASSFISH-15791</a> (resolved)
*
* @author <a href="http://community.jboss.org/people/jharting">Jozef Hartinger</a>
*/
@RunWith(Arquillian.class)
public class AlternativeTest {
@Inject
private Foo foo;

@Deployment
public static WebArchive getDeployment() {
return create(WebArchive.class, "test.war").addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml").addAsLibrary(getJar());
}

public static JavaArchive getJar() {
BeansDescriptor beansXml = Descriptors.create(BeansDescriptor.class).alternativeClass(BarAlternative.class);
return create(JavaArchive.class, "test.jar")
.addClasses(Foo.class, Bar.class, BarAlternative.class, NoopExtension.class)
.addAsManifestResource(new StringAsset(beansXml.exportAsString()), beansXml.getDescriptorName())
.addAsServiceProvider(Extension.class, NoopExtension.class);
}

@Test
public void testAlternative() {
assertEquals("barAlternative", foo.getBar().ping());
}
}
23 changes: 23 additions & 0 deletions src/test/java/org/jboss/seam/compat/alternative/Bar.java
@@ -0,0 +1,23 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.jboss.seam.compat.alternative;

public class Bar {
public String ping() {
return "bar";
}
}
@@ -0,0 +1,27 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.jboss.seam.compat.alternative;

import javax.enterprise.inject.Alternative;

@Alternative
public class BarAlternative extends Bar {
@Override
public String ping() {
return super.ping() + "Alternative";
}
}
28 changes: 28 additions & 0 deletions src/test/java/org/jboss/seam/compat/alternative/Foo.java
@@ -0,0 +1,28 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.jboss.seam.compat.alternative;

import javax.inject.Inject;

public class Foo {
@Inject
private Bar bar;

public Bar getBar() {
return bar;
}
}
23 changes: 23 additions & 0 deletions src/test/java/org/jboss/seam/compat/alternative/NoopExtension.java
@@ -0,0 +1,23 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.jboss.seam.compat.alternative;

import javax.enterprise.inject.spi.Extension;

public class NoopExtension implements Extension {

}
Expand Up @@ -4,8 +4,11 @@
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.descriptor.api.Descriptors;
import org.jboss.shrinkwrap.descriptor.api.spec.cdi.beans.BeansDescriptor;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -24,10 +27,11 @@ public static WebArchive createDeployment() {
.addClasses(Bit.class, FlipBit.class, FlipBitInterceptor.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

BeansDescriptor beansXml = Descriptors.create(BeansDescriptor.class).interceptor(FlipBitInterceptor.class);
return ShrinkWrap.create(WebArchive.class, "test.war")
.addClasses(Bean.class)
.addAsLibrary(jar)
.addAsWebInfResource(EnableInterceptorTest.class.getPackage(), "EnableInterceptorTest-beans.xml", "beans.xml");
.addAsWebInfResource(new StringAsset(beansXml.exportAsString()), beansXml.getDescriptorName());
}

@Test
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/org/jboss/seam/compat/package-info.java
@@ -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.
*/
/**
* A collection of tests that explore CDI implementation problems that have threatened
* the portability of Seam 3.
*
* @author <a href="http://community.jboss.org/people/dan.j.allen">Dan Allen</a>
* @author <a href="http://community.jboss.org/people/lightguard">Jason Porter</a>
* @author <a href="http://community.jboss.org/people/jharting">Jozef Hartinger</a>
*/
package org.jboss.seam.compat;

@@ -0,0 +1,28 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.jboss.seam.compat.registration;

import javax.inject.Inject;

public class AnotherBeanClassToRegister {
@Inject
private BeanClassToRegister collaborator;

public BeanClassToRegister getCollaborator() {
return collaborator;
}
}
@@ -0,0 +1,33 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.jboss.seam.compat.registration;

import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.enterprise.inject.spi.Extension;

/**
* An extension which registers a bean programmatically.
*
* @author <a href="http://community.jboss.org/people/dan.j.allen">Dan Allen</a>
*/
public class AnotherManualBeanRegistrationExtension implements Extension {
public void registerBeans(@Observes BeforeBeanDiscovery event, BeanManager bm) {
event.addAnnotatedType(bm.createAnnotatedType(AnotherBeanClassToRegister.class));
}
}
@@ -0,0 +1,30 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.jboss.seam.compat.registration;

/**
* A valid bean class which will be registered manually using a CDI extension rather than auto-discovered by inclusion in a bean
* archive.
*
* @author <a href="http://community.jboss.org/people/LightGuard">Jason Porter</a>
* @author <a href="http://community.jboss.org/people/dan.j.allen">Dan Allen</a>
*/
public class BeanClassToRegister {
public boolean isInvokable() {
return true;
}
}
@@ -0,0 +1,61 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.jboss.seam.compat.registration;

import javax.enterprise.inject.spi.Extension;

import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;

/**
* Validates that a bean can be registered by an extension that resides in a non-bean archive.
*
* @see <a href="http://java.net/jira/browse/GLASSFISH-14808">GLASSFISH-14808</a> (resolved)
*
* @author <a href="http://community.jboss.org/people/LightGuard">Jason Porter</a>
* @author <a href="http://community.jboss.org/people/dan.j.allen">Dan Allen</a>
*/
@RunWith(Arquillian.class)
public class BeanRegistrationByExtensionInNonBeanArchiveTest {
@Deployment
public static Archive<?> createTestArchive() {
// Our non-bean archive with an extension
JavaArchive jar1 = ShrinkWrap.create(JavaArchive.class, "a.jar")
.addClasses(BeanClassToRegister.class, ManualBeanRegistrationExtension.class)
.addAsServiceProvider(Extension.class, ManualBeanRegistrationExtension.class);

// Web archive is necessary so that Arquillian can find the BeanManager
return ShrinkWrap.create(WebArchive.class, "test.war").addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsLibrary(jar1);
}

@Test
public void shouldFindBeanReference(BeanClassToRegister bean) {
assertThat(bean, is(notNullValue()));
assertThat(bean.isInvokable(), equalTo(true));
}
}

0 comments on commit 2f3aab0

Please sign in to comment.