mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1206 - NPE when using @Encrypted with Enum property that is null
This commit is contained in:
@@ -4,13 +4,11 @@ import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.SqlQuery;
|
||||
import io.ebean.SqlRow;
|
||||
import io.ebean.Update;
|
||||
import io.ebean.annotation.ForPlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.config.dbplatform.DbEncrypt;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.EBasicEncrypt;
|
||||
|
||||
@@ -18,6 +16,7 @@ import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestEncrypt extends BaseTestCase {
|
||||
|
||||
@@ -40,8 +39,7 @@ public class TestEncrypt extends BaseTestCase {
|
||||
@ForPlatform(Platform.H2)
|
||||
public void test() {
|
||||
|
||||
Update<EBasicEncrypt> deleteAll = Ebean.createUpdate(EBasicEncrypt.class, "delete from EBasicEncrypt");
|
||||
deleteAll.execute();
|
||||
Ebean.find(EBasicEncrypt.class).delete();
|
||||
|
||||
EBasicEncrypt e = new EBasicEncrypt();
|
||||
e.setName("testname");
|
||||
@@ -63,12 +61,14 @@ public class TestEncrypt extends BaseTestCase {
|
||||
|
||||
e1.setName("testmod");
|
||||
e1.setDescription("moddesc");
|
||||
e1.setStatus(EBasicEncrypt.Status.ONE);
|
||||
|
||||
Ebean.save(e1);
|
||||
|
||||
EBasicEncrypt e2 = Ebean.find(EBasicEncrypt.class, e.getId());
|
||||
|
||||
e2.getDescription();
|
||||
assertEquals("moddesc", e2.getDescription());
|
||||
assertEquals(EBasicEncrypt.Status.ONE, e2.getStatus());
|
||||
|
||||
SpiEbeanServer server = (SpiEbeanServer) Ebean.getServer(null);
|
||||
DbEncrypt dbEncrypt = server.getDatabasePlatform().getDbEncrypt();
|
||||
@@ -82,11 +82,11 @@ public class TestEncrypt extends BaseTestCase {
|
||||
List<EBasicEncrypt> list = Ebean.find(EBasicEncrypt.class).where()
|
||||
.eq("description", "moddesc").findList();
|
||||
|
||||
Assert.assertEquals(1, list.size());
|
||||
assertEquals(1, list.size());
|
||||
|
||||
list = Ebean.find(EBasicEncrypt.class).where().startsWith("description", "modde").findList();
|
||||
|
||||
Assert.assertEquals(1, list.size());
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.tests.model.basic;
|
||||
import io.ebean.annotation.Encrypted;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.sql.Date;
|
||||
@@ -12,6 +14,11 @@ import java.sql.Timestamp;
|
||||
@Table(name = "e_basicenc")
|
||||
public class EBasicEncrypt {
|
||||
|
||||
public enum Status {
|
||||
ONE,
|
||||
TWO
|
||||
}
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
@@ -24,6 +31,10 @@ public class EBasicEncrypt {
|
||||
@Encrypted(dbLength = 20)
|
||||
Date dob;
|
||||
|
||||
@Enumerated(EnumType.ORDINAL)
|
||||
@Encrypted(dbLength = 20)
|
||||
Status status;
|
||||
|
||||
//@Version
|
||||
Timestamp lastUpdate;
|
||||
|
||||
@@ -51,6 +62,14 @@ public class EBasicEncrypt {
|
||||
this.dob = dob;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user