Manual Test Scripts

This page lists scripts for testing the different parts of the MyBatis Generator UI. This information may also be helpful in learning how to use the different parts of the Eclipse user interface for MyBatis Generator.

Setup

  1. Make sure that MySQL is installed and running. The following scripts also assume that the password for root is also root
  2. Make sure that you have downloaded the MySQL Connector for Java and unzipped it somewhere on your local drive. The following scripts assume the MySQL JDBC driver is located at "/JavaTools/mysql-connector-java-5.1.12/mysql-connector-java-5.1.12-bin.jar".
  3. If you have not created the test database already, then execute the following script:
    
    drop schema if exists mbgtest;
    create schema mbgtest;
    use mbgtest;
    create table a (id int not null, description varchar(50), primary key(id));
    create table b (id int not null, description varchar(50), primary key(id));
    create table c (id int not null, description varchar(50), primary key(id));
    create table d (id int not null, description varchar(50), primary key(id));
    create table e (id int not null, description varchar(50), primary key(id));
    create table f (id int not null, description varchar(50), primary key(id));
    create table g (id int not null, description varchar(50), primary key(id));
    create table h (id int not null, description varchar(50), primary key(id));
    create table i (id int not null, description varchar(50), primary key(id));
    create table j (id int not null, description varchar(50), primary key(id));
          
  4. Make sure that the new version of the plugin has been built.

Tests

The following tests are intended to be executed in the order listed. Some tests build on items created in previous tests.

Installation

  1. Install a fresh version of Eclipse (version 3.6.1 or later)
  2. Open the fresh Eclipse install, and create a new (empty) workspace
  3. Configure a local update site to point to the newly generated site (Help>Install New Software...)
  4. Show all versions of the feature
  5. Install the oldest version of the feature
  6. Restart Eclipse
  7. Do a regular software update and verify that the newest version of the feature is listed as an install option (this may also install other Eclipse updates)
  8. Restart Eclipse
  9. Verify that the latest version of the feature is listed as installed

Documentation

  1. Open the Eclipse help (Help>Help Contents)
  2. Verify that the book "MyBatis Generator User's Guide" appears in the contents.
  3. Verify that every item in the contents points to a valid page, and that all pages are referenced in the table of contents. This is especially important if new packages or help pages have been added anywhere.
  4. Verify that the core MyBatis Generator documentation pages do not show the options to show or hide the menu. These options should be disabled by the style sheet.
  5. Verify that the latest version of the release notes is shown both in the Eclipse UI documentation, and the Core MyBatis Generator documentation.

New File Wizard

  1. Create a new JavaProject called "MBGTest". Make sure there is a separate source folder called src
  2. Add an additional source folder called generatedsrc
  3. Configure the build path to add the iBATIS 2 JAR file (typically an external JAR in the local maven repo)
  4. Create a new package in the src folder called config
  5. Make a new configuration file:
    1. Right click on the config package
    2. Select New>Other>MyBatis>MyBatis Generator Configuration File
    3. Press Next
    4. Verify that Location is set to "MBGTest/src/config"
    5. Verify that File Name is set to "generatorConfig.xml"
    6. Press Finish
    7. Verify that an editor opens with a skeleton configuration File
  6. Right click on the new file, then take the option "Generate MyBatis/iBATIS Artifacts"
  7. Verify that an error dialog is shown with the detail message "Exception getting JDBC Driver"
  8. Press "OK" to dismiss the dialog

Generate MyBatis/iBATIS Artifacts

  1. Open an editor on the file "generatorConfig.xml" that you created in the previous test
  2. Change the contents of the file to the following:
    
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE generatorConfiguration
      PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
      "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
    <generatorConfiguration>
      <classPathEntry location="/JavaTools/mysql-connector-java-5.1.17/mysql-connector-java-5.1.17-bin.jar" />
      <context id="context1" targetRuntime="MyBatis3" >
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
          connectionURL="jdbc:mysql://localhost/mbgtest"
          userId="root" password="root" >
        </jdbcConnection>
        <javaModelGenerator targetPackage="gen.model" targetProject="MBGTest" />
        <sqlMapGenerator targetPackage="gen.mapper" targetProject="MBGTest" />
        <javaClientGenerator targetPackage="gen.mapper" targetProject="MBGTest" type="XMLMAPPER" />
        <table tableName="a" />
      </context>
    
      <context id="context2" targetRuntime="MyBatis3" >
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
          connectionURL="jdbc:mysql://localhost/mbgtest"
          userId="root" password="root" >
        </jdbcConnection>
        <javaModelGenerator targetPackage="gen.src.model" targetProject="MBGTest/generatedsrc" />
        <sqlMapGenerator targetPackage="gen.src.mapper" targetProject="MBGTest/generatedsrc" />
        <javaClientGenerator targetPackage="gen.src.mapper" targetProject="MBGTest/generatedsrc" type="XMLMAPPER" />
        <table schema="mbgtest" tableName="%" />
      </context>
    </generatorConfiguration>
        
  3. Change the location of the JDBC driver in the <classPathEntry> element if different on your system
  4. Save the file
  5. Right click on the file, then take the option "Generate MyBatis/iBATIS Artifacts"
  6. Verify that code is generated in the two different source folders. Code for table "a" should be in the "src" folder, code for tables "a" through "j" should be in the "generatedsrc" folder. Verify that there are no compilation errors or warnings.

Java File Merger

  1. Open the Java file gen.model.A.java in the "src" folder
  2. Note the time of generation of the file from one of the @mbggenerated comments
  3. Add a private field of any type called mergetest and generate a getter and setter for the field.
  4. Save and close the file
  5. Right click on the configuration file from the last test, and then take the option "Generate MyBatis/iBATIS Artifacts"
  6. Verify that the progress bar is reasonably accurate
  7. Open the Java file gen.model.A.java in the "src" folder
  8. Verify that the time of generation is later than the time noted above
  9. Verify that the field mergetest, and its getter and setter remain in the file (they will have been moved to the bottom of the file)
  10. Open the configuration file from the last test.
  11. Change the Java client type in context1 to SPRING
  12. Save and close the file
  13. Right click on the configuration file, and then take the option "Generate MyBatis/iBATIS Artifacts"
  14. Verify that src.dao.ADAOImpl now extends SqlMapClientDaoSupport. Note that there will be several errors in the workspace now because of the new dependencies on Spring that were generated.
  15. Re open the configuration file.
  16. Change the Java client type in context1 back to GENERIC-CI
  17. Save and close the file
  18. Right click on the configuration file, and then take the option "Generate MyBatis/iBATIS Artifacts"
  19. Verify that src.dao.ADAOImpl doesn't extend anything. There will be one error in the file related to the Spring import (the Java merger does not reconcile all imports). Delete the import and verify that there are no other errors in the workspace. Also, verify that the field mergetest and its associated getter and setter still exist.

Ant Build

  1. Close Eclipse if it is still open, then reopen Eclipse (this resets the plugin classloader for the custom classpath portion of the test).
  2. Open the configuration file from the last test.
  3. Delete the <classPathEntry> element from the file.
  4. Save and close the file.
  5. Create a new file build.xml in the "MBGTest/src/config" package.
  6. Change the contents of the new file to the following:
    
    <project default="runMyBatisGenerator">
      <target name="runMyBatisGenerator">
        <eclipse.convertPath resourcepath="MBGTest/src/config/generatorConfig.xml"
                             property="thePath"/>
        <mybatis.generate configfile="${thePath}" >
        </mybatis.generate>
      </target>
    </project>
        
  7. Save and close the file.
  8. Delete the Java file gen.dao.ADAO.java. There will now be errors in the workspace.
  9. Right click on the new build.xml file, then select the menu option "Run As>Ant Build...". You should see the Ant launch configuration dialog open.
  10. Select the "JRE" tab, then select the "Run in the same JRE as the workspace" radio button.
  11. Press the "Run" button
  12. You should see an error dialog open with a runtime exception stating "Exception getting JDBC Driver". Press "OK" to dismiss the dialog.
  13. Right click on the new build.xml file, then select the menu option "Run As>Ant Build...". You should see the Ant launch configuration dialog open.
  14. Select the "Classpath" tab, then add the MySQL driver to "User Entries"
  15. Press the "Run" button
  16. After MyBatis Generator runs, you should see a "BUILD SUCCESSFUL" message. You may see build warnings related to log4j if it is installed in your Eclipse distribution. You can safely ignore these warnings.
  17. Verify that the workspace errors are gone.