예제 #1
0
  @Test
  public void test() {

    Cat cat = new Cat();
    cat.setName("Puss");
    Ebean.save(cat);

    Dog dog = new Dog();
    dog.setRegistrationNumber("DOGGIE");
    Ebean.save(dog);

    BigDog bd = new BigDog();
    bd.setDogSize("large");
    bd.setRegistrationNumber("BG1");
    Ebean.save(bd);

    AnimalShelter shelter = new AnimalShelter();
    shelter.setName("My Animal Shelter");
    shelter.getAnimals().add(cat);
    shelter.getAnimals().add(dog);

    Ebean.save(shelter);

    AnimalShelter shelter2 = Ebean.find(AnimalShelter.class, shelter.getId());
    List<Animal> animals = shelter2.getAnimals();

    BeanList<?> beanList = (BeanList<?>) animals;
    ModifyListenMode modifyListenMode = beanList.getModifyListenMode();

    assertNotNull(modifyListenMode);

    assertNotNull(Ebean.find(Animal.class).findList());
  }
예제 #2
0
  @Ignore
  @Test
  public void test() {

    Update<EBasicEncrypt> deleteAll =
        Ebean.createUpdate(EBasicEncrypt.class, "delete from EBasicEncrypt");
    deleteAll.execute();

    EBasicEncrypt e = new EBasicEncrypt();
    e.setName("testname");
    e.setDescription("testdesc");
    e.setDob(new Date(System.currentTimeMillis() - 100000));

    Ebean.save(e);

    Date earlyDob = new Date(System.currentTimeMillis() - 500000);

    SqlQuery q = Ebean.createSqlQuery("select * from e_basicenc where id = :id");
    q.setParameter("id", e.getId());

    SqlRow row = q.findUnique();
    row.getString("name");
    row.get("description");

    EBasicEncrypt e1 = Ebean.find(EBasicEncrypt.class, e.getId());

    e1.getDescription();

    e1.setName("testmod");
    e1.setDescription("moddesc");

    Ebean.save(e1);

    EBasicEncrypt e2 = Ebean.find(EBasicEncrypt.class, e.getId());

    e2.getDescription();

    SpiEbeanServer server = (SpiEbeanServer) Ebean.getServer(null);
    DbEncrypt dbEncrypt = server.getDatabasePlatform().getDbEncrypt();

    if (dbEncrypt == null) {
      // can not test the where clause
      System.out.println("TestEncrypt: Not testing where clause as no DbEncrypt");

    } else {

      List<EBasicEncrypt> list =
          Ebean.find(EBasicEncrypt.class).where().eq("description", "moddesc").findList();

      Assert.assertEquals(1, list.size());

      list = Ebean.find(EBasicEncrypt.class).where().startsWith("description", "modde").findList();

      Assert.assertEquals(1, list.size());
    }
  }
 @Test
 public void test() {
   try {
     new UserService().create(new User(1L, "David"));
     fail("Exception should be thrown");
   } catch (PersistenceException pe) {
     LOG.error("e: " + pe);
   }
   List<User> users = Ebean.find(User.class).findList();
   LOG.debug("users: {}", users);
   assertTrue("users should be empty", users.isEmpty());
 }
예제 #4
0
  @Test
  public void testQueryBind() {

    if (!isH2()) {
      // only run this on H2 - PGCrypto not happy on CI server
      return;
    }

    LoggedSqlCollector.start();
    Ebean.find(EBasicEncrypt.class).where().startsWith("description", "Rob").findList();

    List<String> loggedSql = LoggedSqlCollector.stop();
    assertThat(loggedSql).hasSize(1);
    assertThat(loggedSql.get(0)).contains("; --bind(****,Rob%)");
  }
예제 #5
0
  private static void test() {
    RawSql rawSql =
        RawSqlBuilder.unparsed(
                "select r.id, r.name from o_customer r where r.id >= :a and r.name like :b")
            .columnMapping("r.id", "id")
            .columnMapping("r.name", "name")
            .create();

    Query<Customer> query = Ebean.find(Customer.class);
    query.setRawSql(rawSql);
    query.setParameter("a", 1);
    query.setParameter("b", "R%");

    List<Customer> list = query.findList();
    Assert.assertNotNull(list);
  }
예제 #6
0
  @Test
  public void fetchWithInvalidPropertyName_expect_allowed() {

    Ebean.find(Customer.class).fetch("billingAddress", "invalidPropertyName").findList();
  }
예제 #7
0
  @Test(expected = PersistenceException.class)
  public void invalidFetchPath_expect_error() {

    Ebean.find(Customer.class).fetch("notValidPath").findList();
  }
예제 #8
0
  @Test(expected = PersistenceException.class)
  public void invalidFetchPathAndProperties_expect_error() {

    Ebean.find(Customer.class).fetch("notValidPath", "notHaveProps").findList();
  }