@Override public String saveForm(FormRepresentation form) throws FormBuilderServiceException { String encode = null; try { encode = FormEncodingServerFactory.getEncoder().encode(form); } catch (FormEncodingException ex) { logger.error("Error while saving form", ex); } return encode; }
private void writeMenuItems(Map<String, List<MenuItemDescription>> items) throws MenuServiceException { try { FormRepresentationEncoder encoder = FormEncodingFactory.getEncoder(); String json = encoder.encodeMenuItemsMap(items); URL url = asURL("/menuItems.json"); writeToURL(url, json); } catch (FormEncodingException e) { throw new MenuServiceException("Problem transforming menu items to json", e); } catch (URISyntaxException e) { throw new MenuServiceException("Problem finding menu items json file", e); } catch (FileNotFoundException e) { throw new MenuServiceException("No menu items json file found", e); } catch (IOException e) { throw new MenuServiceException("Problem writing menu items json file", e); } catch (Exception e) { throw new MenuServiceException("Unexpected error", e); } }
private void writeMenuItems(Map<String, List<MenuItemDescription>> items) throws MenuServiceException { try { FormRepresentationEncoder encoder = FormEncodingFactory.getEncoder(); String json = encoder.encodeMenuItemsMap(items); URL url = asURL("/menuItems.json"); writeToURL(url, json); } catch (FormEncodingException e) { throw new MenuServiceException("Problem transforming menu items to json", e); } catch (URISyntaxException e) { throw new MenuServiceException("Problem finding menu items json file", e); } catch (FileNotFoundException e) { throw new MenuServiceException("No menu items json file found", e); } catch (IOException e) { throw new MenuServiceException("Problem writing menu items json file", e); } catch (Exception e) { throw new MenuServiceException("Unexpected error", e); } }
@Test public void testSaveMenuItemEncodingProblem() throws Exception { FSMenuService service = createMockedService(null); MenuItemDescription sampleDescription = new MenuItemDescription(); sampleDescription.setAllowedEvents(new ArrayList<String>()); sampleDescription.setEffects(new ArrayList<FormEffectDescription>()); FormItemRepresentation item = MockFormHelper.createMockForm("form", "param1").getFormItems().iterator().next(); sampleDescription.setItemRepresentationMap(item.getDataMap()); sampleDescription.setName("name"); FormRepresentationEncoder encoder = EasyMock.createMock(FormRepresentationEncoder.class); FormEncodingException exception = new FormEncodingException(); @SuppressWarnings("unchecked") Map<String, List<MenuItemDescription>> anyObject = EasyMock.anyObject(Map.class); EasyMock.expect(encoder.encodeMenuItemsMap(anyObject)).andThrow(exception).once(); FormEncodingFactory.register(encoder, FormEncodingFactory.getDecoder()); EasyMock.replay(encoder); try { service.saveMenuItem("group", sampleDescription); fail("saveMenuItem shouldn't succeed"); } catch (MenuServiceException e) { assertNotNull("e shouldn't be null", e); Throwable cause = e.getCause(); assertNotNull("cause shouldn't be null", cause); assertTrue("cause should be a FormEncodingException", cause instanceof FormEncodingException); } EasyMock.verify(encoder); } // THIS TEST REQUIRES THE REAL GWT Components so it should be executed in the showcase
@Override public String saveForm(FormRepresentation form) throws FormBuilderServiceException { String encode = null; try { encode = FormEncodingServerFactory.getEncoder().encode(form); } catch (FormEncodingException ex) { Logger.getLogger(FormBuilderServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } return encode; }
@Test public void testSaveMenuItemEncodingProblem() throws Exception { FSMenuService service = createMockedService(null); MenuItemDescription sampleDescription = new MenuItemDescription(); sampleDescription.setAllowedEvents(new ArrayList<String>()); sampleDescription.setEffects(new ArrayList<FormEffectDescription>()); FormItemRepresentation item = MockFormHelper.createMockForm("form", "param1").getFormItems().iterator().next(); sampleDescription.setItemRepresentationMap(item.getDataMap()); sampleDescription.setName("name"); FormRepresentationEncoder encoder = EasyMock.createMock(FormRepresentationEncoder.class); FormEncodingException exception = new FormEncodingException(); @SuppressWarnings("unchecked") Map<String, List<MenuItemDescription>> anyObject = EasyMock.anyObject(Map.class); EasyMock.expect(encoder.encodeMenuItemsMap(anyObject)).andThrow(exception).once(); FormEncodingFactory.register(encoder, FormEncodingFactory.getDecoder()); EasyMock.replay(encoder); try { service.saveMenuItem("group", sampleDescription); fail("saveMenuItem shouldn't succeed"); } catch (MenuServiceException e) { assertNotNull("e shouldn't be null", e); Throwable cause = e.getCause(); assertNotNull("cause shouldn't be null", cause); assertTrue("cause should be a FormEncodingException", cause instanceof FormEncodingException); } EasyMock.verify(encoder); } // THIS TEST REQUIRES THE REAL GWT Components so it should be executed in the showcase