View Javadoc
1   /**
2    *    Copyright 2006-2016 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.generator;
17  
18  import static org.junit.Assert.assertEquals;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.junit.Test;
24  import org.mybatis.generator.api.MyBatisGenerator;
25  import org.mybatis.generator.config.Configuration;
26  import org.mybatis.generator.config.xml.ConfigurationParser;
27  import org.mybatis.generator.exception.InvalidConfigurationException;
28  import org.mybatis.generator.internal.DefaultShellCallback;
29  
30  public class MyBatisGeneratorTest {
31  
32      @Test(expected=InvalidConfigurationException.class)
33      public void testGenerateMyBatis3() throws Exception {
34          List<String> warnings = new ArrayList<String>();
35          ConfigurationParser cp = new ConfigurationParser(warnings);
36          Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream("generatorConfigMyBatis3.xml"));
37              
38          DefaultShellCallback shellCallback = new DefaultShellCallback(true);
39          
40          try {
41              MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
42              myBatisGenerator.generate(null, null, null, false);
43          } catch (InvalidConfigurationException e) {
44              assertEquals(2, e.getErrors().size());
45              throw e;
46          }
47      }
48  
49      @Test(expected=InvalidConfigurationException.class)
50      public void testGenerateIbatis2() throws Exception {
51          List<String> warnings = new ArrayList<String>();
52          ConfigurationParser cp = new ConfigurationParser(warnings);
53          Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream("generatorConfigIbatis2.xml"));
54              
55          DefaultShellCallback shellCallback = new DefaultShellCallback(true);
56          
57          try {
58              MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
59              myBatisGenerator.generate(null, null, null, false);
60          } catch (InvalidConfigurationException e) {
61              assertEquals(1, e.getErrors().size());
62              throw e;
63          }
64      }
65  }