-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WELD-1823 a null value should be returned for the injection point if …
…it is not being injected into any injection point
- Loading branch information
Showing
6 changed files
with
288 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
tests-arquillian/src/test/java/org/jboss/weld/tests/injectionPoint/weld1823/CDIBean.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,48 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, 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.weld.tests.injectionPoint.weld1823; | ||
|
||
import java.util.Set; | ||
|
||
import javax.enterprise.context.spi.CreationalContext; | ||
import javax.enterprise.inject.spi.Bean; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
|
||
/* | ||
*@author Emily Jiang | ||
*/ | ||
public class CDIBean { | ||
|
||
CDIBean2 beanManagerInstance; | ||
|
||
public CDIBean(BeanManager manager){ | ||
Set<Bean<?>> beanList = manager.getBeans(CDIBean2.class); | ||
if (beanList!=null && !beanList.isEmpty()){ | ||
Bean<?> bean = beanList.iterator().next(); | ||
CreationalContext<?> context = manager.createCreationalContext(bean); | ||
beanManagerInstance = (CDIBean2) manager.getReference(bean, CDIBean2.class, context); | ||
} | ||
} | ||
|
||
public String getData() { | ||
return beanManagerInstance.getData(); | ||
} | ||
|
||
public void setData(String data) { | ||
beanManagerInstance.setData(data); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests-arquillian/src/test/java/org/jboss/weld/tests/injectionPoint/weld1823/CDIBean2.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 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, 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.weld.tests.injectionPoint.weld1823; | ||
|
||
/* | ||
*@author Emily Jiang | ||
*/ | ||
public class CDIBean2 { | ||
private String data; | ||
|
||
public String getData() { | ||
return data; | ||
} | ||
|
||
public void setData(String data) { | ||
this.data = data; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...quillian/src/test/java/org/jboss/weld/tests/injectionPoint/weld1823/CDIBean2Producer.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,35 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, 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.weld.tests.injectionPoint.weld1823; | ||
|
||
import javax.enterprise.inject.Produces; | ||
import javax.enterprise.inject.spi.InjectionPoint; | ||
|
||
/* | ||
*@author Emily Jiang | ||
*/ | ||
public class CDIBean2Producer { | ||
|
||
@Produces | ||
public CDIBean2 produce(InjectionPoint ip) { | ||
|
||
if (ip != null) { | ||
throw new RuntimeException("InjectionPoint exists when producing CDIBean2: " + ip.toString()); | ||
} | ||
return new CDIBean2(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...rquillian/src/test/java/org/jboss/weld/tests/injectionPoint/weld1823/CDIBeanProducer.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,40 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, 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.weld.tests.injectionPoint.weld1823; | ||
|
||
import javax.enterprise.inject.Produces; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.enterprise.inject.spi.InjectionPoint; | ||
import javax.inject.Inject; | ||
|
||
/* | ||
*@author Emily Jiang | ||
*/ | ||
public class CDIBeanProducer { | ||
|
||
@Inject | ||
private BeanManager manager; | ||
|
||
@Produces | ||
public CDIBean produce(InjectionPoint ip) { | ||
|
||
if (ip == null) { | ||
throw new RuntimeException("InjectionPoint is NULL when producing CDIBean"); | ||
} | ||
return new CDIBean(manager); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
tests-arquillian/src/test/java/org/jboss/weld/tests/injectionPoint/weld1823/TestServlet.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,72 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, 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.weld.tests.injectionPoint.weld1823; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.Set; | ||
|
||
import javax.enterprise.context.spi.CreationalContext; | ||
import javax.enterprise.inject.Instance; | ||
import javax.enterprise.inject.spi.Bean; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.inject.Inject; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
/* | ||
*@author Emily Jiang | ||
*/ | ||
@WebServlet("/ProducerNullIPServlet") | ||
public class TestServlet extends HttpServlet { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@SuppressWarnings("unused") | ||
@Inject | ||
private CDIBean bean; | ||
|
||
@Inject | ||
private BeanManager manager; | ||
|
||
@SuppressWarnings("unused") | ||
@Inject | ||
private Instance<CDIBean2> anotherBeanInstance; | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
doPost(req, resp); | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
|
||
PrintWriter out = resp.getWriter(); | ||
|
||
Set<Bean<?>> beanList = manager.getBeans(CDIBean2.class); | ||
if (beanList != null && !beanList.isEmpty()) { | ||
Bean<?> bean = beanList.iterator().next(); | ||
CreationalContext<?> context = manager.createCreationalContext(bean); | ||
CDIBean2 beanManagerInstance = (CDIBean2) manager.getReference(bean, CDIBean2.class, context); | ||
beanManagerInstance.setData("Test2"); | ||
} | ||
out.println("Test Sucessful!"); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
tests-arquillian/src/test/java/org/jboss/weld/tests/injectionPoint/weld1823/Weld1823.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,61 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, 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.weld.tests.injectionPoint.weld1823; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.URL; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.ArchivePaths; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.jboss.weld.tests.category.Integration; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
|
||
/* | ||
*@author Kirill Gaevskii | ||
*/ | ||
@RunWith(Arquillian.class) | ||
@Category(Integration.class) | ||
@Ignore("WELD-1823") | ||
public class Weld1823 { | ||
|
||
@Deployment(testable = false) | ||
public static Archive<?> deploy() { | ||
return ShrinkWrap.create(WebArchive.class).addPackage(CDIBean.class.getPackage()) | ||
.addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")); | ||
} | ||
|
||
@Test | ||
public void testNullValueForInjectionPoint(@ArquillianResource(TestServlet.class) URL baseURL) throws IOException { | ||
final URL url = new URL(baseURL, "ProducerNullIPServlet"); | ||
|
||
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); | ||
assertEquals(reader.readLine(), "Test Sucessful!"); | ||
} | ||
} |