#2335 Initial test work

This commit is contained in:
rbygrave
2021-09-02 11:57:59 +12:00
parent 2f18e97a44
commit d9cef737e3
2 changed files with 103 additions and 0 deletions
@@ -0,0 +1,69 @@
package org.tests.model.basic.cache;
import io.ebean.Model;
import io.ebean.annotation.Cache;
import io.ebean.annotation.SoftDelete;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
@Cache
@Entity
@Table(name = "e_softwithcache")
public class ESoftWithCache extends Model {
@Id
long id;
String name;
String description;
@SoftDelete
boolean deleted;
@Version
long version;
public ESoftWithCache(String name) {
this.name = name;
}
public long id() {
return id;
}
public ESoftWithCache id(long id) {
this.id = id;
return this;
}
public String name() {
return name;
}
public ESoftWithCache name(String name) {
this.name = name;
return this;
}
public String description() {
return description;
}
public ESoftWithCache description(String description) {
this.description = description;
return this;
}
public long version() {
return version;
}
public ESoftWithCache version(long version) {
this.version = version;
return this;
}
}
@@ -0,0 +1,34 @@
package org.tests.model.basic.cache;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import org.junit.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class TestCacheWithSoftDelete extends BaseTestCase {
@Test
public void idIn_expect_hitCache() {
ESoftWithCache bean = new ESoftWithCache("hello");
DB.save(bean);
final List<ESoftWithCache> found = DB.find(ESoftWithCache.class)
.where().idIn(bean.id())
//.setUseCache(true)
.findList();
assertThat(found).hasSize(1);
final List<ESoftWithCache> foundAgain = DB.find(ESoftWithCache.class)
.where().idIn(bean.id())
//.setUseCache(true)
.findList();
assertThat(foundAgain).hasSize(1);
}
}