TestDriver loadEntity (Entity entity) 메소드를 사용하여 BOM 프로젝트에서
하나씩 엔티티를 초기화할 수 있습니다.
시작하기 전에
TestDriver 클래스의 메소드를 사용하려면
테스트 클라이언트 프로젝트를 작성해야 합니다.
프로시저
- 테스트 클라이언트 프로젝트에서 TestDriver 클래스를 포함하는 .java
파일에 모델의 Java™ 패키지를 가져오십시오. 예제:
import com.example.model.ConceptFactory;
import com.example.model.Customer;
import com.example.model.ParkingLot;
- 메소드를 정의하여 엔티티를 그리드에 로드하고 솔루션 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);
}
- 엔티티의 지리적 속성을 인스턴스화하십시오. 이 데이터는 이벤트가
이 지리적 영역 내에서 발생했는지 여부를 테스트하기 위해 사용할 수 있습니다. 다음 예제에서는 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;
}
- 엔티티가 작성되었는지 확인하십시오.
예를 들어, 다음 코드는 Customer 엔티티가 작성되었는지 확인합니다.
if (testDriver.waitUntilSolutionIdle(10) == true) {
Customer customer = testDriver.fetchEntity(Customer.class, customerId);
assertNotNull(customer);
}
- Insight Designer에서 테스트 클라이언트를
JUnit 테스트로 실행하십시오.
다음에 수행할 작업
예를 들어, REST API는 엔티티를 그리드에 로드하는 유효성 검증하는 빠른 방법입니다.
브라우저의 주소 필드에 REST URL을 입력하여 서버의 저장된 솔루션 및 엔티티에 액세스할 수 있습니다. 다음 URL 예제는
솔루션 배치 및 고객 작성 유효성을 검증하는 방법을 보여줍니다.
- 배치된 모든 솔루션 나열: 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