Persistence Editor Support Test Specification
Author: Jindrich Sedek
Version: 1.3
Last update: 2006/07/19
Introduction:
This test specification is focused on testing EJB support in Java editor which features code verification, error highlighting, hints or code completion of persistence annotations.
Comment:
Please note that execution of the following tests requires GlassFish application server installed on your computer.
Table of Contents
|
Purpose: This test suite checks that error highlighting and annotations work correctly.
Setup:
No special setup is required for this test suite. Just follow all the test cases stated below.
| # | Test case | Description |
| 1 | Register application server |
-
Download latest milestone build of GlassFish application server.
-
Unzip it by
java -Xmx256m -jar filename.jar command and install by ant -f setup.xml command.
- Launch NetBeans 5.5 and switch to Runtime tab.
- Right click Servers node and select Add Server... from popup menu.
-
Setup
GlassFish Application Server as Name and push Next button.
-
Use Browse... to point to GlassFish installation directory and press Finish.
|
|
| RESULT: |
GlassFish Application Server node shows up under Servers node. |  |
|
|
|
test / AppServerTest.java ; testWaitAppServerInstall()
|
|
| 2 | Create EJB module |
- Invoke File|New Project... from main menu.
-
Select Enterprise category and EJB Module project type. Push Next > button.
-
Make sure GlassFish Application Server is selected and push Finish button.
|
|
| RESULT: |
| New EJBModule1 project node shows up in Projects tab. |  |
|
|
|
test / J2eeProjectsTest.java ; testCreateEjbProject()
|
|
| 3 | Create entity |
- Invoke File|New File... from main menu.
-
Select Persistence category and Entity Class file type. Push Next > button.
-
Type
test into Package field. A warning about a missing persistence unit is displayed: There is no persistence unit in the project yet. You need a persistence unit... Push Create Persistence Unit... button.
- Push Create button. Then push Finish button.
|
|
| RESULT: |
| New entity class gets created under Source Packages together with specified package. |  |
|
|
|
test / NewFileWizardsTest.java ; testLocalEntityBean()
|
|
| 4 | No ID defined |
- Delete line 25 with
@Id statement.
|
|
| RESULT: |
NewEntity at line 23 gets underlined because of No ID specfied for this hierarchy error. Besides, red rectangle symbol appears instead of the line number. Move your mouse to that identifier and There is no ID defined for this entity hierarchy message shows up. |  |
At line 26 should be underlined expression @GeneratedValue(strategy = GenerationType.AUTO) with yellow color. |
In addition to that both errors must be marked in an error stripe using the appropriate color. Error stripes must work and correspond with locations of errors and warnings in the source.
|
|
| 5 | Duplicate annotation error |
-
Move to line 24, create new line there and type
@Entity.
|
|
| RESULT: |
|
Error message duplicate annotation should be shown up.
|
|
|
|
|
|
Purpose:
This test suite checks that error hints work correctly suggesting appropriate solutions to make user code EJB compliant.
Setup:
No special setup is required for this test suite. Just follow all the test cases stated below.
| # | Test case | Description |
| 1 | Create entity ID |
-
>Set cursor at position 23:14 i.e.
|NewEntity. Small hint shows up.
-
Press ALT+Enter to display Create Entity ID... hint. Press Enter. |  |
-
In the next Create Entity ID dialog don't change anything, just push OK button.
|
|
| RESULT: |
Two public methods getId() and setId() were added.
|
|
|
test / EntityRelations.java ; testCreateID()
|
|
| 2 | Make public |
- Delete world
public on line 24.
-
|
Error message Class is not public should be announced and hint bulb should be shown.
|
|
- Press Alt+Enter to invoke hint a press Enter to apply it.
|
|
| RESULT: |
Word public should be added before class definition.
|
|
| 3 | Encapsulate field |
-
Add these two lines below the declaration of
id field:
@PersistenceContext()
private Integer age;
-
Set the cursor at position 29:5 at the start of
|@PersistenceContext()
and press ALT+Enter.
-
Select
Add import for javax.persistence.PersistenceContext hint and press Enter.
-
Put mouse cursor to the position 31:21. Click on the menu Refactoring|Encapsulate Fields. Press Next > button. Check the proposed changes. In case of the correct proposal press Do Refactoring button.
|
|
| RESULT: |
Two public methods getAge() and setAge() get added.
|
|
|
|
Purpose: This test suite checks that code completion of persistence annotations works.
Setup:
No special setup is required for this test suite. Just follow all the test cases stated below.
| # | Test case | Description |
| 1 | Annotations |
-
Right click test package node and choose New|Java Class... from popup menu.
- In the next New Java Class wizard just push Finish button.
-
Create new line at line 16 above a class declaration and type
@ character. Press CTRL+Space.
-
Code completion offers all available annotations. Type
Em characters.
-
Suggestions get reduced to only three items. Javadoc window shows online documentation for the selected item. Select the first one and press Enter.
-
The word
NewClass gets underlined with yellow because of missing implementation. Put the cursor on the line 19 and press Alt+Enter. Select the proposed hint.
|
|
| RESULT: |
The code is completed to @Embeddable, the class has a definition to implement java.io.Serializable and import javax.persistence.Embeddable; statement gets added to imports section.
|
|
|
test / TestAdvancedAnnotation.java
|
|
| 2 | Attributes |
- Press End and Enter to create new line 19.
-
Type
@Ba and press CTRL+Space. Instant substitution autocompletes it to @Basic(|) and adds appropriate import statement.
-
Press CTRL+Space. Code completion suggests two attributes fetch and optional. |  |
-
Type
op characters. The list is reduced to one item optional.
-
Press ESC to close code completion window and then CTRL+Space again.
|
|
| RESULT: |
Instant substitution completes the statement to @Basic(optional=).
|
|
|
test / TestAdvancedAnnotation.java
|
|
| 3 | Values |
-
Having
@Basic(optional=|) in editor press CTRL+Space.
-
Code completion window displays
true and false. Select the former and press Enter.
-
The statement is completed to
@Basic(optional=true) and underlined with red line.
-
Press CTRL+Z 3 times to undo completion of both attribute and value. Press CTRL+Space and press Enter.
-
Having @Basic(fetch=|) in editor press CTRL+Space. EAGER and LAZY fetch types are suggested. |  |
-
Type
l character. List of possibilities is reduced to items starting with L. Press Enter.
|
|
| RESULT: |
Now you have @Basic(fetch=FetchType.LAZY) in editor still underlined. Check whether the position of the error in the source correspond with the position of the error stripe on the right. Besides valid import javax.persistence.FetchType; statement was added automatically in the code above.
|
|
|
test / TestBasicAnnotation.java
|
|
| 4 | Tables |
- Invoke File|New File... from main menu.
-
Select Persistence category and Persistence Unit file type. Change the name of the persistence unit to
secondPersistence. Push Next >, then Finish buttons.
-
Push XML button in editor toolbar and replace generated content of persistence.xml file by this version.
-
Switch to NewClass.java, erase content on line 21 and type a new one
@Table(name=|
- With cursor at position 22:13 denoted by
| press CTRL+Space.
-
Select Connect To Database and press Enter. Afterwards repeat step 5. Code completion offers all tables from the connected Derby database. Select PRODUCT item and press Enter. |  |
|
|
| RESULT: |
Auto completion expands the statement to @Table(name="PRODUCT").
|
|
|
test / TestDBCompletion.java
|
|
| 5 | Columns |
-
Switch to NewEntity.java file and insert new line
@Table(name="PRODUCT") between @Entity and class definition. Press Alt+Shift+F to fix imports.
-
Right click test node and invoke New|Entity Class... from popup menu.
-
Type
Test into Class Name and push Finish button.
- Add three lines below declaration of
id field:
-
@ManyToOne()
@JoinColumn()
private Set<NewEntity> s;
Press Alt+Shift+F to fix imports. Set cursor at position 32:17 denoted by | character i.e. @JoinColumn(|) and press CTRL+Space. Type character n and press Enter. n gets expanded to name=. Then invoke Code Completion once more and it suggests all columns of the PRODUCT table. Select PRODUCT.DESCRIPTION item and press Enter. |  |
|
|
| RESULT: |
The code gets expanded to @JoinColumn(name="DESCRIPTION") statement.
|
|
|
test / TestDBCompletion.java
|
|
|
|
Purpose:
This test suit checks that it's possible to create entity classes and generate relations.
Setup: No preparation is necessary for this test suite .
| # | Test case | Description |
| 1 | Creating Entity Classes |
- Invoke Menu|New File/Folder... from main menu.
- Choose Entity Class file type from Persistence Category.
- Set A as Class Name, Entity as Package.
-
Repeat steps 1,2,3 once more, but change the Class Name to B in step 3.
|
|
| RESULT: |
|
Files A.java and B.java should be created in the Entity package.
|
|
|
|
test / NewFileWizardsTest.java ; TestEntityClassInEjb()
test / NewProjectWizardsTest.java ; testNewEJBModWizard()
|
|
| 2 | Entity Code generating |
-
Open B.java file and type
A a; to the line number 24.
-
In two seconds a yellow square will by painted instaid of line number. Move your mouse cursor over this square.
-
|
The message entity relation not defined will be shown.
|
|
- Set your cursor to 24:9 and press Alt+Enter to display a hint.
-
Choose Create "ManyToOne" relationship... and press OK in the displayed dialog.
|
|
| RESULT: |
New annotation @ManyToOne should be added above A a; and javax.persistence.ManyToOne should be added to imports.
|
|
In A.java two lines of code should be added and javax.persistence.OneToMany should be added to imports.
|
|
|
|
|
test / EntityRelations.java
|
|
|
Generated: 2006 11 07 06:52