Commit a3c6cf6bfcf2140683a2224439aa6071f023f6ff
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.
Showing
2 changed files
with
37 additions
and
9 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContextProducer.java
| @@ -134,27 +134,52 @@ public class CustomContextProducer { | @@ -134,27 +134,52 @@ public class CustomContextProducer { | ||
| 134 | 134 | ||
| 135 | @Produces | 135 | @Produces |
| 136 | public RequestContext getRequestContext(InjectionPoint ip){ | 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 | @Produces | 145 | @Produces |
| 141 | public SessionContext getSessionContext(InjectionPoint ip){ | 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 | @Produces | 155 | @Produces |
| 146 | public ViewContext getViewContext(InjectionPoint ip){ | 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 | @Produces | 165 | @Produces |
| 151 | public StaticContext getStaticContext(InjectionPoint ip){ | 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 | @Produces | 175 | @Produces |
| 156 | public ConversationContext getConversationContext(InjectionPoint ip){ | 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 | /////////////END OF PRODUCERS/////////////////// | 185 | /////////////END OF PRODUCERS/////////////////// |
| @@ -175,7 +200,8 @@ public class CustomContextProducer { | @@ -175,7 +200,8 @@ public class CustomContextProducer { | ||
| 175 | return producedContext; | 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 | CustomContext producedContext = null; | 205 | CustomContext producedContext = null; |
| 180 | 206 | ||
| 181 | ArrayList<CustomContext> selectableContexts = new ArrayList<CustomContext>(); | 207 | ArrayList<CustomContext> selectableContexts = new ArrayList<CustomContext>(); |
| @@ -196,7 +222,7 @@ public class CustomContextProducer { | @@ -196,7 +222,7 @@ public class CustomContextProducer { | ||
| 196 | producedContext = StrategySelector.selectInstance(CustomContext.class, selectableContexts); | 222 | producedContext = StrategySelector.selectInstance(CustomContext.class, selectableContexts); |
| 197 | } | 223 | } |
| 198 | 224 | ||
| 199 | - return producedContext; | 225 | + return (T) producedContext; |
| 200 | } | 226 | } |
| 201 | 227 | ||
| 202 | private Logger getLogger() { | 228 | private Logger getLogger() { |
impl/extension/jpa/src/test/java/producer/ProducerTest.java
| @@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals; | @@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals; | ||
| 4 | import static org.junit.Assert.assertNotNull; | 4 | import static org.junit.Assert.assertNotNull; |
| 5 | import static org.junit.Assert.assertTrue; | 5 | import static org.junit.Assert.assertTrue; |
| 6 | 6 | ||
| 7 | +import javax.inject.Inject; | ||
| 7 | import javax.persistence.EntityManager; | 8 | import javax.persistence.EntityManager; |
| 8 | 9 | ||
| 9 | import org.jboss.arquillian.container.test.api.Deployment; | 10 | import org.jboss.arquillian.container.test.api.Deployment; |
| @@ -25,6 +26,9 @@ import br.gov.frameworkdemoiselle.util.NameQualifier; | @@ -25,6 +26,9 @@ import br.gov.frameworkdemoiselle.util.NameQualifier; | ||
| 25 | public class ProducerTest { | 26 | public class ProducerTest { |
| 26 | 27 | ||
| 27 | private static final String PATH = "src/test/resources/producer"; | 28 | private static final String PATH = "src/test/resources/producer"; |
| 29 | + | ||
| 30 | + @Inject | ||
| 31 | + private RequestContext ctx; | ||
| 28 | 32 | ||
| 29 | @Deployment(name="request_scoped_producer") | 33 | @Deployment(name="request_scoped_producer") |
| 30 | public static WebArchive createDeployment() { | 34 | public static WebArchive createDeployment() { |
| @@ -46,13 +50,11 @@ public class ProducerTest { | @@ -46,13 +50,11 @@ public class ProducerTest { | ||
| 46 | 50 | ||
| 47 | @Before | 51 | @Before |
| 48 | public void before(){ | 52 | public void before(){ |
| 49 | - RequestContext ctx = Beans.getReference(RequestContext.class); | ||
| 50 | ctx.activate(); | 53 | ctx.activate(); |
| 51 | } | 54 | } |
| 52 | 55 | ||
| 53 | @After | 56 | @After |
| 54 | public void after(){ | 57 | public void after(){ |
| 55 | - RequestContext ctx = Beans.getReference(RequestContext.class); | ||
| 56 | ctx.deactivate(); | 58 | ctx.deactivate(); |
| 57 | } | 59 | } |
| 58 | 60 |