mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-19 23:02:24 +00:00
Refactor move tests from ebean-core to ebean-test
This commit is contained in:
1 parent
0b00a14fd3
commit
eab56d323b
1650 files changed
+185
-147
No files matched your search
@@ -0,0 +1,37 @@
|
||||
package org.tests.repository;
|
||||
|
||||
import io.ebean.BeanRepository;
|
||||
import io.ebean.Database;
|
||||
import org.tests.model.basic.Customer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//import javax.inject.Inject;
|
||||
|
||||
public class CustomerRepository extends BeanRepository<Integer, Customer> {
|
||||
|
||||
//@Inject
|
||||
public CustomerRepository(Database server) {
|
||||
super(Customer.class, server);
|
||||
}
|
||||
|
||||
public List<Customer> findByName(String nameStart) {
|
||||
return query().where()
|
||||
.istartsWith("name", nameStart)
|
||||
.findList();
|
||||
}
|
||||
|
||||
public Customer findMatchName(String matchName) {
|
||||
return nativeSql("select id, name from o_customer where name = ?")
|
||||
.setParameter(matchName)
|
||||
.findOne();
|
||||
}
|
||||
|
||||
public int updateNotes(String blah, String whot) {
|
||||
|
||||
return updateQuery()
|
||||
.set("smallnote", whot)
|
||||
.where().eq("name", blah)
|
||||
.update();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package org.tests.repository;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestBeanRepository extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
DB.find(Customer.class).where().in("name", "c0", "c1").delete();
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
CustomerRepository repository = new CustomerRepository(server());
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.setName("RepoCustomer");
|
||||
|
||||
repository.save(customer);
|
||||
|
||||
Customer fetchCustomer = repository.findById(customer.getId());
|
||||
fetchCustomer.setSmallnote("yeah maybe");
|
||||
|
||||
repository.update(fetchCustomer);
|
||||
repository.delete(fetchCustomer);
|
||||
|
||||
List<Customer> custs = new ArrayList<>();
|
||||
custs.add(newCustomer("c0"));
|
||||
custs.add(newCustomer("c1"));
|
||||
|
||||
int count = repository.saveAll(custs);
|
||||
assertThat(count).isEqualTo(2);
|
||||
|
||||
count = repository.deleteAll(custs);
|
||||
assertThat(count).isEqualTo(2);
|
||||
}
|
||||
|
||||
private Customer newCustomer(String name) {
|
||||
Customer customer = new Customer();
|
||||
customer.setName(name);
|
||||
return customer;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findByName() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
CustomerRepository repository = new CustomerRepository(server());
|
||||
|
||||
Customer blah = new Customer();
|
||||
blah.setName("Blah");
|
||||
|
||||
repository.markAsDirty(blah);
|
||||
repository.markPropertyUnset(blah, "smallnote");
|
||||
repository.save(blah);
|
||||
|
||||
Optional<Customer> maybe = repository.findByIdOrEmpty(blah.getId());
|
||||
assertThat(maybe.isPresent()).isTrue();
|
||||
|
||||
List<Customer> names = repository.findByName("bla");
|
||||
assertThat(names).hasSize(1);
|
||||
|
||||
Customer matchName = repository.findMatchName("Blah");
|
||||
assertThat(matchName).isNotNull();
|
||||
|
||||
int rows = repository.updateNotes("Blah", "whot");
|
||||
assertThat(rows).isEqualTo(1);
|
||||
|
||||
repository.deletePermanent(blah);
|
||||
|
||||
repository.deleteById(1099);
|
||||
repository.findAll();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user