EasyMock.expectLastCall().anyTimes();
_mocksControl.replay();
// get the VDL
UIViewRoot view = facesContext.getViewRoot();
MockFaceletViewDeclarationLanguage vdl
= (MockFaceletViewDeclarationLanguage) _testApplication.getViewHandler()
.getViewDeclarationLanguage(facesContext, view.getViewId());
// ---- first component test - without any special settings ----------------------------
// configure the Resource needed for this test
MockSimpleResource resource = new MockSimpleResource(null, "testlib", null, "composite.xhtml",
null, new File("src/test/resources/org/apache/myfaces/application"));
// get the BeanInfo metadata
BeanInfo metadata = vdl.getComponentMetadata(facesContext, resource);
// create the component
UIComponent component = _testApplication.createComponent(facesContext, resource);
// asserts for the first component
assertTrue("The component has to be an UINamingContainer", component instanceof UINamingContainer);
assertRendererTypeResourceBeanInfo(component, resource, metadata);
// ---- second component test - from a script ------------------------------------------
MockSimpleResource scriptResource = new MockSimpleResource(null, "testlib", null,
"org.apache.myfaces.application.MockResourceComponent.groovy",
null, new File("src/test/resources/org/apache/myfaces/application"));
// install the script resource to the VDL-mock
vdl.setScriptComponentResource(resource, scriptResource);
// create the component
component = _testApplication.createComponent(facesContext, resource);
// asserts for the second component
assertTrue("The component has to be a MockResourceComponent", component instanceof MockResourceComponent);
assertRendererTypeResourceBeanInfo(component, resource, metadata);
// remove the script resource again
vdl.setScriptComponentResource(resource, null);
// ---- third component test - from libaryName.resourceName.class -----------------------
MockSimpleResource componentResource = new MockSimpleResource(null, "org.apache.myfaces.application",
null, "MockResourceComponent.xhtml", null,
new File("src/test/resources/org/apache/myfaces/application"))
{
/* (non-javadoc)
* We have to overwrite getURL() here, because it has to deliver a valid URL and
* we can't get that out of the library and the resource name we set on this resource.
*/
@Override
public URL getURL()
{
MockServletContext servletContext
= (MockServletContext) FacesContext.getCurrentInstance()
.getExternalContext().getContext();
servletContext.setDocumentRoot(new File("src/test/resources/org/apache/myfaces/application"));
try
{
return servletContext.getResource("/testlib/composite.xhtml");
}
catch (MalformedURLException e)
{
return null;
}
}
};
// get the BeanInfo metadata
BeanInfo metadataComponentResource = vdl.getComponentMetadata(facesContext, componentResource);
// create the component
component = _testApplication.createComponent(facesContext, componentResource);
// asserts for the third component
assertTrue("The component has to be a MockResourceComponent", component instanceof MockResourceComponent);
assertRendererTypeResourceBeanInfo(component, componentResource, metadataComponentResource);
// ---- fourth component test - with a custom componentType ------------------------------
// change the resource
resource = new MockSimpleResource(null, "testlib", null, "compositeWithComponentType.xhtml",
null, new File("src/test/resources/org/apache/myfaces/application"));
// FIXME resource.setResourceName(resourceName) did not work
// this can be changed in the next release of MyFaces test (1.0.0-beta.NEXT)
// register the new component type
_testApplication.addComponent(TEST_COMPONENT_TYPE, UIOutput.class.getName());
// get the BeanInfo metadata
metadata = vdl.getComponentMetadata(facesContext, resource);
// create the component
component = _testApplication.createComponent(facesContext, resource);
// asserts for the fourth component