*/
public void generateTest(final JavaType controller, String name,
String serverURL) {
Validate.notNull(controller, "Controller type required");
final ClassOrInterfaceTypeDetails controllerTypeDetails = typeLocationService
.getTypeDetails(controller);
Validate.notNull(
controllerTypeDetails,
"Class or interface type details for type '%s' could not be resolved",
controller);
final LogicalPath path = PhysicalTypeIdentifier
.getPath(controllerTypeDetails.getDeclaredByMetadataId());
final String webScaffoldMetadataIdentifier = WebScaffoldMetadata
.createIdentifier(controller, path);
final WebScaffoldMetadata webScaffoldMetadata = (WebScaffoldMetadata) metadataService
.get(webScaffoldMetadataIdentifier);
Validate.notNull(
webScaffoldMetadata,
"Web controller '%s' does not appear to be an automatic, scaffolded controller",
controller.getFullyQualifiedTypeName());
// We abort the creation of a selenium test if the controller does not
// allow the creation of new instances for the form backing object
if (!webScaffoldMetadata.getAnnotationValues().isCreate()) {
LOGGER.warning("The controller you specified does not allow the creation of new instances of the form backing object. No Selenium tests created.");
return;
}
if (!serverURL.endsWith("/")) {
serverURL = serverURL + "/";
}
final JavaType formBackingType = webScaffoldMetadata
.getAnnotationValues().getFormBackingObject();
final String relativeTestFilePath = "selenium/test-"
+ formBackingType.getSimpleTypeName().toLowerCase() + ".xhtml";
final String seleniumPath = pathResolver.getFocusedIdentifier(
Path.SRC_MAIN_WEBAPP, relativeTestFilePath);
final InputStream templateInputStream = FileUtils.getInputStream(
getClass(), "selenium-template.xhtml");
Validate.notNull(templateInputStream,
"Could not acquire selenium.xhtml template");
final Document document = XmlUtils.readXml(templateInputStream);
final Element root = (Element) document.getLastChild();
if (root == null || !"html".equals(root.getNodeName())) {
throw new IllegalArgumentException(
"Could not parse selenium test case template file!");
}
name = name != null ? name : "Selenium test for "
+ controller.getSimpleTypeName();
XmlUtils.findRequiredElement("/html/head/title", root).setTextContent(
name);
XmlUtils.findRequiredElement("/html/body/table/thead/tr/td", root)
.setTextContent(name);
final Element tbody = XmlUtils.findRequiredElement(
"/html/body/table/tbody", root);
tbody.appendChild(openCommand(
document,
serverURL
+ projectOperations.getProjectName(projectOperations
.getFocusedModuleName()) + "/"
+ webScaffoldMetadata.getAnnotationValues().getPath()
+ "?form"));
final ClassOrInterfaceTypeDetails formBackingTypeDetails = typeLocationService
.getTypeDetails(formBackingType);
Validate.notNull(
formBackingType,
"Class or interface type details for type '%s' could not be resolved",
formBackingType);