Update { @RequestMapping(value = "/{portal}/{lang}/admin.category.update", produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) @ResponseBody public CategoryUpdateResponse exec( @RequestParam final Integer id, @RequestParam final String name ) throws Exception { if (name == null) { throw new MissingParameterEx("name"); } ConfigurableApplicationContext appContext = ApplicationContextHolder.get(); MetadataCategoryRepository categoryRepository = appContext.getBean(MetadataCategoryRepository.class); LanguageRepository langRepository = appContext.getBean(LanguageRepository.class); CategoryUpdateResponse response = new CategoryUpdateResponse(); MetadataCategory category; if (id == null) { category = new MetadataCategory(); category.setName(name); java.util.List<Language> allLanguages = langRepository.findAll(); for (Language l : allLanguages) { category.getLabelTranslations().put(l.getId(), name); } categoryRepository.save(category); response.addOperation(CategoryUpdateResponse.Operation.added); } else { categoryRepository.update(id, new Updater<MetadataCategory>() { @Override public void apply(@Nonnull MetadataCategory entity) { entity.setName(name); } }); response.addOperation(CategoryUpdateResponse.Operation.updated); } return response; }  @RequestMapping(value = "/{portal}/{lang}/admin.category.update", produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) @ResponseBody CategoryUpdateResponse exec(
        @RequestParam final Integer id,
        @RequestParam final String name
    );  }
@Test public void createCategoryTest() throws Exception { final String name = "createdcategory_updatetest"; CategoryUpdateResponse ret = updateCategoryController.exec(null, name); assertEquals(1, ret.getOperations().size()); assertTrue(ret.getOperations().contains(Operation.added)); MetadataCategory category = categoryRepository.findOneByName(name); assertTrue(category != null); }
@Test public void badParameterCategoryTest() throws Exception { try { updateCategoryController.exec(42, null); } catch (Throwable e) { assertTrue(e.getClass().toString(), e instanceof MissingParameterEx); } }
@Test public void updateCategoryTest() throws Exception { final String categoryName = "updatecategorytest_renamed"; CategoryUpdateResponse ret = updateCategoryController.exec(1, categoryName); assertEquals(1, ret.getOperations().size()); assertTrue(ret.getOperations().contains(Operation.updated)); MetadataCategory category = categoryRepository.findOne(1); assertTrue(category.getName().equals(categoryName)); }