Skip to main content
Jump to: navigation, search

OSEE/Developer Guidelines

Revision as of 20:31, 4 October 2013 by (Talk | contribs) (Java Development)

Before Committing Code

  1. Synchronize and Update
  2. Run Code Quality Checks
  3. Ensure all the tests are green. (Tests projects can be identified by their '*.test' suffix. All tests have to be executed as plug-in unit tests.)
  4. Ensure the reference documentation is up to date (i.e. reflects your changes) (Documentation is maintained in project 'via the OSEE wiki').

Code Quality Tools

Update your eclipse installation with the following tools:

Installation for Find Bugs, PMD, Emma, and Check Style:

  1. Launch Eclipse and go to Help->Software Updates->Available Software
  2. Drag the Update Site URLs into the Software Update and Add-ons dialog
  3. Select code style tools to install - for Find Bugs make sure you only select the Eclipse 3.4 or later entry
  4. Click the Install button
  5. Once installation completes, restart eclipse

Code Quality Configuration

Import OSEE Team Preferences

  1. Right-click on the following link OSEE Team Preferences
  2. Select Save Link As
  3. Enter osee_team_preferences.epf and click Save
  4. Launch Eclipse
  5. Select File->Import
  6. Open the General folder
  7. Select Preferences
  8. Click on the Browse... button, navigate to the location where you saved osee_team_preferences.epf
  9. Select Import all
  10. Click Finish to import settings

Check Style Configuration

  1. Select Window->Preferences
  2. Select Checkstyle
  3. Under the General Settings set Rebuild projects if needed to always
  4. Under the Global Check Configurations, click the New button
  5. Select Remote Configuration under the Type drop down
  6. Set name to OSEE Checks (Eclipse)
  7. Copy the following link into the Location entry OSEE Checks (Eclipse)
  8. Set the Cache configuration file checkbox to true
  9. Click OK
  10. Select the OSEE Checks (Eclipse) configuration and click on Set as Default
  11. Click OK to accept settings

Find Bugs Configuration

  1. Select Window->Preferences->Java
  2. Select Find Bugs
  3. Set analysis effort to Default
  4. Click OK to accept settings

PMD Configuration

  1. Right-click on the following link OSEE PMD Rule Set
  2. Select Save Link As
  3. Enter osee_pmd_rule_set.xml and click Save
  4. In Eclipse, select Window->Preferences
  5. Select PMD->Rules Configuration
  6. Click on Import rule set...
  7. Click on Browse, navigate to the location where you saved osee_pmd_rule_set.xml
  8. Set the Import by Copy check box to true
  9. Select OK to import the rule set
  10. Select OK to accept the change and close the Preferences Dialog

Monitor OSEE Bugs using Mylyn

See Integrating OSEE and Bugzilla.

Coding Standards


  1. Redundant modifiers on interface method declarations

Chapter 9.4 of the Java Language Specification states: It is permitted, but discouraged as a matter of style, to redundantly specify the public and/or abstract modifier for a method declared in an interface.

Utility Classes

In order to optimize reuse of code, OSEE developers have adopted a set of standards.

Utility classes should:

  1. Be named xxxUtil. This allows for each searching and location by looking for *Util. This excludes stand-alone utility classes like HashCollection or CountingMap.
  2. As much as possible, be located in a package postfix'd with .util. eg. org.eclipse.osee.ats.util
  3. Should contain static methods

Cleanup of existing utility methods

The following needs to be done:

  1. Create set of common utility class names
  2. Move utilities to their respective places
  3. Either deprecate or replace uses of old locations


Most comments offer more clutter than information, especially non-Javadoc comments which can be removed using the following regular expression \R[ \t]*/\*\s+[\* ]*\(non-Javadoc\)[^/]+/.

Regular Expression Find/Replace application of standards

  • ([^ ]+) != null && !(\1).equals\(""\) replace with Strings.isValid($1)
  • ([^ ]+) == null \|\| (\1).equals\(""\) replace with !Strings.isValid($1)

REST API Documentation

Jersey and Javadoc supported tags in the code are processed during the maven compile phase to create an enhanced application.wadl file. The enhancements include extra documentation pulled from the source. The following set of tags should be used so a consistant set of documentation is available for all REST interfaces.

Jersey Tags

  1. Every class implementing REST methods should use an @Path tag even if the paths is empty (e.g. @Path("") ).
  2. All parameters should be tagged with the appropriate @xxxParam tag (e.g. @PathParam, @QueryParam, etc.).
  3. The @Consumes tag should be used as appropriate for methods that take in data.
  4. The @Produces tag should be used as appropriate for methods returning information.

Javadoc Tags

  1. Use the '@param name description' for every parameter in the method. The 'name' needs to match the method paramater name
  2. Use the '@return description' as appropriate

The Jersey wadl generator supports additional tags for documenting request and response information.

  1. Use the ' description' for all valid responses from the method
  2. Use the ' type' when the media type is different than specified in @Produces


public class TakeAREST {
	 * Find a great RESTing place for your resources
	 * @param place The ideal spot to look for RESTing
	 * @return The best RESTing spot available
	 * @response.representation.200.doc found the spot for you
         * @response.representation.503.doc RESTing places are currently unavailable.  Try again later.
	@Produces({"application/xml", "application/json"})
	public String getPlaceToREST(@QueryParam("place") String place) {
		return "RESTing Place";
	 * Store a RESTing spot for others to find and use
	 * @param spot Just a good spot for RESTing
	 * @return Acknowledging the location of the RESTing spot
	 * @response.representation.200.doc This is a good spot
	 * @response.representation.404.doc Wasn't able to create the shared RESTing spot
	 * @response.representation.404.mediaType plain/txt
	public RestReturn createRESTingSpot(@PathParam("spot") String spot) {
		RestReturn myRet = new RestReturn();
		myRet.setName("A Great Name");
		return myRet;

OSEE Master Test Suite

OSEE uses JUnit 4 for its test suites. Some links to get started:

Use Cases

Requirements of the OSEE test suite:

  1. Single button press to run all tests
  2. Minimal number of launch configurations to maintain
  3. Ability for any user, internal or external, to easily run a suite of tests before commit
  4. Continuous integration (checkout, build, test, report)
  5. Use JUnit framework for all testing
  6. Enable health checks against production database to be part of test suite
  7. New test cases can be added easily

Running the OSEE Test Suite

The OSEE test suite uses the org.eclipse.osee.ats.config.demo plugin to initialize a demo database, populate it with demo data and run the majority of the OSEE tests against this common data set.

These tests are contributed to the MasterTestSuite groups using Eclipse's extension point framework. Any Test Suite can implement IOseeTest and extend the OseeTest extension point to be contributed to the appropriate test suite(s).

Steps to test

  1. Checkout org.eclipse.osee.ats.config.demo
  2. Checkout
  3. Run the following tests in order and resolve any errors:
    1. Run the Demo database tests:
      1. Run the OSEE Demo Application Server launch config
      2. Run the MasterTestSuite_DemoDbInit launch config. This initializes the postgres database for demo populate and tests
      3. Run the MasterTestSuite_DemoDbPopulate launch config. This loads the database with branches, actions and sets conditions for populate tests.
      4. Run the MasterTestSuite_DemoDbTests launch config. This runs tests against the DemoDb Populated database.
      5. Stop the OSEE Demo Application Server if still running
    2. Run the Production TestDb tests:
      1. Run the OSEE Application Server launch config.
      2. Run the MasterTestSuite_TestDbInit launch config. This initializes the postgres database for production testdb tests
      3. Run the MasterTestSuite_TestDbTests launch config. - This runs production specific tests using a TestDb.
    3. Run the Production tests and health checks against the current production release
      1. Run the MasterTestSuite_ProductionTests launch config. This runs tests and health checks against the current production released database.

Common test utility plugin

The plugin is in support of our testing framework. It has a number of common enums and a TestUtil class that should be used by any junit tests. The intent is to keep this plugin lightweight and without many dependencies cause all the testing fragments "should" include it. In addition, it should not be included by any production plugins, only test fragments.

Adding new Tests to MasterTestSuite

To create test fragment off plugin to be tested

All OSEE JUnit tests should live in a fragment of the plugin to be tested.

  1. Select plugin to be tested
  2. Right-click -> New Project -> Plugin Project -> Plugin Fragment
  3. Enter plugin to be tested as Host plugin
  4. Complete wizard
  5. In plugin to be tested (eg org.eclipse.osee.ats)
    1. Add "Eclipse-ExtensibleAPI: true" to MANIFEST.MF of plugin to be tested. This allows test suites to see tests in this plugin
  6. In new fragment (eg org.eclipse.osee.ats.test)
    1. Add org.junit4 (make sure junit4, not junit) to dependencies
    2. Add the common test utility plugin plugin to dependencies
    3. Export packages containing TestCases and TestSuites
  7. In MasterTestSuite plugin (eg
    1. Add dependency on plugin to be tested (ge org.eclipse.osee.ats)
    2. Add test cases and suites from fragment to appropriate MasterTestSuite java Test Suites

To add a new JUnit TestCase

  1. Write the TestCase to run against a database populated with DemoDbInit and DemoDbPopulate
  2. Add the TestCase to an existing MasterTestSuite_DemoDbTests test suite

Things to consider

  1. Your tests must clean-up after themselves to ensure that the entire test suite can be run.
  2. Do not assume order of execution except within your own Test Suite

Master Test Suite - Frequently Asked Questions

What do I need for every test case?

  • import static org.junit.Assert.*;
  • In setup method (@Before), always assert that you are on correct database by adding one of these
assertTrue("Should be run on production datbase.", TestUtil.isProductionDb());
assertTrue("Should be run on test datbase.", TestUtil.isTestDb());
assertTrue("Should be run on demo datbase.", TestUtil.isDemoDb());
  • In setup method (@Before), always assert that you have correct app server running *
assertTrue("Demo Application Server must be running.",
assertTrue("Client must authenticate using demo protocol",
assertFalse("Application Server must be running.",
assertFalse("Client can't authenticate using demo protocol",

Why do I get an exception on synchronized-lock when I launch the tests

The launch configuration does not have all plugins necessary to run.

  1. Open Debug Configurations for that launch item
  2. Go to plugins tab and select "Validate Plugins". This will show if any plugins are missing from selected items.
  3. Select "Add Required Plugins" to add them.
  4. Re-launch.

Why do I get exceptions that cycle was detected when I add things to the org.eclipse.osee.test.util plugin

This plugin is meant to be extremely light-weight and only provide simple statics and methods to all the test plugins. Because it has to be included in all test fragments from jdk.core all the way up to framework.ui (skynet.ui), it can not depend on any of the higher level plugins or cycles will occur. Remove these dependencies and cycles will be fixed.

How do I timeout a test?

Define a timeout period in miliseconds with “timeout” parameter. The test fails when the timeout period exceeds. view

@Test(timeout = 1000)  
public void infinity() {  
    while (true);  

How do I test exception handling

Exception Handling Use “expected” paramater with @Test annotation for test cases that expect exception. Write the class name of the exception that will be thrown. view plainprint?

@Test(expected = ArithmeticException.class)  
public void divisionWithException() {  
   // divide by zero  
   simpleMath.divide(1, 0);  

To add a new JUnit TestSuite

  1. Create a fragment for the plugin (see above)
  2. Create new JUnit TestCases as above
  3. Create a new JUnit TestSuite
  4. Add new TestSuite to one of the MasterTestSuite java test suites

Common test cases

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
 * @link <link_to_class_under_test>
 * @author <you>
public final class MySuperbTest {
   private static SevereLogging