@Test public final void shouldDoNothingIfCategoryAlreadyExists() { MenuCategoryDefinition menuCategoryDefinition = new MenuCategoryDefinition(PLUGIN_IDENTIFIER, "categoryName", ROLE_VISIBLE); Entity categoryEntity = mock(Entity.class); given(menuCrudService.getCategory(menuCategoryDefinition)).willReturn(categoryEntity); menuService.createCategory(menuCategoryDefinition); verify(menuCrudService, never()).save(any(Entity.class)); }
@Override @Transactional public void createCategory(final MenuCategoryDefinition menuCategoryDefinition) { Entity menuCategory = menuCrudService.getCategory(menuCategoryDefinition); if (menuCategory != null) { return; } menuCategory = menuCrudService.createEntity(QcadooViewConstants.MODEL_CATEGORY); menuCategory.setField(MenuCategoryFields.PLUGIN_IDENTIFIER, menuCategoryDefinition.getPluginIdentifier()); menuCategory.setField(MenuCategoryFields.NAME, menuCategoryDefinition.getName()); menuCategory.setField("accessible", true); menuCategory.setField(MenuCategoryFields.SUCCESSION, menuCrudService.getTotalNumberOfCategories()); menuCategory.setField(MenuCategoryFields.AUTH_ROLE, menuCategoryDefinition.getAuthRole()); menuCrudService.save(menuCategory); }
MenuServiceImpl implements InternalMenuService { @Override @Transactional public void createCategory(final MenuCategoryDefinition menuCategoryDefinition) { Entity menuCategory = menuCrudService.getCategory(menuCategoryDefinition); if (menuCategory != null) { return; } menuCategory = menuCrudService.createEntity(QcadooViewConstants.MODEL_CATEGORY); menuCategory.setField(MenuCategoryFields.PLUGIN_IDENTIFIER, menuCategoryDefinition.getPluginIdentifier()); menuCategory.setField(MenuCategoryFields.NAME, menuCategoryDefinition.getName()); menuCategory.setField("accessible", true); menuCategory.setField(MenuCategoryFields.SUCCESSION, menuCrudService.getTotalNumberOfCategories()); menuCategory.setField(MenuCategoryFields.AUTH_ROLE, menuCategoryDefinition.getAuthRole()); menuCrudService.save(menuCategory); } }
MenuServiceImpl implements InternalMenuService { @Override @Transactional public void createCategory(final MenuCategoryDefinition menuCategoryDefinition) { Entity menuCategory = menuCrudService.getCategory(menuCategoryDefinition); if (menuCategory != null) { return; } menuCategory = menuCrudService.createEntity(QcadooViewConstants.MODEL_CATEGORY); menuCategory.setField(MenuCategoryFields.PLUGIN_IDENTIFIER, menuCategoryDefinition.getPluginIdentifier()); menuCategory.setField(MenuCategoryFields.NAME, menuCategoryDefinition.getName()); menuCategory.setField("accessible", true); menuCategory.setField(MenuCategoryFields.SUCCESSION, menuCrudService.getTotalNumberOfCategories()); menuCategory.setField(MenuCategoryFields.AUTH_ROLE, menuCategoryDefinition.getAuthRole()); menuCrudService.save(menuCategory); }  }
MenuServiceImpl implements InternalMenuService { @Override @Transactional public void createCategory(final MenuCategoryDefinition menuCategoryDefinition) { Entity menuCategory = menuCrudService.getCategory(menuCategoryDefinition); if (menuCategory != null) { return; } menuCategory = menuCrudService.createEntity(QcadooViewConstants.MODEL_CATEGORY); menuCategory.setField(MenuCategoryFields.PLUGIN_IDENTIFIER, menuCategoryDefinition.getPluginIdentifier()); menuCategory.setField(MenuCategoryFields.NAME, menuCategoryDefinition.getName()); menuCategory.setField("accessible", true); menuCategory.setField(MenuCategoryFields.SUCCESSION, menuCrudService.getTotalNumberOfCategories()); menuCategory.setField(MenuCategoryFields.AUTH_ROLE, menuCategoryDefinition.getAuthRole()); menuCrudService.save(menuCategory); }  @Override @Transactional(readOnly = true) @Monitorable MenuDefinition getMenu(final Locale locale); @Override @Transactional void addView(final MenuItemDefinition itemDefinition); @Override @Transactional void removeView(final MenuItemDefinition itemDefinition); @Override @Transactional void createCategory(final MenuCategoryDefinition menuCategoryDefinition); @Override @Transactional void removeCategory(final MenuCategoryDefinition menuCategoryDefinition); @Override @Transactional void createItem(final MenuItemDefinition itemDefinition); @Override @Transactional void removeItem(final MenuItemDefinition itemDefinition); }
MenuServiceImpl implements InternalMenuService { @Override @Transactional public void createCategory(final MenuCategoryDefinition menuCategoryDefinition) { Entity menuCategory = menuCrudService.getCategory(menuCategoryDefinition); if (menuCategory != null) { return; } menuCategory = menuCrudService.createEntity(QcadooViewConstants.MODEL_CATEGORY); menuCategory.setField(MenuCategoryFields.PLUGIN_IDENTIFIER, menuCategoryDefinition.getPluginIdentifier()); menuCategory.setField(MenuCategoryFields.NAME, menuCategoryDefinition.getName()); menuCategory.setField("accessible", true); menuCategory.setField(MenuCategoryFields.SUCCESSION, menuCrudService.getTotalNumberOfCategories()); menuCategory.setField(MenuCategoryFields.AUTH_ROLE, menuCategoryDefinition.getAuthRole()); menuCrudService.save(menuCategory); }  @Override @Transactional(readOnly = true) @Monitorable MenuDefinition getMenu(final Locale locale); @Override @Transactional void addView(final MenuItemDefinition itemDefinition); @Override @Transactional void removeView(final MenuItemDefinition itemDefinition); @Override @Transactional void createCategory(final MenuCategoryDefinition menuCategoryDefinition); @Override @Transactional void removeCategory(final MenuCategoryDefinition menuCategoryDefinition); @Override @Transactional void createItem(final MenuItemDefinition itemDefinition); @Override @Transactional void removeItem(final MenuItemDefinition itemDefinition);  }