Class TestUtil

java.lang.Object
com.bloomberglp.blpapi.test.TestUtil

public final class TestUtil extends Object
This class (along with MessageFormatter) provides static utility for unit testing BLPAPI applications.

This component defines a class, TestUtil, that provides helpers unit-testing BLPAPI. This includes deserializing services, creating test events, and appending/formatting messages in these events.

Usage
-----
Example: Create subscription data with correlation id:
- - - - - - - - - - - - - - - - - - - - - - - - - - -
For the purpose of unit testing the behavior of tick processing, create a subscription data event containing a single tick for a given subscription, identified with a correlation id CorrelationID that is available in the test.

First create the service from a string:

  String schema ="<ServiceDefinition name=...>...</ServiceDefinition>";
  InputStream stream = new ByteArrayInputStream(
          schema.getBytes(Charset.forName("UTF-8")));
  Service service = TestUtil.deserializeService(stream);

  // Then create a subscription event
  Event event = TestUtil.createEvent(Event.EventType.SUBSCRIPTION_DATA);

  // Prepare the message properties:
  MessageProperties properties = new MessageProperties();
  properties.setCorrelationId(correlationId);

  // Then, obtain the definition for the message from the schema:
  Name msgName = new Name("MarketDataEvents");
  SchemaElementDefinition def = service.getEventDefinition(msgName);

  // Now append a message and obtain a formatter:
  MessageFormatter fmt = TestUtil.appendMessage(event, def, properties);
 

The formatter can now be used to fill in the data to be used in the test.

Note that service creation and the definitions for the ticks can be shared by all of the unit tests that need to create the same type of events.