@Test public void testBasicBatch() throws Exception { setupRequest("[{method:test.get,id:'1'},{method:test.get,id:'2'}]"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals("[{id:'1',result:{foo:'bar'}},{id:'2',result:{foo:'bar'}}]", getOutput()); }
@Test public void testMethodRecognition() throws Exception { setupRequest("{method:test.get,id:id,params:{userId:5,groupId:@self}}"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals("{id: 'id', result: {foo:'bar'}}", getOutput()); }
@Test public void testInvalidService() throws Exception { setupRequest("{method:junk.get,id:id,params:{userId:5,groupId:@self}}"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals( "{id:id,error:{message:'notImplemented: The method junk.get is not implemented',code:501}}", getOutput()); }
@Test public void testInvalidService() throws Exception { setupRequest("{method:junk.get,id:id,params:{userId:5,groupId:@self}}"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals( "{id:id,error:{message:'notImplemented: The method junk.get is not implemented',code:501}}", getOutput()); }
@Test public void testBasicBatch() throws Exception { setupRequest("[{method:test.get,id:'1'},{method:test.get,id:'2'}]"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals("[{id:'1',result:{foo:'bar'}},{id:'2',result:{foo:'bar'}}]", getOutput()); }
@Test public void testBasicBatch() throws Exception { setupRequest("[{method:test.get,id:'1'},{method:test.get,id:'2'}]"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals("[{id:'1',result:{foo:'bar'}},{id:'2',result:{foo:'bar'}}]", getOutput()); }
@Test public void testMethodRecognition() throws Exception { setupRequest("{method:test.get,id:id,params:{userId:5,groupId:@self}}"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals("{id: 'id', result: {foo:'bar'}}", getOutput()); }
@Test public void testInvalidService() throws Exception { setupRequest("{method:junk.get,id:id,params:{userId:5,groupId:@self}}"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals( "{id:id,error:{message:'notImplemented: The method junk.get is not implemented',code:501}}", getOutput()); }
@Test public void testInvalidService() throws Exception { setupRequest("{method:junk.get,id:id,params:{userId:5,groupId:@self}}"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals( "{id:id,error:{message:'notImplemented: The method junk.get is not implemented',code:501}}", getOutput()); }
@Test public void testBasicBatch() throws Exception { setupRequest("[{method:test.get,id:'1'},{method:test.get,id:'2'}]"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals("[{id:'1',result:{foo:'bar'}},{id:'2',result:{foo:'bar'}}]", getOutput()); }
@Test public void testInvalidService() throws Exception { setupRequest("{method:junk.get,id:id,params:{userId:5,groupId:@self}}"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals( "{id:id,error:{message:'notImplemented: The method junk.get is not implemented',code:501}}", getOutput()); }
@Test public void testMethodRecognition() throws Exception { setupRequest("{method:test.get,id:id,params:{userId:5,groupId:@self}}"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals("{id: 'id', result: {foo:'bar'}}", getOutput()); }
@Test public void testMethodRecognition() throws Exception { setupRequest("{method:test.get,id:id,params:{userId:5,groupId:@self}}"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals("{id: 'id', result: {foo:'bar'}}", getOutput()); }
@Test public void testMethodRecognition() throws Exception { setupRequest("{method:test.get,id:id,params:{userId:5,groupId:@self}}"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals("{id: 'id', result: {foo:'bar'}}", getOutput()); }
@Test public void testBasicBatch() throws Exception { setupRequest("[{method:test.get,id:'1'},{method:test.get,id:'2'}]"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals("[{id:'1',result:{foo:'bar'}},{id:'2',result:{foo:'bar'}}]", getOutput()); }
/** * Tests a data handler that returns a failed Future. * @throws Exception on failure */ @Test public void testFailedRequest() throws Exception { setupRequest("{id:id,method:test.futureException}"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals( "{id:id,error:{message:'badRequest: FAILURE_MESSAGE',code:400}}", getOutput()); }
/** * Tests a data handler that returns a failed Future. * @throws Exception on failure */ @Test public void testFailedRequest() throws Exception { setupRequest("{id:id,method:test.futureException}"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals( "{id:id,error:{message:'badRequest: FAILURE_MESSAGE',code:400}}", getOutput()); }
@Test public void testDisallowJSONP() throws Exception { servlet.setJSONPAllowed(false); setupRequest("[{method:test.get,id:'1'},{method:test.get,id:'2'}]"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals("[{id:'1',result:{foo:'bar'}},{id:'2',result:{foo:'bar'}}]", getOutput()); servlet.setJSONPAllowed(true); }
@Test public void testDisallowJSONP() throws Exception { servlet.setJSONPAllowed(false); setupRequest("[{method:test.get,id:'1'},{method:test.get,id:'2'}]"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals("[{id:'1',result:{foo:'bar'}},{id:'2',result:{foo:'bar'}}]", getOutput()); servlet.setJSONPAllowed(true); }
@Test public void testDisallowJSONP() throws Exception { servlet.setJSONPAllowed(false); setupRequest("[{method:test.get,id:'1'},{method:test.get,id:'2'}]"); expect(res.getWriter()).andReturn(writer); expectLastCall(); mockControl.replay(); servlet.service(req, res); mockControl.verify(); JsonAssert.assertJsonEquals("[{id:'1',result:{foo:'bar'}},{id:'2',result:{foo:'bar'}}]", getOutput()); servlet.setJSONPAllowed(true); }