Editing StreamBase JUnit Tests

Overview

Java test files generated by the StreamBase JUnit wizard are incomplete and must be edited to become a useful test. This topic provides guidelines for completing the edit of your generated StreamBase JUnit test files.

File Contents

A generated JUnit test file includes:

  • One example tuple using generated test data for one input stream of the module to be tested.

  • An Expecter object that defines a tuple for each of the module's output ports.

Using Non-Default Container Names in Tests

The generated JUnit test file includes a loadApp() line like the following example. This line is responsible for loading the specified application module into the test StreamBase Server.

server.loadApp("appname.sbapp");

The line as generated loads the named module into a container named default. In this case, the StreamBase paths to the names of streams in your test code can be simple names without a container name, because StreamBase presumes a container named default if you don't specify a container. Thus, for a test of the Best Bids and Asks sample included with StreamBase, when using the default container, the following test code fragments are valid:

server.getEnqueuer("NYSE_Feed").enqueue( ...
...
new Expecter(server.getDequeuer("BestAsks"))

You may have an application-specific reason to load your test module into a container other than default. To do this in your test code, add a container name as a second argument to the loadApp method, like the following example:

server.loadApp("appname.sbapp", "testcontainer");

In this case, you must make sure that all StreamBase paths in the test file include the container name. For example:

server.getEnqueuer("testcontainer.NYSE_Feed").enqueue( ...
...
new Expecter(server.getDequeuer("testcontainer.BestAsks"))

Using Non-Default Container Names with Deployment Files

The same rule applies if you specify a non-default container name in a deployment file: you must make sure all StreamBase paths in the test file include the container name.

For example, you might generate a test file to run the following simple deployment file, and you select the module in thedeploycontainer container in the Container application field of the New Unit Test Class dialog:

<?xml version="1.0" encoding="UTF-8"?>
<deploy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:noNamespaceSchemaLocation="http://www.streambase.com/schemas/sbdeploy/">
    <runtime>
      <application container="default" module="BestBidsAsks.sbapp"/>
      <application container="deploycontainer" module="BestBidsAlt.sbapp"/>
    </runtime>
</deploy>

In this case, the JUnit wizard automatically places the container name in the generated getEnqueuer() line:

server.getEnqueuer("deploycontainer.NYSE_Feed").enqueue( ...

It is up to you to include the container name when you add further getEnqueuer() and getDequeuer() lines. For example:

...
new Expecter(server.getDequeuer("deploycontainer.BestAsks"))
...
new Expecter(server.getDequeuer("deploycontainer.BestBids"))
...

Further Options

You are not limited to the code generated by the wizard. For example, you might prefer to enqueue your input tuples constructed with ObjectArrayTupleMaker.MAKER instead of JSONSingleQuotesTupleMaker.MAKER.

If you need your test to reset the state of the module under test in preparation for further tests, your test code can include a passage like the following:

stopContainers(); startContainers();

Use the Javadoc documentation for the com.streambase.sb.unittest package as a guide to the test features available. See Java API Documentation.

Back to Top ^