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.View;
25 import org.kuali.common.impex.schema.impl.mysql.MySqlViewSqlProducer;
26
27 import static junit.framework.Assert.assertEquals;
28 import static junit.framework.Assert.assertTrue;
29 import static junit.framework.Assert.fail;
30
31 public class TestMySqlViewSqlProducer {
32
33 private static final String[] EXPECTED_SQL = {"DROP VIEW IF EXISTS TEST_V1\n",
34
35 "CREATE VIEW TEST_V1 AS\n" +
36 "SELECT ID, NAME FROM FOO_T\n" +
37 "WHERE NAME LIKE 'TEST%'\n"};
38
39 @Test
40 public void testEmptyViewList() {
41 List<View> empty = Collections.emptyList();
42
43 MySqlViewSqlProducer sqlProducer = new MySqlViewSqlProducer();
44 List<String> results = sqlProducer.getViewsSql(empty);
45
46 assertTrue(results.isEmpty());
47 }
48
49 @Test
50 public void testGetViewSql() {
51 List<View> views = Collections.singletonList(MockDataUtil.buildSimpleView());
52
53 MySqlViewSqlProducer sqlProducer = new MySqlViewSqlProducer();
54 List<String> results = sqlProducer.getViewsSql(views);
55
56 assertEquals(EXPECTED_SQL.length, results.size());
57
58 List<String> expected = Arrays.asList(EXPECTED_SQL);
59
60 List<String> foundExpected = new ArrayList<String>(expected);
61 for (String e : expected) {
62 if(results.contains(e)) {
63 foundExpected.remove(e);
64 }
65 else {
66 fail("Expected sql statment **" + e + "** not found in generated statements.\n Generated statements were: " + results.toString());
67 }
68 }
69
70 if(!foundExpected.isEmpty()) {
71 fail("Following expected sql statements not found in generated statements: \n" + foundExpected.toString());
72 }
73 }
74
75 }