TS 65 Entity Classes From Database
"Test Specification for NetBeans 6.5"
Author: "Michal Vanek"
Version: ""
Last update: "11/25/2008"
Comments: "MySQL server with Sakila database scheme needed for tests"
Contents |
Test suite: "Sakila database connection on localhost"
Purpose: "create Sakila database connection "
- "Creating jdbc/sakila connection"
- "Start mySQL server if not already running"
- "Download and create Sakila DB if needed - http://downloads.mysql.com/docs/sakila-db.zip"
- "Use File | New Project... to create new Web Application project located in your home directory."
- "Choose your own project name and click next"
- "If not chosen automatically, choose Glassfish v3 and Java EE5, click next"
- "Right click project name | New | Other | choose Persistence - Persistent Unit and click next"
- "Choose Data source | New Data source | Database connection | New Database connection "
- "Name: enroll for MySQL (Connector/Jdriver)"
- "Host:localhost"
- "Port: 3309"
- "Database: sakila"
- "User Name: usrname"
- "Password: password"
- "Click OK - connection is created, no error appears"
- "JNDI Name: jdbc/sakila and click OK"
- "Right click project name | New | Other | choose Persistence - Entity Class from Database and click next"
- "Select Data Source: jdbc/sakila"
- EXPECTED RESULT: "Sakila tables are displayed in Available Tables area."
Test suite: "Not related database tables and not included relationship"
Purpose: "Verification single tables creation"
Setup: "Create Simple web application, create Persistent Unit with connection to MySQL database."
- "New Entity Class from Database - Single table, Include Related Tables checked, "
- "Right click project name | New | Other | choose Persistence - Entity Classes from Database and click next"
- "Select Data Source: from Drop down jdbc/sakila "
- "Make sure Include Related Tables button is checked"
- "From Available Tables: choose any table without other relations and Add to selected Tables. For example - Actor and click next"
- "Make sure Generate Query Anotations for Persistent Fields is checked"
- "Choose web package from drop down and click next "
- "Choose Association Fetch: default"
- "Collection type: java.util.collection"
- "Check boxes are unchecked and click finish"
- "New java file named by the table is created in web package."
- "Clean and Build a project"
- "Repeat all the steps for all Association Fetch types and all Collection Types"
- EXPECTED RESULT: "For each case new java file with table is created and project Build is successful. Fetch type is not imported."
This is not imported in generated code - import javax.persistence.FetchType;
Code created by wizard in a java file is similar to this one
@Entity
@Table(name = "actor")
@NamedQueries({
@NamedQuery(name = "Actor.findAll", query = "SELECT a FROM Actor a"),
@NamedQuery(name = "Actor.findByActorId", query = "SELECT a FROM Actor a WHERE a.actorId = :actorId"),
@NamedQuery(name = "Actor.findByFirstName", query = "SELECT a FROM Actor a WHERE a.firstName = :firstName"),
@NamedQuery(name = "Actor.findByLastName", query = "SELECT a FROM Actor a WHERE a.lastName = :lastName"),
@NamedQuery(name = "Actor.findByLastUpdate", query = "SELECT a FROM Actor a WHERE a.lastUpdate = :lastUpdate")
})
public class Actor implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "actor_id")
private Short actorId;
@Basic(optional = false)
@Column(name = "first_name")
private String firstName;
@Basic(optional = false)
@Column(name = "last_name")
private String lastName;
@Basic(optional = false)
@Column(name = "last_update")
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdate;
- "New Entity Class from Database - Relationship table, Include Related Tables unchecked "
- "If necessary create new simple web aplication with Persistent Unit and connection to MySQL database"
- "Right click project name | New | Other | choose Persistence - Entity Classes from Database and click next"
- "Select Data Source: from Drop down jdbc/sakila "
- "Make sure Include Related Tables button is unchecked"
- "From Available Tables: choose table which has any relationship to other tables and Add to selected Tables. For example - Actor and click next"
- "Only one table is added to Selected tables field"
- "Make sure Generate Query Anotations for Persistent Fields is checked"
- "Choose web package from drop down and click next "
- "Choose Association Fetch: default"
- "Collection type: java.util.collection"
- "Check boxes are unchecked and click finish"
- "New java file named by the table is created in web package."
- "Clean and Build a project"
- "Repeat all the steps for all Association Fetch types and Collection Types"
- EXPECTED RESULT: "For each case new java file with table is created and project Build is successful"
this code is not present in a java file @ManyToOne(optional=false), @OneToMany(Cascade...
Test suite: "Related database tables "
Purpose: "Verification of creation correct relationship between tables"
Setup: "Create Simple web application, create Persistent Unit with connection to MySQL database."
- "Related tables - java.util.Collection"
- "If necessary create new simple web aplication with Persistent Unit and connection to MySQL database"
- "Right click project name | New | Other | choose Persistence - Entity Classes from Database and click next"
- "Select Data Source: from Drop down jdbc/sakila "
- "Make sure Include Related Tables button is checked"
- "Add any table which is related to other tables(customer) and click next"
- "Choose web package and click next"
- "Choose Association Fetch: Default"
- "Java files corresponding to table names are created"
- "Build project is successful"
- "Repeat for all Association Fetch types"
- {{result|EXPECTED RESULT: "Build project is successful. Collection is used to create related tables. Java files contains this code "
Java file with main table contains in class definition: @ManyToOne(optional = false) Other java files with related tables contains in class definition: @OneToMany(cascade = CascadeType.ALL, mappedBy = "someID") private Collection<Customer> customerCollection; If fetch type is different from default, it is inserted in @ManyToOne and @OneToOne option for example: @OneToMany(cascade = CascadeType.ALL, mappedBy = "film", fetch = FetchType.EAGER) @ManyToOne(optional = false, fetch = FetchType.LAZY)
- "Related tables - java.util.List"
- "If necessary create new simple web aplication with Persistent Unit and connection to MySQL database"
- "Right click project name | New | Other | choose Persistence - Entity Classes from Database and click next"
- "Select Data Source: from Drop down jdbc/sakila "
- "Make sure Include Related Tables button is checked"
- "Add any table which is related to other tables(customer) and click next"
- "Choose web package and click next"
- "Choose Association Fetch: Default"
- "Java files corresponding to table names are created"
- "Build project is successful"
- "Repeat for all Association Fetch types"
- EXPECTED RESULT: "Build project is successful. List is used to create related tables.
Java files contains this code "
Java file with main table contains in class definition: @ManyToOne(optional = false) Other java files with related tables contains in class definition: @OneToMany(cascade = CascadeType.ALL, mappedBy = "someID") private List<Customer> customerCollection; If fetch type is different from default, it is inserted in @ManyToOne and @OneToOne option for example: @OneToMany(cascade = CascadeType.ALL, mappedBy = "film", fetch = FetchType.EAGER) @ManyToOne(optional = false, fetch = FetchType.LAZY)
- "Related tables - java.util.Set"
- "If necessary create new simple web aplication with Persistent Unit and connection to MySQL database"
- "Right click project name | New | Other | choose Persistence - Entity Classes from Database and click next"
- "Select Data Source: from Drop down jdbc/sakila "
- "Make sure Include Related Tables button is checked"
- "Add any table which is related to other tables(customer) and click next"
- "Choose web package and click next"
- "Choose Association Fetch: Default"
- "Java files corresponding to table names are created"
- "Build project is successful"
- "Repeat for all Association Fetch types"
- EXPECTED RESULT: "Build project is successful. Set is used to create related tables.
Java file with main table contains in class definition: @ManyToOne(optional = false) Other java files with related tables contains in class definition: @OneToMany(cascade = CascadeType.ALL, mappedBy = "someID") private Set<Customer> customerCollection; If fetch type is different from default, it is inserted in @ManyToOne and @OneToOne option for example: @OneToMany(cascade = CascadeType.ALL, mappedBy = "film", fetch = FetchType.EAGER) @ManyToOne(optional = false, fetch = FetchType.LAZY)
Test suite: "New Entity Class from Database - Database table wizard window "
Purpose: "Verification of adding removing related tables "
Setup: "Create Simple web application, create Persistent Unit with connection to MySQL database. Add New Entity Class from Database and navigate to Database tables step in wizard"
- "Remove not related table"
- "Add any table which is related to other tables"
- "Other related tables are added to Selected Tables"
- "Select previously selected table and click remove"
- EXPECTED RESULT: "All tables are removed from Selected Tables"
- "Removing related table"
- "Add any table which is related to other tables"
- "Other related tables are added to Selected Tables"
- "Select any related table and try click remove button"
- EXPECTED RESULT: "Removed button is disabled. No tables are removed"
- "Add all button"
- "Click Add All button"
- EXPECTED RESULT: "All tables are added to Selected Tables"
- "Remove all button"
- "Click Add All button"
- "Click Remove All button"
- EXPECTED RESULT: "All tables are removed from Selected Tables to Available tables"
- "Checked box Generate Named query Annotations for Persistent Fields"
- "Add any not related table into Selected tables and click next "
- "Make sure - Generated Named Query Annotations for Persistent Fields check box is checked"
- "Click Finish"
- "Open new generated file"
- EXPECTED RESULT: "NamedQueries are generated in a java file"
Source file contains similar code:
@NamedQueries({@NamedQuery(name = "Address.findAll", query = "SELECT a FROM Address a");
- "Unchecked box Generate Named query Annotations for Persistent Fields"
- "Add any not related table into Selected tables and click next "
- "Make sure - Generated Named Query Annotations for Persistent Fields check box is unchecked"
- "Click Finish"
- "Open new generated file"
- EXPECTED RESULT: "No NamedQueries are generated in a java file"
Source file does not contains similar code:
@NamedQueries({@NamedQuery(name = "Address.findAll", query = "SELECT a FROM Address a");
- "Fully Qualified Database Table Names - checked"
- "Add any table which is related to other tables"
- "Navigate to step - Mapping Options"
- "Check Fully Qualified Database Table Names and click Finish"
- EXPECTED RESULT: "Database Table name is generated in a source file"
Example of generated Table name and other attributes in the header of the file: @Entity @Table(name = "actor", catalog = "sakila", schema = "")
- "Attributes for Regenerating Tables - checked"
- "Add any table which is related to other tables"
- "Navigate to step - Mapping Options"
- "Check Attributes for Regenerating Tables check box"
- "Uncheck Fully Qualified Database Table Names check box and click Finish"
- EXPECTED RESULT: "Attributes for Regenerating Table are generated in a source file"
Example of generated attributes in the header of the file: @Entity @Table(name = "country")

