1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.impex.schema.impl;
17
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.Collections;
21 import java.util.List;
22
23 import org.junit.Test;
24 import org.kuali.common.impex.model.Table;
25 import org.kuali.common.impex.schema.impl.mysql.MySqlTableSqlProducer;
26
27 import static junit.framework.Assert.assertEquals;
28 import static junit.framework.Assert.fail;
29
30 public class TestMySqlTableSqlProducer {
31
32 private final static String[] EXPECTED_SIMPLE_SQL = {"DROP TABLE IF EXISTS FOO_T\n",
33 "CREATE TABLE FOO_T\n" +
34 "(\n" +
35 "\tID VARCHAR(36),\n" +
36 "\tCREATETIME TIMESTAMP NOT NULL,\n" +
37 "\tFOO_COUNT FLOAT(10),\n" +
38 "\tNAME VARCHAR(255),\n" +
39 "\tCONSTRAINT FOO_TP1 PRIMARY KEY(ID),\n" +
40 "\tCONSTRAINT FOO_TP1 UNIQUE (NAME)\n" +
41 ") ENGINE InnoDB CHARACTER SET utf8 COLLATE utf8_bin\n"
42 };
43
44 @Test
45 public void simpleTableTest() {
46 MySqlTableSqlProducer producer = new MySqlTableSqlProducer();
47
48 producer.setMappingProvider(new NoOpProvider());
49
50 Table table = MockDataUtil.buildSimpleTable();
51
52 List<String> results = producer.getTablesSql(Collections.singletonList(table));
53
54 assertEquals(EXPECTED_SIMPLE_SQL[1], results.get(1));
55
56 List<String> expected = Arrays.asList(EXPECTED_SIMPLE_SQL);
57
58 List<String> foundExpected = new ArrayList<String>(expected);
59 for (String e : expected) {
60 if (results.contains(e)) {
61 foundExpected.remove(e);
62 } else {
63 fail("Expected sql statment **" + e + "** not found in generated statements.");
64 }
65 }
66
67 if (!foundExpected.isEmpty()) {
68 fail("Following expected sql statements not found in generated statements: \n" + foundExpected.toString());
69 }
70 }
71
72 }