Commit 40c78306ca0e799f1979a03b6bd65a4ef37ec46e
Exists in
master
Merge branch '2.4.0' of git@github.com:demoiselle/framework.git into 2.4.0
Showing
9 changed files
with
250 additions
and
125 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CoreBootstrap.java
@@ -86,9 +86,9 @@ public class CoreBootstrap implements Extension { | @@ -86,9 +86,9 @@ public class CoreBootstrap implements Extension { | ||
86 | } | 86 | } |
87 | 87 | ||
88 | public void initializeCustomContexts(@Observes final AfterBeanDiscovery event) { | 88 | public void initializeCustomContexts(@Observes final AfterBeanDiscovery event) { |
89 | - //StaticContext já é criado e gerenciado por esta chamada | 89 | + // StaticContext já é criado e gerenciado por esta chamada |
90 | ContextManager.initialize(event); | 90 | ContextManager.initialize(event); |
91 | - | 91 | + |
92 | ContextManager.activate(StaticContext.class, StaticScoped.class); | 92 | ContextManager.activate(StaticContext.class, StaticScoped.class); |
93 | } | 93 | } |
94 | 94 | ||
@@ -97,7 +97,7 @@ public class CoreBootstrap implements Extension { | @@ -97,7 +97,7 @@ public class CoreBootstrap implements Extension { | ||
97 | } | 97 | } |
98 | 98 | ||
99 | public void engineOff(@Observes final BeforeShutdown event) { | 99 | public void engineOff(@Observes final BeforeShutdown event) { |
100 | - ContextManager.deactivate(StaticContext.class, StaticScoped.class); | 100 | + ContextManager.shutdown(); |
101 | getLogger().info(getBundle().getString("engine-off")); | 101 | getLogger().info(getBundle().getString("engine-off")); |
102 | } | 102 | } |
103 | } | 103 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ContextManager.java
@@ -9,6 +9,7 @@ import java.util.Locale; | @@ -9,6 +9,7 @@ import java.util.Locale; | ||
9 | import javax.enterprise.context.ContextNotActiveException; | 9 | import javax.enterprise.context.ContextNotActiveException; |
10 | import javax.enterprise.context.spi.Context; | 10 | import javax.enterprise.context.spi.Context; |
11 | import javax.enterprise.inject.spi.AfterBeanDiscovery; | 11 | import javax.enterprise.inject.spi.AfterBeanDiscovery; |
12 | +import javax.enterprise.inject.spi.BeanManager; | ||
12 | 13 | ||
13 | import org.slf4j.Logger; | 14 | import org.slf4j.Logger; |
14 | 15 | ||
@@ -20,62 +21,84 @@ import br.gov.frameworkdemoiselle.util.Beans; | @@ -20,62 +21,84 @@ import br.gov.frameworkdemoiselle.util.Beans; | ||
20 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 21 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
21 | 22 | ||
22 | /** | 23 | /** |
23 | - * <p>Manage custom contexts relevant to Demoiselle operations.</p> | ||
24 | - * | ||
25 | - * <p>When starting, the ContextManager must be initialized by calling {@link #initialize(AfterBeanDiscovery event)} | ||
26 | - * inside any methods observing the {@link AfterBeanDiscovery} event. Upon initialization a {@link StaticContext} will be | ||
27 | - * created to handle {@link StaticScoped} beans (but not activated, you must call {@link #activate(Class customContextClass, Class scope)} | ||
28 | - * to activate this context).</p> | ||
29 | - * | ||
30 | - * <p>If an extension wants to manage another custom context, it must first call {@link #add(CustomContext context, AfterBeanDiscovery event)} | ||
31 | - * to add it's context to the list of managed contexts and then call {@link #activate(Class customContextClass, Class scope)} whenever | ||
32 | - * it wants to activate this added context (contexts added through the {@link #add(CustomContext context, AfterBeanDiscovery event)} method are also | ||
33 | - * not activated upon adding).</p> | 24 | + * <p> |
25 | + * Manage custom contexts relevant to Demoiselle operations. | ||
26 | + * </p> | ||
27 | + * <p> | ||
28 | + * When starting, the ContextManager must be initialized by calling {@link #initialize(AfterBeanDiscovery event)} inside | ||
29 | + * any methods observing the {@link AfterBeanDiscovery} event. Upon initialization a {@link StaticContext} will be | ||
30 | + * created to handle {@link StaticScoped} beans (but not activated, you must call | ||
31 | + * {@link #activate(Class customContextClass, Class scope)} to activate this context). | ||
32 | + * </p> | ||
33 | + * <p> | ||
34 | + * If an extension wants to manage another custom context, it must first call | ||
35 | + * {@link #add(CustomContext context, AfterBeanDiscovery event)} to add it's context to the list of managed contexts and | ||
36 | + * then call {@link #activate(Class customContextClass, Class scope)} whenever it wants to activate this added context | ||
37 | + * (contexts added through the {@link #add(CustomContext context, AfterBeanDiscovery event)} method are also not | ||
38 | + * activated upon adding). | ||
39 | + * </p> | ||
34 | * | 40 | * |
35 | * @author serpro | 41 | * @author serpro |
36 | - * | ||
37 | */ | 42 | */ |
38 | public class ContextManager { | 43 | public class ContextManager { |
39 | - | ||
40 | - private static List<CustomContextCounter> contexts = Collections.synchronizedList(new ArrayList<CustomContextCounter>()); | ||
41 | - | 44 | + |
45 | + private static List<CustomContextCounter> contexts = Collections | ||
46 | + .synchronizedList(new ArrayList<CustomContextCounter>()); | ||
47 | + | ||
42 | private static boolean initialized = false; | 48 | private static boolean initialized = false; |
43 | - | 49 | + |
44 | private static ResourceBundle bundle; | 50 | private static ResourceBundle bundle; |
45 | - | 51 | + |
46 | private static Logger logger; | 52 | private static Logger logger; |
47 | 53 | ||
54 | + private ContextManager(){} | ||
55 | + | ||
48 | /** | 56 | /** |
49 | - * <p>Initializes this manager and adds the {@link StaticContext} context to the list of managed contexts. Other | ||
50 | - * contexts must be added before they can be activated.</p> | ||
51 | - * | ||
52 | - * <p>It's OK to call this method multiple times, it will be initialized only once.</p> | 57 | + * <p> |
58 | + * Initializes this manager and adds the {@link StaticContext} context to the list of managed contexts. Other | ||
59 | + * contexts must be added before they can be activated. | ||
60 | + * </p> | ||
61 | + * <p> | ||
62 | + * It's OK to call this method multiple times, it will be initialized only once. | ||
63 | + * </p> | ||
53 | * | 64 | * |
54 | - * @param event The CDI event indicating all beans have been discovered. | 65 | + * @param event |
66 | + * The CDI event indicating all beans have been discovered. | ||
55 | */ | 67 | */ |
56 | - public static void initialize(AfterBeanDiscovery event){ | ||
57 | - if (initialized){ | 68 | + public static void initialize(AfterBeanDiscovery event) { |
69 | + if (initialized) { | ||
58 | return; | 70 | return; |
59 | } | 71 | } |
60 | - | ||
61 | - add(new StaticContext(),event); | ||
62 | - initialized=true; | 72 | + |
73 | + add(new StaticContext(), event); | ||
74 | + initialized = true; | ||
63 | } | 75 | } |
64 | - | 76 | + |
65 | /** | 77 | /** |
66 | - * <p>Adds a context to the list of managed contexts.</p> | ||
67 | - * | ||
68 | - * <p>A context added through this method will be deactivated before management can start. Only after calling | ||
69 | - * {@link #activate(Class customContextClass, Class scope)} the context will be activated.</p> | ||
70 | - * | ||
71 | - * <p>Trying to add a context already managed will result in this method call being ignored.</p> | 78 | + * <p> |
79 | + * Adds a context to the list of managed contexts. | ||
80 | + * </p> | ||
81 | + * <p> | ||
82 | + * A context added through this method will be deactivated before management can start. Only after calling | ||
83 | + * {@link #activate(Class customContextClass, Class scope)} the context will be activated. | ||
84 | + * </p> | ||
85 | + * <p> | ||
86 | + * Trying to add a context already managed will result in this method call being ignored. | ||
87 | + * </p> | ||
72 | * | 88 | * |
73 | - * @param context The context to be added | ||
74 | - * @param event The CDI event indicating all beans have been discovered. | 89 | + * @param context |
90 | + * The context to be added | ||
91 | + * @param event | ||
92 | + * The CDI event indicating all beans have been discovered. | ||
75 | */ | 93 | */ |
76 | - public static void add(CustomContext context,AfterBeanDiscovery event){ | ||
77 | - for (CustomContextCounter contextCounter : contexts){ | ||
78 | - if (contextCounter.isSame(context.getClass(), context.getScope())){ | 94 | + public static void add(CustomContext context, AfterBeanDiscovery event) { |
95 | + for (CustomContextCounter contextCounter : contexts) { | ||
96 | + if (contextCounter.isSame(context.getClass(), context.getScope())) { | ||
97 | + | ||
98 | + ContextManager.getLogger().trace( | ||
99 | + ContextManager.getBundle().getString("bootstrap-context-already-managed", | ||
100 | + context.getClass().getCanonicalName(), context.getScope().getCanonicalName())); | ||
101 | + | ||
79 | return; | 102 | return; |
80 | } | 103 | } |
81 | } | 104 | } |
@@ -84,154 +107,172 @@ public class ContextManager { | @@ -84,154 +107,172 @@ public class ContextManager { | ||
84 | event.addContext(context); | 107 | event.addContext(context); |
85 | contexts.add(new CustomContextCounter(context)); | 108 | contexts.add(new CustomContextCounter(context)); |
86 | } | 109 | } |
87 | - | 110 | + |
88 | /** | 111 | /** |
89 | - * <p>Activates a managed context.</p> | ||
90 | - * | ||
91 | - * <p>To be activated, a context must fulfill the following requisites: | 112 | + * <p> |
113 | + * Activates a managed context. | ||
114 | + * </p> | ||
115 | + * <p> | ||
116 | + * To be activated, a context must fulfill the following requisites: | ||
92 | * <ul> | 117 | * <ul> |
93 | - * | ||
94 | - * <li>Must be managed by this class (be of type {@link StaticScoped} or be added with {@link #add(CustomContext context, AfterBeanDiscovery event)})</li> | 118 | + * <li>Must be managed by this class (be of type {@link StaticScoped} or be added with |
119 | + * {@link #add(CustomContext context, AfterBeanDiscovery event)})</li> | ||
95 | * <li>Must be of a scope not already attached to another active context</li> | 120 | * <li>Must be of a scope not already attached to another active context</li> |
96 | - * | ||
97 | * </ul> | 121 | * </ul> |
98 | * </p> | 122 | * </p> |
99 | * | 123 | * |
100 | - * @param customContextClass Type of context to activate | ||
101 | - * @param scope The scope to activate this context for | ||
102 | - * @return <code>true</code> if there is a managed context of the provided type and scope and no other context is active for the provided scope, | ||
103 | - * <code>false</code> if there is a managed context of the provided type and scope but another context is active for the provided scope. | ||
104 | - * | ||
105 | - * @throws DemoiselleException if there is no managed context of the provided type and scope. | 124 | + * @param customContextClass |
125 | + * Type of context to activate | ||
126 | + * @param scope | ||
127 | + * The scope to activate this context for | ||
128 | + * @return <code>true</code> if there is a managed context of the provided type and scope and no other context is | ||
129 | + * active for the provided scope, <code>false</code> if there is a managed context of the provided type and | ||
130 | + * scope but another context is active for the provided scope. | ||
131 | + * @throws DemoiselleException | ||
132 | + * if there is no managed context of the provided type and scope. | ||
106 | */ | 133 | */ |
107 | - public static synchronized void activate(Class<? extends CustomContext> customContextClass , Class<? extends Annotation> scope){ | ||
108 | - if (!initialized){ | 134 | + public static synchronized void activate(Class<? extends CustomContext> customContextClass, |
135 | + Class<? extends Annotation> scope) { | ||
136 | + if (!initialized) { | ||
109 | throw new DemoiselleException(getBundle().getString("custom-context-manager-not-initialized")); | 137 | throw new DemoiselleException(getBundle().getString("custom-context-manager-not-initialized")); |
110 | } | 138 | } |
111 | - | ||
112 | - for (CustomContextCounter context : contexts){ | ||
113 | - if ( context.isSame(customContextClass, scope) ){ | 139 | + |
140 | + for (CustomContextCounter context : contexts) { | ||
141 | + if (context.isSame(customContextClass, scope)) { | ||
114 | context.activate(); | 142 | context.activate(); |
115 | return; | 143 | return; |
116 | } | 144 | } |
117 | } | 145 | } |
118 | 146 | ||
119 | - throw new DemoiselleException(getBundle().getString("custom-context-not-found",customContextClass.getCanonicalName(),scope.getSimpleName())); | 147 | + throw new DemoiselleException(getBundle().getString("custom-context-not-found", |
148 | + customContextClass.getCanonicalName(), scope.getSimpleName())); | ||
120 | } | 149 | } |
121 | - | 150 | + |
122 | /** | 151 | /** |
123 | - * <p>Deactivates a managed context.</p> | ||
124 | - * | ||
125 | - * <p>To be deactivated, a context must fulfill the following requisites: | 152 | + * <p> |
153 | + * Deactivates a managed context. | ||
154 | + * </p> | ||
155 | + * <p> | ||
156 | + * To be deactivated, a context must fulfill the following requisites: | ||
126 | * <ul> | 157 | * <ul> |
127 | - * | ||
128 | - * <li>Must be managed by this class (be of type {@link StaticScoped} or be added with {@link #add(CustomContext context, AfterBeanDiscovery event)})</li> | 158 | + * <li>Must be managed by this class (be of type {@link StaticScoped} or be added with |
159 | + * {@link #add(CustomContext context, AfterBeanDiscovery event)})</li> | ||
129 | * <li>Must have been activated by a previous call to {@link #activate(Class customContextClass, Class scope)}</li> | 160 | * <li>Must have been activated by a previous call to {@link #activate(Class customContextClass, Class scope)}</li> |
130 | * <li>This previous call must have returned <code>true</code>. | 161 | * <li>This previous call must have returned <code>true</code>. |
131 | - * | ||
132 | * </ul> | 162 | * </ul> |
133 | * </p> | 163 | * </p> |
134 | * | 164 | * |
135 | - * @param customContextClass Type of context to deactivate | ||
136 | - * @param scope The scope the context controled when it was active | ||
137 | - * @return <code>true</code> if there was an active context of this type and scope and it was activated by a previous | ||
138 | - * call to {@link #activate(Class customContextClass, Class scope)} | ||
139 | - * | ||
140 | - * @throws DemoiselleException if there is no managed context of the provided type and scope. | 165 | + * @param customContextClass |
166 | + * Type of context to deactivate | ||
167 | + * @param scope | ||
168 | + * The scope the context controled when it was active | ||
169 | + * @return <code>true</code> if there was an active context of this type and scope and it was activated by a | ||
170 | + * previous call to {@link #activate(Class customContextClass, Class scope)} | ||
171 | + * @throws DemoiselleException | ||
172 | + * if there is no managed context of the provided type and scope. | ||
141 | */ | 173 | */ |
142 | - public static synchronized void deactivate(Class<? extends CustomContext> customContextClass,Class<? extends Annotation> scope){ | ||
143 | - if (!initialized){ | 174 | + public static synchronized void deactivate(Class<? extends CustomContext> customContextClass, |
175 | + Class<? extends Annotation> scope) { | ||
176 | + if (!initialized) { | ||
144 | throw new DemoiselleException(getBundle().getString("custom-context-manager-not-initialized")); | 177 | throw new DemoiselleException(getBundle().getString("custom-context-manager-not-initialized")); |
145 | } | 178 | } |
146 | - | ||
147 | - for (CustomContextCounter context : contexts){ | ||
148 | - if (context.isSame(customContextClass, scope)){ | 179 | + |
180 | + for (CustomContextCounter context : contexts) { | ||
181 | + if (context.isSame(customContextClass, scope)) { | ||
149 | context.deactivate(); | 182 | context.deactivate(); |
150 | return; | 183 | return; |
151 | } | 184 | } |
152 | } | 185 | } |
153 | 186 | ||
154 | - throw new DemoiselleException(getBundle().getString("custom-context-not-found",customContextClass.getCanonicalName(),scope.getSimpleName())); | 187 | + throw new DemoiselleException(getBundle().getString("custom-context-not-found", |
188 | + customContextClass.getCanonicalName(), scope.getSimpleName())); | ||
155 | } | 189 | } |
156 | 190 | ||
157 | - static Logger getLogger(){ | ||
158 | - if (logger==null){ | 191 | + public static synchronized void shutdown() { |
192 | + for (CustomContextCounter context : contexts) { | ||
193 | + context.deactivate(); | ||
194 | + } | ||
195 | + | ||
196 | + contexts.clear(); | ||
197 | + initialized = false; | ||
198 | + } | ||
199 | + | ||
200 | + static Logger getLogger() { | ||
201 | + if (logger == null) { | ||
159 | logger = LoggerProducer.create(ContextManager.class); | 202 | logger = LoggerProducer.create(ContextManager.class); |
160 | } | 203 | } |
161 | - | 204 | + |
162 | return logger; | 205 | return logger; |
163 | } | 206 | } |
164 | - | ||
165 | - static ResourceBundle getBundle(){ | ||
166 | - if (bundle==null){ | ||
167 | - bundle = ResourceBundleProducer.create("demoiselle-core-bundle",Locale.getDefault()); | 207 | + |
208 | + static ResourceBundle getBundle() { | ||
209 | + if (bundle == null) { | ||
210 | + bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault()); | ||
168 | } | 211 | } |
169 | - | 212 | + |
170 | return bundle; | 213 | return bundle; |
171 | } | 214 | } |
172 | } | 215 | } |
216 | + | ||
173 | /** | 217 | /** |
174 | - * Class that counts how many attemps to activate and deactivate this context received, avoiding cases | ||
175 | - * where one client activates given context and another one deactivates it, leaving the first client | ||
176 | - * with no active context before completion. | 218 | + * Class that counts how many attemps to activate and deactivate this context received, avoiding cases where one client |
219 | + * activates given context and another one deactivates it, leaving the first client with no active context before | ||
220 | + * completion. | ||
177 | * | 221 | * |
178 | * @author serpro | 222 | * @author serpro |
179 | - * | ||
180 | */ | 223 | */ |
181 | -class CustomContextCounter{ | 224 | +class CustomContextCounter { |
225 | + | ||
182 | private CustomContext context; | 226 | private CustomContext context; |
227 | + | ||
183 | private int activationCounter = 0; | 228 | private int activationCounter = 0; |
184 | - | 229 | + |
185 | public CustomContextCounter(CustomContext customContext) { | 230 | public CustomContextCounter(CustomContext customContext) { |
186 | this.context = customContext; | 231 | this.context = customContext; |
187 | } | 232 | } |
188 | - | ||
189 | - public boolean isSame(Class<? extends CustomContext> customContextClass,Class<? extends Annotation> scope){ | ||
190 | - if (context.getClass().getCanonicalName().equals( customContextClass.getCanonicalName() ) | ||
191 | - && context.getScope().equals(scope)){ | 233 | + |
234 | + public boolean isSame(Class<? extends CustomContext> customContextClass, Class<? extends Annotation> scope) { | ||
235 | + if (context.getClass().getCanonicalName().equals(customContextClass.getCanonicalName()) | ||
236 | + && context.getScope().equals(scope)) { | ||
192 | return true; | 237 | return true; |
193 | } | 238 | } |
194 | - | 239 | + |
195 | return false; | 240 | return false; |
196 | } | 241 | } |
197 | - | ||
198 | - public CustomContext getInternalContext(){ | 242 | + |
243 | + public CustomContext getInternalContext() { | ||
199 | return this.context; | 244 | return this.context; |
200 | } | 245 | } |
201 | - | ||
202 | - public synchronized void activate(){ | ||
203 | - try{ | ||
204 | - Context c = Beans.getBeanManager().getContext(context.getScope()); | ||
205 | - if (c==context){ | 246 | + |
247 | + public synchronized void activate() { | ||
248 | + try { | ||
249 | + BeanManager beanManager = Beans.getReference(BeanManager.class); | ||
250 | + Context c = beanManager.getContext(context.getScope()); | ||
251 | + if (c == context) { | ||
206 | activationCounter++; | 252 | activationCounter++; |
207 | } | 253 | } |
208 | - } | ||
209 | - catch(ContextNotActiveException ce){ | 254 | + } catch (ContextNotActiveException ce) { |
210 | context.setActive(true); | 255 | context.setActive(true); |
211 | activationCounter++; | 256 | activationCounter++; |
212 | ContextManager.getLogger().trace( | 257 | ContextManager.getLogger().trace( |
213 | - ContextManager.getBundle().getString("custom-context-was-activated" | ||
214 | - , context.getClass().getCanonicalName() | ||
215 | - ,context.getScope().getCanonicalName() | ||
216 | - )); | 258 | + ContextManager.getBundle().getString("custom-context-was-activated", |
259 | + context.getClass().getCanonicalName(), context.getScope().getCanonicalName())); | ||
217 | } | 260 | } |
218 | } | 261 | } |
219 | - | ||
220 | - public synchronized void deactivate(){ | ||
221 | - try{ | 262 | + |
263 | + public synchronized void deactivate() { | ||
264 | + try { | ||
222 | Context c = Beans.getBeanManager().getContext(context.getScope()); | 265 | Context c = Beans.getBeanManager().getContext(context.getScope()); |
223 | - if (c==context){ | 266 | + if (c == context) { |
224 | activationCounter--; | 267 | activationCounter--; |
225 | - if (activationCounter==0){ | 268 | + if (activationCounter == 0) { |
226 | context.setActive(false); | 269 | context.setActive(false); |
227 | ContextManager.getLogger().trace( | 270 | ContextManager.getLogger().trace( |
228 | - ContextManager.getBundle().getString("custom-context-was-deactivated" | ||
229 | - , context.getClass().getCanonicalName() | ||
230 | - ,context.getScope().getCanonicalName() | ||
231 | - )); | 271 | + ContextManager.getBundle().getString("custom-context-was-deactivated", |
272 | + context.getClass().getCanonicalName(), context.getScope().getCanonicalName())); | ||
232 | } | 273 | } |
233 | } | 274 | } |
275 | + } catch (ContextNotActiveException ce) { | ||
234 | } | 276 | } |
235 | - catch(ContextNotActiveException ce){} | ||
236 | } | 277 | } |
237 | } | 278 | } |
impl/core/src/main/resources/demoiselle-core-bundle.properties
@@ -53,6 +53,7 @@ transaction-commited=Transa\u00E7\u00E3o finalizada com sucesso | @@ -53,6 +53,7 @@ transaction-commited=Transa\u00E7\u00E3o finalizada com sucesso | ||
53 | transaction-rolledback=Transa\u00E7\u00E3o finalizada com rollback | 53 | transaction-rolledback=Transa\u00E7\u00E3o finalizada com rollback |
54 | 54 | ||
55 | bootstrap.configuration.processing=Processando {0} | 55 | bootstrap.configuration.processing=Processando {0} |
56 | +bootstrap-context-already-managed=O contexto {0} para o escopo {1} j\u00E1 \u00E9 gerenciado | ||
56 | 57 | ||
57 | loading-configuration-class=Carregando a classe de configura\u00E7\u00E3o {0} | 58 | loading-configuration-class=Carregando a classe de configura\u00E7\u00E3o {0} |
58 | configuration-field-loaded=Configura\u00E7\u00E3o {0} atribu\u00EDda a {1} com o valor {2} | 59 | configuration-field-loaded=Configura\u00E7\u00E3o {0} atribu\u00EDda a {1} com o valor {2} |
impl/core/src/test/java/management/AnnotationTestCase.java
@@ -49,13 +49,17 @@ import org.jboss.shrinkwrap.api.ShrinkWrap; | @@ -49,13 +49,17 @@ import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
49 | import org.jboss.shrinkwrap.api.asset.FileAsset; | 49 | import org.jboss.shrinkwrap.api.asset.FileAsset; |
50 | import org.jboss.shrinkwrap.api.spec.JavaArchive; | 50 | import org.jboss.shrinkwrap.api.spec.JavaArchive; |
51 | import org.junit.Assert; | 51 | import org.junit.Assert; |
52 | +import org.junit.Ignore; | ||
52 | import org.junit.Test; | 53 | import org.junit.Test; |
53 | import org.junit.runner.RunWith; | 54 | import org.junit.runner.RunWith; |
54 | 55 | ||
55 | import test.LocaleProducer; | 56 | import test.LocaleProducer; |
56 | 57 | ||
58 | +//TODO O arquillian está com um problema onde, embora os testes rodem todos individualmente, | ||
59 | +//ao pedir para rodar todos este teste individual causa todos os testes executados após esse | ||
60 | +//falharem. Até este problema ser resolvido este teste será ignorado. | ||
57 | @RunWith(Arquillian.class) | 61 | @RunWith(Arquillian.class) |
58 | -// @Ignore | 62 | +@Ignore |
59 | public class AnnotationTestCase { | 63 | public class AnnotationTestCase { |
60 | 64 | ||
61 | /** | 65 | /** |
impl/core/src/test/java/management/ManagementTestCase.java
@@ -42,6 +42,8 @@ import junit.framework.Assert; | @@ -42,6 +42,8 @@ import junit.framework.Assert; | ||
42 | import management.testclasses.DummyManagedClass; | 42 | import management.testclasses.DummyManagedClass; |
43 | import management.testclasses.DummyManagementExtension; | 43 | import management.testclasses.DummyManagementExtension; |
44 | import management.testclasses.ManagedClassStore; | 44 | import management.testclasses.ManagedClassStore; |
45 | +import management.testclasses.RequestScopeBeanClient; | ||
46 | +import management.testclasses.RequestScopedClass; | ||
45 | 47 | ||
46 | import org.jboss.arquillian.container.test.api.Deployment; | 48 | import org.jboss.arquillian.container.test.api.Deployment; |
47 | import org.jboss.arquillian.junit.Arquillian; | 49 | import org.jboss.arquillian.junit.Arquillian; |
@@ -75,7 +77,11 @@ public class ManagementTestCase { | @@ -75,7 +77,11 @@ public class ManagementTestCase { | ||
75 | new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"), | 77 | new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"), |
76 | "services/javax.enterprise.inject.spi.Extension") | 78 | "services/javax.enterprise.inject.spi.Extension") |
77 | .addPackages(false, ManagementTestCase.class.getPackage()) | 79 | .addPackages(false, ManagementTestCase.class.getPackage()) |
78 | - .addClasses(DummyManagementExtension.class, DummyManagedClass.class, ManagedClassStore.class); | 80 | + .addClasses(DummyManagementExtension.class |
81 | + , DummyManagedClass.class | ||
82 | + , ManagedClassStore.class | ||
83 | + , RequestScopeBeanClient.class | ||
84 | + , RequestScopedClass.class); | ||
79 | } | 85 | } |
80 | 86 | ||
81 | @Test | 87 | @Test |
@@ -161,4 +167,18 @@ public class ManagementTestCase { | @@ -161,4 +167,18 @@ public class ManagementTestCase { | ||
161 | } | 167 | } |
162 | 168 | ||
163 | } | 169 | } |
170 | + | ||
171 | + @Test | ||
172 | + public void testRequestScopedOperation() { | ||
173 | + ManagedClassStore store = Beans.getReference(ManagedClassStore.class); | ||
174 | + | ||
175 | + //Esta operação faz multiplos acessos a um bean RequestScoped. Durante a operação todos os acessos devem | ||
176 | + //operar sob a mesma instância, mas uma segunda invocação deve operar em uma instância nova | ||
177 | + Object info = store.invoke(DummyManagedClass.class, "requestScopedOperation"); | ||
178 | + Assert.assertEquals("-OPERATION ONE CALLED--OPERATION TWO CALLED-", info); | ||
179 | + | ||
180 | + //Segunda invocação para testar se uma nova instância é criada, já que esse é um novo request. | ||
181 | + info = store.invoke(DummyManagedClass.class, "requestScopedOperation"); | ||
182 | + Assert.assertEquals("-OPERATION ONE CALLED--OPERATION TWO CALLED-", info); | ||
183 | + } | ||
164 | } | 184 | } |
impl/core/src/test/java/management/testclasses/DummyManagedClass.java
@@ -43,6 +43,7 @@ import javax.validation.constraints.NotNull; | @@ -43,6 +43,7 @@ import javax.validation.constraints.NotNull; | ||
43 | import br.gov.frameworkdemoiselle.annotation.ManagedOperation; | 43 | import br.gov.frameworkdemoiselle.annotation.ManagedOperation; |
44 | import br.gov.frameworkdemoiselle.annotation.ManagedProperty; | 44 | import br.gov.frameworkdemoiselle.annotation.ManagedProperty; |
45 | import br.gov.frameworkdemoiselle.stereotype.ManagementController; | 45 | import br.gov.frameworkdemoiselle.stereotype.ManagementController; |
46 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
46 | 47 | ||
47 | @ManagementController | 48 | @ManagementController |
48 | public class DummyManagedClass { | 49 | public class DummyManagedClass { |
@@ -196,7 +197,15 @@ public class DummyManagedClass { | @@ -196,7 +197,15 @@ public class DummyManagedClass { | ||
196 | this.gender = gender; | 197 | this.gender = gender; |
197 | } | 198 | } |
198 | 199 | ||
199 | - | 200 | + @ManagedOperation |
201 | + public String requestScopedOperation(){ | ||
202 | + RequestScopeBeanClient client = Beans.getReference(RequestScopeBeanClient.class); | ||
203 | + client.operationOne(); | ||
204 | + client.operationTwo(); | ||
205 | + | ||
206 | + RequestScopedClass bean = Beans.getReference(RequestScopedClass.class); | ||
207 | + return bean.getInfo(); | ||
208 | + } | ||
200 | 209 | ||
201 | 210 | ||
202 | } | 211 | } |
impl/core/src/test/java/management/testclasses/RequestScopeBeanClient.java
0 → 100644
@@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
1 | +package management.testclasses; | ||
2 | + | ||
3 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
4 | + | ||
5 | + | ||
6 | +public class RequestScopeBeanClient { | ||
7 | + | ||
8 | + public void operationOne(){ | ||
9 | + | ||
10 | + RequestScopedClass bean = Beans.getReference(RequestScopedClass.class); | ||
11 | + bean.setInfo( bean.getInfo() + "-OPERATION ONE CALLED-"); | ||
12 | + | ||
13 | + } | ||
14 | + | ||
15 | + public void operationTwo(){ | ||
16 | + | ||
17 | + RequestScopedClass bean = Beans.getReference(RequestScopedClass.class); | ||
18 | + bean.setInfo( bean.getInfo() + "-OPERATION TWO CALLED-"); | ||
19 | + | ||
20 | + } | ||
21 | + | ||
22 | +} |
impl/core/src/test/java/management/testclasses/RequestScopedClass.java
0 → 100644
@@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
1 | +package management.testclasses; | ||
2 | + | ||
3 | +import javax.enterprise.context.RequestScoped; | ||
4 | + | ||
5 | +@RequestScoped | ||
6 | +public class RequestScopedClass { | ||
7 | + | ||
8 | + private String info = ""; | ||
9 | + | ||
10 | + | ||
11 | + public String getInfo() { | ||
12 | + return info; | ||
13 | + } | ||
14 | + | ||
15 | + | ||
16 | + public void setInfo(String info) { | ||
17 | + this.info = info; | ||
18 | + } | ||
19 | + | ||
20 | + | ||
21 | + | ||
22 | +} |
parent/bom/pom.xml
@@ -349,6 +349,11 @@ | @@ -349,6 +349,11 @@ | ||
349 | <version>${arquillian.weld.se.embedded.version}</version> | 349 | <version>${arquillian.weld.se.embedded.version}</version> |
350 | </dependency> | 350 | </dependency> |
351 | <dependency> | 351 | <dependency> |
352 | + <groupId>org.jboss.arquillian.container</groupId> | ||
353 | + <artifactId>arquillian-weld-ee-embedded-1.1</artifactId> | ||
354 | + <version>${arquillian.weld.ee.embedded.version}</version> | ||
355 | + </dependency> | ||
356 | + <dependency> | ||
352 | <groupId>org.jboss.weld.se</groupId> | 357 | <groupId>org.jboss.weld.se</groupId> |
353 | <artifactId>weld-se-core</artifactId> | 358 | <artifactId>weld-se-core</artifactId> |
354 | <version>${weld.version}</version> | 359 | <version>${weld.version}</version> |
@@ -399,6 +404,7 @@ | @@ -399,6 +404,7 @@ | ||
399 | 404 | ||
400 | <arquillian.version>1.0.3.Final</arquillian.version> | 405 | <arquillian.version>1.0.3.Final</arquillian.version> |
401 | <arquillian.weld.se.embedded.version>1.0.0.CR6</arquillian.weld.se.embedded.version> | 406 | <arquillian.weld.se.embedded.version>1.0.0.CR6</arquillian.weld.se.embedded.version> |
407 | + <arquillian.weld.ee.embedded.version>1.0.0.CR6</arquillian.weld.ee.embedded.version> | ||
402 | 408 | ||
403 | <powermock.version>1.4.6</powermock.version> | 409 | <powermock.version>1.4.6</powermock.version> |
404 | <primefaces.version>3.4</primefaces.version> | 410 | <primefaces.version>3.4</primefaces.version> |