-
-
Notifications
You must be signed in to change notification settings - Fork 265
Expand file tree
/
Copy pathTestPropertyAccess.java
More file actions
118 lines (88 loc) · 4.21 KB
/
TestPropertyAccess.java
File metadata and controls
118 lines (88 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package org.tests.inheritance;
import io.ebean.DB;
import io.ebean.plugin.ExpressionPath;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.*;
import java.sql.Timestamp;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* @author Roland Praml, FOCONIS AG
*/
public class TestPropertyAccess {
private ExpressionPath custCretime = DB.getDefault().pluginApi().beanType(Customer.class).expressionPath("cretime");
private ExpressionPath custName = DB.getDefault().pluginApi().beanType(Customer.class).expressionPath("name");
// Note: Animal.name is only present in "Cat" not in "Dog"
private ExpressionPath animalName = DB.getDefault().pluginApi().beanType(Animal.class).expressionPath("name");
private ExpressionPath productName = DB.getDefault().pluginApi().beanType(Product.class).expressionPath("name");
private ExpressionPath animalSpecies = DB.getDefault().pluginApi().beanType(Animal.class).expressionPath("species");
@Test
void testOnInheritance() {
Cat cat = new Cat();
cat.setName("Tom");
DB.save(cat);
Dog dog = new Dog();
dog.setRegistrationNumber("FOO");
DB.save(dog);
Animal animal = DB.find(Animal.class, cat.getId());
assertThat(animalName.pathGet(animal)).isEqualTo("Tom");
animal = DB.find(Animal.class, dog.getId());
assertThat(animalName.pathGet(animal)).isNull();
animalName.pathSet(cat, "Jerry");
assertThat(cat.getName()).isEqualTo("Jerry");
assertThatThrownBy(() -> animalName.pathSet(dog, "Jerry"))
.isInstanceOf(IllegalArgumentException.class);
animalSpecies.pathSet(cat, "Angora");
animalSpecies.pathSet(dog, "Bulldog");
assertThat(cat.getSpecies()).isEqualTo("Angora");
assertThat(dog.getSpecies()).isEqualTo("Bulldog");
}
@Test
void testOnMappedSuperClass() {
Customer cust = new Customer();
Timestamp ts = new Timestamp(123);
custCretime.pathSet(cust, ts);
assertThat(custCretime.pathGet(cust)).isEqualTo(ts);
custName.pathSet(cust, "Roland");
assertThat(custName.pathGet(cust)).isEqualTo("Roland");
}
@Test
void testOnPlainBean() {
Product product = new Product();
productName.pathSet(product, "Roland");
assertThat(productName.pathGet(product)).isEqualTo("Roland");
}
@Test
void testOnContactGroup() {
ContactGroup cg = new ContactGroup();
// CHECKEM: Ist it OK to us the "custCretime" on "contactGroup"
assertThatThrownBy(() -> custCretime.pathGet(cg)).isInstanceOf(IllegalArgumentException.class);
}
@Test
void testOnCrossUsage() {
Product product = new Product();
Customer cust = new Customer();
Cat cat = new Cat();
Dog dog = new Dog();
assertThatThrownBy(() -> custCretime.pathGet(product)).isInstanceOf(IllegalArgumentException.class);
custCretime.pathGet(cust);
assertThatThrownBy(() -> custCretime.pathGet(cat)).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> custCretime.pathGet(dog)).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> custName.pathGet(product)).isInstanceOf(IllegalArgumentException.class);
custName.pathGet(cust);
assertThatThrownBy(() -> custName.pathGet(cat)).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> custName.pathGet(dog)).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> animalName.pathGet(product)).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> animalName.pathGet(cust)).isInstanceOf(IllegalArgumentException.class);
animalName.pathGet(cat);
animalName.pathGet(dog);
productName.pathGet(product);
assertThatThrownBy(() -> productName.pathGet(cust)).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> productName.pathGet(cat)).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> productName.pathGet(dog)).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> animalSpecies.pathGet(product)).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> animalSpecies.pathGet(cust)).isInstanceOf(IllegalArgumentException.class);
animalSpecies.pathGet(cat);
animalSpecies.pathGet(dog);
}
}