エンティティーのロード

TestDriver の loadEntity (Entity entity) メソッドを使用して、BOM プロジェクトのエンティティーを 1 つずつ初期化できます。

始める前に

TestDriver クラスのメソッドを使用するためには、テスト・クライアント・プロジェクトを作成しておく必要があります。

手順

  1. 使用するモデルの Java パッケージを、テスト・クライアント・プロジェクトの TestDriver クラスが含まれている .java ファイルにインポートします。 例:
    import com.example.model.ConceptFactory;
    import com.example.model.Customer;
    import com.example.model.ParkingLot;
  2. エンティティーをグリッドにロードするメソッドを定義し、ソリューション BOM への接続をコーディングします。 例えば、以下の loadCustomer メソッドは、「Jack Smith」という名前の Customer エンティティーをロードします。
    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. エンティティーの地理的属性をすべてインスタンス化します。このデータを使用して、イベントがこの地理的領域内で発生したかどうかをテストできます。 以下の例は、parkingLot という名前のエンティティーの parkingArea (ポリゴン) 属性をインスタンス化する方法を示しています。
    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. エンティティーが作成されていることを確認します。

    例えば、以下のコードは、Customer エンティティーが作成されていることをチェックします。

    if (testDriver.waitUntilSolutionIdle(10) == true) {
       Customer customer = testDriver.fetchEntity(Customer.class, customerId);  
       assertNotNull(customer);
    }
  5. Insight Designer で、テスト・クライアントを JUnit テストとして実行します。

次のタスク

エンティティーがグリッドにロードされたことを検証するための簡単な方法に REST API があります。ご使用のブラウザーのアドレス・フィールドに REST URL を入力して、サーバー内の保管されたソリューションとエンティティーにアクセスします。以下の URL の例は、ソリューションがデプロイされ、Customer が作成されたことを確認する方法を示しています。
  • デプロイされたすべてのソリューションをリストする場合: http://localhost:9080/ibm/ia/rest/solutions
  • ソリューションによって管理されるすべてのエンティティー・タイプをリストする場合: http://localhost:9080/ibm/ia/rest/solutions/MySolution/entity-types
  • ソリューション内の特定のエンティティー・タイプのインスタンスをすべてリストする場合: http://localhost:9080/ibm/ia/rest/solutions/MySolution/entity-types/com.example.model.Customer/entities