Submitting an ordered collection of events

You can submit a collection of events by creating a Java List of the events and using the test driver submitEvents(Iterator<Event> events) method. You can define and change the order in which the events are submitted to analyze the behavior of your solution.

About this task

To test an event collection, create a test client project. You can create an event collection by using any Java collection class that contains an object of the type Event, such as List<Event> or Set<Event>. Submit the event collection by passing an event iterator to the submitEvents() method.

When you submit an event collection, the events are processed in the order in which they are returned by the iterator. The iterator returns the event collections in an order that depends on your collection implementation. Consult the Javadoc for the implementation that you use for an accurate description of the iteration order.

The TestDriver class is the main entry point for testing a solution.

If a failure occurs during the event submission process, the process stops and a MultipleEventSubmissionException exception is thrown. The exception includes the cause of the failure and the results for any successful event submissions that occurred before the failure.

Procedure

  1. Import the Java™ packages for your model into the .java file that contains the TestDriver class in the test client project. For example:
    import com.example.model.ConceptFactory;
    import com.example.model.Customer;
    import com.example.model.CreateCartEvent;
    import com.example.model.ShoppingCart;
  2. Create an event collection that contains objects of the type Event. For example:
    List<Event> events = new ArrayList<Event>();
    CreateCartEvent createCartEvent1 = testDriver.getEventFactory().createEvent(CreateCartEvent.class);
    createCartEvent1.setShoppingCartId(shoppingCartId);
    Relationship<Customer> customerRel = testDriver.getEventFactory().createRelationship(Customer.class, customerId);
    createCartEvent1.setCustomer(customerRel);
    events.add(createCartEvent1);
    CreateCartEvent createCartEvent2 = testDriver.getEventFactory().createEvent(CreateCartEvent.class);
    createCartEvent2.setShoppingCartId(shoppingCartId);
    Relationship<Customer> customerRel2 = testDriver.getEventFactory().createRelationship(Customer.class, customerId);
    createCartEvent2.setCustomer(customerRel2);
    events.add(createCartEvent2); 
  3. Submit the event collection by passing the iterator for your collection to the submitEvents() method. For example:
    Map<String,RoutingStatus> results = testDriver.submitEvents(events.iterator());
  4. In Insight Designer, run the test client as a JUnit test.