@Test
  public void testFindByCatalogCategory() {

    _logger.info("Starting FindByCatalogCategory test");

    ModelClient modelClient = getModelClient();

    CatalogCategory root = createCategoryWithLabel("rooty");
    modelClient.save(root);

    CatalogService s1 = createWithLabel("s1");
    s1.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
    modelClient.save(s1);

    CatalogCategory c1 = createCategoryWithLabel("asdf");
    c1.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
    modelClient.save(c1);

    CatalogService s2 = createWithLabel("s2");
    s2.setCatalogCategoryId(new NamedURI(c1.getId(), c1.getLabel()));
    modelClient.save(s2);

    CatalogService s3 = createWithLabel("s3");
    s3.setCatalogCategoryId(new NamedURI(c1.getId(), c1.getLabel()));
    modelClient.save(s3);

    CatalogCategory c2 = createCategoryWithLabel("asdf2");
    c2.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
    modelClient.save(c2);

    CatalogService s4 = createWithLabel("s4");
    s4.setCatalogCategoryId(new NamedURI(c2.getId(), c2.getLabel()));
    modelClient.save(s4);

    CatalogService s5 = createWithLabel("s5");
    s5.setCatalogCategoryId(new NamedURI(c2.getId(), c2.getLabel()));
    modelClient.save(s5);

    CatalogService s6 = createWithLabel("s6");
    s6.setCatalogCategoryId(new NamedURI(c2.getId(), c2.getLabel()));
    modelClient.save(s6);

    List<CatalogService> results =
        modelClient.catalogServices().findByCatalogCategory(root.getId());
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());

    results = modelClient.catalogServices().findByCatalogCategory(c1.getId());
    Assert.assertNotNull(results);
    Assert.assertEquals(2, results.size());

    results = modelClient.catalogServices().findByCatalogCategory(c2.getId());
    Assert.assertNotNull(results);
    Assert.assertEquals(3, results.size());
  }
 public CatalogService createCatalogService(
     ServiceDef serviceDef, CatalogCategory parentCategory) {
   CatalogBuilder builder = new CatalogBuilder(client, serviceDescriptors);
   NamedURI namedUri = new NamedURI(parentCategory.getId(), parentCategory.getLabel());
   CatalogService newService = builder.createService(serviceDef, namedUri);
   newService.setSortedIndex(null);
   client.save(newService);
   return newService;
 }
 private void setParent(CatalogCategory parent, CatalogService child) {
   child.setCatalogCategoryId(new NamedURI(parent.getId(), parent.getLabel()));
 }