use of org.springframework.roo.classpath.details.MethodMetadataBuilder in project spring-roo by spring-projects.
the class RepositoryJpaIntegrationTestMetadata method getCountTestMethod.
/**
* Builds a method to test count method.
*
* @return {@link MethodMetadata}
*/
private MethodMetadata getCountTestMethod() {
MethodMetadata method = getGovernorMethod(COUNT_TEST_METHOD_NAME);
if (method != null) {
return method;
}
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
// Verify
bodyBuilder.appendFormalLine("// Verify");
// assertThat(repository.count()).as("Check there are available 'Pet' entries").isGreaterThan(0);
bodyBuilder.appendFormalLine("%s(%s().count()).as(\"Check there are available '%s' entries\").isGreaterThan(0);", getNameOfJavaType(ASSERT_THAT), getAccessorMethod(this.repositoryField).getMethodName(), getNameOfJavaType(this.entity));
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, COUNT_TEST_METHOD_NAME, JavaType.VOID_PRIMITIVE, bodyBuilder);
// Add @Test
methodBuilder.addAnnotation(new AnnotationMetadataBuilder(TEST));
return methodBuilder.build();
}
use of org.springframework.roo.classpath.details.MethodMetadataBuilder in project spring-roo by spring-projects.
the class RepositoryJpaIntegrationTestMetadata method getFindOneTestMethod.
/**
* Builds a method to test find one method.
*
* @return {@link MethodMetadata}
*/
private MethodMetadata getFindOneTestMethod() {
final JavaSymbolName methodName = new JavaSymbolName(String.format("findOneShouldReturnExisting%s", this.entity.getSimpleTypeName()));
MethodMetadata method = getGovernorMethod(methodName);
if (method != null) {
return method;
}
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
// Setup
bodyBuilder.appendFormalLine("// Setup");
// Long id = getRandomPetId();
bodyBuilder.appendFormalLine("%s id = %s();", getNameOfJavaType(this.identifierType), this.getRandomIdMethodName);
// Exercise
bodyBuilder.newLine();
bodyBuilder.appendFormalLine("// Exercise");
// Pet pet = repository.findOne(id);
bodyBuilder.appendFormalLine("%s %s = %s().findOne(id);", getNameOfJavaType(this.entity), entityVar, getAccessorMethod(this.repositoryField).getMethodName());
// Verify
bodyBuilder.newLine();
bodyBuilder.appendFormalLine("// Verify");
// assertThat(pet).as("Check that findOne illegally returned null for id %s", id).isNotNull();
bodyBuilder.appendFormalLine("%s(%s).as(\"Check that findOne illegally returned null for id %s\", id).isNotNull();", getNameOfJavaType(ASSERT_THAT), this.entityVar, "%s");
// assertThat(id).as("Check the identifier of the found 'Pet' is the same used to look for it")
bodyBuilder.appendFormalLine("%s(id).as(\"Check the identifier of the found '%s' is the same used to look for it\")", getNameOfJavaType(ASSERT_THAT), getNameOfJavaType(this.entity));
// .isEqualTo(pet.getId());
bodyBuilder.indent();
bodyBuilder.appendFormalLine(".isEqualTo(%s.%s());", this.entityVar, this.identifierAccessorMethodName);
bodyBuilder.reset();
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, JavaType.VOID_PRIMITIVE, bodyBuilder);
// Add @Test
methodBuilder.addAnnotation(new AnnotationMetadataBuilder(TEST));
return methodBuilder.build();
}
use of org.springframework.roo.classpath.details.MethodMetadataBuilder in project spring-roo by spring-projects.
the class ServiceImplMetadata method getIdentifierTypeGetterMethod.
/**
* Builds a method which returns the class of the entity identifier JavaType.
*
* @return MethodMetadataBuilder
*/
private MethodMetadata getIdentifierTypeGetterMethod() {
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
MethodMetadata existingMethod = getGovernorMethod(GET_ID_TYPE_METHOD_NAME, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
if (existingMethod != null) {
return existingMethod;
}
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
// return IDENTIFIER_TYPE.class;
bodyBuilder.appendFormalLine("return %s.class;", getNameOfJavaType(this.entityIdentifierType));
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, GET_ID_TYPE_METHOD_NAME, JavaType.wrapperOf(JavaType.CLASS, this.serviceMetadata.getIdType()), parameterTypes, parameterNames, bodyBuilder);
// Build and return a MethodMetadata instance
return methodBuilder.build();
}
use of org.springframework.roo.classpath.details.MethodMetadataBuilder in project spring-roo by spring-projects.
the class ServiceImplMetadata method getMethod.
/**
* Method that generates implementation of provided method with specified
* body
*
* @param methodToBeImplemented
* @param isTransactional
* @param bodyBuilder
* @return
*/
private MethodMetadata getMethod(final MethodMetadata methodToBeImplemented, boolean isTransactional, InvocableMemberBodyBuilder bodyBuilder) {
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(methodToBeImplemented.getParameterNames());
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(methodToBeImplemented.getParameterTypes());
MethodMetadata existingMethod = getGovernorMethod(methodToBeImplemented.getMethodName(), AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
if (existingMethod != null) {
return existingMethod;
}
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodToBeImplemented.getMethodName(), methodToBeImplemented.getReturnType(), parameterTypes, parameterNames, bodyBuilder);
// Adding @Transactional
if (isTransactional) {
AnnotationMetadataBuilder transactionalAnnotation = new AnnotationMetadataBuilder(SpringJavaType.TRANSACTIONAL);
methodBuilder.addAnnotation(transactionalAnnotation);
}
// Build and return a MethodMetadata instance
return methodBuilder.build();
}
use of org.springframework.roo.classpath.details.MethodMetadataBuilder in project spring-roo by spring-projects.
the class ServiceMetadata method getFindAllMethod.
/**
* Method that generates method "findAll" method.
*
* @return MethodMetadataBuilder with public List <Entity> findAll();
* structure
*/
private MethodMetadata getFindAllMethod() {
// Define method name
JavaSymbolName methodName = new JavaSymbolName("findAll");
// Define method parameter types
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
// Define method parameter names
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
MethodMetadata existingMethod = getGovernorMethod(methodName, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
if (existingMethod != null) {
return existingMethod;
}
JavaType listEntityJavaType = JavaType.listOf(entity);
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, methodName, listEntityJavaType, parameterTypes, parameterNames, null);
// Build and return a MethodMetadata
return methodBuilder.build();
// instance
}
Aggregations