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 you have access to the HSQLDB JAR file and know where the file is on your file system. You can obtain the JAR from http://hsqldb.org. The jar will probably be on your system in your local Maven repository (../.m2/repository/org/hsqldb/..).
  2. 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 4.10 (2018-12) 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. Install the feature
  5. Restart Eclipse
  6. 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.

XML Catalog

  1. Open Window>Preferences
  2. Navigate to XML>XML Catalog
  3. Verify that an XML catalog entry is present for MyBatis Generator

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. Create a new package in the src folder called config
  4. 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
  5. Make a new package in the src folder called base
  6. Add a new class to the base package named BaseModel
  7. Add a private Integer id to BaseModel and generate getters and setters. Then mark the getter and setter final

Generate MyBatis 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>
      <context id="context1" targetRuntime="MyBatis3Simple" >
        <jdbcConnection driverClass="${driver}"
          connectionURL="jdbc:hsqldb:mem:aname"
          userId="sa" >
        </jdbcConnection>
        <javaModelGenerator targetPackage="gen.model" targetProject="MBGTest" >
            <!--
            <property name="rootClass" value="base.BaseModel" />
            --> 
        </javaModelGenerator>
        <sqlMapGenerator targetPackage="gen.mapper" targetProject="MBGTest" />
        <javaClientGenerator targetPackage="gen.mapper" targetProject="MBGTest" type="XMLMAPPER" />
        <table tableName="a" />
      </context>
    
      <context id="context2" targetRuntime="MyBatis3Simple" >
        <connectionFactory type="DEFAULT" >
            <property name="driverClass" value="org.hsqldb.jdbcDriver" />
            <property name="connectionURL" value="jdbc:hsqldb:mem:aname" />
            <property name="userId" value="sa" />
        </connectionFactory>
        <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. Save the file
  4. Right click on the file, then take the option "Run As>Run MyBatis Generator"
  5. Verify that an error dialog is shown with the detail message "Exception getting JDBC Driver"
  6. Press "OK" to dismiss the dialog
  7. Create a new file in the "config" package named "create_db.sql"
  8. Change the contents of the file to the following:
          
    drop table a if exists;
    drop table mbgtest.b if exists;
    drop table mbgtest.b if exists;
    drop table mbgtest.c if exists;
    drop table mbgtest.d if exists;
    drop table mbgtest.e if exists;
    drop table mbgtest.f if exists;
    drop table mbgtest.g if exists;
    drop table mbgtest.h if exists;
    drop table mbgtest.i if exists;
    drop table mbgtest.j if exists;
    drop schema if exists mbgtest;
    create schema mbgtest;
    create table a (id int not null, description varchar(50), primary key(id));
    create table mbgtest.b (id int not null, description varchar(50), primary key(id));
    create table mbgtest.c (id int not null, description varchar(50), primary key(id));
    create table mbgtest.d (id int not null, description varchar(50), primary key(id));
    create table mbgtest.e (id int not null, description varchar(50), primary key(id));
    create table mbgtest.f (id int not null, description varchar(50), primary key(id));
    create table mbgtest.g (id int not null, description varchar(50), primary key(id));
    create table mbgtest.h (id int not null, description varchar(50), primary key(id));
    create table mbgtest.i (id int not null, description varchar(50), primary key(id));
    create table mbgtest.j (id int not null, description varchar(50), primary key(id));
          
  9. Open the launch configuration for this new configuration file. The launch configuration should be named MBGTest-generatorConfig.xml
  10. Alter the launch configuration to run the script before code generation:
  11. Run the launch configuration
  12. Verify that code is generated in the two different source folders. Code for table "a" should be in the "src" folder, code for tables "b" 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 @mbg.generated 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 "Run As>Run MyBatis Generator"
  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)

Adventures with Rootclass

  1. Open the configuration file from the last test.
  2. Uncomment the "rootClass" property line
  3. Save and close the file
  4. Right click on the configuration file, and then take the option "Run As>Run MyBatis Generator"
  5. Verify that gen.model.A now extends BaseModel. You should not have needed to alter the launch configuration classpath - the launch configuration automatically adds the project to the classpath of the generator.
  6. Also verify that there are no errors in gen.model.A - the generator should not have generated a get and set method that override the final methods in the base class
  7. Re open the configuration file.
  8. Re comment the "rootClass" property line
  9. Save and close the file
  10. Right click on the configuration file, and then take the option "Run As>Run MyBatis Generator"
  11. Verify that gen.model.A doesn't extend anything. There will be one warning in the file related to an unused 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, and that the id field and its getter and setter are back in the class.

Ant Build

  1. Create a new file build.xml in the "MBGTest/src/config" package.
  2. Change the contents of the new file to the following:
        
    <project default="runMyBatisGenerator">
      <target name="runMyBatisGenerator">
        <eclipse.convertPath resourcepath="MBGTest/src/config/create_db.sql"
                             property="theScriptPath"/>
        <sql driver="org.hsqldb.jdbcDriver" url="jdbc:hsqldb:mem:aname"
                userid="sa" password="" src="${theScriptPath}"/>
        <eclipse.convertPath resourcepath="MBGTest/src/config/generatorConfig.xml"
                             property="thePath"/>
        <mybatis.generate configfile="${thePath}" />
      </target>
    </project>
        
  3. Save and close the file.
  4. Delete the Java class gen.src.model.A. There will now be errors in the workspace.
  5. 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.
  6. Select the "JRE" tab, then select the "Run in the same JRE as the workspace" radio button.
  7. Press the "Run" button
  8. You should see an error in the progress window stating "Class not found: JDBC Driver...".
  9. Open the configuration file and replace ${driver} with org.hsqldb.jdbcDriver. There is a limitation in Eclipse that you cannot change environment variables for builds that run in the same JRE as the workspace.
  10. 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.
  11. Select the "Classpath" tab, then add the HSQLDB driver to "User Entries"
  12. Press the "Run" button
  13. After MyBatis Generator runs, you should see a "BUILD SUCCESSFUL" message. You may see build warnings related to logging. You can safely ignore these warnings.
  14. Verify that the workspace errors are gone.