mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2361 - Update test-java16 tests - use record style accessors with entity beans
This commit is contained in:
@@ -17,19 +17,19 @@ public class BaseModel extends Model {
|
||||
@Version
|
||||
long version;
|
||||
|
||||
public long getId() {
|
||||
public long id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
public void id(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
public long version() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(long version) {
|
||||
public void version(long version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,31 +28,31 @@ public class Contact extends Model {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Address getHomeAddress() {
|
||||
public Address homeAddress() {
|
||||
return homeAddress;
|
||||
}
|
||||
|
||||
public void setHomeAddress(Address homeAddress) {
|
||||
public void homeAddress(Address homeAddress) {
|
||||
this.homeAddress = homeAddress;
|
||||
}
|
||||
|
||||
public Address getWorkAddress() {
|
||||
public Address workAddress() {
|
||||
return workAddress;
|
||||
}
|
||||
|
||||
public void setWorkAddress(Address workAddress) {
|
||||
public void workAddress(Address workAddress) {
|
||||
this.workAddress = workAddress;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
public long id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
public long version() {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,15 +19,15 @@ public class Course extends BaseModel {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getSummary() {
|
||||
public String summary() {
|
||||
return summary;
|
||||
}
|
||||
|
||||
public void setSummary(String summary) {
|
||||
public void summary(String summary) {
|
||||
this.summary = summary;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,15 +22,15 @@ public class UserRole extends Model {
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
public UserRoleId getId() {
|
||||
public UserRoleId id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
public String note() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
public long version() {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,27 +25,27 @@ public class UserSite extends Model {
|
||||
this.siteId = siteId;
|
||||
}
|
||||
|
||||
public UUID getUserId() {
|
||||
public UUID userId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public UUID getSiteId() {
|
||||
public UUID siteId() {
|
||||
return siteId;
|
||||
}
|
||||
|
||||
public void setNote(String note) {
|
||||
public void note(String note) {
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
public void setVersion(long version) {
|
||||
public void version(long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
public String note() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
public long version() {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class DtoQueryUsingRecordsTest {
|
||||
void dtoQuery_projectRecords() {
|
||||
|
||||
var course = new Course("Calculus");
|
||||
course.setSummary("Something here");
|
||||
course.summary("Something here");
|
||||
course.save();
|
||||
|
||||
performOrmQuery();
|
||||
@@ -41,7 +41,7 @@ class DtoQueryUsingRecordsTest {
|
||||
.findList();
|
||||
|
||||
assertThat(records).hasSize(1);
|
||||
assertThat(records.get(0).name()).isEqualTo(course.getName());
|
||||
assertThat(records.get(0).name()).isEqualTo(course.name());
|
||||
}
|
||||
|
||||
private void records_via_OrmQueryToDtoQuery(Course course) {
|
||||
@@ -52,7 +52,7 @@ class DtoQueryUsingRecordsTest {
|
||||
.findList();
|
||||
|
||||
assertThat(records2).hasSize(1);
|
||||
assertThat(records2.get(0).name()).isEqualTo(course.getName());
|
||||
assertThat(records2.get(0).name()).isEqualTo(course.name());
|
||||
}
|
||||
|
||||
public record Foo(long id, String name){}
|
||||
|
||||
@@ -13,36 +13,41 @@ public class RecordAsEmbeddedTest {
|
||||
void insert_query() {
|
||||
|
||||
var contact = new Contact("Rob");
|
||||
contact.setWorkAddress(new Address("45 work", "workling", "wo"));
|
||||
contact.setHomeAddress(new Address("94 home st", "homeline", "wo"));
|
||||
contact.workAddress(new Address("45 work", "workling", "wo"));
|
||||
contact.homeAddress(new Address("94 home st", "homeline", "wo"));
|
||||
|
||||
contact.save();
|
||||
|
||||
Contact found = new QContact()
|
||||
.id.eq(contact.getId())
|
||||
.id.eq(contact.id())
|
||||
.findOne();
|
||||
|
||||
assertThat(found.getWorkAddress().toString()).isEqualTo("Address[line1=45 work, line2=workling, city=wo]");
|
||||
assertThat(found.getHomeAddress().toString()).isEqualTo("Address[line1=94 home st, line2=homeline, city=wo]");
|
||||
assert found != null;
|
||||
|
||||
assertThat(found.workAddress().toString()).isEqualTo("Address[line1=45 work, line2=workling, city=wo]");
|
||||
assertThat(found.homeAddress().toString()).isEqualTo("Address[line1=94 home st, line2=homeline, city=wo]");
|
||||
|
||||
Contact foundPartial = new QContact()
|
||||
.select(name, homeAddress)
|
||||
.id.eq(contact.getId())
|
||||
.id.eq(contact.id())
|
||||
.findOne();
|
||||
|
||||
// invoke lazy loading on getWorkAddress
|
||||
assertThat(foundPartial.getWorkAddress().toString()).isEqualTo("Address[line1=45 work, line2=workling, city=wo]");
|
||||
assertThat(foundPartial.getHomeAddress().toString()).isEqualTo("Address[line1=94 home st, line2=homeline, city=wo]");
|
||||
assert foundPartial != null;
|
||||
|
||||
// invoke lazy loading on workAddress
|
||||
assertThat(foundPartial.workAddress().toString()).isEqualTo("Address[line1=45 work, line2=workling, city=wo]");
|
||||
assertThat(foundPartial.homeAddress().toString()).isEqualTo("Address[line1=94 home st, line2=homeline, city=wo]");
|
||||
|
||||
Contact foundNoLazyLoading = new QContact()
|
||||
.select(name, homeAddress)
|
||||
.setDisableLazyLoading(true)
|
||||
.id.eq(contact.getId())
|
||||
.id.eq(contact.id())
|
||||
.findOne();
|
||||
|
||||
// no lazy loading on getWorkAddress this time
|
||||
assertThat(foundNoLazyLoading.getWorkAddress()).isNull();
|
||||
assertThat(foundNoLazyLoading.getHomeAddress().toString()).isEqualTo("Address[line1=94 home st, line2=homeline, city=wo]");
|
||||
assert foundNoLazyLoading != null;
|
||||
// no lazy loading on workAddress this time
|
||||
assertThat(foundNoLazyLoading.workAddress()).isNull();
|
||||
assertThat(foundNoLazyLoading.homeAddress().toString()).isEqualTo("Address[line1=94 home st, line2=homeline, city=wo]");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class RecordIdClassTest {
|
||||
UUID siteId = UUID.randomUUID();
|
||||
|
||||
var userSite = new UserSite(userId, siteId);
|
||||
userSite.setNote("HelloIdClass");
|
||||
userSite.note("HelloIdClass");
|
||||
userSite.save();
|
||||
|
||||
var id = new UserSiteId(userId, siteId);
|
||||
@@ -25,10 +25,20 @@ class RecordIdClassTest {
|
||||
.setId(id)
|
||||
.findOne();
|
||||
|
||||
assertThat(found.getUserId()).isEqualTo(userId);
|
||||
assertThat(found.getSiteId()).isEqualTo(siteId);
|
||||
assertThat(found.getNote()).isEqualTo("HelloIdClass");
|
||||
assert found != null;
|
||||
assertThat(found.userId()).isEqualTo(userId);
|
||||
assertThat(found.siteId()).isEqualTo(siteId);
|
||||
assertThat(found.note()).isEqualTo("HelloIdClass");
|
||||
|
||||
// again but using the scalar id properties
|
||||
UserSite found2 = new QUserSite()
|
||||
.siteId.eq(id.siteId())
|
||||
.userId.eq(id.userId())
|
||||
.findOne();
|
||||
|
||||
assert found2 != null;
|
||||
assertThat(found2.userId()).isEqualTo(userId);
|
||||
assertThat(found2.siteId()).isEqualTo(siteId);
|
||||
assertThat(found2.note()).isEqualTo("HelloIdClass");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class UserRoleTest {
|
||||
.id.eq(new UserRoleId(42, "R7"))
|
||||
.findOne();
|
||||
|
||||
UserRoleId id1 = found.getId();
|
||||
UserRoleId id1 = found.id();
|
||||
assertThat(id1).isEqualTo(id);
|
||||
assertThat(id1.userId()).isEqualTo(42);
|
||||
assertThat(id1.roleId()).isEqualTo("R7");
|
||||
|
||||
Reference in New Issue
Block a user