Search in sources :

Example 6 with TstBean

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

the class OrderingTest method testOrderList.

@Test
public void testOrderList() {
    List<TstBean> list = new ArrayList<>(3);
    list.add(new TstBean(5));
    list.add(new TstBean(2));
    list.add(new TstBean(3));
    new Ordering("integer", SortOrder.ASCENDING).orderList(list);
    assertEquals(2, list.get(0).getInteger().intValue());
    assertEquals(3, list.get(1).getInteger().intValue());
    assertEquals(5, list.get(2).getInteger().intValue());
}
Also used : ArrayList(java.util.ArrayList) TstBean(org.apache.cayenne.unit.util.TstBean) Test(org.junit.Test)

Example 7 with TstBean

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

the class CayenneDataObjectIT method testReadNestedPropertyNonDataObjectPath.

@Test
public void testReadNestedPropertyNonDataObjectPath() {
    CayenneDataObject o1 = new CayenneDataObject();
    TstBean o2 = new TstBean();
    o2.setInteger(new Integer(55));
    o1.writePropertyDirectly("o2", o2);
    assertSame(o2, o1.readNestedProperty("o2"));
    assertEquals(new Integer(55), o1.readNestedProperty("o2.integer"));
    assertEquals(TstBean.class, o1.readNestedProperty("o2.class"));
    assertEquals(TstBean.class.getName(), o1.readNestedProperty("o2.class.name"));
}
Also used : TstBean(org.apache.cayenne.unit.util.TstBean) Test(org.junit.Test)

Example 8 with TstBean

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

the class PersistentDescriptorTest method testCopyObjectProperties.

@Test
public void testCopyObjectProperties() {
    PersistentDescriptor d1 = new PersistentDescriptor();
    ObjAttribute attribute = mock(ObjAttribute.class);
    FieldAccessor accessor = new FieldAccessor(TstBean.class, "string", String.class);
    PropertyDescriptor property = new SimpleAttributeProperty(d1, accessor, attribute);
    d1.addDeclaredProperty(property);
    TstBean from = new TstBean();
    from.setString("123");
    TstBean to = new TstBean();
    d1.shallowMerge(from, to);
    assertEquals("123", to.getString());
}
Also used : ObjAttribute(org.apache.cayenne.map.ObjAttribute) TstBean(org.apache.cayenne.unit.util.TstBean) Test(org.junit.Test)

Example 9 with TstBean

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

the class OrderingTest method testOrderedList_Static.

@Test
public void testOrderedList_Static() {
    Collection<TstBean> set = new HashSet<>(6);
    TstBean shouldBe0 = new TstBean("a", 5);
    TstBean shouldBe1 = new TstBean("b", 5);
    TstBean shouldBe2 = new TstBean("b", 2);
    TstBean shouldBe3 = new TstBean("b", 1);
    TstBean shouldBe4 = new TstBean("c", 30);
    TstBean shouldBe5 = new TstBean("c", 1);
    set.add(shouldBe0);
    set.add(shouldBe5);
    set.add(shouldBe3);
    set.add(shouldBe1);
    set.add(shouldBe4);
    set.add(shouldBe2);
    List<Ordering> orderings = asList(new Ordering("string", SortOrder.ASCENDING), new Ordering("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 10 with TstBean

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

the class OrderingTest method testOrderListWithFunction.

@Test
public void testOrderListWithFunction() {
    Collection<TstBean> set = new HashSet<>(6);
    TstBean shouldBe0 = new TstBean("", 0);
    TstBean shouldBe1 = new TstBean("", -1);
    TstBean shouldBe2 = new TstBean("", -2);
    TstBean shouldBe3 = new TstBean("", 5);
    TstBean shouldBe4 = new TstBean("", -6);
    TstBean shouldBe5 = new TstBean("", -30);
    set.add(shouldBe4);
    set.add(shouldBe2);
    set.add(shouldBe1);
    set.add(shouldBe5);
    set.add(shouldBe0);
    set.add(shouldBe3);
    List<TstBean> orderedList = new Ordering(FunctionExpressionFactory.absExp("integer"), SortOrder.ASCENDING).orderedList(set);
    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)

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