How to create StreamBase JUnit tests for complex results

How to create StreamBase JUnit tests for complex results

book

Article ID: KB0074104

calendar_today

Updated On:

Products

TIBCO Streaming

Description

There doesn't appear to be an expecter for my test, which is to check a tuple with a field which is a list of tuples and check for the specific size of the list, regardless of contents.

Issue/Introduction

Using a dequeue client instead of an expecter

Resolution

In any case where there is no obvious or convenient expecter, dequeue directly and use the full Client API to perform the test.

Example

In this case where what is expected is a single tuple with a List(Tuple) field, where the list is unordered and only the size matters, use:
// Collect output tuples for the test
List<Tuple> output = outputStream.dequeue(1);

// Check for no tuples returned
if (output.isEmpty()){ throw new junit.framework.AssertionFailedError("Expected at least one tuple."); }

// Inspect the tuple and throw a JUnit error if the test fails
if (!output.get(0).getList("TupleList").size()==expectedTupleCount) {
  String error = String.format("Expected %s tuples in TupleList field.",expectedTupleCount);
  throw new junit.framework.AssertionFailedError(error);
}