TS 61 PersistenceUnit

Test Specification for Persistence Unit

Author: Radim Roska, Jan Horvath
Estimated time: 2 hours
Default IZ component(s): j2ee/persistence
Version: 1.2
Last update: 2008/05/13


Contents


Test suite: Persistence Unit in EJB Module

Purpose: Test creating of persistence unit and persistence.xml editor Setup: Registered Java EE 5 compliant application server. Created/opened EJB project.

  1. Create Persistence Unit
    1. File - New File - Persistence - Persistence Unit
    2. Select persistence library - default is toplink.
    3. Select database connection (e.g. some of sample database)
    4. Select Table Generation Strategy
    5. Finish
    • EXPECTED RESULT: persistence.xml is created and accessible in Configuration Files. Persistence Unit is opened in editor, when you open xml view you will see something like this

<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">

 <persistence-unit name="EJBModule1PU" transaction-type="JTA">
   <provider>oracle.toplink.essentials.PersistenceProvider</provider>
   <jta-data-source>jdbc/sample</jta-data-source>
   <properties>
     <property name="toplink.ddl-generation" value="create-tables"/>
   </properties>
 </persistence-unit>

</persistence>

  1. Modifying Persistence Unit
    1. Open persitence.xml
    2. Uncheck Include All Entity Classes in ... Module
    3. Add Class - list of Entity class is complete for this module. Added classes are written to the XML file (Check XML view)
    4. Change name of persitence unit.
    5. Switch to XML view and check that persistence unit element has correct name attribute.
    6. Change Persitence unit in design view and check changes modified XML file in XML view.
    7. Change XML file in XML view, save it and check design view for new changes.
    8. In design view add Persistence Unit - Add button in top-right corner.
    9. In XML view you can see new persitence unit element.
    10. Delete this new persistence unit in editor and check design view. In editor perform undo which will return persistence unit.
    11. Delete new persistence unit in Design view.
    12. Try to add new persistence unit with the same name as already existing persistence unit has.
    • EXPECTED RESULT: All modifications modify Persistence Unit correctly in both views. Its not possible to create Persistence Unit with non-unique name.


Test suite: Persistence Unit in Web Application

Purpose: Test PU in Web Application Setup: Registered Java EE 5 compliant application server. Created/opened Web project.

  1. Create Persistence Unit
    1. Perform step 1 of first test suit
    • EXPECTED RESULT: persistence.xml is created and accessible in Configuration Files. Persistence Unit is opened in editor


Test suite: Persistence Unit in Java Application

Purpose: Test PU in Java Application Setup: Registered Java EE 5 compliant application server. Created/opened Java application project.

  1. Create Persistence Unit
    1. Perform step 1 of first test suit
    • EXPECTED RESULT: persistence.xml is created and accessible in META-INF package. Persistence Unit is opened in editor


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