|
1 | 1 | package org.javawebstack.orm.test.automigrate; |
2 | 2 |
|
3 | | -import org.javawebstack.orm.Model; |
4 | 3 | import org.javawebstack.orm.ORM; |
5 | 4 | import org.javawebstack.orm.ORMConfig; |
6 | | -import org.javawebstack.orm.annotation.Column; |
7 | 5 | import org.javawebstack.orm.exception.ORMConfigurationException; |
8 | 6 | import org.javawebstack.orm.test.ORMTestCase; |
| 7 | +import org.javawebstack.orm.test.shared.models.Datatype; |
9 | 8 | import org.javawebstack.orm.test.shared.verification.Field; |
10 | 9 | import org.javawebstack.orm.test.shared.verification.IdField; |
11 | 10 | import org.junit.jupiter.api.BeforeEach; |
12 | 11 | import org.junit.jupiter.api.Test; |
13 | 12 |
|
14 | | -import java.sql.Date; |
15 | 13 | import java.sql.SQLException; |
16 | | -import java.sql.Timestamp; |
17 | 14 | import java.util.HashMap; |
18 | 15 | import java.util.Map; |
19 | | -import java.util.UUID; |
20 | 16 |
|
21 | 17 | public class CommonTest extends ORMTestCase { |
22 | 18 |
|
23 | 19 | private static final String tableName = "datatypes"; |
| 20 | + private final Map<String, String> columnDataTypeMap; |
24 | 21 |
|
25 | | - @BeforeEach |
26 | | - public void setUp() throws ORMConfigurationException { |
27 | | - ORMConfig config = new ORMConfig() |
28 | | - .setDefaultSize(255); |
29 | | - ORM.register(Datatype.class, sql(), config); |
30 | | - ORM.autoMigrate(true); |
31 | | - } |
32 | | - |
33 | | - |
34 | | - |
35 | | - @Test |
36 | | - public void testId() throws SQLException { |
37 | | - IdField.assertCorrectDatabaseFormat(tableName); |
38 | | - } |
39 | | - |
40 | | - @Test |
41 | | - public void testPrimitiveIntegerDatatype() throws SQLException { |
42 | | - Field checkedField; |
43 | | - |
44 | | - Map<String, String> columnDataTypeMap = new HashMap<>(); |
| 22 | + { |
| 23 | + columnDataTypeMap = new HashMap<>(); |
45 | 24 |
|
46 | 25 | columnDataTypeMap.put("primitive_boolean", "tinyint(1)"); |
47 | 26 | columnDataTypeMap.put("wrapper_boolean", "tinyint(1)"); |
@@ -79,93 +58,60 @@ public void testPrimitiveIntegerDatatype() throws SQLException { |
79 | 58 | columnDataTypeMap.put("uuid", "varchar(36)"); |
80 | 59 |
|
81 | 60 | columnDataTypeMap.put("option_enum", "enum('OPTION1','OPTION2')"); |
| 61 | + } |
| 62 | + |
| 63 | + @BeforeEach |
| 64 | + public void setUp() throws ORMConfigurationException { |
| 65 | + ORMConfig config = new ORMConfig() |
| 66 | + .setDefaultSize(255); |
| 67 | + ORM.register(Datatype.class, sql(), config); |
| 68 | + ORM.autoMigrate(true); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void testId() throws SQLException { |
| 73 | + IdField.assertCorrectDatabaseFormat(tableName); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + public void testDatatypes() throws SQLException { |
| 78 | + Field checkedField; |
82 | 79 |
|
83 | 80 | for(Map.Entry<String, String> entry : columnDataTypeMap.entrySet()) { |
84 | 81 | checkedField = new Field(tableName, entry.getKey()); |
85 | | - |
86 | 82 | checkedField.assertType(entry.getValue()); |
87 | | - checkedField.assertNullable(); |
88 | | - checkedField.assertNotPrimaryKey(); |
89 | | - checkedField.assertNotAutoIncrementing(); |
90 | 83 | } |
91 | 84 |
|
92 | 85 | } |
93 | 86 |
|
94 | | - public static class Datatype extends Model { |
95 | | - @Column |
96 | | - int id; |
97 | | - |
98 | | - @Column |
99 | | - boolean primitiveBoolean; |
100 | | - |
101 | | - @Column |
102 | | - Boolean wrapperBoolean; |
103 | | - |
104 | | - @Column |
105 | | - byte primitiveByte; |
106 | | - |
107 | | - @Column |
108 | | - Byte wrapperByte; |
109 | | - |
110 | | - @Column |
111 | | - short primitiveShort; |
112 | | - |
113 | | - @Column |
114 | | - Short wrapperShort; |
115 | | - |
116 | | - @Column |
117 | | - int primitiveInteger; |
118 | | - |
119 | | - @Column |
120 | | - Integer wrapperInteger; |
121 | | - |
122 | | - @Column |
123 | | - long primitiveLong; |
124 | | - |
125 | | - @Column |
126 | | - Long wrapperLong; |
127 | | - |
128 | | - @Column |
129 | | - float primitiveFloat; |
130 | | - |
131 | | - @Column |
132 | | - Float wrapperFloat; |
133 | | - |
134 | | - @Column |
135 | | - double primitiveDouble; |
136 | | - |
137 | | - @Column |
138 | | - Double wrapperDouble; |
139 | | - |
140 | | - @Column |
141 | | - char primitiveChar; |
142 | | - |
143 | | - @Column |
144 | | - String wrapperString; |
145 | | - |
146 | | - @Column |
147 | | - char[] charArray; |
148 | | - |
149 | | - @Column |
150 | | - byte[] byteArray; |
151 | | - |
152 | | - @Column |
153 | | - Timestamp timestamp; |
154 | | - |
155 | | - @Column |
156 | | - Date date; |
| 87 | + @Test |
| 88 | + public void testNullable() throws SQLException { |
| 89 | + Field checkedField; |
157 | 90 |
|
158 | | - @Column |
159 | | - UUID uuid; |
| 91 | + for(Map.Entry<String, String> entry : columnDataTypeMap.entrySet()) { |
| 92 | + checkedField = new Field(tableName, entry.getKey()); |
| 93 | + checkedField.assertNullable(); |
| 94 | + } |
| 95 | + } |
160 | 96 |
|
161 | | - @Column |
162 | | - OptionEnum optionEnum; |
| 97 | + @Test |
| 98 | + public void testNotPrimaryKey() throws SQLException { |
| 99 | + Field checkedField; |
163 | 100 |
|
| 101 | + for(Map.Entry<String, String> entry : columnDataTypeMap.entrySet()) { |
| 102 | + checkedField = new Field(tableName, entry.getKey()); |
| 103 | + checkedField.assertNotPrimaryKey(); |
| 104 | + } |
164 | 105 | } |
165 | 106 |
|
166 | | - public static enum OptionEnum { |
| 107 | + @Test |
| 108 | + public void testNotAutoIncrement() throws SQLException { |
| 109 | + Field checkedField; |
167 | 110 |
|
168 | | - OPTION1, |
169 | | - OPTION2; |
| 111 | + for(Map.Entry<String, String> entry : columnDataTypeMap.entrySet()) { |
| 112 | + checkedField = new Field(tableName, entry.getKey()); |
| 113 | + checkedField.assertNotAutoIncrementing(); |
| 114 | + } |
170 | 115 | } |
| 116 | + |
171 | 117 | } |
0 commit comments