Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Gyrex/Developer Guide"

m
Line 24: Line 24:
 
* Repositories
 
* Repositories
 
* Logging
 
* Logging
 +
 +
 +
[[Category:Gyrex]]

Revision as of 15:26, 28 November 2012

Gyrex
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug Day
Contribute
Browse SourceProject Set File
Warning2.png
Draft Content
This page is currently under construction. Community members are encouraged to maintain the page, and make sure the information is accurate.


A guide to developing server applications based on Gyrex.


Testing with JUnit

Gyrex supports and recommends writing tests with JUnit. Any JUnit tests must be run as JUnit OSGi plug-in tests in headless mode. Both, PDE Build and Tycho support such execution of tests. In order to assist developers with running and developing tests, Gyrex provides a few helpers for JUnit.

Dependencies

  • Bundle org.eclipse.gyrex.junit (Gyrex 1.2 or higher)
  • JUnit (4.10 or higher)

Integration Tests

Some tests may require a full Gyrex environment to be bootstrapped and running. We call those Integration Tests as they test a certain functionality in the system while operating/integrating with other essential services of the platform (for example, the cloud services backed by ZooKeeper).

Writing integration tests with Gyrex should be done by using the JUnit rules. JUnit rules allow defining dependencies/requirements for JUnit tests. Gyrex provides a rule which ensures that a Gyrex environment is bootstrapped and started before a test is run. Consequently, the server will be stopped after a test is finished. It’s recommended to implement dependencies as a @ClassRule inside a JUnit suite. This groups integration tests together and start the server only once and stop it after executing all tests.

Bundle Activation

Bundle activation is important when writing tests. Basically, you can not assume that a Gyrex server environment is fully bootstrapped and started in any bundle activator. This shouldn't be done anyway because OSGi is a dynamic environment and bundles can come and go at any time. Thus, make sure that you do not execute any logic during bundle activation which can fail if a Gyrex server environment is not available.

Instead, it's recommended to use Declarative Services or Gyrex Server Roles to trigger lazy activation once an environment is ready.

Example

The following example defines a JUnit suite for running integration test.

import org.eclipse.gyrex.context.tests.internal.AllContextTests;
import org.eclipse.gyrex.junit.GyrexServerResource;
 
import org.junit.ClassRule;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
 
@RunWith(Suite.class)
@SuiteClasses({ /* list test classes here */ })
public class AllServerTests {
 
  @ClassRule
  public static final GyrexServerResource server = new GyrexServerResource();
 
}

TODO: Topics to cover

Note to self: Below is a random list of topics that we should cover. Any contribution is welcome! This is a wiki. Please feel free to edit and amend.

  • Servlets
  • Web Apps
  • HttpService
  • Contexts
  • Cloud Preferences
  • Repositories
  • Logging

Back to the top