-
1. Re: How to test an application scoped component?
blabno Mar 18, 2010 2:58 PM (in response to cinconnu)Something like this should do. I do not have IDE around now, so i'm writting off the top of my head.
Contexts.getApplicationContext().remove("bean");
-
2. Re: How to test an application scoped component?
cinconnu Mar 18, 2010 3:40 PM (in response to cinconnu)Thank you for your answer but I have already tried this, in fact I replaced it with the more general
removeFromAllContexts
, but no luck so far. -
3. Re: How to test an application scoped component?
cinconnu Mar 18, 2010 9:28 PM (in response to cinconnu)Well, I tried the following (from org.jboss.seam.contexts.Contexts.destroy) which is called when the application is shut down but it does not work:
Component component = Component.forName("my.full.bean"); Object object = Contexts.getApplicationContext().get("bean"); component.destroy(object); Contexts.removeFromAllContexts("bean");
So guys how do you test your application scopped components ???
-
4. Re: How to test an application scoped component?
cinconnu Mar 18, 2010 10:08 PM (in response to cinconnu)I found this that seems to do the job:
/** * Creates a new instance of the specified component and registers it in its scope. * * @param <T> the class of the component. * @param clazz the class of the component. * @param aliases the factory aliases of the component. * * @throws Exception if an error occurs. */ @SuppressWarnings("unchecked") protected <T> void newInstance(final Class<T> clazz, final String... aliases) throws Exception { new FacesRequestEx() { @Override protected void invokeApplication() { final String componentName = Component.getComponentName(clazz); final Component component = Component.forName(componentName); final Context componentContext = component.getScope().getContext(); final T result = (T) component.newInstance(); componentContext.set(componentName, result); for (String alias : aliases) { componentContext.set(alias, result); } } }.run(); }
-
5. Re: How to test an application scoped component?
blabno Mar 19, 2010 8:41 AM (in response to cinconnu)I just don't believe that
removeFromAllContexts
does not work. I have no problem with testing application scoped components.What is your problem with viewId ? It is always provided if you use the Faces/NonFacesRequest. Besides, in my opinion, the application scoped components should be designed in such a way that they could have without knowledge about views.