diff --git a/tests/test-java16/src/main/java/org/example/resource/AttributeDescriptor.java b/tests/test-java16/src/main/java/org/example/resource/AttributeDescriptor.java new file mode 100644 index 000000000..0d09614b5 --- /dev/null +++ b/tests/test-java16/src/main/java/org/example/resource/AttributeDescriptor.java @@ -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; + } +} diff --git a/tests/test-java16/src/main/java/org/example/resource/AttributeValue.java b/tests/test-java16/src/main/java/org/example/resource/AttributeValue.java new file mode 100644 index 000000000..d997ffb95 --- /dev/null +++ b/tests/test-java16/src/main/java/org/example/resource/AttributeValue.java @@ -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; + } +} diff --git a/tests/test-java16/src/main/java/org/example/resource/AttributeValueOwner.java b/tests/test-java16/src/main/java/org/example/resource/AttributeValueOwner.java new file mode 100644 index 000000000..ad5036878 --- /dev/null +++ b/tests/test-java16/src/main/java/org/example/resource/AttributeValueOwner.java @@ -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 attributeValues; + + public List getAttributeValues() { + return attributeValues; + } + + public void setAttributeValues(List attributeValues) { + this.attributeValues = attributeValues; + } + + public void addAttributeValue(AttributeValue attributeValue){ + getAttributeValues().add(attributeValue); + attributeValue.setAttributeValueOwner(this); + } +} diff --git a/tests/test-java16/src/main/java/org/example/resource/Label.java b/tests/test-java16/src/main/java/org/example/resource/Label.java new file mode 100644 index 000000000..9f61681c2 --- /dev/null +++ b/tests/test-java16/src/main/java/org/example/resource/Label.java @@ -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 labelTexts; + + public List getLabelTexts() { + return labelTexts; + } + + public void setLabelTexts(List 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; + } +} diff --git a/tests/test-java16/src/main/java/org/example/resource/LabelText.java b/tests/test-java16/src/main/java/org/example/resource/LabelText.java new file mode 100644 index 000000000..468f3e227 --- /dev/null +++ b/tests/test-java16/src/main/java/org/example/resource/LabelText.java @@ -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; + } +} diff --git a/tests/test-java16/src/main/java/org/example/resource/Resource.java b/tests/test-java16/src/main/java/org/example/resource/Resource.java new file mode 100644 index 000000000..f6f8ab747 --- /dev/null +++ b/tests/test-java16/src/main/java/org/example/resource/Resource.java @@ -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; + } +} diff --git a/tests/test-java16/src/test/java/org/example/resource/ResourceEntityTest.java b/tests/test-java16/src/test/java/org/example/resource/ResourceEntityTest.java new file mode 100644 index 000000000..de42686df --- /dev/null +++ b/tests/test-java16/src/test/java/org/example/resource/ResourceEntityTest.java @@ -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 resources = qresource.findList(); + + assertThat(resources).isNotEmpty(); + } + + +}