Skip to content

Commit 114a701

Browse files
Segment CommonTest and internal class
1 parent f4617b5 commit 114a701

File tree

2 files changed

+132
-99
lines changed

2 files changed

+132
-99
lines changed
Lines changed: 45 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,26 @@
11
package org.javawebstack.orm.test.automigrate;
22

3-
import org.javawebstack.orm.Model;
43
import org.javawebstack.orm.ORM;
54
import org.javawebstack.orm.ORMConfig;
6-
import org.javawebstack.orm.annotation.Column;
75
import org.javawebstack.orm.exception.ORMConfigurationException;
86
import org.javawebstack.orm.test.ORMTestCase;
7+
import org.javawebstack.orm.test.shared.models.Datatype;
98
import org.javawebstack.orm.test.shared.verification.Field;
109
import org.javawebstack.orm.test.shared.verification.IdField;
1110
import org.junit.jupiter.api.BeforeEach;
1211
import org.junit.jupiter.api.Test;
1312

14-
import java.sql.Date;
1513
import java.sql.SQLException;
16-
import java.sql.Timestamp;
1714
import java.util.HashMap;
1815
import java.util.Map;
19-
import java.util.UUID;
2016

2117
public class CommonTest extends ORMTestCase {
2218

2319
private static final String tableName = "datatypes";
20+
private final Map<String, String> columnDataTypeMap;
2421

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<>();
4524

4625
columnDataTypeMap.put("primitive_boolean", "tinyint(1)");
4726
columnDataTypeMap.put("wrapper_boolean", "tinyint(1)");
@@ -79,93 +58,60 @@ public void testPrimitiveIntegerDatatype() throws SQLException {
7958
columnDataTypeMap.put("uuid", "varchar(36)");
8059

8160
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;
8279

8380
for(Map.Entry<String, String> entry : columnDataTypeMap.entrySet()) {
8481
checkedField = new Field(tableName, entry.getKey());
85-
8682
checkedField.assertType(entry.getValue());
87-
checkedField.assertNullable();
88-
checkedField.assertNotPrimaryKey();
89-
checkedField.assertNotAutoIncrementing();
9083
}
9184

9285
}
9386

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;
15790

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+
}
16096

161-
@Column
162-
OptionEnum optionEnum;
97+
@Test
98+
public void testNotPrimaryKey() throws SQLException {
99+
Field checkedField;
163100

101+
for(Map.Entry<String, String> entry : columnDataTypeMap.entrySet()) {
102+
checkedField = new Field(tableName, entry.getKey());
103+
checkedField.assertNotPrimaryKey();
104+
}
164105
}
165106

166-
public static enum OptionEnum {
107+
@Test
108+
public void testNotAutoIncrement() throws SQLException {
109+
Field checkedField;
167110

168-
OPTION1,
169-
OPTION2;
111+
for(Map.Entry<String, String> entry : columnDataTypeMap.entrySet()) {
112+
checkedField = new Field(tableName, entry.getKey());
113+
checkedField.assertNotAutoIncrementing();
114+
}
170115
}
116+
171117
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package org.javawebstack.orm.test.shared.models;
2+
3+
import org.javawebstack.orm.Model;
4+
import org.javawebstack.orm.annotation.Column;
5+
6+
import java.sql.Date;
7+
import java.sql.Timestamp;
8+
import java.util.UUID;
9+
10+
/*
11+
* Collection of all considered datatypes for columns.
12+
*/
13+
public class Datatype extends Model {
14+
@Column
15+
int id;
16+
17+
@Column
18+
boolean primitiveBoolean;
19+
20+
@Column
21+
Boolean wrapperBoolean;
22+
23+
@Column
24+
byte primitiveByte;
25+
26+
@Column
27+
Byte wrapperByte;
28+
29+
@Column
30+
short primitiveShort;
31+
32+
@Column
33+
Short wrapperShort;
34+
35+
@Column
36+
int primitiveInteger;
37+
38+
@Column
39+
Integer wrapperInteger;
40+
41+
@Column
42+
long primitiveLong;
43+
44+
@Column
45+
Long wrapperLong;
46+
47+
@Column
48+
float primitiveFloat;
49+
50+
@Column
51+
Float wrapperFloat;
52+
53+
@Column
54+
double primitiveDouble;
55+
56+
@Column
57+
Double wrapperDouble;
58+
59+
@Column
60+
char primitiveChar;
61+
62+
@Column
63+
String wrapperString;
64+
65+
@Column
66+
char[] charArray;
67+
68+
@Column
69+
byte[] byteArray;
70+
71+
@Column
72+
Timestamp timestamp;
73+
74+
@Column
75+
Date date;
76+
77+
@Column
78+
UUID uuid;
79+
80+
@Column
81+
OptionEnum optionEnum;
82+
83+
public enum OptionEnum {
84+
OPTION1,
85+
OPTION2,
86+
}
87+
}

0 commit comments

Comments
 (0)