Montag, 7. Juni 2010

OSGi Console Services and Filter

In the Equinox OSGi Console with the command services all running services will be listed. When you like to filter you can use the OSGi Filter Syntax. The filter I use often is services (objectClass=com.github.tux2323*) then all services which starts with the Java package com.github.tux2323 will be listed.

Example:
osgi> services (objectClass=com.github.tux2323*)
{com.github.tux2323.demo.chat.server.ChatServer}={service.id=26}
  Registered by bundle: com.github.tux2323.demo.chat.server_1.0.0.qualifier [1]
  No bundles using service.

A nice german article from Heiko Seeberger about OSGi filter can be found here.

Mittwoch, 21. April 2010

My first op4j code

I play around with op4j makes a lot of fun. Here my first op4j code:
// Create a array with out null and 0 values
Integer[] integers = Op.onArrayFor(1, 2, 3, null, 4, null, 0).removeAllNull().removeAllEqual(0).get();
  
// Assert
for (Integer value : integers) {
   assertNotNull(value);
   assertNotSame(0, value);
}

Link:

Sonntag, 11. April 2010

jSonde – Generate a UML Sequence Diagram

The eclipse TPTP profiler has a very cool feature, create a UML sequence diagram from a profiling session. But the problem the TPTP profiling agent doesn’t run on my MacBook. So I looked for other free tools and I found jSonde an open source Java profiler (GPL).

jSonde can be used to generate a UML sequence diagram from a java application by profiling the app e.g. this can be used to document the actual implementation of a use case. How a this can be done, I will show step by step here in this post:

Step 1.) Get jSonde from http://www.jsonde.com/

Step 2.) Create a JUnit test case for the use case / function which you want to document, or when you do TDD look for an existing test...

Here the example code of my test:

@Test
 public void testPurchase() {

  Seller sellerOne = kasse.getSeller(100);
  Seller sellerTwo = kasse.getSeller(101);

  Position hose = new Position();
  hose.setDescription("Hose");
  hose.setPrice(2150);
  hose.setSeller(sellerOne);

  Position kleid = new Position();
  kleid.setDescription("Kleid");
  kleid.setPrice(2150);
  kleid.setSeller(sellerTwo);

  Sale sale = new Sale();
  sale.addPosition(hose);
  sale.addPosition(kleid);

  kasse.purchase(sale);  
 
}

Step 3.) Run the test e.g. in eclipse (or in other IDE) with the follow VM parameter: “-javaagent${JSONE_PATH}/lib/jsonde.agent-1.0.0.beta7.jar=60001”





Step 4.) Start jSonde and click File -> New Project



Step 5.) Enter a project name and the namespace of the application then click Connect


Step 6.) After the test is pass, click sequence diagram and select the test method in the tree view



Here the full UML sequence diagram for the "Purchase" test implementation:



Links:

Donnerstag, 18. März 2010

TwiP JUnit Test with more then one Parameter

Here a example, how a JUnit test which use TwiP, can use more then one test parameter.



See also my previous contribution on TwiP here.

Links: