Loading a collection of entities

You can load a collection of entities by creating a Java List and using the test driver loadEntities(Iterator<Entity> entities) method.

About this task

To load entities to a server, you first create a test client project. You can create an entity collection by using any Java collection class that contains an object of the type Entity, such as List<Entity> or Set<Entity>. Submit the entity collection by passing an entity iterator to the loadEntities() method.

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

If a failure occurs during the entity submission process, the process stops and a MultipleEntitySubmissionException exception is thrown. The exception includes the cause of the failure and the results for any successful entity 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.CreateCartEntity;
    import com.example.model.ShoppingCart;
  2. Create an entity collection that contains objects of the type Entity. For example:
    List<Entity> entities = new ArrayList<Entity>();
    Customer customer1 = testDriver.getConceptFactory(ConceptFactory.class).createCustomer(customerId);
    entities.add(customer1); 
    Customer customer2 = testDriver.getConceptFactory(ConceptFactory.class).createCustomer(customerId);
    entities.add(customer2);
    ShoppingCart shoppingCart = testDriver.getConceptFactory(ConceptFactory.class).createShoppingCart(shoppingCartId);
    entities.add(shoppingCart); 
  3. Submit the entity collection by passing the iterator for your collection to the loadEntities() method. For example:
    Map<String,RoutingStatus> results = testDriver.loadEntities(entities.iterator());
    Entities are submitted in ascending order.
  4. In Insight Designer, run the test client as a JUnit test.