Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WELD-632, support static resource producer fields
- Loading branch information
Showing
13 changed files
with
407 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
tests-arquillian/src/test/java/org/jboss/weld/tests/resources/EMFConsumer1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.jboss.weld.tests.resources; | ||
|
||
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.inject.Inject; | ||
import javax.persistence.EntityManagerFactory; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@WebServlet("emfconsumer1") | ||
public class EMFConsumer1 extends HttpServlet | ||
{ | ||
|
||
@Inject | ||
@ProducedViaStaticFieldOnEJB | ||
private EntityManagerFactory emf; | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException | ||
{ | ||
if (emf == null || emf.createEntityManager() == null) | ||
{ | ||
resp.sendError(SC_INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
tests-arquillian/src/test/java/org/jboss/weld/tests/resources/EMFConsumer2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.jboss.weld.tests.resources; | ||
|
||
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.inject.Inject; | ||
import javax.persistence.EntityManagerFactory; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@WebServlet("emfconsumer2") | ||
public class EMFConsumer2 extends HttpServlet | ||
{ | ||
|
||
@Inject | ||
@ProducedViaInstanceFieldOnManagedBean | ||
private EntityManagerFactory emf; | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException | ||
{ | ||
if (emf == null || emf.createEntityManager() == null) | ||
{ | ||
resp.sendError(SC_INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
tests-arquillian/src/test/java/org/jboss/weld/tests/resources/EMFConsumer3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.jboss.weld.tests.resources; | ||
|
||
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.inject.Inject; | ||
import javax.persistence.EntityManagerFactory; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@WebServlet("emfconsumer3") | ||
public class EMFConsumer3 extends HttpServlet | ||
{ | ||
|
||
@Inject | ||
@ProducedViaStaticFieldOnManagedBean | ||
private EntityManagerFactory emf; | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException | ||
{ | ||
if (emf == null || emf.createEntityManager() == null) | ||
{ | ||
resp.sendError(SC_INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
|
||
} |
102 changes: 102 additions & 0 deletions
102
tests-arquillian/src/test/java/org/jboss/weld/tests/resources/EMFFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* 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.resources; | ||
|
||
import static org.jboss.arquillian.api.RunModeType.AS_CLIENT; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.jboss.arquillian.api.Deployment; | ||
import org.jboss.arquillian.api.Run; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.Asset; | ||
import org.jboss.shrinkwrap.api.asset.ByteArrayAsset; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.jboss.weld.tests.category.Integration; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
|
||
import com.gargoylesoftware.htmlunit.Page; | ||
import com.gargoylesoftware.htmlunit.WebClient; | ||
|
||
@Category(Integration.class) | ||
@RunWith(Arquillian.class) | ||
@Run(AS_CLIENT) | ||
public class EMFFactoryTest | ||
{ | ||
|
||
public static final Asset PERSISTENCE_XML = new ByteArrayAsset("<persistence xmlns=\"http://java.sun.com/xml/ns/persistence\" version=\"1.0\"><persistence-unit name=\"pu1\"><jta-data-source>java:/DefaultDS</jta-data-source></persistence-unit></persistence>".getBytes()); | ||
public static final Asset EMPTY_BEANS_XML = new ByteArrayAsset("<beans />".getBytes()); | ||
|
||
@Deployment | ||
public static Archive<?> deploy() | ||
{ | ||
return ShrinkWrap.create(WebArchive.class, "test.war") | ||
.addClasses(JPAResourceProducerSingletonEJB_StaticField.class, ProducedViaStaticFieldOnEJB.class, EMFConsumer1.class) | ||
.addClasses(JPAResourceProducerManagedBean_InstanceField.class, ProducedViaInstanceFieldOnManagedBean.class, EMFConsumer2.class) | ||
.addClasses(JPAResourceProducerManagedBean_StaticField.class, ProducedViaStaticFieldOnManagedBean.class, EMFConsumer3.class) | ||
.addManifestResource(PERSISTENCE_XML, "persistence.xml") | ||
.addWebResource(EMPTY_BEANS_XML, "beans.xml"); | ||
} | ||
|
||
/* | ||
* description = "WELD-632" | ||
*/ | ||
@Test | ||
public void testStaticEJBEMFProducerField() throws Exception | ||
{ | ||
WebClient client = new WebClient(); | ||
client.setThrowExceptionOnFailingStatusCode(false); | ||
Page page = client.getPage(getPath("emfconsumer1")); | ||
|
||
assertEquals(200, page.getWebResponse().getStatusCode()); | ||
} | ||
|
||
/* | ||
* description = "WELD-632" | ||
*/ | ||
@Test | ||
public void testInstanceManagedBeanEMFProducerField() throws Exception | ||
{ | ||
WebClient client = new WebClient(); | ||
client.setThrowExceptionOnFailingStatusCode(false); | ||
Page page = client.getPage(getPath("emfconsumer2")); | ||
|
||
assertEquals(200, page.getWebResponse().getStatusCode()); | ||
} | ||
|
||
/* | ||
* description = "WELD-632" | ||
*/ | ||
@Test | ||
public void testStaticManagedBeanEMFProducerField() throws Exception | ||
{ | ||
WebClient client = new WebClient(); | ||
client.setThrowExceptionOnFailingStatusCode(false); | ||
Page page = client.getPage(getPath("emfconsumer3")); | ||
|
||
assertEquals(200, page.getWebResponse().getStatusCode()); | ||
} | ||
|
||
protected String getPath(String viewId) | ||
{ | ||
// TODO: this should be moved out and be handled by Arquillian | ||
return "http://localhost:8080/test/" + viewId; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...est/java/org/jboss/weld/tests/resources/JPAResourceProducerManagedBean_InstanceField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.jboss.weld.tests.resources; | ||
|
||
import javax.enterprise.inject.Produces; | ||
import javax.persistence.EntityManagerFactory; | ||
import javax.persistence.PersistenceUnit; | ||
|
||
public class JPAResourceProducerManagedBean_InstanceField | ||
{ | ||
@Produces | ||
@PersistenceUnit(unitName = "pu1") | ||
@ProducedViaInstanceFieldOnManagedBean | ||
public EntityManagerFactory customerDatabasePersistenceUnit1; | ||
} |
13 changes: 13 additions & 0 deletions
13
.../test/java/org/jboss/weld/tests/resources/JPAResourceProducerManagedBean_StaticField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.jboss.weld.tests.resources; | ||
|
||
import javax.enterprise.inject.Produces; | ||
import javax.persistence.EntityManagerFactory; | ||
import javax.persistence.PersistenceUnit; | ||
|
||
public class JPAResourceProducerManagedBean_StaticField | ||
{ | ||
@Produces | ||
@PersistenceUnit(unitName = "pu1") | ||
@ProducedViaStaticFieldOnManagedBean | ||
public static EntityManagerFactory customerDatabasePersistenceUnit1; | ||
} |
15 changes: 15 additions & 0 deletions
15
...test/java/org/jboss/weld/tests/resources/JPAResourceProducerSingletonEJB_StaticField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.jboss.weld.tests.resources; | ||
|
||
import javax.ejb.Singleton; | ||
import javax.enterprise.inject.Produces; | ||
import javax.persistence.EntityManagerFactory; | ||
import javax.persistence.PersistenceUnit; | ||
|
||
@Singleton | ||
public class JPAResourceProducerSingletonEJB_StaticField | ||
{ | ||
@Produces | ||
@PersistenceUnit(unitName = "pu1") | ||
@ProducedViaStaticFieldOnEJB | ||
public static EntityManagerFactory customerDatabasePersistenceUnit1; | ||
} |
36 changes: 36 additions & 0 deletions
36
...n/src/test/java/org/jboss/weld/tests/resources/ProducedViaInstanceFieldOnManagedBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.resources; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.inject.Qualifier; | ||
|
||
@Qualifier | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({FIELD, METHOD, TYPE, PARAMETER}) | ||
public @interface ProducedViaInstanceFieldOnManagedBean | ||
{ | ||
|
||
} |
Oops, something went wrong.