//test response to a FormEncodingException for RESTFormService.getFormPreview(...)
public void testGetFormPreviewEncodingProblem() throws Exception {
final ServletContext context = EasyMock.createMock(ServletContext.class);
final HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
FormRepresentationDecoder decoder = EasyMock.createMock(FormRepresentationDecoder.class);
RESTFormService restService = new RESTFormService();
restService.setFormService(new MockFormDefinitionService());
FormEncodingFactory.register(FormEncodingFactory.getEncoder(), decoder);
FormPreviewDTO dto = new FormPreviewDTO();
FormRepresentation form = createMockForm("myForm", "key1", "key2");
String jsonBody = FormEncodingFactory.getEncoder().encode(form);
dto.setRepresentation(jsonBody);
FormEncodingException exception = new FormEncodingException("Something going wrong");
EasyMock.expect(decoder.decode(EasyMock.eq(jsonBody))).andThrow(exception).once();
EasyMock.replay(context, request);
Response resp = restService.getFormPreview(dto, "lang", context, request);
EasyMock.verify(context, request);