public void testInitRobot() throws Exception { AbstractRobot robot = new MockRobot(); AbstractRobot spyRobot = spy(robot); spyRobot.initRobot(); verify(spyRobot).computeCapabilityMap(); verify(spyRobot).computeHash(); }
public void testInitRobot() throws Exception { AbstractRobot robot = new MockRobot(); AbstractRobot spyRobot = spy(robot); spyRobot.initRobot(); verify(spyRobot).computeCapabilityMap(); verify(spyRobot).computeHash(); }
public void testSubmit() throws Exception { HttpFetcher fetcher = mock(HttpFetcher.class); when(fetcher.execute(any(HttpMessage.class), anyMapOf(String.class, Object.class))) .thenReturn(new HttpResponse("POST", new URL("http://foo.google.com"), 0, new ByteArrayInputStream("[{\"id\":\"op1\",\"data\":{}}]".getBytes()))); MockRobot robot = new MockRobot(); robot.setupOAuth("consumerKey", "consumerSecret", "http://gmodules.com/api/rpc"); WaveService service = new WaveService(fetcher, robot.computeHash()); service.setupOAuth("consumerKey", "consumerSecret", "http://gmodules.com/api/rpc"); OperationQueue opQueue = new OperationQueue(); opQueue.appendOperation(OperationType.ROBOT_NOTIFY, Parameter.of(ParamsProperty.CAPABILITIES_HASH, "123")); Wavelet wavelet = mock(Wavelet.class); when(wavelet.getOperationQueue()).thenReturn(opQueue); assertEquals(1, opQueue.getPendingOperations().size()); robot.submit(wavelet, "http://gmodules.com/api/rpc", service); assertEquals(0, opQueue.getPendingOperations().size()); verify(fetcher, times(1)).execute(any(HttpMessage.class), anyMapOf(String.class, Object.class)); }
public void testSubmit() throws Exception { HttpFetcher fetcher = mock(HttpFetcher.class); when(fetcher.execute(any(HttpMessage.class), anyMapOf(String.class, Object.class))) .thenReturn(new HttpResponse("POST", new URL("http://foo.google.com"), 0, new ByteArrayInputStream("[{\"id\":\"op1\",\"data\":{}}]".getBytes()))); MockRobot robot = new MockRobot(); robot.setupOAuth("consumerKey", "consumerSecret", "http://gmodules.com/api/rpc"); WaveService service = new WaveService(fetcher, robot.computeHash()); service.setupOAuth("consumerKey", "consumerSecret", "http://gmodules.com/api/rpc"); OperationQueue opQueue = new OperationQueue(); opQueue.appendOperation(OperationType.ROBOT_NOTIFY, Parameter.of(ParamsProperty.CAPABILITIES_HASH, "123")); Wavelet wavelet = mock(Wavelet.class); when(wavelet.getOperationQueue()).thenReturn(opQueue); assertEquals(1, opQueue.getPendingOperations().size()); robot.submit(wavelet, "http://gmodules.com/api/rpc", service); assertEquals(0, opQueue.getPendingOperations().size()); verify(fetcher, times(1)).execute(any(HttpMessage.class), anyMapOf(String.class, Object.class)); }
public void testProxiedBlindWavelet() throws Exception { AbstractRobot robot = new MockRobot(); Wavelet blindWavelet = robot.blindWavelet(WAVE_1, WAVELET_1, "proxyid"); assertEquals(0, blindWavelet.getOperationQueue().getPendingOperations().size()); blindWavelet.reply("\n"); List<OperationRequest> ops = blindWavelet.getOperationQueue().getPendingOperations(); assertEquals(1, ops.size()); assertEquals(OperationType.WAVELET_APPEND_BLIP.method(), ops.get(0).getMethod()); assertEquals("proxyid", ops.get(0).getParameter(ParamsProperty.PROXYING_FOR)); // Assert that proxy id should be valid. try { robot.blindWavelet(WAVE_1, WAVELET_1, "foo@bar.com"); fail("Should have failed since proxy id is not valid."); } catch (IllegalArgumentException e) { // Expected. } }
public void testProxiedBlindWavelet() throws Exception { AbstractRobot robot = new MockRobot(); Wavelet blindWavelet = robot.blindWavelet(WAVE_1, WAVELET_1, "proxyid"); assertEquals(0, blindWavelet.getOperationQueue().getPendingOperations().size()); blindWavelet.reply("\n"); List<OperationRequest> ops = blindWavelet.getOperationQueue().getPendingOperations(); assertEquals(1, ops.size()); assertEquals(OperationType.WAVELET_APPEND_BLIP.method(), ops.get(0).getMethod()); assertEquals("proxyid", ops.get(0).getParameter(ParamsProperty.PROXYING_FOR)); // Assert that proxy id should be valid. try { robot.blindWavelet(WAVE_1, WAVELET_1, "foo@bar.com"); fail("Should have failed since proxy id is not valid."); } catch (IllegalArgumentException e) { // Expected. } }
public void testServiceProfileRequest() throws Exception { AbstractRobot robot = new MockRobot(); MockWriter writer = new MockWriter(); robot.doGet(makeMockRequest(PROFILE_PATH), makeMockResponse(writer)); String profileJson = writer.getString(); String expectedProfileJson = "{\"address\":\"\",\"name\":\"Foo\",\"imageUrl\":\"http://foo.com/foo.png\"," + "\"profileUrl\":\"http://foo.com\"}"; assertEquals(expectedProfileJson, profileJson); }
public void testServiceVerificationTokenRequest() throws Exception { AbstractRobot robot = new MockRobot(); robot.setupVerificationToken("vertoken", "sectoken"); MockWriter writer = new MockWriter(); robot.doGet(makeMockRequest(VERIFY_TOKEN_PATH, "st", "sectoken"), makeMockResponse(writer)); assertEquals("vertoken", writer.getString()); HttpServletResponse response = makeMockResponse(new MockWriter()); robot.doGet(makeMockRequest(VERIFY_TOKEN_PATH), response); verify(response).setStatus(HttpURLConnection.HTTP_UNAUTHORIZED); }
public void testBlindWavelet() throws Exception { AbstractRobot robot = new MockRobot(); Wavelet blindWavelet = robot.blindWavelet(WAVE_1, WAVELET_1); assertEquals(0, blindWavelet.getOperationQueue().getPendingOperations().size()); blindWavelet.getParticipants().add("foo@test.com"); blindWavelet.reply("\n"); assertEquals(2, blindWavelet.getOperationQueue().getPendingOperations().size()); assertEquals(OperationType.WAVELET_ADD_PARTICIPANT_NEWSYNTAX.method(), blindWavelet.getOperationQueue().getPendingOperations().get(0).getMethod()); assertEquals(OperationType.WAVELET_APPEND_BLIP.method(), blindWavelet.getOperationQueue().getPendingOperations().get(1).getMethod()); }
public void testServiceProfileRequest() throws Exception { AbstractRobot robot = new MockRobot(); MockWriter writer = new MockWriter(); robot.doGet(makeMockRequest(PROFILE_PATH), makeMockResponse(writer)); String profileJson = writer.getString(); String expectedProfileJson = "{\"address\":\"\",\"name\":\"Foo\",\"imageUrl\":\"http://foo.com/foo.png\"," + "\"profileUrl\":\"http://foo.com\"}"; assertEquals(expectedProfileJson, profileJson); }
public void testBlindWavelet() throws Exception { AbstractRobot robot = new MockRobot(); Wavelet blindWavelet = robot.blindWavelet(WAVE_1, WAVELET_1); assertEquals(0, blindWavelet.getOperationQueue().getPendingOperations().size()); blindWavelet.getParticipants().add("foo@test.com"); blindWavelet.reply("\n"); assertEquals(2, blindWavelet.getOperationQueue().getPendingOperations().size()); assertEquals(OperationType.WAVELET_ADD_PARTICIPANT_NEWSYNTAX.method(), blindWavelet.getOperationQueue().getPendingOperations().get(0).getMethod()); assertEquals(OperationType.WAVELET_APPEND_BLIP.method(), blindWavelet.getOperationQueue().getPendingOperations().get(1).getMethod()); }
public void testServiceVerificationTokenRequest() throws Exception { AbstractRobot robot = new MockRobot(); robot.setupVerificationToken("vertoken", "sectoken"); MockWriter writer = new MockWriter(); robot.doGet(makeMockRequest(VERIFY_TOKEN_PATH, "st", "sectoken"), makeMockResponse(writer)); assertEquals("vertoken", writer.getString()); HttpServletResponse response = makeMockResponse(new MockWriter()); robot.doGet(makeMockRequest(VERIFY_TOKEN_PATH), response); verify(response).setStatus(HttpURLConnection.HTTP_UNAUTHORIZED); }