|
11 | 11 | import org.junit.Before; |
12 | 12 | import org.junit.Test; |
13 | 13 |
|
14 | | -import com.dieselpoint.norm.Database; |
15 | | - |
16 | | - |
17 | 14 | public class TestGeneratedId { |
18 | 15 |
|
19 | 16 | static String DB_DRIVER_CLASS_NAME = "org.postgresql.ds.PGSimpleDataSource"; |
20 | | - static String DB_SERVER_NAME = "localhost"; |
21 | | - static String DB_DATABASE = "testdb"; |
22 | | - static String DB_USERNAME = "postgres"; |
23 | | - static String DB_PASSWORD = "rootpassword"; |
24 | | - |
25 | | - private Database db; |
26 | | - |
27 | | - @Before |
28 | | - public void setUp() { |
29 | | - System.setProperty("norm.dataSourceClassName", DB_DRIVER_CLASS_NAME); |
30 | | - System.setProperty("norm.serverName", DB_SERVER_NAME); |
31 | | - System.setProperty("norm.databaseName", DB_DATABASE); |
32 | | - System.setProperty("norm.user", DB_USERNAME); |
33 | | - System.setProperty("norm.password", DB_PASSWORD); |
34 | | - |
35 | | - db = new Database(); |
36 | | - } |
37 | | - |
38 | | - @Test |
39 | | - public void testCreate() { |
40 | | - NormPojo np = new NormPojo(); |
41 | | - np.setId("MyID"); |
42 | | - np.setName("My name"); |
43 | | - db.generatedKeyReceiver(np, "id").insert(np); |
44 | | - Assert.assertNotNull(np.getDatabaseId()); |
45 | | - } |
46 | | - |
47 | | - @Test |
48 | | - public void testRetrieval() { |
49 | | - List<NormPojo> npList = null; |
50 | | - npList = db.results(NormPojo.class); |
51 | | - Assert.assertNotNull(npList); |
52 | | - Assert.assertTrue(npList.size() > 0); |
53 | | - } |
54 | | - |
55 | | - @Table(name = "pojo") |
56 | | - public static class NormPojo { |
57 | | - |
58 | | - /** Database record ID. */ |
59 | | - private Integer databaseId; |
60 | | - |
61 | | - /** Unique identifier of the object. */ |
62 | | - private String id; |
63 | | - |
64 | | - /** Human readable name. */ |
65 | | - private String name; |
66 | | - |
67 | | - /** |
68 | | - * @return the id |
69 | | - */ |
70 | | - @Column(name = "object_id", unique = true) |
71 | | - public String getId() { |
72 | | - return id; |
73 | | - } |
74 | | - |
75 | | - /** |
76 | | - * @param id the id to set |
77 | | - */ |
78 | | - public void setId(String id) { |
79 | | - this.id = id; |
80 | | - } |
81 | | - |
82 | | - /** |
83 | | - * @return the name |
84 | | - */ |
85 | | - @Column(name = "name") |
86 | | - public String getName() { |
87 | | - return name; |
88 | | - } |
89 | | - |
90 | | - /** |
91 | | - * @param name the name to set |
92 | | - */ |
93 | | - public void setName(String name) { |
94 | | - this.name = name; |
95 | | - } |
96 | | - |
97 | | - @Id |
98 | | - @GeneratedValue |
99 | | - @Column(name = "id") |
100 | | - public Integer getDatabaseId() { |
101 | | - return databaseId; |
102 | | - } |
103 | | - |
104 | | - public void setDatabaseId(Integer databaseId) { |
105 | | - this.databaseId = databaseId; |
106 | | - } |
107 | | - |
108 | | - } |
109 | | - |
110 | | - |
111 | | - |
| 17 | + static String DB_SERVER_NAME = "localhost"; |
| 18 | + static String DB_DATABASE = "testdb"; |
| 19 | + static String DB_USERNAME = "postgres"; |
| 20 | + static String DB_PASSWORD = "rootpassword"; |
| 21 | + |
| 22 | + private Database db; |
| 23 | + |
| 24 | + @Before |
| 25 | + public void setUp() { |
| 26 | + System.setProperty("norm.dataSourceClassName", DB_DRIVER_CLASS_NAME); |
| 27 | + System.setProperty("norm.serverName", DB_SERVER_NAME); |
| 28 | + System.setProperty("norm.databaseName", DB_DATABASE); |
| 29 | + System.setProperty("norm.user", DB_USERNAME); |
| 30 | + System.setProperty("norm.password", DB_PASSWORD); |
| 31 | + |
| 32 | + db = new Database(); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void testCreate() { |
| 37 | + NormPojo np = new NormPojo(); |
| 38 | + np.setId("MyID"); |
| 39 | + np.setName("My name"); |
| 40 | + db.generatedKeyReceiver(np, "id").insert(np); |
| 41 | + Assert.assertNotNull(np.getDatabaseId()); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testRetrieval() { |
| 46 | + List<NormPojo> npList = null; |
| 47 | + npList = db.results(NormPojo.class); |
| 48 | + Assert.assertNotNull(npList); |
| 49 | + Assert.assertTrue(npList.size() > 0); |
| 50 | + } |
| 51 | + |
| 52 | + @Table(name = "pojo") |
| 53 | + public static class NormPojo { |
| 54 | + |
| 55 | + /** Database record ID. */ |
| 56 | + private Integer databaseId; |
| 57 | + |
| 58 | + /** Unique identifier of the object. */ |
| 59 | + private String id; |
| 60 | + |
| 61 | + /** Human readable name. */ |
| 62 | + private String name; |
| 63 | + |
| 64 | + /** |
| 65 | + * @return the id |
| 66 | + */ |
| 67 | + @Column(name = "object_id", unique = true) |
| 68 | + public String getId() { |
| 69 | + return id; |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * @param id the id to set |
| 74 | + */ |
| 75 | + public void setId(String id) { |
| 76 | + this.id = id; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * @return the name |
| 81 | + */ |
| 82 | + @Column(name = "name") |
| 83 | + public String getName() { |
| 84 | + return name; |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * @param name the name to set |
| 89 | + */ |
| 90 | + public void setName(String name) { |
| 91 | + this.name = name; |
| 92 | + } |
| 93 | + |
| 94 | + @Id |
| 95 | + @GeneratedValue |
| 96 | + @Column(name = "id") |
| 97 | + public Integer getDatabaseId() { |
| 98 | + return databaseId; |
| 99 | + } |
| 100 | + |
| 101 | + public void setDatabaseId(Integer databaseId) { |
| 102 | + this.databaseId = databaseId; |
| 103 | + } |
| 104 | + |
| 105 | + } |
| 106 | + |
112 | 107 | } |
0 commit comments