/** * 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); } }
/** * @return the type of operation present in the request */ public static OperationType getOperationType(OperationRequest operation) { String methodName = operation.getMethod(); // TODO(ljvderijk): This might be removed after the deserialization is fixed if (methodName.startsWith("wave.")) { methodName = methodName.replaceFirst("^wave[.]", ""); } return OperationType.fromMethodName(methodName); }
/** * Registers the {@link OperationService} for the given {@link OperationType}. * * @param operation the type of the operation to register for * @param service the {@link OperationService} to be registered */ protected final void register(OperationType operation, OperationService service) { // Do a put first so we can make it use a concurrent map if needed. OperationService oldValue = operationMap.put(operation, service); if (oldValue != null) { LOG.warning("The OperationService for " + operation.name() + " was overwritten"); } } }
/** * Determines the protocol version of a given operation bundle by inspecting * the first operation in the bundle. If it is a {@code robot.notify} * operation, and contains {@code protocolVersion} parameter, then this method * will return the value of that parameter. Otherwise, this method will return * the default version. * * @param operations the {@link OperationRequest}s to inspect. * @return the wire protocol version of the given operation bundle. */ public static ProtocolVersion getProtocolVersion(List<OperationRequest> operations) { if (operations.size() == 0) { return ProtocolVersion.DEFAULT; } OperationRequest firstOperation = operations.get(0); if (firstOperation.getMethod().equals(OperationType.ROBOT_NOTIFY.method())) { String versionString = (String) firstOperation.getParameter(ParamsProperty.PROTOCOL_VERSION); if (versionString != null) { return ProtocolVersion.fromVersionString(versionString); } } return ProtocolVersion.DEFAULT; }
OperationRequest operation = new OperationRequest(opType.method(), String.format(OP_ID_FORMAT, nextOpId++), waveIdString, waveletIdString, blipId, parameters);
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); }
@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)); }
/** 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); }
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 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 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 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 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()); }