EasyMock.verify(encoder);
}
public void testSaveMenuItemOK() throws Exception {
GuvnorMenuService service = new GuvnorMenuService();
FormRepresentationDecoder decoder = FormEncodingFactory.getDecoder();
File dbFile = new File(getClass().getResource("/menuItems.json").getFile());
String jsonInitial = FileUtils.readFileToString(dbFile);
Map<String, List<MenuItemDescription>> descsInitial = decoder.decodeMenuItemsMap(jsonInitial);
MenuItemDescription desc = new MenuItemDescription();
desc.setClassName(CustomMenuItem.class.getName());
List<FormEffectDescription> effects = new ArrayList<FormEffectDescription>();
FormEffectDescription effDesc1 = new FormEffectDescription();
effDesc1.setClassName(RemoveEffect.class.getName());
effects.add(effDesc1);
FormEffectDescription effDesc2 = new FormEffectDescription();
effDesc2.setClassName(DoneEffect.class.getName());
effects.add(effDesc2);
desc.setEffects(effects);
File file = new File(getClass().getResource("testSaveMenuItem.json").getFile());
String json = FileUtils.readFileToString(file);
FormItemRepresentation itemRepresentation = decoder.decodeItem(json);
desc.setName("test component");
desc.setItemRepresentation(itemRepresentation);
String groupName = "Test Components";
service.saveMenuItem(groupName, desc);
String jsonResult = FileUtils.readFileToString(dbFile);
Map<String, List<MenuItemDescription>> descsResult = decoder.decodeMenuItemsMap(jsonResult);
assertNotNull("saved menu items shouldn't be null", descsResult);
assertNotNull("saved menu items should contain a list of " + groupName, descsResult.get(groupName));
assertFalse(groupName + " list should not be empty", descsResult.get(groupName).isEmpty());
assertFalse("descsInitial and descsResult should not be the same", descsInitial.equals(descsResult));
service.deleteMenuItem(groupName, desc);
String jsonFinal = FileUtils.readFileToString(dbFile);
Map<String, List<MenuItemDescription>> descsFinal = decoder.decodeMenuItemsMap(jsonFinal);
assertEquals("descsInitial and descsFinal should be the same", descsInitial.entrySet(), descsFinal.entrySet());
}