Commit a3c6cf6bfcf2140683a2224439aa6071f023f6ff

Authored by Dancovich
1 parent fd12a4b3
Exists in master

Resolvido bug onde produtor de contexto não produzia se InjectionPoint

no produtor for nulo, mesmo quando um InjectionPoint não é necessário
para produzir.
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContextProducer.java
... ... @@ -134,27 +134,52 @@ public class CustomContextProducer {
134 134  
135 135 @Produces
136 136 public RequestContext getRequestContext(InjectionPoint ip){
137   - return getContext(ip);
  137 + if (ip!=null){
  138 + return getContext(ip);
  139 + }
  140 + else{
  141 + return getContext(RequestContext.class);
  142 + }
138 143 }
139 144  
140 145 @Produces
141 146 public SessionContext getSessionContext(InjectionPoint ip){
142   - return getContext(ip);
  147 + if (ip!=null){
  148 + return getContext(ip);
  149 + }
  150 + else{
  151 + return getContext(SessionContext.class);
  152 + }
143 153 }
144 154  
145 155 @Produces
146 156 public ViewContext getViewContext(InjectionPoint ip){
147   - return getContext(ip);
  157 + if (ip!=null){
  158 + return getContext(ip);
  159 + }
  160 + else{
  161 + return getContext(ViewContext.class);
  162 + }
148 163 }
149 164  
150 165 @Produces
151 166 public StaticContext getStaticContext(InjectionPoint ip){
152   - return getContext(ip);
  167 + if (ip!=null){
  168 + return getContext(ip);
  169 + }
  170 + else{
  171 + return getContext(StaticContext.class);
  172 + }
153 173 }
154 174  
155 175 @Produces
156 176 public ConversationContext getConversationContext(InjectionPoint ip){
157   - return getContext(ip);
  177 + if (ip!=null){
  178 + return getContext(ip);
  179 + }
  180 + else{
  181 + return getContext(ConversationContext.class);
  182 + }
158 183 }
159 184  
160 185 /////////////END OF PRODUCERS///////////////////
... ... @@ -175,7 +200,8 @@ public class CustomContextProducer {
175 200 return producedContext;
176 201 }
177 202  
178   - private CustomContext getContext(Class<? extends CustomContext> contextClass){
  203 + @SuppressWarnings("unchecked")
  204 + private <T extends CustomContext> T getContext(Class<T> contextClass){
179 205 CustomContext producedContext = null;
180 206  
181 207 ArrayList<CustomContext> selectableContexts = new ArrayList<CustomContext>();
... ... @@ -196,7 +222,7 @@ public class CustomContextProducer {
196 222 producedContext = StrategySelector.selectInstance(CustomContext.class, selectableContexts);
197 223 }
198 224  
199   - return producedContext;
  225 + return (T) producedContext;
200 226 }
201 227  
202 228 private Logger getLogger() {
... ...
impl/extension/jpa/src/test/java/producer/ProducerTest.java
... ... @@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
4 4 import static org.junit.Assert.assertNotNull;
5 5 import static org.junit.Assert.assertTrue;
6 6  
  7 +import javax.inject.Inject;
7 8 import javax.persistence.EntityManager;
8 9  
9 10 import org.jboss.arquillian.container.test.api.Deployment;
... ... @@ -25,6 +26,9 @@ import br.gov.frameworkdemoiselle.util.NameQualifier;
25 26 public class ProducerTest {
26 27  
27 28 private static final String PATH = "src/test/resources/producer";
  29 +
  30 + @Inject
  31 + private RequestContext ctx;
28 32  
29 33 @Deployment(name="request_scoped_producer")
30 34 public static WebArchive createDeployment() {
... ... @@ -46,13 +50,11 @@ public class ProducerTest {
46 50  
47 51 @Before
48 52 public void before(){
49   - RequestContext ctx = Beans.getReference(RequestContext.class);
50 53 ctx.activate();
51 54 }
52 55  
53 56 @After
54 57 public void after(){
55   - RequestContext ctx = Beans.getReference(RequestContext.class);
56 58 ctx.deactivate();
57 59 }
58 60  
... ...