Loading entities

It is possible to initialize entities from your BOM project one by one by using the TestDriver loadEntity (Entity entity) method.

Before you begin

You must create a test client project before you can use the methods of the TestDriver class.

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.ParkingLot;
  2. Define a method to load your entities into the grid and code a connection to your solution BOM. For example, the following loadCustomer method loads a Customer entity named "Jack Smith":
    private void loadCustomer() throws Exception {
       Customer customer = testDriver.getConceptFactory(ConceptFactory.class).createCustomer("Smith");
       customer.setFirstName("Jack");
       customer.setLastName("Smith");		 		 
       customer.setLoyaltyCardOwner(true);
       testDriver.loadEntity(customer);
    }
  3. Instantiate any geographic attributes of your entities. This data can be used to test if an event occurred within this geographical area. The following example shows how to instantiate a parkingArea (polygon) attribute of an entity named parkingLot.
    protected static TestDriver td;
    ...
    private ParkingLot createParkingLot() throws Exception {
       ParkingLot parkingLot = td.getConceptFactory(ConceptFactory.class).createParkingLot("p1");
       GeometryFactory geoFactory = GeoSpatialService.getService().getGeometryFactory();
       Point p1 = geoFactory.getPoint(-111.90863, 33.50211);
       Point p2 = geoFactory.getPoint(-111.90863, 33.49489);
       Point p3 = geoFactory.getPoint(-111.9003, 33.49481);
       Point p4 = geoFactory.getPoint(-111.90056, 33.50233);
       Polygon parkingArea = geoFactory.getPolygon(p1, p2, p3, p4);
       parkingLot.setParkingArea(parkingArea);
       return parkingLot;
       }
  4. Check that the entity is created.

    For example, the following code checks that the Customer entity is created.

    if (testDriver.waitUntilSolutionIdle(10) == true) {
       Customer customer = testDriver.fetchEntity(Customer.class, customerId);  
       assertNotNull(customer);
    }
  5. In Insight Designer, run the test client as a JUnit test.

What to do next

The REST API is a quick way to validate that entities are loaded into the grid. Enter REST URLs in the address field of your browser to access the stored solutions and entities in the server. The following URL examples show how you can validate that your solution is deployed and the Customer is created:
  • To list all deployed solutions: http://localhost:9080/ibm/ia/rest/solutions
  • To list all entity types that are managed by your solution: http://localhost:9080/ibm/ia/rest/solutions/MySolution/entity-types
  • To list all instances of a specific entity type in your solution: http://localhost:9080/ibm/ia/rest/solutions/MySolution/entity-types/com.example.model.Customer/entities