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.Sequence;
25 import org.kuali.common.impex.schema.impl.mysql.MySqlSequenceSqlProducer;
26
27 import static junit.framework.Assert.assertEquals;
28 import static junit.framework.Assert.fail;
29
30 public class TestMySqlSequenceSqlProducer {
31
32 public static final String[] EXPECTED_SQL = {"DROP TABLE IF EXISTS FOO_SEQ\n",
33 "CREATE TABLE FOO_SEQ\n" +
34 "(\n" +
35 "\tID BIGINT(19) NOT NULL AUTO_INCREMENT, PRIMARY KEY (ID)\n" +
36 ") ENGINE MyISAM\n",
37
38 "ALTER TABLE FOO_SEQ AUTO_INCREMENT = 500\n"
39 };
40
41 @Test
42 public void testGetSequencesSql() {
43 Sequence sequence = new Sequence("FOO_SEQ", "500");
44
45 MySqlSequenceSqlProducer producer = new MySqlSequenceSqlProducer();
46
47 List<String> results = producer.getSequencesSql(Collections.singletonList(sequence));
48
49 assertEquals(EXPECTED_SQL.length, results.size());
50
51 List<String> expected = Arrays.asList(EXPECTED_SQL);
52
53 List<String> foundExpected = new ArrayList<String>(expected);
54 for (String e : expected) {
55 if(results.contains(e)) {
56 foundExpected.remove(e);
57 }
58 else {
59 fail("Expected sql statment **" + e + "** not found in generated statements.\n Generated statements were: " + results.toString());
60 }
61 }
62
63 if(!foundExpected.isEmpty()) {
64 fail("Following expected sql statements not found in generated statements: \n" + foundExpected.toString());
65 }
66 }
67
68 }