@Test
public void testExec() throws Exception {

    long beforeCount = _categoryRepository.count();
    final MetadataCategory category = _categoryRepository.findAll().get(0);
    assertEquals(beforeCount, _categoryRepository.count());
    AbstractMetadata entity = MetadataRepositoryTest.newMetadata(inc);
    entity.getCategories().add(category);
    entity = metadataManager.save(entity);
    ServiceContext context = createServiceContext();
    loginAsAdmin(context);
    remove.exec(category.getId());
    assertEquals(beforeCount - 1, _categoryRepository.count());
    assertEquals(1, metadataUtils.count());
    entity = metadataUtils.findOne(entity.getId());
    assertTrue(entity.getCategories().isEmpty());
}