FeaturesPluginsDocs & SupportCommunityPartners

Sun ONE Studio Test tool i18n Guide

 

1. Introduction

1.1 Document Name

Sun ONE Studio Test tool i18n Guide

1.2 Author

Honza Firich Honza.Firich@sun.com

1.3 Name of Major Document Customer

Netbeans Base team – Prague, Czech Republic

 

2. Overview

Netbeans Base team in Prague uses automated tests for Netbeans/Sun ONE studio English versions QA.
These tests can be used in Sun ONE studio other language versions as well.

This document describes how to achieve it.

 

3. Test Cases Development

3.1 What and why needs to be done

All tests should be internationalized to be able to work in an international environment as well as in English environment.

3.1 Current approach

If someone needs to internationalize a test, he needs to internationalize the test himself.
I.e. he needs to take a test what it tested in English environment only and has a lot of strings usually hard-coded and replate all hardcoded strings by resource bundles then.
This process is rather slow and has to be done each time anyone needs execute a test in an international environment.

3.2 How to make i18n process faster

In the future internationalization could be done during test cases development by Netbeans team.
Prauge QA team could write tests internationalized from the beginning.
Once a test is developed anyone else who wants to run the test in an international environment can use the test without any additional work.

 

4. Internationalization

4.1 What needs to be done to internationalize a test case

If you write a test case for Netbeans/Sun ONE studio, all UI strings should be taken from resource bundles.
If you do not take a string from a bundle, the test will not be able to work in Japanese environment.

4.1.1 IDE execution

You need to execute IDE with the switches:

     -nosplash
     -J-Dorg.openide.util.NbBundle.DEBUG=true
e.g.:
     /f4j/bin/runide.sh -userdir /f4j_bundles -nosplash -J-Dorg.openide.util.NbBundle.DEBUG=true

These switches will display IDE with bundle ID's at every string what is taken from a bundle.
It also displays bundle numbers in a terminal. Please see the following pictures:


Picture 1 – Sun ONE studio with bundle ID's



Picture 2 – Resource bundles ID's in a terminal


4.1.2 How to find the name of a bundle

E.g. you want to know, what bundle is string File (from File menu – see Picture 1) taken from.

You can see, that there is File (1:517).

It means, that it is bundle number 1, line 517.
You need to check the terminal for number 1.

You can see, that there is the following line in the terminal (see Picture 2):

     NbBundle trace: #1 = org/netbeans/core/Bundle.properties

It means, that you are looking for Bundle.properties in org.netbeans.core

This bundle is in core.jar file, which is in Sun ONE Studio /lib directory.

You need to mount this jar file to reach Bundle.properties file or edit the file in any editor.


4.1.3 How to find the key from a bundle

Number 517 at File (1:517) string means, that it is key at line number 517.

At this line in bundle org.netbeans.core.Bundle.properties you can find:

     Menu/File=&File

So, the key from the bundle is: Menu/File

 

4.2 How to change test source code

All hard-coded UI strings should be replaced by using resource bundles.
Please see the following example.

Example: Click on File menu.

Code before i18n:

     new Action("File", null).perform();

Code after i18n:

     new Action(Bundle.getStringTrimmed("org.netbeans.core.Bundle","Menu/File"), null).perform();


You can see, that there is used method getStringTrimmed() from org.netbeans.jellytools.Bundle class.

Usually it is enough to use getString() method.
But at this example is used method getStringTrimmed(), because it trims & at &File string, what is necessary to reach the menu.

 

4.3 Jemmy support module

4.3.1 Description

You can utilize Resource Bundle Lookup from Jemmysupport module developed by Adam Sotona.
This tool looks into mounted resource bundles and helps you develop internationalized source code.

You need to have mounted jar file which contains resource bundle you are looking for.
But if you develop a test case for a module, usually a lot of strings are taken from bundles what are part of one jar file.
So it should not be a problem to have mounted all necessary jar file(s) while creating its module tests.


4.3.2 Where to get jemmysupport module from

Please find jemmysuport module webpage at: http://jemmysupport.netbeans.org

You can download jemmysupport.nbm using autoupdate from Sun ONE Studio IDE as well.


4.3.3 Jemmysuport usage example

You want to get piece of source code which gets string File from org.netbeans.core Bundle (see example in chapter 4.2).

You need to have mounted core.jar file.

Run Resource Bundle Lookup (click on Resource Bundle Lookup icon )

Put string &File into Searched text field.

Click on Search.

In the Search Results window you can see founded string.


Picture 3 – Resource Bundle Lookup - Founded string

Click on the string (select it – the string color will change) and right click on the string.

The following menu appears:


Picture 4 – List of possible source code

Click on the last item:

     Copy: org.netbeans.jellytools.Bundle.getStringTrimmed(“org.netbeans.core.Bundle”, “Menu/File”)

This will copy the part of source code into clipboard. You can easily paste it into your source code then.

 

5. Examples

Example 1

You need to invoke e.g. New Wizard.

You need to click File, New.

How to find bundle and key for File, please see 4.1.2.

You can see at Picture 1 that string New... contains (59:147) bundle and key location string.

From the terminal you can find 59:

     NbBundle trace: #59 = org/netbeans/core/actions/Bundle.properties
which means Bundle.properties file from core.jar file, folder actions.

When you edit this file, you can find the following string at line 147:

     NewTemplate=&New...
So, the key is: NewTemplate

Hard-coded code:

     new Action("File" + "|" + "New", null).perform();
Possible approach of an internationalized code:

     String fileItem = Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Menu/File");
     String newItem = Bundle.getStringTrimmed("org.netbeans.core.actions.Bundle", "NewTemplate");
     new Action(fileItem + "|" + newItem, null).perform();


Example 2

Sometimes occurs the following situation (this work on SDI only):

You need to take a string from a bundle, but the key look like the following:

     CTL_FMT_LocalProperties={0,choice,0#No Properties|1#Properties of {1}|2#Properties of Multiple Objects}
You want to check string No Properties in Properties window (String is displayed as: No Properties 1:254)

bundle 1: org.netbeans.core.Bundle.properties
line 254: CTL_FMT_LocalProperties={0,choice,0#No Properties|1#Properties of {1}|2#Properties of Multiple Objects}

String No Properties is taken from bundle org.netbeans.core.Bundle, key is CTL_FMT_LocalProperties.


You need to add e.g. the following code to get string No Properties:

     String noPropertiesTitle = Bundle.getString("org.netbeans.core.Bundle","CTL_FMT_LocalProperties", new Integer[] {new Integer(0)});

Output of

     System.out.println(noPropertiesTitle);
is: No Properties


If you take the string from the bundle using the following:

     String noPropertiesTitle = Bundle.getString("org.netbeans.core.Bundle", "CTL_FMT_LocalProperties");
the output is:
     {0,choice,0#No Properties|1#Properties of {1}|2#Properties of Multiple Objects}


Example 3

You need to check if new project was opened. (Run Project Manager and Create New Project).

You want to check message: Project NewProject opened.

In IDE is: Project NewProject opened. (12:41)

bundle 12: org.netbeans.modules.projects.Bundle.properties
line 41: MSG_OpenProjectDone=Project {0} opened.

String NewProject is displayed at Create New Project Dialog as: NewProject (12:60)

bundle 12: org.netbeans.modules.projects.Bundle.properties
line 60: FMT_NewProjectName=NewProject

This string needs to be created e.g. the following way:

     String projectName = Bundle.getString("org.netbeans.modules.projects.Bundle", "FMT_NewProjectName");
     String projectOpened = Bundle.getString("org.netbeans.modules.projects.Bundle", "MSG_OpenProjectDone", new String[] {projectName});


Example 4

You need to e.g. check status of a source code compilation.

Name of this code is not taken from a bundle, e.g. ColorPicker from Sun ONE Studio examples.

When you compile it, you wait for status: Finished ColorPicker.

In IDE is: Finished ColorPicker (25:84). (74:41)
bundle 25: org.openide.compiler.Bundle.properties line 84: FMT_Compile={0,choice,0#no objects|1#{1}|2#two objects|3#{0}objects}

bundle 74: org.netbeans.core.compiler.Bundle.properties
line 41: MSG_CompilationSuccessful=Finished{1,choice,0#.|1# {0}.}

This string needs to be created e.g. the following way:

     Object[] param = {"ColorPicker", new Integer(1)};
     String finishedLabel = Bundle.getString("org.netbeans.core.compiler.Bundle", "MSG_CompilationSuccessful", param);

Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Virtual Box - full virtualizer  Open ESB - The Open Enterprise Service Bus Powered by