Search in sources :

Example 1 with TstBean

use of org.apache.cayenne.unit.util.TstBean in project cayenne by apache.

the class FieldAccessorTest method testGet.

@Test
public void testGet() {
    FieldAccessor accessor = new FieldAccessor(TstBean.class, "string", String.class);
    TstBean object = new TstBean();
    object.setString("abc");
    assertEquals("abc", accessor.getValue(object));
}
Also used : TstBean(org.apache.cayenne.unit.util.TstBean) Test(org.junit.Test)

Example 2 with TstBean

use of org.apache.cayenne.unit.util.TstBean in project cayenne by apache.

the class ASTObjPathTest method testEvaluate_JavaBean.

@Test
public void testEvaluate_JavaBean() {
    ASTObjPath node = new ASTObjPath("property2");
    TstBean b1 = new TstBean();
    b1.setProperty2(1);
    assertEquals(1, node.evaluate(b1));
    TstBean b2 = new TstBean();
    b2.setProperty2(-3);
    assertEquals(-3, node.evaluate(b2));
}
Also used : TstBean(org.apache.cayenne.unit.util.TstBean) Test(org.junit.Test)

Example 3 with TstBean

use of org.apache.cayenne.unit.util.TstBean in project cayenne by apache.

the class OrderingTest method testCompare4.

@Test
public void testCompare4() {
    // compare on non-persistent property
    TstBean t1 = new TstBean(1000);
    TstBean t2 = new TstBean(2000);
    TstBean t3 = new TstBean(2000);
    Ordering ordering = new Ordering("integer", SortOrder.ASCENDING);
    assertTrue(ordering.compare(t1, t2) < 0);
    assertTrue(ordering.compare(t2, t1) > 0);
    assertTrue(ordering.compare(t2, t3) == 0);
}
Also used : TstBean(org.apache.cayenne.unit.util.TstBean) Test(org.junit.Test)

Example 4 with TstBean

use of org.apache.cayenne.unit.util.TstBean in project cayenne by apache.

the class OrderingTest method testOrderListWithFunction_Static.

@Test
public void testOrderListWithFunction_Static() {
    Collection<TstBean> set = new HashSet<>(6);
    TstBean shouldBe0 = new TstBean("cx", -2);
    TstBean shouldBe1 = new TstBean("cf", -1);
    TstBean shouldBe2 = new TstBean("basa", 2);
    TstBean shouldBe3 = new TstBean("abcd", -1);
    TstBean shouldBe4 = new TstBean("bdsasd", -2);
    TstBean shouldBe5 = new TstBean("bdsadf", 1);
    set.add(shouldBe4);
    set.add(shouldBe2);
    set.add(shouldBe1);
    set.add(shouldBe5);
    set.add(shouldBe0);
    set.add(shouldBe3);
    List<Ordering> orderings = asList(new Ordering(FunctionExpressionFactory.lengthExp("string"), SortOrder.ASCENDING), new Ordering(FunctionExpressionFactory.absExp("integer"), SortOrder.DESCENDING));
    List<TstBean> orderedList = Ordering.orderedList(set, orderings);
    assertEquals(shouldBe0, orderedList.get(0));
    assertEquals(shouldBe1, orderedList.get(1));
    assertEquals(shouldBe2, orderedList.get(2));
    assertEquals(shouldBe3, orderedList.get(3));
    assertEquals(shouldBe4, orderedList.get(4));
    assertEquals(shouldBe5, orderedList.get(5));
}
Also used : TstBean(org.apache.cayenne.unit.util.TstBean) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with TstBean

use of org.apache.cayenne.unit.util.TstBean in project cayenne by apache.

the class OrderingTest method testOrderList_Static.

@Test
public void testOrderList_Static() {
    List<TstBean> list = new ArrayList<>(6);
    list.add(new TstBean("c", 1));
    list.add(new TstBean("c", 30));
    list.add(new TstBean("a", 5));
    list.add(new TstBean("b", 1));
    list.add(new TstBean("b", 2));
    list.add(new TstBean("b", 5));
    List<Ordering> orderings = asList(new Ordering("string", SortOrder.ASCENDING), new Ordering("integer", SortOrder.DESCENDING));
    // clone list and then order
    List<TstBean> orderedList = new ArrayList<>(list);
    Ordering.orderList(orderedList, orderings);
    assertEquals(list.get(2), orderedList.get(0));
    assertEquals(list.get(5), orderedList.get(1));
    assertEquals(list.get(4), orderedList.get(2));
    assertEquals(list.get(3), orderedList.get(3));
    assertEquals(list.get(1), orderedList.get(4));
    assertEquals(list.get(0), orderedList.get(5));
}
Also used : ArrayList(java.util.ArrayList) TstBean(org.apache.cayenne.unit.util.TstBean) Test(org.junit.Test)

Aggregations

TstBean (org.apache.cayenne.unit.util.TstBean)11 Test (org.junit.Test)11 HashSet (java.util.HashSet)4 ArrayList (java.util.ArrayList)2 ObjAttribute (org.apache.cayenne.map.ObjAttribute)1