Search in sources :

Example 6 with PartTree

use of org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree in project spring-roo by spring-projects.

the class PartTreeUnitTest method validateReturnTypeEntity.

@Test
public void validateReturnTypeEntity() throws Exception {
    JavaType exampleType = new JavaType("Example");
    JavaType examplePageType = new JavaType("org.springframework.data.domain.Page", 0, DataType.TYPE, null, Arrays.asList(exampleType));
    assertEquals(examplePageType, new PartTree("findDistinctByText", memberDetails).getReturnType());
    assertEquals(examplePageType, new PartTree("findByText", memberDetails).getReturnType());
    assertEquals(examplePageType, new PartTree("findTop2ByText", memberDetails).getReturnType());
    assertEquals(examplePageType, new PartTree("findDistinctTop10ByText", memberDetails).getReturnType());
    assertEquals(examplePageType, new PartTree("findFirst2ByText", memberDetails).getReturnType());
    assertEquals(exampleType, new PartTree("findTopByText", memberDetails).getReturnType());
    assertEquals(exampleType, new PartTree("findTopFirst1ByText", memberDetails).getReturnType());
    assertEquals(exampleType, new PartTree("findDistinctFirstByText", memberDetails).getReturnType());
    assertEquals(exampleType, new PartTree("findDistinctTop1ByText", memberDetails).getReturnType());
}
Also used : JavaType(org.springframework.roo.model.JavaType) PartTree(org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree) Test(org.junit.Test)

Example 7 with PartTree

use of org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree in project spring-roo by spring-projects.

the class PartTreeUnitTest method validateReturnsTypeInteger.

@Test
public void validateReturnsTypeInteger() throws Exception {
    JavaType intPageType = new JavaType("org.springframework.data.domain.Page", 0, DataType.TYPE, null, Arrays.asList(JavaType.INT_OBJECT));
    assertEquals(intPageType, new PartTree("findDistinctNumberByText", memberDetails).getReturnType());
    assertEquals(intPageType, new PartTree("findNumberByText", memberDetails).getReturnType());
    assertEquals(intPageType, new PartTree("findTop2NumberByText", memberDetails).getReturnType());
    assertEquals(intPageType, new PartTree("findDistinctTop10NumberByText", memberDetails).getReturnType());
    assertEquals(intPageType, new PartTree("findFirst2NumberByText", memberDetails).getReturnType());
    assertEquals(JavaType.INT_OBJECT, new PartTree("findTopNumberByText", memberDetails).getReturnType());
    assertEquals(JavaType.INT_OBJECT, new PartTree("findFirst1NumberByText", memberDetails).getReturnType());
    assertEquals(JavaType.INT_OBJECT, new PartTree("findDistinctFirstNumberByText", memberDetails).getReturnType());
    assertEquals(JavaType.INT_OBJECT, new PartTree("findDistinctTop1NumberByText", memberDetails).getReturnType());
}
Also used : JavaType(org.springframework.roo.model.JavaType) PartTree(org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree) Test(org.junit.Test)

Example 8 with PartTree

use of org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree in project spring-roo by spring-projects.

the class PartTreeUnitTest method detectsDistinctCorrectly.

@Test
public void detectsDistinctCorrectly() throws Exception {
    for (String prefix : QUERIES) {
        PartTree partTree = new PartTree(prefix + "DistinctByText", memberDetails);
        assertTrue(partTree.isValid() && partTree.isDistinct());
        partTree = new PartTree(prefix + "DistinctTextByText", memberDetails);
        assertTrue(partTree.isValid() && partTree.isDistinct());
        partTree = new PartTree(prefix + "DistinctTop100TextByText", memberDetails);
        assertTrue(partTree.isValid() && partTree.isDistinct());
        partTree = new PartTree(prefix + "DistinctFirstByText", memberDetails);
        assertTrue(partTree.isValid() && partTree.isDistinct());
        partTree = new PartTree(prefix + "DistinctTopTextByText", memberDetails);
        assertTrue(partTree.isValid() && partTree.isDistinct());
    }
}
Also used : PartTree(org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree) Test(org.junit.Test)

Example 9 with PartTree

use of org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree in project spring-roo by spring-projects.

the class PartTreeUnitTest method validateReturnsTypeDate.

@Test
public void validateReturnsTypeDate() throws Exception {
    JavaType dateType = new JavaType(Date.class);
    JavaType datePageType = new JavaType("org.springframework.data.domain.Page", 0, DataType.TYPE, null, Arrays.asList(dateType));
    assertEquals(datePageType, new PartTree("findDistinctDateByText", memberDetails).getReturnType());
    assertEquals(datePageType, new PartTree("findDateByText", memberDetails).getReturnType());
    assertEquals(datePageType, new PartTree("findTop2DateByText", memberDetails).getReturnType());
    assertEquals(datePageType, new PartTree("findDistinctTop10DateByText", memberDetails).getReturnType());
    assertEquals(datePageType, new PartTree("findFirst2DateByText", memberDetails).getReturnType());
    assertEquals(dateType, new PartTree("findTopDateByText", memberDetails).getReturnType());
    assertEquals(dateType, new PartTree("findFirst1DateByText", memberDetails).getReturnType());
    assertEquals(dateType, new PartTree("findDistinctFirstDateByText", memberDetails).getReturnType());
    assertEquals(dateType, new PartTree("findDistinctTop1DateByText", memberDetails).getReturnType());
}
Also used : JavaType(org.springframework.roo.model.JavaType) PartTree(org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree) Test(org.junit.Test)

Example 10 with PartTree

use of org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree in project spring-roo by spring-projects.

the class PartTreeUnitTest method validateSeveralParameters.

@Test
public void validateSeveralParameters() throws Exception {
    List<FinderParameter> parameters = new ArrayList<FinderParameter>();
    parameters.add(new FinderParameter(JavaType.INT_OBJECT, new JavaSymbolName("number1")));
    parameters.add(new FinderParameter(JavaType.INT_OBJECT, new JavaSymbolName("number2")));
    assertEqualsParameters(parameters, new PartTree("findByNumberBetween", memberDetails).getParameters());
    parameters.add(new FinderParameter(JavaType.INT_OBJECT, new JavaSymbolName("number3")));
    parameters.add(new FinderParameter(JavaType.INT_OBJECT, new JavaSymbolName("number4")));
    assertEqualsParameters(parameters, new PartTree("findByNumberBetweenAndNumberBetween", memberDetails).getParameters());
    parameters.add(new FinderParameter(JavaType.INT_OBJECT, new JavaSymbolName("number5")));
    assertEqualsParameters(parameters, new PartTree("countByNumberBetweenAndNumberBetweenAndNumberLessThan", memberDetails).getParameters());
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) FinderParameter(org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.FinderParameter) ArrayList(java.util.ArrayList) PartTree(org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree) Test(org.junit.Test)

Aggregations

PartTree (org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree)26 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)10 JavaType (org.springframework.roo.model.JavaType)10 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)8 FinderParameter (org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.FinderParameter)6 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)6 List (java.util.List)4 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)4 RooJavaType (org.springframework.roo.model.RooJavaType)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 JpaEntityMetadata (org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata)3 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)3 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)3 Pair (org.apache.commons.lang3.tuple.Pair)2 RepositoryJpaMetadata (org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaMetadata)2 FinderMethod (org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.FinderMethod)2 MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)2 NestedAnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue)2