Re: How to configure the default renderers and component within a Shale-Test based unit test

2006-08-21 Thread Dennis Byrne
A more conservative approach would be to build an abstract base test case
that did the manual configuration operations (as you are doing them), for
the combination of components that you want to test, in its setUp() method.

Hmmm ... so AbstractJsfTestCase would be extended by AbstractMyFacesTestCase?

Craig

Dennis Byrne

-Original Message-
 From: Paul Spencer [mailto:[EMAIL PROTECTED]
 Sent: Sunday, August 20, 2006 11:42 PM
 To: 'MyFaces Development'
 Subject: How to configure the default renderers and component within a
 Shale-Test based unit test
 
 I am writing a unit test based on the Shale Test Framework for a Tomahawk
 component.  My current problem is the I need to add the default MyFaces
 and
 Tomahawk components and renderers to the FacesContext. To date I have
 been
 using facesContext.getApplication().addComponent(...) and
 facesContext.getRenderKit().addRenderer(...).  This is becoming very
 cumbersome.  I know the defaults are out their in various configuration
 files,
 but I do not know how to tell Shale's test framework how to use them.
 
 Suggestions?
 
 Paul Spencer
 
 








Re: Re: How to configure the default renderers and component within a Shale-Test based unit test

2006-08-21 Thread Adam Winer

One might also have a look at the Trinidad RenderKit test framework,
which does a lot of work to make writing unit tests for renderers
oh so trivial, including parsing faces-config.xmls on the classpath.

http://wiki.apache.org/myfaces/Trinidad_RenderKit_test_framework

-- Adam


On 8/20/06, Dennis Byrne [EMAIL PROTECTED] wrote:

I would be suprised if you found a quick and easy way to do this. MyFaces core 
uses digester to unmarshal the config files.  It then calls the API you 
mention. I would start digging around in org.apache.myfaces.config .

Dennis Byrne

-Original Message-
From: Paul Spencer [mailto:[EMAIL PROTECTED]
Sent: Sunday, August 20, 2006 11:42 PM
To: 'MyFaces Development'
Subject: How to configure the default renderers and component within a 
Shale-Test based unit test

I am writing a unit test based on the Shale Test Framework for a Tomahawk
component.  My current problem is the I need to add the default MyFaces and
Tomahawk components and renderers to the FacesContext. To date I have been
using facesContext.getApplication().addComponent(...) and
facesContext.getRenderKit().addRenderer(...).  This is becoming very
cumbersome.  I know the defaults are out their in various configuration files,
but I do not know how to tell Shale's test framework how to use them.

Suggestions?

Paul Spencer







Re: How to configure the default renderers and component within a Shale-Test based unit test

2006-08-21 Thread Gary VanMatre

From: "Dennis Byrne" [EMAIL PROTECTED]  I would be suprised if you found a quick and easy way to do this. MyFaces core  uses digester to unmarshal the config files. It then calls the API you mention.  I would start digging around in org.apache.myfaces.config .  

Or, another way would be to write a simple helper method to extract the information from a working web application. You could build some code and drop it into an abstract test case. 

Consider the following to extract component's and renderers:


private void captureMetadata() {

FacesContext context = FacesContext.getCurrentInstance();

RenderKitFactory factory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
RenderKit defaultRenderKit = factory.getRenderKit(context, context.getViewRoot().getRenderKitId());

Iterator cti = context.getApplication().getComponentTypes();
List componentInfo = new ArrayList();
List rendererInfo = new ArrayList();
while (cti.hasNext()) {
try {
String componentType = (String) cti.next();
UIComponent component = (UIComponent) context.getApplication().createComponent(componentType);

String family = component.getFamily();

String rendererType = component.getRendererType();
Renderer renderer = defaultRenderKit.getRenderer(family, rendererType);

String[] componentRegInfo = new String[2];
componentRegInfo[0] = componentType;
componentRegInfo[1] = component.getClass().getName();
componentInfo.add(componentRegInfo);

String[] rendererRegInfo = new String[3];
rendererRegInfo[0] = family;
rendererRegInfo[1] = rendererType;
rendererRegInfo[2] = renderer.getClass().getName();
rendererInfo.add(rendererRegInfo);

} catch (Exception e) {
e.printStackTrace();
}

}

StringBuffer buff = new StringBuffer();
buff.append("protected static final Object[] COMPONENTS = {\n");
for (int i = 0; i  componentInfo.size(); i++) {
String[] componentRegInfo = (String[]) componentInfo.get(i);

buff.append(" new String[] {\"").append(componentRegInfo[0])
.append("\", \"").append(componentRegInfo[1])
.append("},\n");

}
buff.append("};\n\n\n;");

buff.append("protected static final Object[] RENDERERS = {\n");
for (int i = 0; i  rendererInfo.size(); i++) {
String[] rendererRegInfo = (String[]) rendererInfo.get(i);

buff.append(" new String[] {\"").append(rendererRegInfo[0])
.append("\", \"").append(rendererRegInfo[1])
.append("\", \"").append(rendererRegInfo[2]).append("},\n");

}
buff.append("};\n");

System.out.print(buff.toString());

}



And the following to register with the shale test case framework:




The validators, converters and listeners can be introspected in the same fashion.

for (int i = 0; i  RENDERERS.length; i++) {

Renderer renderer = null;
renderer: for (int j = 2; j  4; j++) {
try {
Class clazz = Class.forName(RENDERERS[i][j]);
if (clazz != null) {
renderer = (Renderer) clazz.newInstance();
if (renderer != null) {
//System.out.println(RENDERERS[i][j]);
break renderer;
}
}
} catch (ClassNotFoundException e) {
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
}
}

if (renderer != null) {
 facesContext.getRenderKit().addRenderer(RENDERERS[i][0], RENDERERS[i][1],renderer);
 }
} 


for (int i = 0; i  COMPONENTS.length; i++) {
application.addComponent(((String[])COMPONENTS[i])[0], ((String[])COMPONENTS[i])[1]);
}

Gary


 Dennis Byrne   -Original Message-  From: Paul Spencer [mailto:[EMAIL PROTECTED]  Sent: Sunday, August 20, 2006 11:42 PM  To: 'MyFaces Development'  Subject: How to configure the default renderers and component within a  Shale-Test based unit testI am writing a unit test based on the Shale Test Framework for a Tomahawk  component. My current problem is the I need to add the default MyFaces and  Tomahawk components and renderers to the FacesContext. To date I have been  using facesContext.getApplication().addComponent(...) and  facesContext.getRenderKit().addRenderer(...). This is becoming very  cumbersome. I know the defaults are out their in various configuration files,  but I do not know how to tell Shale's test framework how to use them.Suggestions? &
 gt; 
t;  Paul Spencer   



How to configure the default renderers and component within a Shale-Test based unit test

2006-08-20 Thread Paul Spencer

I am writing a unit test based on the Shale Test Framework for a Tomahawk
component.  My current problem is the I need to add the default MyFaces and
Tomahawk components and renderers to the FacesContext. To date I have been
using facesContext.getApplication().addComponent(...) and
facesContext.getRenderKit().addRenderer(...).  This is becoming very
cumbersome.  I know the defaults are out their in various configuration files,
but I do not know how to tell Shale's test framework how to use them.

Suggestions?

Paul Spencer



Re: How to configure the default renderers and component within a Shale-Test based unit test

2006-08-20 Thread Dennis Byrne
I would be suprised if you found a quick and easy way to do this. MyFaces core 
uses digester to unmarshal the config files.  It then calls the API you 
mention. I would start digging around in org.apache.myfaces.config .

Dennis Byrne

-Original Message-
From: Paul Spencer [mailto:[EMAIL PROTECTED]
Sent: Sunday, August 20, 2006 11:42 PM
To: 'MyFaces Development'
Subject: How to configure the default renderers and component within a 
Shale-Test based unit test

I am writing a unit test based on the Shale Test Framework for a Tomahawk
component.  My current problem is the I need to add the default MyFaces and
Tomahawk components and renderers to the FacesContext. To date I have been
using facesContext.getApplication().addComponent(...) and
facesContext.getRenderKit().addRenderer(...).  This is becoming very
cumbersome.  I know the defaults are out their in various configuration files,
but I do not know how to tell Shale's test framework how to use them.

Suggestions?

Paul Spencer






Re: How to configure the default renderers and component within a Shale-Test based unit test

2006-08-20 Thread Craig McClanahan
On 8/20/06, Dennis Byrne [EMAIL PROTECTED] wrote:
I would be suprised if you found a quick and easy way to do this. MyFaces core uses digester to unmarshal the config files.It then calls the API you mention. I would start digging around in org.apache.myfaces.config .
One aggressive approach you might consider is to set up a directory structure that looks like a webapp, and then fire off the real MyFaces context listener that initializes things. It would tie you using the MyFaces implementation for your tests, but it would pre-initialize all that stuff. (I haven't tried this myself, so it might also run into cases where the mock objects need some extended behavior ... but i'd certainly be open to improving the test library so that it enables this use case.)
A more conservative approach would be to build an abstract base test case that did the manual configuration operations (as you are doing them), for the combination of components that you want to test, in its setUp() method. At least that way, you'd only have to write them once.
Dennis ByrneCraig 
-Original Message-From: Paul Spencer [mailto:[EMAIL PROTECTED]]Sent: Sunday, August 20, 2006 11:42 PMTo: 'MyFaces Development'Subject: How to configure the default renderers and component within a Shale-Test based unit test
I am writing a unit test based on the Shale Test Framework for a Tomahawkcomponent.My current problem is the I need to add the default MyFaces andTomahawk components and renderers to the FacesContext. To date I have been
using facesContext.getApplication().addComponent(...) andfacesContext.getRenderKit().addRenderer(...).This is becoming verycumbersome.I know the defaults are out their in various configuration files,
but I do not know how to tell Shale's test framework how to use them.Suggestions?Paul Spencer