Remove { @RequestMapping(value = "/{portal}/{lang}/admin.category.remove", produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) @ResponseBody public CategoryUpdateResponse exec( @RequestParam Integer id ) throws Exception { if (id == null) { throw new IllegalArgumentException("parameter id is required"); } ConfigurableApplicationContext appContext = ApplicationContextHolder.get(); MetadataCategoryRepository categoryRepository = appContext.getBean(MetadataCategoryRepository.class); IMetadataUtils metadataRepository = appContext.getBean(IMetadataUtils.class); DataManager dataManager = appContext.getBean(DataManager.class); final MetadataCategory category = categoryRepository.findOne(id); final List<Integer> affectedMd = metadataRepository.findAllIdsBy(MetadataSpecs.hasCategory(category)); categoryRepository.deleteCategoryAndMetadataReferences(id); dataManager.indexMetadata(Lists.transform(affectedMd, Functions.toStringFunction())); CategoryUpdateResponse response = new CategoryUpdateResponse(); response.addOperation(CategoryUpdateResponse.Operation.removed); return response; }  @RequestMapping(value = "/{portal}/{lang}/admin.category.remove", produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) @ResponseBody CategoryUpdateResponse exec(
        @RequestParam Integer id
    );  }
@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()); }