GameBootMessageController implements ResponseContextCodes { public <AGBM extends AbstractGameBootMessage> String process(String request) throws Exception { helper.incr(MESSAGE_COUNTER); if (isEmpty(request)) fail(getResponseContext(NO_MESSAGE), "Empty message"); AGBM msg = converter.fromJson(request); Response r = process(msg); return r == null ? null : converter.toJson(r); }  @Autowired void setErrorLookup(ResponseContextLookup lookup); @PostConstruct void postConstruct(); String process(String request); @SuppressWarnings("unchecked") Response process(AGBM msg);  }
@Test public void testCreateUser() throws Exception { UserMessage msg = new UserMessage(); msg.setUserName("test user"); msg.setFunction(Function.CREATE); msg.setNewPassword("password"); String s = controller.process(mapper.writeValueAsString(msg)); assertNotNull(s); Response r = mapper.readValue(s, Response.class); Object[] response = r.getPayload(); assertEquals(ResponseCode.SUCCESS, r.getResponseCode()); assertNotNull(response); assertEquals(1, response.length); Map<?, ?> blah = (Map<?, ?>) response[0]; Object id = blah.get("id"); assertNotNull(id); this.userId = Long.parseLong(id.toString()); }
@Test public void testErrorConditions() throws Exception { process(null, "null message"); process("", "empty message"); process("hello", "not a message"); process(mapper.writeValueAsString(new Response()), "no processor"); }