#919 - io.ebean package initial

This commit is contained in:
Rob Bygrave
2016-12-11 23:23:22 +13:00
parent 5821dc96b9
commit 971e2dc91b
2134 changed files with 10721 additions and 8652 deletions
@@ -0,0 +1,18 @@
package org.tests.basic.encrypt;
import io.ebean.config.EncryptKey;
public class BasicEncryptKey implements EncryptKey {
private final String key;
public BasicEncryptKey(String key) {
this.key = key;
}
public String getStringValue() {
return key;
}
}
@@ -0,0 +1,20 @@
package org.tests.basic.encrypt;
import io.ebean.config.EncryptKey;
import io.ebean.config.EncryptKeyManager;
public class BasicEncyptKeyManager implements EncryptKeyManager {
/**
* Initialise the key manager.
*/
public void initialise() {
}
public EncryptKey getEncryptKey(String tableName, String columnName) {
// Must be 16 Chars for Oracle function
return new BasicEncryptKey("simple0123456789");
}
}
@@ -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());
}
}
}
@@ -0,0 +1,53 @@
package org.tests.basic.encrypt;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.SqlQuery;
import io.ebean.SqlRow;
import org.tests.model.basic.EBasicEncryptBinary;
import org.junit.Assert;
import org.junit.Test;
import java.sql.Timestamp;
public class TestEncryptBinary extends BaseTestCase {
@Test
public void test() {
Timestamp t0 = new Timestamp(System.currentTimeMillis());
EBasicEncryptBinary e = new EBasicEncryptBinary();
e.setName("test1");
e.setDescription("testdesc1");
e.setSomeTime(t0);
e.setData("HelloWorld".getBytes());
Ebean.save(e);
SqlQuery q = Ebean.createSqlQuery("select * from e_basicenc_bin where id = :id");
q.setParameter("id", e.getId());
SqlRow row = q.findUnique();
row.getString("name");
row.get("data");
row.get("some_time");
EBasicEncryptBinary e1 = Ebean.find(EBasicEncryptBinary.class, e.getId());
Timestamp t1 = e1.getSomeTime();
e1.getData();
e1.getDescription();
Assert.assertEquals(t0, t1);
e1.setName("testmod");
e1.setDescription("moddesc");
Ebean.save(e1);
EBasicEncryptBinary e2 = Ebean.find(EBasicEncryptBinary.class, e.getId());
e2.getDescription();
}
}