TS 71 HibernateSupport

Hibernate Support Test Specification for NetBeans 7.1

Author: Petr Dvorak, Jiri Skrivanek
Estimated time: 1 hour
Last update: 16-th November 2011
Introduction: This document contains procedures for testing Hibernate Support.
Requirements: Connection to sample database in Java DB is available in NetBeans.
Comments:

Contents


Test suite: Support in Java Web project

  1. Create new project with Hibernate Framework.
    1. Start new project wizard.
    2. Choose "Java Web|Web Application" and click Next
    3. Click Next once more to confirm default name and location
    4. Choose/Add GlassFish server and click Next
    5. Select Hibernate on Frameworks page
    6. Check database connection to sample database is selected
    7. Click Finish
    • EXPECTED RESULT: hibernate.cfg.xml file should be created in Source Packages/<default package>, file content should look like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
    <property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
    <property name="hibernate.connection.url">jdbc:derby://localhost:1527/sample</property>
    <property name="hibernate.connection.username">app</property>
    <property name="hibernate.connection.password">app</property>
  </session-factory>
</hibernate-configuration>

  1. Create new Project without Hibernate and add it using the Customizer.
    1. Create a new Web Project as in the previous test case but without Hibernate framework
    2. Right-click project node and open project Properties
    3. Go to Frameworks category
    4. Click Add, select Hibernate and click OK
    5. Click OK to save project properties
    • EXPECTED RESULT: hibernate.cfg.xml file should be created in Source Packages/<default package> content should look like the example above.

Test suite: Hibernate Wizards

  1. Create configuration file
    1. Open new file wizard
    2. Choose "Hibernate|Hibernate Configuration Wizard" and click Next
    3. Click Next to confirm name and location
    4. Click Finish to create configuration file with sample database
    5. Switch to the Design view
    6. Make some change in the JDBC part: change username, password
    7. Switch to the Source view and check whether the changes are propagated
    8. Repeat these steps for next parts of the Design view
    9. Save file and check changes in the History view
    10. Delete config file
    • EXPECTED RESULT: Design and Source views are consistent.
  2. Create mapping file
    1. Open new file wizard
    2. Choose "Hibernate|Hibernate Mapping Wizard" and click Next
    3. Click Next to confirm name and location. It should make a connection to database if we are not already connected
    4. Type class name to the "Class to Map" field (e.g. MyClass)
    5. Choose CUSTOMER database table from combo box
    6. Finish the wizard
    • EXPECTED RESULT: hibernate.hbm.xml is created.
  3. Create reverse engineering file
    1. Open new file wizard
    2. Choose "Hibernate|Hibernate Reverse Engineering Wizard" and click Next
    3. Browse for src/java folder and click Next
    4. Wizard should connect to database and populate available tables (bug 205183)
    5. Click "Add All" and finish the wizard
    • EXPECTED RESULT: hibernate.reveng.xml file is opened in editor with all tables mapping
  4. Create POJOs from database
    1. Open new file wizard
    2. Choose "Hibernate|Hibernate Mapping Files and POJOs from Database" and click Next
    3. Type arbitrary package name and finish the wizard
    4. Repeat the wizard with checked/unchecked JDK5 features, EJB3 annotations and other configurable options
    • EXPECTED RESULT: HBM files should be generated for every table (e.g. Customer.hbm.xml). Those files should contain property mapping as well as relationship mappings. POJOs should be generated for every table. This should be plain java class containing fields for every column (e.g. Customer.java). The hibernate.cfg.xml file should contain links to hibernate mapping files (e.g. <mapping resource="abc/Customer.hbm.xml"/>)
  5. Code completion in mapping file
    1. Open Customer.hbm.xml file
    2. After <hibernate-mapping> element type < and invoke code completion
    3. Check hibernate elements are offered starting with class element
    4. Try code completion at various places for hibernate elements and their attributes
    5. Put cursor at table="| and invoke code completion
    6. Check tables from database are listed
    7. Put cursor at <column name="| and invoke code completion
    8. Check columns from Customer table are listed
    9. Ctrl+click Customer class name
    10. Check Customer.java is opened and close it
    11. Ctrl+click customerId field
    12. Check Customer.java is opened and cursor stands at customerId field definition
    • EXPECTED RESULT: Code completion and hyper-linking work correctly.
  6. Create util file
    1. Open new file wizard
    2. Choose "Hibernate|HibernateUtil.java" and click Next
    3. Provide package name and click Finish
    • EXPECTED RESULT: Util class is created with getSessionFactory() method.

Test suite: HQL Editor

  1. HQL editor
    1. Deploy tested project
    2. Invoke "Run HQL Query" action from context menu on hibernate.cfg.xml
    3. Run a query "select c from Customer c"
    • EXPECTED RESULT: Result should be consistent with equivalent SQL query "select * from Customer".
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo