Merge pull request #3585 from nedge/feature/Create_test_entities

Simple Test Entities in preparation for type scoped loading
This commit is contained in:
Rob Bygrave
2025-03-05 08:06:39 +13:00
committed by GitHub
7 changed files with 313 additions and 0 deletions
@@ -0,0 +1,32 @@
package org.example.resource;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;
import org.example.records.BaseModel;
@Entity
public class AttributeDescriptor extends BaseModel {
@ManyToOne(cascade = CascadeType.ALL)
private Label name;
@ManyToOne(cascade = CascadeType.ALL)
private Label description;
public Label getName() {
return name;
}
public void setName(Label name) {
this.name = name;
}
public Label getDescription() {
return description;
}
public void setDescription(Label description) {
this.description = description;
}
}
@@ -0,0 +1,63 @@
package org.example.resource;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import org.example.records.BaseModel;
@Entity
public class AttributeValue extends BaseModel {
private String stringValue;
private int intValue;
@ManyToOne
private AttributeDescriptor attributeDescriptor;
@ManyToOne
private AttributeValueOwner attributeValueOwner;
public AttributeValueOwner getAttributeValueOwner() {
return attributeValueOwner;
}
public void setAttributeValueOwner(AttributeValueOwner attributeValueOwner) {
this.attributeValueOwner = attributeValueOwner;
}
public AttributeValue() {
}
public AttributeValue(String stringValue, AttributeDescriptor attributeDescriptor) {
this.stringValue = stringValue;
this.attributeDescriptor = attributeDescriptor;
}
public AttributeValue(int intValue, AttributeDescriptor attributeDescriptor) {
this.intValue = intValue;
this.attributeDescriptor = attributeDescriptor;
}
public String getStringValue() {
return stringValue;
}
public void setStringValue(String stringValue) {
this.stringValue = stringValue;
}
public int getIntValue() {
return intValue;
}
public void setIntValue(int intValue) {
this.intValue = intValue;
}
public AttributeDescriptor getAttributeDescriptor() {
return attributeDescriptor;
}
public void setAttributeDescriptor(AttributeDescriptor attributeDescriptor) {
this.attributeDescriptor = attributeDescriptor;
}
}
@@ -0,0 +1,27 @@
package org.example.resource;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.OneToMany;
import org.example.records.BaseModel;
import java.util.List;
@Entity
public class AttributeValueOwner extends BaseModel {
@OneToMany(cascade = CascadeType.ALL)
private List<AttributeValue> attributeValues;
public List<AttributeValue> getAttributeValues() {
return attributeValues;
}
public void setAttributeValues(List<AttributeValue> attributeValues) {
this.attributeValues = attributeValues;
}
public void addAttributeValue(AttributeValue attributeValue){
getAttributeValues().add(attributeValue);
attributeValue.setAttributeValueOwner(this);
}
}
@@ -0,0 +1,31 @@
package org.example.resource;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.OneToMany;
import org.example.records.BaseModel;
import java.util.List;
import java.util.Locale;
@Entity
public class Label extends BaseModel {
@OneToMany(cascade= CascadeType.ALL)
private List<LabelText> labelTexts;
public List<LabelText> getLabelTexts() {
return labelTexts;
}
public void setLabelTexts(List<LabelText> labelTexts) {
this.labelTexts = labelTexts;
}
public LabelText addLabelText(Locale locale, String text){
LabelText labelText = new LabelText(locale, text);
getLabelTexts().add(labelText);
labelText.setLabel(this);
return labelText;
}
}
@@ -0,0 +1,49 @@
package org.example.resource;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;
import org.example.records.BaseModel;
import java.util.Locale;
@Entity
public class LabelText extends BaseModel {
private String localeText;
private Locale locale;
@ManyToOne
private Label label;
public LabelText(){
}
public LabelText(Locale locale, String localeText) {
this.locale = locale;
this.localeText = localeText;
}
public Locale getLocale() {
return locale;
}
public void setLocale(Locale locale) {
this.locale = locale;
}
public String getLocaleText() {
return localeText;
}
public Label getLabel() {
return label;
}
public void setLabel(Label label) {
this.label = label;
}
public void setLocaleText(String localeText) {
this.localeText = localeText;
}
}
@@ -0,0 +1,50 @@
package org.example.resource;
import jakarta.persistence.*;
import org.example.records.BaseModel;
@Entity
public class Resource extends BaseModel {
@ManyToOne(cascade = CascadeType.ALL)
private Label name;
@ManyToOne(cascade = CascadeType.ALL)
private Label description;
private String resourceId;
@ManyToOne(cascade = CascadeType.ALL)
private AttributeValueOwner attributeValueOwner;
public Label getName() {
return name;
}
public void setName(Label name) {
this.name = name;
}
public Label getDescription() {
return description;
}
public void setDescription(Label description) {
this.description = description;
}
public AttributeValueOwner getAttributeValueOwner() {
return attributeValueOwner;
}
public void setAttributeValueOwner(AttributeValueOwner attributeValueOwner) {
this.attributeValueOwner = attributeValueOwner;
}
public String getResourceId() {
return resourceId;
}
public void setResourceId(String resourceId) {
this.resourceId = resourceId;
}
}
@@ -0,0 +1,61 @@
package org.example.resource;
import io.ebean.DB;
import org.example.records.CourseRecordEntity;
import org.example.records.query.QCourseRecordEntity;
import org.example.resource.query.QResource;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Locale;
import static org.assertj.core.api.Assertions.assertThat;
class ResourceEntityTest {
@Test
void testSimpleResource() {
Locale en = Locale.GERMAN;
Locale de = Locale.ENGLISH;
AttributeDescriptor heightDescriptor = new AttributeDescriptor();
heightDescriptor.setName(new Label());
heightDescriptor.getName().addLabelText(en,"Height");
heightDescriptor.getName().addLabelText(de,"Höhe");
heightDescriptor.setDescription(new Label());
heightDescriptor.getDescription().addLabelText(en, "Height property");
heightDescriptor.getDescription().addLabelText(de, "Höhe Eigenschaft");
DB.save(heightDescriptor);
AttributeDescriptor widthDescriptor = new AttributeDescriptor();
widthDescriptor.setName(new Label());
widthDescriptor.getName().addLabelText(en,"Width");
widthDescriptor.getName().addLabelText(de,"Breite");
widthDescriptor.setDescription(new Label());
widthDescriptor.getDescription().addLabelText(en, "Width property");
widthDescriptor.getDescription().addLabelText(de, "Breite Eigenschaft");
DB.save(widthDescriptor);
Resource resource = new Resource();
resource.setResourceId("R1");
resource.setName(new Label());
resource.getName().addLabelText(en, "R1_en");
resource.getName().addLabelText(de, "R1_de");
resource.setAttributeValueOwner(new AttributeValueOwner());
resource.getAttributeValueOwner().addAttributeValue(new AttributeValue(1, heightDescriptor));
resource.getAttributeValueOwner().addAttributeValue(new AttributeValue(2, widthDescriptor));
DB.save(resource);
QResource qresource = new QResource().resourceId.eq(resource.getResourceId());
List<Resource> resources = qresource.findList();
assertThat(resources).isNotEmpty();
}
}