Search in sources :

Example 1 with MemberTypeAdditions

use of org.springframework.roo.classpath.layers.MemberTypeAdditions in project spring-roo by spring-projects.

the class RepositoryJpaLayerProviderTest method testGetAdditionsWhenNoRepositoriesExist.

@Test
public void testGetAdditionsWhenNoRepositoriesExist() {
    // Invoke
    final MemberTypeAdditions additions = layerProvider.getMemberTypeAdditions(CALLER_MID, FIND_ALL_METHOD.name(), mockTargetEntity, mockIdType);
    // Check
    assertNull(additions);
}
Also used : MemberTypeAdditions(org.springframework.roo.classpath.layers.MemberTypeAdditions) Test(org.junit.Test)

Example 2 with MemberTypeAdditions

use of org.springframework.roo.classpath.layers.MemberTypeAdditions in project spring-roo by spring-projects.

the class RepositoryJpaLayerProviderTest method assertMethodCall.

/**
 * Asserts that the {@link RepositoryJpaLayerProvider} generates the
 * expected call for the given method with the given parameters
 *
 * @param expectedMethodCall
 * @param methodKey
 * @param callerParameters
 */
private void assertMethodCall(final String expectedMethodCall, final MethodMetadataCustomDataKey methodKey, final MethodParameter... callerParameters) {
    // Set up
    setUpMockRepository();
    // Invoke
    final MemberTypeAdditions additions = layerProvider.getMemberTypeAdditions(CALLER_MID, methodKey.name(), mockTargetEntity, mockIdType, callerParameters);
    // Check
    assertEquals(expectedMethodCall, additions.getMethodCall());
}
Also used : MemberTypeAdditions(org.springframework.roo.classpath.layers.MemberTypeAdditions)

Example 3 with MemberTypeAdditions

use of org.springframework.roo.classpath.layers.MemberTypeAdditions in project spring-roo by spring-projects.

the class RepositoryJpaLayerProvider method getMethodAdditions.

/**
 * Returns the additions that the caller needs to make in order to invoke
 * the given method
 *
 * @param callerMID the caller's metadata ID (required)
 * @param method the method being called (required)
 * @param repositoryType the type of repository being called
 * @param parameterNames the parameter names used by the caller
 * @return a non-<code>null</code> set of additions
 */
private MemberTypeAdditions getMethodAdditions(final String callerMID, final RepositoryJpaLayerMethod method, final JavaType repositoryType, final List<MethodParameter> parameters) {
    // Create a builder to hold the repository field to be copied into the
    // caller
    final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(callerMID);
    final AnnotationMetadataBuilder autowiredAnnotation = new AnnotationMetadataBuilder(AUTOWIRED);
    final String repositoryFieldName = StringUtils.uncapitalize(repositoryType.getSimpleTypeName());
    cidBuilder.addField(new FieldMetadataBuilder(callerMID, 0, Arrays.asList(autowiredAnnotation), new JavaSymbolName(repositoryFieldName), repositoryType));
    // Create the additions to invoke the given method on this field
    final String methodCall = repositoryFieldName + "." + method.getCall(parameters);
    return new MemberTypeAdditions(cidBuilder, method.getName(), methodCall, false, parameters);
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) MemberTypeAdditions(org.springframework.roo.classpath.layers.MemberTypeAdditions) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder)

Example 4 with MemberTypeAdditions

use of org.springframework.roo.classpath.layers.MemberTypeAdditions in project spring-roo by spring-projects.

the class RepositoryJpaLayerProviderTest method testGetAdditionsForNonRepositoryLayerMethod.

@Test
public void testGetAdditionsForNonRepositoryLayerMethod() {
    // Invoke
    final MemberTypeAdditions additions = layerProvider.getMemberTypeAdditions(CALLER_MID, "bogus", mockTargetEntity, mockIdType);
    // Check
    assertNull(additions);
}
Also used : MemberTypeAdditions(org.springframework.roo.classpath.layers.MemberTypeAdditions) Test(org.junit.Test)

Aggregations

MemberTypeAdditions (org.springframework.roo.classpath.layers.MemberTypeAdditions)4 Test (org.junit.Test)2 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)1 FieldMetadataBuilder (org.springframework.roo.classpath.details.FieldMetadataBuilder)1 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)1 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)1