|
| 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.exception.ORMConfigurationException; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | + |
| 11 | +import java.sql.Timestamp; |
| 12 | +import java.time.Instant; |
| 13 | + |
| 14 | +import static org.junit.jupiter.api.Assertions.*; |
| 15 | + |
| 16 | +public class TypesTest extends ORMTestCase { |
| 17 | + |
| 18 | + @Test |
| 19 | + public void testFields() throws ORMConfigurationException { |
| 20 | + ORMConfig config = new ORMConfig() |
| 21 | + .setDefaultSize(255); |
| 22 | + ORM.register(ExampleModel.class, sql(), config); |
| 23 | + ORM.autoMigrate(true); |
| 24 | + |
| 25 | + Timestamp timestamp = Timestamp.from(Instant.now()); |
| 26 | + ExampleModel model = new ExampleModel(); |
| 27 | + model.exampleString = "Hello ;)"; |
| 28 | + model.exampleEnum = ExampleModel.Type.USER; |
| 29 | + |
| 30 | + model.exampleFloatPrimitive = 1.33769F; |
| 31 | + model.exampleFloat = 1.33769F; |
| 32 | + |
| 33 | + model.exampleDoublePrimitive = 123456789.1234567890D; |
| 34 | + model.exampleDouble = 123456789.1234567890D; |
| 35 | + |
| 36 | + model.exampleLongPrimitive = 999999999999999999L; |
| 37 | + model.exampleLong = 999999999999999999L; |
| 38 | + |
| 39 | + model.exampleBooleanPrimitive = true; |
| 40 | + model.exampleBoolean = true; |
| 41 | + |
| 42 | + model.timestampTest = timestamp; |
| 43 | + model.save(); |
| 44 | + |
| 45 | + int id = model.id; |
| 46 | + |
| 47 | + model = Repo.get(ExampleModel.class).get(id); |
| 48 | + |
| 49 | + assertEquals(model.id, id); |
| 50 | + assertNull(model.exampleNull); |
| 51 | + assertTrue(model.exampleBoolean); |
| 52 | + assertTrue(model.exampleBooleanPrimitive); |
| 53 | + assertEquals(model.exampleEnum, ExampleModel.Type.USER); |
| 54 | + assertEquals(model.exampleString, "Hello ;)"); |
| 55 | + assertEquals(model.exampleFloatPrimitive, 1.33769f); |
| 56 | + assertEquals(model.exampleFloat, 1.33769f); |
| 57 | + assertEquals(model.exampleDoublePrimitive, 123456789.1234567890D); |
| 58 | + assertEquals(model.exampleDouble, 123456789.1234567890D); |
| 59 | + assertEquals(model.exampleLong, 999999999999999999L); |
| 60 | + assertEquals(model.exampleLongPrimitive, 999999999999999999L); |
| 61 | + |
| 62 | + // TODO: Use |
| 63 | + assertNotNull(model.timestampTest); |
| 64 | + |
| 65 | + model.exampleNull = "Text"; |
| 66 | + model.save(); |
| 67 | + model = Repo.get(ExampleModel.class).get(id); |
| 68 | + assertEquals(model.exampleNull, "Text"); |
| 69 | + } |
| 70 | + |
| 71 | + public static class ExampleModel extends Model { |
| 72 | + |
| 73 | + @Column |
| 74 | + public int id; |
| 75 | + |
| 76 | + @Column |
| 77 | + public String exampleString; |
| 78 | + |
| 79 | + @Column |
| 80 | + public float exampleFloatPrimitive; |
| 81 | + |
| 82 | + @Column |
| 83 | + public Float exampleFloat; |
| 84 | + |
| 85 | + @Column |
| 86 | + public double exampleDoublePrimitive; |
| 87 | + |
| 88 | + @Column |
| 89 | + public Double exampleDouble; |
| 90 | + |
| 91 | + @Column |
| 92 | + public long exampleLongPrimitive; |
| 93 | + |
| 94 | + @Column |
| 95 | + public Long exampleLong; |
| 96 | + |
| 97 | + @Column |
| 98 | + public boolean exampleBooleanPrimitive; |
| 99 | + |
| 100 | + @Column |
| 101 | + public Boolean exampleBoolean; |
| 102 | + |
| 103 | + @Column |
| 104 | + public Type exampleEnum; |
| 105 | + |
| 106 | + @Column |
| 107 | + public String exampleNull; |
| 108 | + |
| 109 | + @Column |
| 110 | + public Timestamp timestampTest; |
| 111 | + |
| 112 | + public enum Type { |
| 113 | + ADMIN, USER, GUEST |
| 114 | + } |
| 115 | + |
| 116 | + } |
| 117 | + |
| 118 | +} |
0 commit comments