/** * Test that when everything is ok, we can connect, submit, create wavelet and disconnect. * This is not supposed to be a thorough test. */ public void testSunnyDayScenario() { open(); viewOpenListener.expectedCall(MockViewChannelListener.MethodCall.ON_CONNECTED); viewOpenListener.expectedCall(MockViewChannelListener.MethodCall.ON_OPEN_FINISHED); // pretend an update with update wavelet. Note we don't add any data in the wavelet // because it's not really relevant for the test. respondWithEmptyUpdate(WAVELET_ID); viewOpenListener.expectedCall(MockViewChannelListener.MethodCall.ON_UPDATE, WAVELET_ID); // Submit a delta and check that we have the right channel id remembered. MockSubmitListener submitListener = new MockSubmitListener(); channel.submitDelta(WAVELET_ID, emptyDelta(), submitListener); assertEquals(1, waveViewService.submits.size()); assertEquals(CHANNEL_ID, waveViewService.lastSubmit().channelId); // Return a success message on the submitted delta byte[] hash = new byte[] {1, 2, 3, 4}; respondToSubmit(HashedVersion.of(2, hash), 1, null, ResponseCode.OK); submitListener.expectedCall(MockSubmitListener.MethodCall.ON_SUCCESS, 1, HashedVersion.of(2, hash)); // Check disconnect channel.close(); assertEquals(1, waveViewService.closes.size()); waveViewService.lastClose().callback.onSuccess(); }
/** * Test that when everything is ok, we can connect, submit, create wavelet and disconnect. * This is not supposed to be a thorough test. */ public void testSunnyDayScenario() { open(); viewOpenListener.expectedCall(MockViewChannelListener.MethodCall.ON_CONNECTED); viewOpenListener.expectedCall(MockViewChannelListener.MethodCall.ON_OPEN_FINISHED); // pretend an update with update wavelet. Note we don't add any data in the wavelet // because it's not really relevant for the test. respondWithEmptyUpdate(WAVELET_ID); viewOpenListener.expectedCall(MockViewChannelListener.MethodCall.ON_UPDATE, WAVELET_ID); // Submit a delta and check that we have the right channel id remembered. MockSubmitListener submitListener = new MockSubmitListener(); channel.submitDelta(WAVELET_ID, emptyDelta(), submitListener); assertEquals(1, waveViewService.submits.size()); assertEquals(CHANNEL_ID, waveViewService.lastSubmit().channelId); // Return a success message on the submitted delta byte[] hash = new byte[] {1, 2, 3, 4}; respondToSubmit(HashedVersion.of(2, hash), 1, null, ResponseCode.OK); submitListener.expectedCall(MockSubmitListener.MethodCall.ON_SUCCESS, 1, HashedVersion.of(2, hash)); // Check disconnect channel.close(); assertEquals(1, waveViewService.closes.size()); waveViewService.lastClose().callback.onSuccess(); }
/** * Tests that a failure of a ViewSubmit rpc causes the channel to call the * failure callback registered on delta submission. */ public void testDeltaSubmissionFailureCallsSubmissionFailureCallback() { open(); // Submit a delta. MockSubmitListener listener = new MockSubmitListener(); channel.submitDelta(WAVELET_ID, emptyDelta(), listener); // Fail the submit delta, and expect that the submit listened got the error. respondToSubmitWithFailure(); listener.expectedCall(MockSubmitListener.MethodCall.ON_FAILURE, "WAVE_SERVER_ERROR"); }
public void testSubmitDeltaWithErrorMessage() { open(); // submit a delta MockSubmitListener submitListener = new MockSubmitListener(); channel.submitDelta(WAVELET_ID, emptyDelta(), submitListener); // Success with error the submit delta. String errorMessage = "Bad things happened on the server"; respondToSubmit(HashedVersion.of(2, new byte[] {1, 2, 3, 4}), 1, errorMessage, ResponseCode.OK); submitListener.expectedCall(MockSubmitListener.MethodCall.ON_SUCCESS, errorMessage); }
/** * Tests that a failure of a ViewSubmit rpc causes the channel to call the * failure callback registered on delta submission. */ public void testDeltaSubmissionFailureCallsSubmissionFailureCallback() { open(); // Submit a delta. MockSubmitListener listener = new MockSubmitListener(); channel.submitDelta(WAVELET_ID, emptyDelta(), listener); // Fail the submit delta, and expect that the submit listened got the error. respondToSubmitWithFailure(); listener.expectedCall(MockSubmitListener.MethodCall.ON_FAILURE, "WAVE_SERVER_ERROR"); }
public void testSubmitDeltaOnClosedChannelThrowsIllegalStateException() { open(); close(); // submit a delta should fail try { channel.submitDelta(WAVELET_ID, emptyDelta(), new MockSubmitListener()); fail("Should not be able to submit on a closed channel"); } catch (IllegalStateException ex) { // expect exception } }
public void testSubmitDeltaOnClosedChannelThrowsIllegalStateException() { open(); close(); // submit a delta should fail try { channel.submitDelta(WAVELET_ID, emptyDelta(), new MockSubmitListener()); fail("Should not be able to submit on a closed channel"); } catch (IllegalStateException ex) { // expect exception } }
public void testSubmitDeltaWithErrorMessage() { open(); // submit a delta MockSubmitListener submitListener = new MockSubmitListener(); channel.submitDelta(WAVELET_ID, emptyDelta(), submitListener); // Success with error the submit delta. String errorMessage = "Bad things happened on the server"; respondToSubmit(HashedVersion.of(2, new byte[] {1, 2, 3, 4}), 1, errorMessage, ResponseCode.OK); submitListener.expectedCall(MockSubmitListener.MethodCall.ON_SUCCESS, errorMessage); }