TS 72 JPA Support

JPA Support Test Specification for NetBeans 7.2

Author: Vladimir Riha
Last update: 30th March 2012
Introduction: Test specification for JPA support in NetBeans 7.2

Contents


JPA Support Test Specification

Test suite: JPQL validation

Prerequisite: Created and opened Java EE sample project called JSF JPA CRUD

  1. Invalid identifier
    1. Open Customer.java file in Source Packages/jpa.entities
    2. Pick some @NamedQuery annotation and change SELECT to invalid value (see example below)
    • EXPECTED RESULT New warning hint is showed on the line with class definition with text containing text 'The query does not start with a valid identifier, has to be either SELECT...'
    @NamedQuery(name = "Customer.findAll", query = "SELECT c FROM Customer c"),

to

    @NamedQuery(name = "Customer.findAll", query = "SLECT c FROM Customer c"),


  1. Invalid schema type
    1. Open Customer.java file in Source Packages/jpa.entities
    2. Pick some @NamedQuery annotation and change Customer to invalid value (see example below)
    • EXPECTED RESULT New warning hint is showed on the line with class definition with text containing text 'The abstract schema Cstumer is unknown'
    @NamedQuery(name = "Customer.findAll", query = "SELECT c FROM Customer c"),

to

    @NamedQuery(name = "Customer.findAll", query = "SELECT c FROM Cstomer c"),


  1. Invalid type
    1. Open Customer.java file in Source Packages/jpa.entities
    2. Pick some @NamedQuery annotation and change SELECT to invalid value (see example below)
    • EXPECTED RESULT New warning hint is showed on the line with class definition with text containing text 'The state field path c.zips cannot be resolved'
    @NamedQuery(name = "Customer.findByZip", query = "SELECT c FROM Customer c WHERE c.zip = :zip"),

to

   @NamedQuery(name = "Customer.findByZip", query = "SELECT c FROM Customer c WHERE c.zips = :zip"),


  1. Invalid type - resolved
    1. Use the invalid annotation from previous case
    2. Refactor|Rename the zip field to zips
    • EXPECTED RESULT The warning hint 'The state field path c.zips cannot be resolved' disappears


Test suite: JPQL completion

Prerequisite: Created and opened Java EE sample project called JSF JPA CRUD

  1. Identifier Completion in @NamedQuery
    1. Open Customer.java file in Source Packages/jpa.entities
    2. Add following @NamedQuery into the @NamedQueries
    3. Invoke CC at the place of "|"
    • EXPECTED RESULT SELECT, DELETE and UPDATE items are offered
@NamedQuery(name = "Customer.findSome", query = "|"),


  1. Matching Identifier Completion in @NamedQuery
    1. Open Customer.java file in Source Packages/jpa.entities
    2. Find the @NamedQuery showed below and invoke code completion at the place of "|"
    • EXPECTED RESULT Only SELECT is offered
    @NamedQuery(name = "Customer.findAll", query = "S|ELECT c FROM Customer c"),


  1. Schema Completion in @NamedQuery
    1. Open Customer.java file in Source Packages/jpa.entities
    2. Find the @NamedQuery showed below and invoke code completion at the place of "|"
    3. List of defined schemas is offered as shown on the screenshot below
    4. Move cursor to the right (using arrow button)
    • EXPECTED RESULT List was reduced and contains only Custom schema.
    @NamedQuery(name = "Customer.findAll", query = "SELECT c FROM |Customer c"),

File:TS_72_JPA_Support_Jpanq.png


  1. Schema Property Completion in @NamedQuery
    1. Open Customer.java file in Source Packages/jpa.entities
    2. Find the @NamedQuery showed below and invoke code completion at the place of "|"
    3. Defined fields like name, state or city are offered
    4. Type "c"
    • EXPECTED RESULT List was reduced and contains only 3 items: city, customerId and creditLimit.
    @NamedQuery(name = "Customer.findByZip", query = "SELECT c FROM Customer c WHERE c.|zips = :zip"),


  1. Identifier Completion in createQuery()
    1. Open CustomerJpaController.java file in Source Packages/jpa.controllers and find function findCustomerEntities()
    2. Modified line with Query q = em. to look like shown below
    3. Invoke CC at the place of "|"
    • EXPECTED RESULT Items like AVG, ABS, CONCAT are offered
    Query q = em.createQuery("select object(o) from Customer as o WHERE |");


  1. Matching Identifier Completion in createQuery()
    1. Open CustomerJpaController.java file in Source Packages/jpa.controllers and find function findCustomerEntities()
    2. Modified line with Query q = em. to look like shown below
    3. Invoke CC at the place of "|"
    • EXPECTED RESULT Only items starting with A are offered
    Query q = em.createQuery("select object(o) from Customer as o WHERE A|");


  1. Schema Completion in createQuery()
    1. Open CustomerJpaController.java file in Source Packages/jpa.controllers and find function findCustomerEntities()
    2. Modified line with Query q = em. to look like shown below
    3. Invoke CC at the place of "|"
    4. List of defined schemas is offered
    5. Type 'M'
    • EXPECTED RESULT List was reduced and contains only schemas that start with M.
   Query q = em.createQuery("select object(o) from |");


  1. Schema Property Completion in createQuery()
    1. Open CustomerJpaController.java file in Source Packages/jpa.controllers and find function findCustomerEntities()
    2. Modified line with Query q = em. to look like shown below
    3. Invoke CC at the place of "|"
    4. Defined fields like name, state or city are offered
    5. Type "c"
    • EXPECTED RESULT List was reduced and contains only 3 items: city, customerId and creditLimit.
   Query q = em.createQuery("select object(o) from Customer c WHERE c.|");


Test suite: Linked to named query

Prerequisite: Created and opened Java EE sample project called JSF JPA CRUD

  1. Identifier Completion in @NamedQuery
    1. Open CustomerJpaController.java file in Source Packages/jpa.controllers and find function findCustomerEntities()
    2. Paste code below at the beginning of the function
    3. Invoke CC at the place of "|"
    4. List of all named queries is among offered items
    5. Pick one and confirm by hitting Enter
    6. While pressing Ctrl move cursor over the inserted named query
    • EXPECTED RESULT Query in JPQL is show in the tooltip similarly to screenshot below. Click on it and you should be moved to the Customer.java to the place where the query is defined
EntityManager eman = getEntityManager();
eman.createNamedQuery("|");

File:Linknamedqueryname.png


Test suite: Completion in persistence.xml

Note: Main support is provided for eclipselink jpa 2.0 provider

Prerequisite: Created and opened Java EE sample project called JSF JPA CRUD

  1. Identifier Completion in persistence.xml
    1. Open persistence.xml
    2. Replace the empty <properties/> element with code below
    3. Invoke CC at the place of "|"
    4. List of all properties is offered
    5. Select eclipselink.cache.type.default
    6. Invoke code completion for the value of attribute value
    • EXPECTED RESULT Items Full, HardWeak, None, Soft, SoftWeak, Weak are offered
    <properties>
        <property name="|" value=""></property>
    </properties>


  1. JDBC Url Value Completion in persistence.xml
    1. Use the persistence.xml from previous case
    2. Insert another property (code below)
    3. Invoke CC at the place of "|"
    • EXPECTED RESULT List of all connections is offered similar to the image below
    <property name="javax.persistence.jdbc.url" value="|"></property>

File:Pucompletionjdbcconnection.png


  1. <class> Completion in persistence.xml
    1. Use the persistence.xml from previous case
    2. Paste class element (code below) into the <persistence-unit> element
    3. Invoke CC at the place of "|"
    • EXPECTED RESULT List of all classes (jpa.entities.Customer etc.) in jpa.entities is offered. Type "jpa.entities.C" and the list should reduce to match the typed text
<class>|</class>


  1. <provider> Completion in persistence.xml
    1. Use the persistence.xml from previous case
    2. Paste provider element (code below) into the <persistence-unit> element
    3. Invoke CC at the place of "|"
    • EXPECTED RESULT List of available providers is offered (e.g. org.hibernate.ejb.HibernatePersistence)
<provider>|</provider>


  1. <jta-data-source> Completion in persistence.xml
    1. Use the persistence.xml from previous case
    2. Paste jta-data-source element (code below) into the <persistence-unit> element
    3. Invoke CC at the place of "|"
    • EXPECTED RESULT List of available data sources is offered (e.g. jdbc/sample)
<jta-data-source>|</jta-data-source>


  1. <exclude-unlisted-classes> Completion in persistence.xml
    1. Use the persistence.xml from previous case
    2. Paste exclude-unlisted-classes element (code below) into the <persistence-unit> element
    3. Invoke CC at the place of "|"
    • EXPECTED RESULT False and True are offered
<exclude-unlisted-classes>|</exclude-unlisted-classes>
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