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 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); }
ProtocolVersion version = OperationUtil.getProtocolVersion(operations); OperationContextImpl context = new OperationContextImpl( waveletProvider, converterManager.getEventDataConverter(version), conversationUtil);
/** * Applies the operations within the context of the wavelet. * * @param operations the operations to apply * @param wavelet the wavelet which is the context in which this operation is * performed. * @param hashedVersion the version of the wavelet to which to apply the * operations to. * @param account the account for which to apply robot operations. */ void applyOperations(List<OperationRequest> operations, ReadableWaveletData wavelet, HashedVersion hashedVersion, RobotAccountData account) { // The robots we support should be sending us their version in their first // operation ProtocolVersion protocolVersion = OperationUtil.getProtocolVersion(operations); OperationContextImpl context = new OperationContextImpl(waveletProvider, converterManager.getEventDataConverter(protocolVersion), conversationUtil, new RobotWaveletData(wavelet, hashedVersion)); executeOperations(context, operations, account); handleResults(context, account); }