mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#919 - io.ebean package initial
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
package org.tests.basic.encrypt;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.SqlQuery;
|
||||
import io.ebean.SqlRow;
|
||||
import io.ebean.Update;
|
||||
import io.ebean.config.dbplatform.DbEncrypt;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import org.tests.model.basic.EBasicEncrypt;
|
||||
import org.avaje.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestEncrypt extends BaseTestCase {
|
||||
|
||||
|
||||
@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%)");
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user