use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class JavaParserTypeParsingServiceTest method testGetTypeFromStringWhenFileContainsNoTypes.
@Test
public void testGetTypeFromStringWhenFileContainsNoTypes() {
// Set up
final JavaType mockTargetType = mock(JavaType.class);
// Invoke
final ClassOrInterfaceTypeDetails locatedType = typeParsingService.getTypeFromString(EMPTY_FILE, DECLARED_BY_MID, mockTargetType);
// Check
assertNull(locatedType);
}
use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class NewUpdateCompilationUnitTest method testSimpleClassAddAnnotation.
@Test
public void testSimpleClassAddAnnotation() throws Exception {
// Set up
final File file = getResource(SIMPLE_CLASS_FILE_PATH);
final String fileContents = getResourceContents(file);
final ClassOrInterfaceTypeDetails simpleInterfaceDetails = typeParsingService.getTypeFromString(fileContents, SIMPLE_CLASS_DECLARED_BY_MID, SIMPLE_CLASS_TYPE);
final AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(new JavaType("org.springframework.roo.addon.javabean.addon.RooToString"));
final ClassOrInterfaceTypeDetails newSimpleInterfaceDetails = addAnnotation(simpleInterfaceDetails, annotationBuilder.build());
// Invoke
final String result = typeParsingService.updateAndGetCompilationUnitContents(file.getCanonicalPath(), newSimpleInterfaceDetails);
saveResult(file, result, "-addedAnnotation");
checkSimpleClass(result);
assertTrue(result.contains("import org.springframework.roo.addon.javabean.addon.RooToString;"));
assertTrue(result.contains("@RooToString"));
// Invoke again
final ClassOrInterfaceTypeDetails simpleInterfaceDetails2 = typeParsingService.getTypeFromString(result, SIMPLE_CLASS_DECLARED_BY_MID, SIMPLE_CLASS_TYPE);
final String result2 = typeParsingService.updateAndGetCompilationUnitContents(file.getCanonicalPath(), simpleInterfaceDetails2);
saveResult(file, result2, "-addedAnnotation2");
checkSimpleClass(result2);
assertTrue(result2.contains("import org.springframework.roo.addon.javabean.addon.RooToString;"));
assertTrue(result2.contains("@RooToString"));
}
use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class NewUpdateCompilationUnitTest method testSimpleClassAddField.
@Test
public void testSimpleClassAddField() throws Exception {
// Set up
final File file = getResource(SIMPLE_CLASS_FILE_PATH);
final String fileContents = getResourceContents(file);
final ClassOrInterfaceTypeDetails simpleInterfaceDetails = typeParsingService.getTypeFromString(fileContents, SIMPLE_CLASS_DECLARED_BY_MID, SIMPLE_CLASS_TYPE);
final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(SIMPLE_CLASS_DECLARED_BY_MID, Modifier.PRIVATE, new JavaSymbolName("newFieldAddedByCode"), new JavaType(String.class), "\"Create by code\"");
final ClassOrInterfaceTypeDetails newSimpleInterfaceDetails = addField(simpleInterfaceDetails, fieldBuilder.build());
// Invoke
final String result = typeParsingService.updateAndGetCompilationUnitContents(file.getCanonicalPath(), newSimpleInterfaceDetails);
saveResult(file, result, "-addedField");
checkSimpleClass(result);
assertTrue(result.contains("private String newFieldAddedByCode = \"Create by code\";"));
}
use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class SeleniumOperationsImpl method generateTest.
/**
* Creates a new Selenium testcase
*
* @param controller the JavaType of the controller under test (required)
* @param name the name of the test case (optional)
* @param serverURL the URL of the Selenium server (optional)
*/
@Override
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());
// 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);
final MemberDetails memberDetails = memberDetailsScanner.getMemberDetails(getClass().getName(), formBackingTypeDetails);
// Add composite PK identifier fields if needed
for (final FieldMetadata field : persistenceMemberLocator.getEmbeddedIdentifierFields(formBackingType)) {
final JavaType fieldType = field.getFieldType();
if (!fieldType.isCommonCollectionType() && !isSpecialType(fieldType)) {
final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(field);
final String fieldName = field.getFieldName().getSymbolName();
fieldBuilder.setFieldName(new JavaSymbolName(fieldName + "." + fieldName));
tbody.appendChild(typeCommand(document, fieldBuilder.build()));
}
}
// Add all other fields
final List<FieldMetadata> fields = webMetadataService.getScaffoldEligibleFieldMetadata(formBackingType, memberDetails, null);
for (final FieldMetadata field : fields) {
final JavaType fieldType = field.getFieldType();
if (!fieldType.isCommonCollectionType() && !isSpecialType(fieldType)) {
tbody.appendChild(typeCommand(document, field));
}
}
tbody.appendChild(clickAndWaitCommand(document, "//input[@id = 'proceed']"));
// Add verifications for all other fields
for (final FieldMetadata field : fields) {
final JavaType fieldType = field.getFieldType();
if (!fieldType.isCommonCollectionType() && !isSpecialType(fieldType)) {
tbody.appendChild(verifyTextCommand(document, formBackingType, field));
}
}
fileManager.createOrUpdateTextFileIfRequired(seleniumPath, XmlUtils.nodeToString(document), false);
manageTestSuite(relativeTestFilePath, name, serverURL);
// Install selenium-maven-plugin
installMavenPlugin();
}
use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class WebFlowCommands method getClassPossibleValues.
@CliOptionAutocompleteIndicator(command = "web flow", param = "class", help = "You should specify an existing and serializable class for option " + "'--class'.", validate = false)
public List<String> getClassPossibleValues(ShellContext shellContext) {
// Get current value of class
String currentText = shellContext.getParameters().get("class");
List<String> allPossibleValues = new ArrayList<String>();
// Getting all existing entities
Set<ClassOrInterfaceTypeDetails> domainClassesInProject = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_JPA_ENTITY, RooJavaType.ROO_DTO);
for (ClassOrInterfaceTypeDetails classDetails : domainClassesInProject) {
// Check if class implements serializable (needed for WebFlow)
boolean isSerializable = false;
// First, chech for @RooSerializable
if (classDetails.getAnnotation(RooJavaType.ROO_SERIALIZABLE) != null) {
isSerializable = true;
}
// Check for the explicit 'implements Serializable'
if (!isSerializable) {
List<JavaType> implementsTypes = classDetails.getImplementsTypes();
for (JavaType type : implementsTypes) {
if (type.equals(JdkJavaType.SERIALIZABLE)) {
isSerializable = true;
break;
}
}
}
if (isSerializable) {
// Add to possible values
String name = replaceTopLevelPackageString(classDetails, currentText);
if (!allPossibleValues.contains(name)) {
allPossibleValues.add(name);
}
}
}
if (allPossibleValues.isEmpty()) {
// Any entity or DTO in project is serializable
LOGGER.info("Any auto-complete value offered because the project hasn't any entity " + "or DTO which implement Serializable");
}
return allPossibleValues;
}
Aggregations