1 package dst.ass1.jpa.tests;
3 import static dst.ass1.jpa.CaseInsensitiveStringCollectionMatcher.hasItems;
4 import static dst.ass1.jpa.util.Constants.*;
5 import static org.hamcrest.CoreMatchers.is;
6 import static org.hamcrest.CoreMatchers.not;
8 import org.junit.Before;
9 import org.junit.ClassRule;
10 import org.junit.FixMethodOrder;
11 import org.junit.Rule;
12 import org.junit.Test;
13 import org.junit.rules.ErrorCollector;
14 import org.junit.runners.MethodSorters;
16 import dst.ass1.jpa.DatabaseGateway;
17 import dst.ass1.jpa.ORMService;
18 import dst.ass1.jpa.util.Constants;
21 * Tests the basic object-relational mapping by examining the created database tables and constraints.
23 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
24 public class Ass1_1_1_01Test {
27 public static ORMService orm = new ORMService();
30 public ErrorCollector err = new ErrorCollector();
32 private DatabaseGateway db;
35 public void setUp() throws Exception {
36 db = orm.getDatabaseGateway();
40 public void printTables() throws Exception {
41 // not a test, just some systout output that may help you to gain insight into the created database schema
42 for (String table : db.getTables()) {
43 System.out.printf("%-30s %s%n", table, db.getColumns(table));
48 public void testBasicTablesJdbc() throws Exception {
49 // checks that all basic tables exist
50 err.checkThat(db.getTables(), hasItems(
65 public void testRelation01Jdbc() throws Exception {
66 // lecturer <-> lesson
67 err.checkThat(db.getTables(), hasItems(J_LECTURER_LESSON));
68 err.checkThat(db.getColumns(J_LECTURER_LESSON), hasItems(
75 public void testRelation02Jdbc() throws Exception {
76 // lecturer <-> course
77 err.checkThat(db.getColumns(T_COURSE), hasItems(I_LECTURER));
81 public void testRelation03Jdbc() throws Exception {
82 // participant <-enrollment-> course
84 err.checkThat(db.getColumns(T_ENROLLMENT), hasItems(
88 err.checkThat(db.getTables(), hasItems(
90 J_PARTICIPANT_ENROLLMENT
95 public void testRelation04Jdbc() throws Exception {
96 // participant <-> membership -> courseplatform
98 err.checkThat(db.getColumns(T_MEMBERSHIP), hasItems(
102 err.checkThat(db.getColumns(T_PARTICIPANT), not(hasItems(I_MEMBERSHIP)));
103 err.checkThat(db.getColumns(T_COURSEPLATFORM), not(hasItems(I_MEMBERSHIP)));
105 err.checkThat(db.getTables(), hasItems(J_PARTICIPANT_MEMBERSHIP));
106 err.checkThat(db.getColumns(J_PARTICIPANT_MEMBERSHIP), hasItems(I_PARTICIPANT));
110 public void testRelation05Jdbc() throws Exception {
113 err.checkThat("join table should be explicitly renamed!", db.getTables(), not(hasItems(
114 T_LESSON + "_" + T_LESSON
116 err.checkThat(db.getTables(), hasItems(
119 err.checkThat(db.getColumns(J_LESSONS_REQUIRED), hasItems(
126 public void testRelation06Jdbc() throws Exception {
128 err.checkThat(db.getColumns(T_LESSON), hasItems(I_COURSE));
129 err.checkThat(db.getColumns(T_COURSE), not(hasItems(I_LESSON)));
130 err.checkThat(db.isIndex(T_LESSON, I_COURSE, true), is(true));
134 public void testRelation07Jdbc() throws Exception {
135 // lesson <-> material
137 err.checkThat(db.getColumns(T_MATERIAL), hasItems(I_LESSON));
138 err.checkThat(db.getColumns(T_LESSON), not(hasItems(I_MATERIAL)));
139 err.checkThat(db.isIndex(T_MATERIAL, I_LESSON, true), is(true));
143 public void testRelation08Jdbc() throws Exception {
144 // course -> courseplatform
145 err.checkThat(db.getColumns(T_COURSE), hasItems(I_COURSEPLATFORM));
146 err.checkThat(db.isIndex(T_COURSE, I_COURSEPLATFORM, true), is(true));
150 public void testRelation09Jdbc() throws Exception {
151 // course -> metadata
152 err.checkThat(db.getTables(), hasItems(T_METADATA));
153 err.checkThat(db.getColumns(T_COURSE), hasItems(I_METADATA));
154 err.checkThat(db.getColumns(T_METADATA), not(hasItems(I_COURSE)));
155 err.checkThat(db.isIndex(Constants.T_COURSE, Constants.I_METADATA, false), is(true));
160 public void testRelation10Jdbc() throws Exception {
161 // courseplatform -> materialserver
162 err.checkThat(db.getTables(), hasItems(J_COURSEPLATFORM_MATERIALSERVER));
163 err.checkThat(db.getColumns(T_MATERIALSERVER), not(hasItems(I_COURSEPLATFORM)));
167 public void testRelation11Jdbc() throws Exception {
168 // material <-> materialserver
170 err.checkThat(db.getTables(), hasItems(J_MATERIALSERVER_MATERIAL));
174 public void testColumnType01Jdbc() {
175 err.checkThat(db.isColumnInTableWithType(T_PARTICIPANT, M_PERSON_PASSWORD, "VARBINARY", "20"), is(true));