/**
   * Validate if BusinessObjectQuery returns business objects which are defined in the models
   * MODEL_NAME2 and MODEL_NAME3. Note: If BusinessObjectsList is executed standalone than
   * bos.size() == expected.size(). But if it is executed after CheckFiltering2 then bos.size() >
   * expected.size() because CheckFiltering2 deployes MODEL_NAME3 as a new version. This means that
   * bos.size() == expected.size()+2 in this case.
   */
  @Test
  public void BusinessObjectsList() {
    BusinessObjectQuery query = BusinessObjectQuery.findAll();
    query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_DESCRIPTION));

    BusinessObjects bos = sf.getQueryService().getAllBusinessObjects(query);

    List<String> expected =
        CollectionUtils.newArrayListFromElements(
            Arrays.asList(
                new QName(MODEL_NAME2, "Account").toString(),
                new QName(MODEL_NAME2, "Customer").toString(),
                new QName(MODEL_NAME2, "Order").toString(),
                new QName(MODEL_NAME2, "Fund").toString(),
                new QName(MODEL_NAME2, "FundGroup").toString(),
                new QName(MODEL_NAME3, "Employee").toString(),
                new QName(MODEL_NAME3, "Fund").toString()));

    List<String> removedEntries = CollectionUtils.newArrayList(expected.size());

    for (BusinessObject bo : bos) {
      String qualifiedBOId = new QName(bo.getModelId(), bo.getId()).toString();
      if (expected.remove(qualifiedBOId)) {
        removedEntries.add(qualifiedBOId);
      } else {
        Assert.assertTrue(
            "Not expected entry: " + qualifiedBOId, removedEntries.contains(qualifiedBOId));
      }
    }
    Assert.assertTrue("Missing business objects: " + expected, expected.isEmpty());
  }
 private void checkValue(
     List<BusinessObject.Value> boValues, boolean strict, String name, Object... values) {
   Set<Object> expected = CollectionUtils.newSetFromIterator(Arrays.asList(values).iterator());
   Set<Object> actual = CollectionUtils.newSet();
   for (BusinessObject.Value boValue : boValues) {
     Map<?, ?> data = (Map<?, ?>) boValue.getValue();
     actual.add(data.get(name));
   }
   if (strict) {
     Assert.assertEquals("Values: ", expected, actual);
   } else {
     expected.removeAll(actual);
     Assert.assertTrue("Missing values: " + expected, expected.isEmpty());
   }
 }
  /**
   * Test if the business object query returns all business object instances for a given business
   * object id. The BO instances was created by the OrderCreation process resp. EnterOrderData
   * activity in the setup() method.
   */
  @Test
  public void CheckOrders() {
    DeployedModelDescription model =
        sf.getQueryService().getModels(DeployedModelQuery.findActiveForId(MODEL_NAME2)).get(0);

    BusinessObjectQuery query =
        BusinessObjectQuery.findForBusinessObject(new QName(model.getId(), "Order").toString());
    query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES));

    BusinessObjects bos = sf.getQueryService().getAllBusinessObjects(query);
    Assert.assertEquals("Objects", 1, bos.getSize());
    BusinessObject bo = bos.get(0);
    List<BusinessObject.Value> values = bo.getValues();
    Assert.assertTrue("Expected at least 5 values: " + values.size(), 5 <= values.size());
    checkValue(values, false, "customerId", 1, 2, 3, 4, 5);
  }