Пример #1
0
 // Oracle10gでの正規表現取得のテスト
 public void testRegExp() throws Exception {
   Extractor e = new Extractor(Item.class);
   e.add(Condition.regex(new Property(Item.NAME), "^N"));
   List<Item> list = BasicService.getService().findByExtractor(e);
   assertEquals("返却数が誤っています。", 1, list.size());
   assertEquals("IDが誤っています。", "NDS", list.get(0).getName());
 }
Пример #2
0
 // 基盤のテスト
 public void testNotIn() throws Exception {
   Extractor e = new Extractor(Item.class);
   e.add(Condition.notIn(new Property(Item.ID), 1L, 2L, 3L));
   List<Item> all = BasicService.getService().findAll(Item.class);
   List<Item> list = BasicService.getService().findByExtractor(e);
   assertEquals("返却数が誤っています。", 3, all.size() - list.size());
 }
Пример #3
0
  public void testJoinを用いた検索結果でコレクションサイズと件数が一致しない不具合解消のテスト() throws Exception {
    Extractor ex = new Extractor(Unit.class);
    ex.addInnerJoin(
        new InnerJoin(
            new Property(Unit.class, null, null), new Property(Unit.class, "child", Unit.BASE)));
    ex.add(Condition.eq(new Property(Unit.class, "child", Unit.BASE + "." + Unit.ID), 1L));
    FindResult<Unit> result = BasicService.getService().findByExtractorWithCount(ex);
    assertEquals("件数が誤っています。", 4, result.list.size());
    assertEquals("総件数が誤っています。", 4, result.count);

    ex.setDistinct(true);
    result = BasicService.getService().findByExtractorWithCount(ex);
    assertEquals("件数が誤っています。", 1, result.list.size());
    assertEquals("総件数が誤っています。", 1, result.count);

    // ExtractValue付きの場合はPreparedStatementを使用するのでこっちも確認
    ex.addExtractValue(new ExtractValue("id", new Property(Unit.ID)));
    ex.setDistinct(false);
    result = BasicService.getService().findByExtractorWithCount(ex);
    assertEquals("件数が誤っています。", 4, result.list.size());
    assertEquals("総件数が誤っています。", 4, result.count);

    ex.setDistinct(true);
    result = BasicService.getService().findByExtractorWithCount(ex);
    assertEquals("件数が誤っています。", 1, result.list.size());
    assertEquals("総件数が誤っています。", 1, result.count);
  }
Пример #4
0
 public void test新規作成したオブジェクトを挿入後更新したら更新後の値が反映されること() throws Exception {
   ServiceLocator.getService(更新メソッドを使わずにデータが更新されないことを確認するService.class).test5();
   Extractor ex = new Extractor(Unit.class);
   ex.add(Condition.eq(new Property(Unit.NAME), "適当データ"));
   Unit u = (Unit) BasicService.getService().findByExtractor(ex).get(0);
   assertEquals("備考が誤っています。", "xyz", u.getDescription());
 }
Пример #5
0
 public void testEventCallback() throws Exception {
   List<Object> list2 = new ArrayList<Object>();
   list2.add(new CallbackListener());
   DIContainer real = DIContainerFactory.getDIContainer();
   Map<Object, Object> map = new HashMap<Object, Object>();
   map.put(BasicService.PERSISTENCE_EVENT_LISTENERS, list2);
   MapDIContainer wrapper = new MapDIContainer(map);
   DIContainerFactory.setDIContainer(
       new CompositeDIContainer(Arrays.asList(new DIContainer[] {wrapper, real})));
   System.out.println(DIContainerFactory.getDIContainer().getClass().getName());
   try {
     Extractor e = new Extractor(Unit.class);
     e.addExtractValue(new ExtractValue("id", new Property(Unit.ID)));
     e.add(Condition.eq(new Property(Unit.ID), 1));
     e.setReturnType(CallbackTestType.class);
     System.out.println(DIContainerFactory.getDIContainer().getClass().getName());
     List<CallbackTestType> list = BasicService.getService().findByExtractor(e);
     System.out.println(DIContainerFactory.getDIContainer().getClass().getName());
     assertEquals("返却値が数が誤っています。", 1, list.size());
     assertEquals("コールバックメソッド呼び出し回数が誤っています。", 6, list.get(0).list.size());
     int index = 0;
     assertEquals(
         "コールバックメソッド呼び出し順序が誤っています.", "CallbackListener#postLoad5", list.get(0).list.get(index++));
     assertEquals("コールバックメソッド呼び出し順序が誤っています.", "postLoad3", list.get(0).list.get(index++));
     assertEquals(
         "コールバックメソッド呼び出し順序が誤っています.", "CallbackListener#apostLoad3", list.get(0).list.get(index++));
     assertEquals(
         "コールバックメソッド呼び出し順序が誤っています.", "CallbackListener#postLoad3", list.get(0).list.get(index++));
     assertEquals("コールバックメソッド呼び出し順序が誤っています.", "postLoad1", list.get(0).list.get(index++));
     assertEquals(
         "コールバックメソッド呼び出し順序が誤っています.", "CallbackListener#postLoad1", list.get(0).list.get(index++));
   } finally {
     DIContainerFactory.setDIContainer(real);
   }
 }
Пример #6
0
 // 基盤のテスト
 public void testIn() throws Exception {
   Extractor e = new Extractor(Item.class);
   e.add(Condition.in(new Property(Item.ID), 1L, 2L, 3L));
   e.addOrder(Order.asc(new Property(Item.ID)));
   List<Item> list = BasicService.getService().findByExtractor(e);
   assertEquals("返却数が誤っています。", 3, list.size());
   assertEquals("IDが誤っています。", 1L, list.get(0).getId().longValue());
   assertEquals("IDが誤っています。", 2L, list.get(1).getId().longValue());
   assertEquals("IDが誤っています。", 3L, list.get(2).getId().longValue());
 }