/** * Checks whether the given operation method is of a robot notify operation. * * @param method the method to check. * @return {@code true} if the given method is a robot notify operation's * method. */ @SuppressWarnings("deprecation") private static boolean isRobotNotifyOperationMethod(String method) { return ROBOT_NOTIFY_CAPABILITIES_HASH.method().equals(method) || ROBOT_NOTIFY.method().equals(method); } }
protected static OperationRequest operationRequest(OperationType opType, String operationId, String rootBlipId, Parameter... params) { return new OperationRequest(opType.method(), operationId, s(WAVE_ID), s(WAVELET_ID), rootBlipId, params); }
/** Creates an operation request. */ protected static OperationRequest operationRequest(OperationType opType, String rootBlipId, Parameter... params) { return new OperationRequest(opType.method(), OPERATION_ID, s(WAVE_ID), s(WAVELET_ID), rootBlipId, params); }
/** Creates an operation request. */ protected static OperationRequest operationRequest(OperationType opType, Parameter... params) { return new OperationRequest(opType.method(), OPERATION_ID, s(WAVE_ID), s(WAVELET_ID), params); }
/** Creates an operation request. */ protected static OperationRequest operationRequest(OperationType opType, String rootBlipId, Parameter... params) { return new OperationRequest(opType.method(), OPERATION_ID, s(WAVE_ID), s(WAVELET_ID), rootBlipId, params); }
@Override protected void setUp() { service = CreateWaveletService.create(); waveletProvider = mock(WaveletProvider.class); converter = mock(EventDataConverter.class); waveletData = mock(WaveletData.class); when(waveletData.getWaveId()).thenReturn(TEMP_WAVE_ID); when(waveletData.getWaveletId()).thenReturn(WAVELET_ID); when(waveletData.getRootBlipId()).thenReturn("b+root"); ConversationUtil conversationUtil = new ConversationUtil(FakeIdGenerator.create()); context = new OperationContextImpl(waveletProvider, converter, conversationUtil); operation = new OperationRequest(OperationType.ROBOT_CREATE_WAVELET.method(), OPERATION_ID, Parameter.of(ParamsProperty.WAVELET_DATA, waveletData), Parameter.of(ParamsProperty.MESSAGE, MESSAGE)); }
protected static OperationRequest operationRequest(OperationType opType, String operationId, String rootBlipId, Parameter... params) { return new OperationRequest(opType.method(), operationId, s(WAVE_ID), s(WAVELET_ID), rootBlipId, params); }
/** Creates an operation request. */ protected static OperationRequest operationRequest(OperationType opType, Parameter... params) { return new OperationRequest(opType.method(), OPERATION_ID, s(WAVE_ID), s(WAVELET_ID), params); }
@Override protected void setUp() { service = CreateWaveletService.create(); waveletProvider = mock(WaveletProvider.class); converter = mock(EventDataConverter.class); waveletData = mock(WaveletData.class); when(waveletData.getWaveId()).thenReturn(TEMP_WAVE_ID); when(waveletData.getWaveletId()).thenReturn(WAVELET_ID); when(waveletData.getRootBlipId()).thenReturn("b+root"); ConversationUtil conversationUtil = new ConversationUtil(FakeIdGenerator.create()); context = new OperationContextImpl(waveletProvider, converter, conversationUtil); operation = new OperationRequest(OperationType.ROBOT_CREATE_WAVELET.method(), OPERATION_ID, Parameter.of(ParamsProperty.WAVELET_DATA, waveletData), Parameter.of(ParamsProperty.MESSAGE, MESSAGE)); }
public void testSubmitWith() throws Exception { OperationQueue queue = new OperationQueue(); queue.createWavelet("example.com", Collections.<String>emptySet()); OperationQueue queue2 = new OperationQueue(); queue2.setTitleOfWavelet(wavelet, "My title"); queue2.submitWith(queue); List<OperationRequest> ops = queue.getPendingOperations(); assertEquals(2, ops.size()); assertEquals(OperationType.ROBOT_CREATE_WAVELET.method(), ops.get(0).getMethod()); assertEquals(OperationType.WAVELET_SET_TITLE.method(), ops.get(1).getMethod()); assertEquals(queue.getPendingOperations(), queue2.getPendingOperations()); }
public void testSubmitWith() throws Exception { OperationQueue queue = new OperationQueue(); queue.createWavelet("example.com", Collections.<String>emptySet()); OperationQueue queue2 = new OperationQueue(); queue2.setTitleOfWavelet(wavelet, "My title"); queue2.submitWith(queue); List<OperationRequest> ops = queue.getPendingOperations(); assertEquals(2, ops.size()); assertEquals(OperationType.ROBOT_CREATE_WAVELET.method(), ops.get(0).getMethod()); assertEquals(OperationType.WAVELET_SET_TITLE.method(), ops.get(1).getMethod()); assertEquals(queue.getPendingOperations(), queue2.getPendingOperations()); }
public void testFetchWaveWithMissingParamThrowsInvalidRequestException() throws Exception { // No wave id or wavelet id set. OperationRequest operation = new OperationRequest(OperationType.ROBOT_FETCH_WAVE.method(), OPERATION_ID); OperationContextImpl context = helper.getContext(); try { service.execute(operation, context, ALEX); fail("Expected InvalidRequestException because params were not set"); } catch (InvalidRequestException e) { // expected } } }
public void testFetchWaveWithMissingParamThrowsInvalidRequestException() throws Exception { // No wave id or wavelet id set. OperationRequest operation = new OperationRequest(OperationType.ROBOT_FETCH_WAVE.method(), OPERATION_ID); OperationContextImpl context = helper.getContext(); try { service.execute(operation, context, ALEX); fail("Expected InvalidRequestException because params were not set"); } catch (InvalidRequestException e) { // expected } } }
public void testGetProtocolVersion() throws Exception { ProtocolVersion protocolVersion = OperationUtil.getProtocolVersion(Collections.<OperationRequest> emptyList()); assertEquals( "Empty list should return default version", ProtocolVersion.DEFAULT, protocolVersion); protocolVersion = OperationUtil.getProtocolVersion(Collections.singletonList(operation)); assertEquals("Non notify op as first op should return default", ProtocolVersion.DEFAULT, protocolVersion); OperationRequest notifyOp = new OperationRequest(OperationType.ROBOT_NOTIFY.method(), "op1"); protocolVersion = OperationUtil.getProtocolVersion(Collections.singletonList(notifyOp)); assertEquals("Notify op as first op without version parameter should return default", ProtocolVersion.DEFAULT, protocolVersion); Parameter versionParameter = Parameter.of(ParamsProperty.PROTOCOL_VERSION, ProtocolVersion.V2_1.getVersionString()); notifyOp = new OperationRequest(OperationType.ROBOT_NOTIFY.method(), "op1", versionParameter); protocolVersion = OperationUtil.getProtocolVersion(Collections.singletonList(notifyOp)); assertEquals( "Notify op as first op should return its version", ProtocolVersion.V2_1, protocolVersion); }
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 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 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 testSetTitle() throws Exception { String title = "Some title"; OperationRequest operation = new OperationRequest(OperationType.WAVELET_SET_TITLE.method(), WAVELET_ID.getId(), Parameter.of( ParamsProperty.WAVELET_TITLE, title), Parameter.of( ParamsProperty.WAVE_ID, LegacyIdSerialiser.INSTANCE.serialiseWaveId(WAVE_ID)), Parameter.of( ParamsProperty.WAVELET_ID, LegacyIdSerialiser.INSTANCE.serialiseWaveletId(WAVELET_ID))); service.execute(operation, helper.getContext(), ALEX); String annotation = getRootBlip().getContent().getAnnotation(0, TitleHelper.TITLE_KEY); assertEquals("Expected conv/title annotation on range (0,1)", title, annotation); }
public void testSetTitle() throws Exception { String title = "Some title"; OperationRequest operation = new OperationRequest(OperationType.WAVELET_SET_TITLE.method(), WAVELET_ID.getId(), Parameter.of( ParamsProperty.WAVELET_TITLE, title), Parameter.of( ParamsProperty.WAVE_ID, LegacyIdSerialiser.INSTANCE.serialiseWaveId(WAVE_ID)), Parameter.of( ParamsProperty.WAVELET_ID, LegacyIdSerialiser.INSTANCE.serialiseWaveletId(WAVELET_ID))); service.execute(operation, helper.getContext(), ALEX); String annotation = getRootBlip().getContent().getAnnotation(0, TitleHelper.TITLE_KEY); assertEquals("Expected conv/title annotation on range (0,1)", title, annotation); }