@Test public void testInvokeFull() throws Exception { InboundMessagesParser<HasMsg> inboundMessagesParser = new JacksonInboundMessagesParser(new InboundMessagesParserObjectMapperFactoryImpl()); inboundMessagesParser.init(); String message = "{\"msg\":\"method\",\"method\":\"/customer/insert\",\"params\":[{\"name\":\"aaaaa\",\"fip\":\"No\",\"type\":\"test\",\"note\":\"test\",\"openingTimes\":{\"MONDAY\":[{\"time\":\"si\"},{\"time\":\"no\"}]}}],\"id\":\"2\",\"randomSeed\":\"70c88aa0cf95d711e947\"}"; Method object = (Method) inboundMessagesParser.parse(message); action.execute(object, session); assertEquals( "{\"collection\":\"customer\",\"id\":\"fixed\",\"fields\":[{\"name\":\"aaaaa\",\"fip\":\"No\",\"type\":\"test\",\"note\":\"test\",\"openingTimes\":{\"MONDAY\":[{\"time\":\"si\"},{\"time\":\"no\"}]}}],\"msg\":\"added\"}", mockSession.lastText.get(0)); assertEquals( "{\"id\":\"2\",\"error\":null,\"result\":null,\"msg\":\"result\"}", mockSession.lastText.get(1)); assertEquals("{\"methods\":[\"2\"],\"msg\":\"updated\"}", mockSession.lastText.get(2)); }
@Test public void testInvokeDelete() throws Exception { InboundMessagesParser<HasMsg> inboundMessagesParser = new JacksonInboundMessagesParser(new InboundMessagesParserObjectMapperFactoryImpl()); inboundMessagesParser.init(); assertEquals(1, collection.find(new BasicDBObject("_id", "testid")).size()); String message = "{\"msg\":\"method\",\"method\":\"/customer/delete\",\"params\":[{\"_id\":\"testid\"}],\"id\":\"2\"}"; Method object = (Method) inboundMessagesParser.parse(message); action.execute(object, session); assertEquals(0, collection.find(new BasicDBObject("_id", "testid")).size()); assertEquals( "{\"collection\":\"customer\",\"id\":\"testid\",\"msg\":\"removed\"}", mockSession.lastText.get(0)); assertEquals( "{\"id\":\"2\",\"error\":null,\"result\":null,\"msg\":\"result\"}", mockSession.lastText.get(1)); assertEquals("{\"methods\":[\"2\"],\"msg\":\"updated\"}", mockSession.lastText.get(2)); }
@Test // Should be useful to test more update queries like $inc public void testInvokeUpdate() throws Exception { InboundMessagesParser<HasMsg> inboundMessagesParser = new JacksonInboundMessagesParser(new InboundMessagesParserObjectMapperFactoryImpl()); inboundMessagesParser.init(); assertEquals(1, collection.find(new BasicDBObject("_id", "testid")).size()); String message = "{\"msg\":\"method\",\"method\":\"/customer/update\",\"params\":[{\"_id\":\"fixed\"},{\"$set\":{\"testField\":\"pippo\"}},{\"validationContext\":\"updateCustomerForm\"}],\"id\":\"2\"}"; Method object = (Method) inboundMessagesParser.parse(message); action.execute(object, session); assertEquals( "pippo", collection.find(new BasicDBObject("_id", "testid")).next().get("testField")); assertEquals( "{\"collection\":\"customer\",\"id\":\"fixed\",\"fields\":[{\"testField\":\"pippo\"}],\"cleared\":null,\"msg\":\"changed\"}", mockSession.lastText.get(0)); assertEquals( "{\"id\":\"2\",\"error\":null,\"result\":null,\"msg\":\"result\"}", mockSession.lastText.get(1)); assertEquals("{\"methods\":[\"2\"],\"msg\":\"updated\"}", mockSession.lastText.get(2)); }