View Javadoc

1   /**
2    * Copyright 2011 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
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  }