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 static junit.framework.Assert.assertEquals;
19 import static junit.framework.Assert.fail;
20
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collections;
24 import java.util.List;
25
26 import org.junit.Test;
27 import org.kuali.common.impex.model.Table;
28 import org.kuali.common.impex.schema.impl.oracle.OracleTableSqlProducer;
29
30 public class TestOracleTableSqlProducer {
31
32 private final static String[] EXPECTED_SIMPLE_SQL = {
33 "DECLARE temp NUMBER;\n" + "BEGIN\n" + "\tSELECT COUNT(*) INTO temp FROM user_tables WHERE table_name = 'FOO_T';\n"
34 + "\tIF temp > 0 THEN EXECUTE IMMEDIATE 'DROP TABLE FOO_T CASCADE CONSTRAINTS PURGE'; END IF;\n" + "END;\n",
35
36 "CREATE TABLE FOO_T\n" + "(\n" + "\tID VARCHAR2(36),\n" + "\tCREATETIME TIMESTAMP NOT NULL,\n" + "\tFOO_COUNT NUMBER(10),\n" + "\tNAME VARCHAR2(255),\n"
37 + "\tCONSTRAINT FOO_U1_NAME UNIQUE (NAME)\n" + ")\n",
38
39 "ALTER TABLE FOO_T\n" + "\tADD CONSTRAINT FOO_TP1\n" + "PRIMARY KEY (ID)\n" };
40
41 @Test
42 public void simpleTableTest() {
43
44 OracleTableSqlProducer producer = new OracleTableSqlProducer();
45
46 producer.setMappingProvider(new NoOpProvider());
47
48 Table table = MockDataUtil.buildSimpleTable();
49
50 List<String> results = producer.getTablesSql(Collections.singletonList(table));
51
52 assertEquals(EXPECTED_SIMPLE_SQL.length, results.size());
53
54 List<String> expected = Arrays.asList(EXPECTED_SIMPLE_SQL);
55
56 List<String> foundExpected = new ArrayList<String>(expected);
57 for (String e : expected) {
58 if (results.contains(e)) {
59 foundExpected.remove(e);
60 } else {
61 fail("Expected sql statment **" + e + "** not found in generated statements.");
62 }
63 }
64
65 if (!foundExpected.isEmpty()) {
66 fail("Following expected sql statements not found in generated statements: \n" + foundExpected.toString());
67 }
68
69 }
70
71 }