@Test
 public void should_return_values_of_property() {
   List<Long> ids = new ArrayList<Long>();
   ids.add(yoda.getId());
   when(propertySupport.propertyValues(propertyName, Long.class, employees)).thenReturn(ids);
   assertSame(ids, properties.from(employees));
 }
Example #2
0
  @Test
  public void loadEmployee() {
    SienaFixtures.loadModels("data1.yml");

    // Bob
    Employee bob = Employee.all(Employee.class).filter("firstName", "Bob").get();
    assertNotNull(bob);
    assertEquals("Bob", bob.firstName);
    assertEquals("Smith", bob.lastName);
    assertEquals("password1", bob.pwd);
    assertEquals("{\"alpha1\": \"beta1\"}", bob.contactInfo.toString());
    // profileImage
    assertEquals("filename1.ext", bob.profileImage.filename);
    assertEquals("title1", bob.profileImage.title);
    assertEquals(1, bob.profileImage.views);
    assertEquals(Employee.MyEnum.VAL1, bob.profileImage.itemEnum);
    // otherImages[0]
    assertEquals("filename1.ext", bob.otherImages.get(0).filename);
    assertEquals("title1", bob.otherImages.get(0).title);
    assertEquals(1, bob.otherImages.get(0).views);
    assertEquals(Employee.MyEnum.VAL1, bob.otherImages.get(0).itemEnum);
    // otherImages[1]
    assertEquals("filename2.ext", bob.otherImages.get(1).filename);
    assertEquals("title2", bob.otherImages.get(1).title);
    assertEquals(2, bob.otherImages.get(1).views);
    assertEquals(Employee.MyEnum.VAL2, bob.otherImages.get(1).itemEnum);
    // stillImages[test1]
    assertEquals("filename1.ext", bob.stillImages.get("test1").filename);
    assertEquals("title1", bob.stillImages.get("test1").title);
    assertEquals(1, bob.stillImages.get("test1").views);
    assertEquals(Employee.MyEnum.VAL1, bob.stillImages.get("test1").itemEnum);
    // stillImages[test2]
    assertEquals("filename2.ext", bob.stillImages.get("test2").filename);
    assertEquals("title2", bob.stillImages.get("test2").title);
    assertEquals(2, bob.stillImages.get("test2").views);
    assertEquals(Employee.MyEnum.VAL2, bob.stillImages.get("test2").itemEnum);
    // items[1]
    assertEquals("alpha1", bob.items.get(0).item);
    assertEquals("beta1", bob.items.get(0).item2);
    assertEquals(Employee.MyEnum.VAL1, bob.items.get(0).itemEnum);
    // items[2]
    assertEquals("alpha2", bob.items.get(1).item);
    assertEquals("beta2", bob.items.get(1).item2);
    assertEquals(Employee.MyEnum.VAL2, bob.items.get(1).itemEnum);
    // enumField
    assertEquals(Employee.MyEnum.VAL3, bob.enumField);

    // John
    Employee john = Employee.all(Employee.class).filter("firstName", "John").get();
    assertNotNull(john);
    assertEquals("John", john.firstName);
    assertEquals("Doe", john.lastName);
    assertEquals("password2", john.pwd);
    assertEquals("{\"alpha2\": \"beta2\"}", john.contactInfo.toString());
    assertEquals("filename2.ext", john.profileImage.filename);
    assertEquals("title2", john.profileImage.title);
    assertEquals(2, john.profileImage.views);
    assertEquals(Employee.MyEnum.VAL2, john.profileImage.itemEnum);
    assertEquals(bob.id, john.boss.id);

    // emp1
    Employee emp1 = Employee.all(Employee.class).filter("firstName", "emp1").get();
    assertNotNull(emp1);
    // emp2
    Employee emp2 = Employee.all(Employee.class).filter("firstName", "emp2").get();
    assertNotNull(emp2);
    // boss
    Employee boss = Employee.all(Employee.class).filter("firstName", "boss").get();
    assertNotNull(boss);
    List<Employee> emps = boss.employees.fetch();
    assertEquals(emp1.id, emps.get(0).id);
    assertEquals(emp2.id, emps.get(1).id);
    assertEquals(emp1.boss.id, boss.id);
    assertEquals(emp2.boss.id, boss.id);
  }