Skip to content

Commit 6f1c66e

Browse files
committed
Simple Test Entities in preparation for type scoped loading
1 parent 11e7839 commit 6f1c66e

File tree

7 files changed

+313
-0
lines changed

7 files changed

+313
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.example.resource;
2+
3+
import jakarta.persistence.CascadeType;
4+
import jakarta.persistence.Entity;
5+
import jakarta.persistence.ManyToOne;
6+
import org.example.records.BaseModel;
7+
8+
@Entity
9+
public class AttributeDescriptor extends BaseModel {
10+
11+
@ManyToOne(cascade = CascadeType.ALL)
12+
private Label name;
13+
14+
@ManyToOne(cascade = CascadeType.ALL)
15+
private Label description;
16+
17+
public Label getName() {
18+
return name;
19+
}
20+
21+
public void setName(Label name) {
22+
this.name = name;
23+
}
24+
25+
public Label getDescription() {
26+
return description;
27+
}
28+
29+
public void setDescription(Label description) {
30+
this.description = description;
31+
}
32+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.example.resource;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.JoinColumn;
5+
import jakarta.persistence.ManyToOne;
6+
import org.example.records.BaseModel;
7+
8+
@Entity
9+
public class AttributeValue extends BaseModel {
10+
private String stringValue;
11+
private int intValue;
12+
13+
@ManyToOne
14+
private AttributeDescriptor attributeDescriptor;
15+
16+
@ManyToOne
17+
private AttributeValueOwner attributeValueOwner;
18+
19+
public AttributeValueOwner getAttributeValueOwner() {
20+
return attributeValueOwner;
21+
}
22+
23+
public void setAttributeValueOwner(AttributeValueOwner attributeValueOwner) {
24+
this.attributeValueOwner = attributeValueOwner;
25+
}
26+
27+
public AttributeValue() {
28+
}
29+
30+
public AttributeValue(String stringValue, AttributeDescriptor attributeDescriptor) {
31+
this.stringValue = stringValue;
32+
this.attributeDescriptor = attributeDescriptor;
33+
}
34+
35+
public AttributeValue(int intValue, AttributeDescriptor attributeDescriptor) {
36+
this.intValue = intValue;
37+
this.attributeDescriptor = attributeDescriptor;
38+
}
39+
40+
public String getStringValue() {
41+
return stringValue;
42+
}
43+
44+
public void setStringValue(String stringValue) {
45+
this.stringValue = stringValue;
46+
}
47+
48+
public int getIntValue() {
49+
return intValue;
50+
}
51+
52+
public void setIntValue(int intValue) {
53+
this.intValue = intValue;
54+
}
55+
56+
public AttributeDescriptor getAttributeDescriptor() {
57+
return attributeDescriptor;
58+
}
59+
60+
public void setAttributeDescriptor(AttributeDescriptor attributeDescriptor) {
61+
this.attributeDescriptor = attributeDescriptor;
62+
}
63+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.example.resource;
2+
3+
import jakarta.persistence.CascadeType;
4+
import jakarta.persistence.Entity;
5+
import jakarta.persistence.OneToMany;
6+
import org.example.records.BaseModel;
7+
8+
import java.util.List;
9+
10+
@Entity
11+
public class AttributeValueOwner extends BaseModel {
12+
@OneToMany(cascade = CascadeType.ALL)
13+
private List<AttributeValue> attributeValues;
14+
15+
public List<AttributeValue> getAttributeValues() {
16+
return attributeValues;
17+
}
18+
19+
public void setAttributeValues(List<AttributeValue> attributeValues) {
20+
this.attributeValues = attributeValues;
21+
}
22+
23+
public void addAttributeValue(AttributeValue attributeValue){
24+
getAttributeValues().add(attributeValue);
25+
attributeValue.setAttributeValueOwner(this);
26+
}
27+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.example.resource;
2+
3+
import jakarta.persistence.CascadeType;
4+
import jakarta.persistence.Entity;
5+
import jakarta.persistence.OneToMany;
6+
import org.example.records.BaseModel;
7+
8+
import java.util.List;
9+
import java.util.Locale;
10+
11+
@Entity
12+
public class Label extends BaseModel {
13+
@OneToMany(cascade= CascadeType.ALL)
14+
private List<LabelText> labelTexts;
15+
16+
public List<LabelText> getLabelTexts() {
17+
return labelTexts;
18+
}
19+
20+
public void setLabelTexts(List<LabelText> labelTexts) {
21+
this.labelTexts = labelTexts;
22+
}
23+
24+
public LabelText addLabelText(Locale locale, String text){
25+
LabelText labelText = new LabelText(locale, text);
26+
27+
getLabelTexts().add(labelText);
28+
labelText.setLabel(this);
29+
return labelText;
30+
}
31+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.example.resource;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.ManyToOne;
5+
import org.example.records.BaseModel;
6+
7+
import java.util.Locale;
8+
9+
@Entity
10+
public class LabelText extends BaseModel {
11+
private String localeText;
12+
13+
private Locale locale;
14+
15+
@ManyToOne
16+
private Label label;
17+
18+
public LabelText(){
19+
}
20+
21+
public LabelText(Locale locale, String localeText) {
22+
this.locale = locale;
23+
this.localeText = localeText;
24+
}
25+
26+
public Locale getLocale() {
27+
return locale;
28+
}
29+
30+
public void setLocale(Locale locale) {
31+
this.locale = locale;
32+
}
33+
34+
public String getLocaleText() {
35+
return localeText;
36+
}
37+
38+
public Label getLabel() {
39+
return label;
40+
}
41+
42+
public void setLabel(Label label) {
43+
this.label = label;
44+
}
45+
46+
public void setLocaleText(String localeText) {
47+
this.localeText = localeText;
48+
}
49+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.example.resource;
2+
3+
import jakarta.persistence.*;
4+
import org.example.records.BaseModel;
5+
6+
@Entity
7+
public class Resource extends BaseModel {
8+
@ManyToOne(cascade = CascadeType.ALL)
9+
private Label name;
10+
11+
@ManyToOne(cascade = CascadeType.ALL)
12+
private Label description;
13+
14+
private String resourceId;
15+
16+
@ManyToOne(cascade = CascadeType.ALL)
17+
private AttributeValueOwner attributeValueOwner;
18+
19+
public Label getName() {
20+
return name;
21+
}
22+
23+
public void setName(Label name) {
24+
this.name = name;
25+
}
26+
27+
public Label getDescription() {
28+
return description;
29+
}
30+
31+
public void setDescription(Label description) {
32+
this.description = description;
33+
}
34+
35+
public AttributeValueOwner getAttributeValueOwner() {
36+
return attributeValueOwner;
37+
}
38+
39+
public void setAttributeValueOwner(AttributeValueOwner attributeValueOwner) {
40+
this.attributeValueOwner = attributeValueOwner;
41+
}
42+
43+
public String getResourceId() {
44+
return resourceId;
45+
}
46+
47+
public void setResourceId(String resourceId) {
48+
this.resourceId = resourceId;
49+
}
50+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.example.resource;
2+
3+
import io.ebean.DB;
4+
import org.example.records.CourseRecordEntity;
5+
import org.example.records.query.QCourseRecordEntity;
6+
import org.example.resource.query.QResource;
7+
import org.junit.jupiter.api.Test;
8+
9+
import java.util.List;
10+
import java.util.Locale;
11+
12+
import static org.assertj.core.api.Assertions.assertThat;
13+
14+
class ResourceEntityTest {
15+
16+
@Test
17+
void testSimpleResource() {
18+
Locale en = Locale.GERMAN;
19+
Locale de = Locale.ENGLISH;
20+
21+
AttributeDescriptor heightDescriptor = new AttributeDescriptor();
22+
heightDescriptor.setName(new Label());
23+
heightDescriptor.getName().addLabelText(en,"Height");
24+
heightDescriptor.getName().addLabelText(de,"Höhe");
25+
heightDescriptor.setDescription(new Label());
26+
heightDescriptor.getDescription().addLabelText(en, "Height property");
27+
heightDescriptor.getDescription().addLabelText(de, "Höhe Eigenschaft");
28+
29+
DB.save(heightDescriptor);
30+
31+
AttributeDescriptor widthDescriptor = new AttributeDescriptor();
32+
widthDescriptor.setName(new Label());
33+
widthDescriptor.getName().addLabelText(en,"Width");
34+
widthDescriptor.getName().addLabelText(de,"Breite");
35+
widthDescriptor.setDescription(new Label());
36+
widthDescriptor.getDescription().addLabelText(en, "Width property");
37+
widthDescriptor.getDescription().addLabelText(de, "Breite Eigenschaft");
38+
39+
DB.save(widthDescriptor);
40+
41+
Resource resource = new Resource();
42+
resource.setResourceId("R1");
43+
resource.setName(new Label());
44+
resource.getName().addLabelText(en, "R1_en");
45+
resource.getName().addLabelText(de, "R1_de");
46+
47+
resource.setAttributeValueOwner(new AttributeValueOwner());
48+
resource.getAttributeValueOwner().addAttributeValue(new AttributeValue(1, heightDescriptor));
49+
resource.getAttributeValueOwner().addAttributeValue(new AttributeValue(2, widthDescriptor));
50+
51+
DB.save(resource);
52+
53+
QResource qresource = new QResource().resourceId.eq(resource.getResourceId());
54+
55+
List<Resource> resources = qresource.findList();
56+
57+
assertThat(resources).isNotEmpty();
58+
}
59+
60+
61+
}

0 commit comments

Comments
 (0)