Files
ebean/src/test/java/org/tests/basic/encrypt/TestEncrypt.java
T
Roland PramlandRob Bygrave 8d334ff2e8 Feature/contitional test runner (#1132)
* FIX: warnings (add generics, overrides, fix imports) - should be no effecive code change

* replaced deprecated methods by default methods

* FIX: more compiler warnings

* FIX more warnings - no code changes

* FIX: deprecated call to JsonParseException

* Remove unused code, check unused variables

* ADD: ContitonaltestRunner to skip tests for certain platforms

* Use annotations to control on which platforms a test shoud run

* FIX: compile errors
2017-09-15 21:03:03 +12:00

94 lines
2.5 KiB
Java

package org.tests.basic.encrypt;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Platform;
import io.ebean.SqlQuery;
import io.ebean.SqlRow;
import io.ebean.Update;
import io.ebean.annotation.ForPlatform;
import io.ebean.config.dbplatform.DbEncrypt;
import io.ebeaninternal.api.SpiEbeanServer;
import org.tests.model.basic.EBasicEncrypt;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Assert;
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
@ForPlatform(Platform.H2) // only run this on H2 - PGCrypto not happy on CI server
public void testQueryBind() {
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%)");
}
@Test
@ForPlatform(Platform.H2)
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);
SqlQuery q = Ebean.createSqlQuery("select * from e_basicenc where id = :id");
q.setParameter("id", e.getId());
SqlRow row = q.findOne();
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());
}
}
}