use of org.springframework.roo.classpath.details.MethodMetadata in project spring-roo by spring-projects.
the class RepositoryJpaMetadata method getFindOneMethod.
private MethodMetadata getFindOneMethod(JavaType entity, FieldMetadata identifierFieldMetadata) {
// Define method parameter type and name
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(identifierFieldMetadata.getFieldType()));
parameterNames.add(identifierFieldMetadata.getFieldName());
MethodMetadata existingMethod = getGovernorMethod(FIND_ONE_METHOD_NAME, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
if (existingMethod != null) {
return existingMethod;
}
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
return new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, FIND_ONE_METHOD_NAME, entity, parameterTypes, parameterNames, null).build();
}
use of org.springframework.roo.classpath.details.MethodMetadata in project spring-roo by spring-projects.
the class RepositoryJpaIntegrationTestMetadata method getFindAllCustomNotFilteredPagedTestMethod.
/**
* Builds a method to test the find all custom method not filtered and paged.
*
* @return {@link MethodMetadata}
*/
private MethodMetadata getFindAllCustomNotFilteredPagedTestMethod() {
JavaSymbolName methodName = new JavaSymbolName(String.format("findAllCustomNotFilteredPagedShouldReturnA%sPage", this.entityPlural));
// Check if method exists on governor
MethodMetadata method = getGovernorMethod(methodName);
if (method != null) {
return method;
}
// Build method body
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
// Exercise
bodyBuilder.appendFormalLine("// Exercise");
// Page<Pet> all = repository.findAll((GlobalSearch) null, new PageRequest(0, 3));
bodyBuilder.appendFormalLine("%s<%s> all = %s().findAll((%s) null, new %s(0, 3));", getNameOfJavaType(SpringJavaType.PAGE), getNameOfJavaType(this.defaultReturnType), getAccessorMethod(this.repositoryField).getMethodName(), getNameOfJavaType(SpringletsJavaType.SPRINGLETS_GLOBAL_SEARCH), getNameOfJavaType(SpringJavaType.PAGE_REQUEST));
// Verify
bodyBuilder.newLine();
bodyBuilder.appendFormalLine("// Verify");
// assertThat(all.getNumberOfElements())
bodyBuilder.appendFormalLine("%s(all.getNumberOfElements())", getNameOfJavaType(ASSERT_THAT));
// .as("Check result number is not greater than the page size").isLessThanOrEqualTo(3);
bodyBuilder.indent();
bodyBuilder.appendFormalLine(".as(\"Check result number is not greater than the page size\").isLessThanOrEqualTo(3);");
bodyBuilder.indentRemove();
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.MethodMetadata 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.MethodMetadata 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.MethodMetadata 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();
}
Aggregations