Skip to content

Commit

Permalink
test[orm]: test
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Jul 1, 2024
1 parent a2832e6 commit 755cc1a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
58 changes: 39 additions & 19 deletions orm/src/test/java/com/zfoo/orm/accessor/AccessorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,56 +28,76 @@
@Ignore
public class AccessorTest {

@Test
public void oneTest() {
var context = new ClassPathXmlApplicationContext("application.xml");
OrmContext.getOrmManager().getCollection(UserEntity.class).drop();
insert();
delete();
insert();
update();
load();
}

@Test
public void insert() {
public void batchTest() {
var context = new ClassPathXmlApplicationContext("application.xml");
OrmContext.getOrmManager().getCollection(UserEntity.class).drop();
batchInsert();
batchUpdate();
queryAll();
deleteAll();
queryAll();
}

public void insert() {
var userEntity = new UserEntity(1, (byte) 2, (short) 3, 5, true, "orm", "orm");
OrmContext.getAccessor().insert(userEntity);
}


@Test
public void delete() {
var context = new ClassPathXmlApplicationContext("application.xml");
OrmContext.getAccessor().delete(1L, UserEntity.class);
}


@Test
public void update() {
var context = new ClassPathXmlApplicationContext("application.xml");
var userEntity = new UserEntity(1, (byte) 2, (short) 3, 5, true, "update", "update");
OrmContext.getAccessor().update(userEntity);
}

@Test
public void load() {
var context = new ClassPathXmlApplicationContext("application.xml");
var ent = (UserEntity) OrmContext.getAccessor().load(1L, UserEntity.class);
System.out.println(ent);
}


// 批量插入
@Test
public void batchInsert() {
var context = new ClassPathXmlApplicationContext("application.xml");
var listUser = new ArrayList<UserEntity>();
var list = new ArrayList<UserEntity>();
for (var i = 1; i <= 10; i++) {
var userEntity = new UserEntity(i, (byte) 1, (short) i, i, true, "helloOrm" + i, "helloOrm" + i);
listUser.add(userEntity);
list.add(userEntity);
}
OrmContext.getAccessor().batchInsert(listUser);
OrmContext.getAccessor().batchInsert(list);
}

// 批量更新
@Test
public void batchUpdate() {
var context = new ClassPathXmlApplicationContext("application.xml");
var userEntity = new UserEntity(1, (byte) 2, (short) 3, 5, true, "helloBatchUpdate", "helloOrm");
userEntity.setC(222);
OrmContext.getAccessor().batchUpdate(Collections.singletonList(userEntity));
var list = new ArrayList<UserEntity>();
for (var i = 1; i <= 10; i++) {
var userEntity = new UserEntity(i, (byte) 1, (short) i, i, true, "update-" + i, "helloOrm" + i);
list.add(userEntity);
}
OrmContext.getAccessor().batchUpdate(list);
}

public void queryAll() {
var list = OrmContext.getQuery(UserEntity.class).queryAll();
list.forEach(it -> System.out.println(it));
}

public void deleteAll() {
var list = OrmContext.getQuery(UserEntity.class).queryAll();
OrmContext.getAccessor().batchDelete(list);
}

}
1 change: 1 addition & 0 deletions orm/src/test/java/com/zfoo/orm/accessor/TtlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class TtlTest {
@Test
public void ttlTest() {
var context = new ClassPathXmlApplicationContext("application.xml");
OrmContext.getOrmManager().getCollection(MailEntity.class).drop();
var mailEntity = MailEntity.valueOf("d", "godot", "hello ttl", new Date(TimeUtils.now()));
OrmContext.getAccessor().insert(mailEntity);
}
Expand Down

0 comments on commit 755cc1a

Please sign in to comment.