@Before public void setUp() throws Exception { FormEncodingFactory.register(FormEncodingServerFactory.getEncoder(), FormEncodingServerFactory.getDecoder()); }
@Before public void setUp() throws Exception { FormEncodingFactory.register(FormEncodingServerFactory.getEncoder(), FormEncodingServerFactory.getDecoder()); }
@Test public void testListItemsEncodingProblem() throws Exception { FSMenuService service = createMockedService(null); FormRepresentationDecoder decoder = EasyMock.createMock(FormRepresentationDecoder.class); FormEncodingFactory.register(FormEncodingFactory.getEncoder(), decoder); FormEncodingException exception = new FormEncodingException("Something going wrong"); EasyMock.expect(decoder.decodeMenuItemsMap(EasyMock.anyObject(String.class))).andThrow(exception).once(); EasyMock.replay(decoder); try { service.listMenuItems(); fail("listOptions 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(decoder); } @Test
@Test public void testListItemsEncodingProblem() throws Exception { FSMenuService service = createMockedService(null); FormRepresentationDecoder decoder = EasyMock.createMock(FormRepresentationDecoder.class); FormEncodingFactory.register(FormEncodingFactory.getEncoder(), decoder); FormEncodingException exception = new FormEncodingException("Something going wrong"); EasyMock.expect(decoder.decodeMenuItemsMap(EasyMock.anyObject(String.class))).andThrow(exception).once(); EasyMock.replay(decoder); try { service.listMenuItems(); fail("listOptions 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(decoder); } @Test
@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
@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