Skip to content

Commit 702b155

Browse files
committed
Added Test for different Types
1 parent 6dcdfa5 commit 702b155

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.javawebstack.orm.test;
2+
3+
import org.javawebstack.orm.Model;
4+
import org.javawebstack.orm.ORM;
5+
import org.javawebstack.orm.ORMConfig;
6+
import org.javawebstack.orm.Repo;
7+
import org.javawebstack.orm.annotation.Column;
8+
import org.javawebstack.orm.annotation.Dates;
9+
import org.javawebstack.orm.annotation.SoftDelete;
10+
import org.javawebstack.orm.exception.ORMConfigurationException;
11+
import org.junit.jupiter.api.Test;
12+
13+
import static org.junit.jupiter.api.Assertions.*;
14+
15+
import java.sql.Timestamp;
16+
17+
public class DatesTest extends ORMTestCase {
18+
@Test
19+
public void testTimes() throws ORMConfigurationException {
20+
ORMConfig config = new ORMConfig()
21+
.setDefaultSize(255);
22+
ORM.register(TimesModel.class, sql(), config);
23+
ORM.autoMigrate(true);
24+
25+
TimesModel timesModel = new TimesModel();
26+
timesModel.save();
27+
28+
timesModel = Repo.get(TimesModel.class).get(timesModel.id);
29+
assertNotNull(timesModel.cratedAt);
30+
31+
// updated_at test
32+
timesModel.exampleField = " ";
33+
timesModel.save();
34+
35+
timesModel = Repo.get(TimesModel.class).get(timesModel.id);
36+
assertNotNull(timesModel.updatedAt);
37+
38+
// deleted_at test
39+
timesModel.delete();
40+
41+
timesModel = Repo.get(TimesModel.class).query().withDeleted().where("id", timesModel.id).first();
42+
assertNotNull(timesModel.deletedAt);
43+
}
44+
45+
@Dates
46+
@SoftDelete
47+
public static class TimesModel extends Model {
48+
@Column
49+
public int id;
50+
51+
@Column
52+
public String exampleField;
53+
54+
@Column
55+
public Timestamp cratedAt;
56+
57+
@Column
58+
public Timestamp updatedAt;
59+
60+
@Column
61+
public Timestamp deletedAt;
62+
}
63+
}

src/test/java/org/javawebstack/orm/test/TypesTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
import org.javawebstack.orm.exception.ORMConfigurationException;
99
import org.junit.jupiter.api.Test;
1010

11+
import java.sql.Timestamp;
12+
import java.time.Instant;
13+
1114
import static org.junit.jupiter.api.Assertions.*;
1215

13-
public class TypesTest extends ExampleTest {
16+
public class TypesTest extends ORMTestCase {
1417

1518
@Test
1619
public void testFields() throws ORMConfigurationException {
@@ -19,6 +22,8 @@ public void testFields() throws ORMConfigurationException {
1922
ORM.register(ExampleModel.class, sql(), config);
2023
ORM.autoMigrate(true);
2124

25+
Timestamp timestamp = Timestamp.from(Instant.now());
26+
2227
ExampleModel model = new ExampleModel();
2328
model.exampleString = "Hello ;)";
2429
model.exampleEnum = ExampleModel.Type.USER;
@@ -27,6 +32,7 @@ public void testFields() throws ORMConfigurationException {
2732

2833
model.exampleLong = 999999999999999999L;
2934
model.exampleBoolean = true;
35+
model.timestampTest = timestamp;
3036
model.save();
3137

3238
int id = model.id;
@@ -41,6 +47,7 @@ public void testFields() throws ORMConfigurationException {
4147
assertEquals(model.exampleFloat, 1.33769f);
4248
assertEquals(model.exampleDouble, 123456789.1234567890D);
4349
assertEquals(model.exampleLong, 999999999999999999L);
50+
assertEquals(model.timestampTest, timestamp);
4451

4552
model.exampleNull = "Text";
4653
model.save();
@@ -74,6 +81,9 @@ public static class ExampleModel extends Model {
7481
@Column
7582
public String exampleNull;
7683

84+
@Column
85+
public Timestamp timestampTest;
86+
7787
public enum Type {
7888
ADMIN, USER, GUEST
7989
}

0 commit comments

Comments
 (0)