@Test public void testExecuteInputMessageStrategy() throws Exception { context = new Context(sxpNode, Version.Version3); Context context_ = new Context(sxpNode, Version.Version4); when(connection.getContext()).thenReturn(context_); OpenMessage message = mock(OpenMessage.class); when(message.getVersion()).thenReturn(Version.Version4); when(message.getType()).thenReturn(MessageType.Open); when(connection.getVersion()).thenReturn(Version.Version3); context.executeInputMessageStrategy(channelHandlerContext, connection, message); when(message.getType()).thenReturn(MessageType.OpenResp); exception.expect(IllegalStateException.class); context.executeInputMessageStrategy(channelHandlerContext, connection, message); }
public void executeInputMessageStrategy(ChannelHandlerContext ctx, SxpConnection connection, Notification message) throws ErrorMessageReceivedException, ErrorMessageException, UpdateMessageConnectionStateException { if (isOpenRespMessage(message)) { Version negotiatedVersion = extractVersion(message); if (isVersionMismatch(negotiatedVersion)) { LOG.info("{} SXP version negotiated to {} from {}", connection, negotiatedVersion, version); connection.setBehaviorContexts(negotiatedVersion); connection.getContext().executeInputMessageStrategy(ctx, connection, message); return; } } else if (isOpenMessage(message)) { Version messageVersion = extractVersion(message); if (!messageVersion.equals(version)) { if (connection.getVersion().equals(Version.Version1)) { MessageDecoder.sendErrorMessage(ctx, new ErrorMessageException(ErrorCodeNonExtended.VersionMismatch, null), connection); connection.setStateOff(ctx); return; } else if (messageVersion.compareTo(version) < 0) { LOG.info("{} SXP version dropping version down from {} to {}", connection, version, messageVersion); connection.setBehaviorContexts(messageVersion); connection.getContext().executeInputMessageStrategy(ctx, connection, message); return; } else if (message instanceof OpenMessage) { message = new OpenMessageLegacyBuilder(((OpenMessage) message)).build(); } } } this.strategy.onInputMessage(ctx, connection, message); }
Context { public void executeInputMessageStrategy(ChannelHandlerContext ctx, SxpConnection connection, Notification message) throws ErrorMessageReceivedException, ErrorMessageException, UpdateMessageConnectionStateException { if (isOpenRespMessage(message)) { Version negotiatedVersion = extractVersion(message); if (isVersionMismatch(negotiatedVersion)) { LOG.info("{} SXP version negotiated to {} from {}", connection, negotiatedVersion, version); connection.setBehaviorContexts(negotiatedVersion); connection.getContext().executeInputMessageStrategy(ctx, connection, message); return; } } else if (isOpenMessage(message)) { Version messageVersion = extractVersion(message); if (!messageVersion.equals(version)) { if (connection.getVersion().equals(Version.Version1)) { MessageDecoder.sendErrorMessage(ctx, new ErrorMessageException(ErrorCodeNonExtended.VersionMismatch, null), connection); connection.setStateOff(ctx); return; } else if (messageVersion.compareTo(version) < 0) { LOG.info("{} SXP version dropping version down from {} to {}", connection, version, messageVersion); connection.setBehaviorContexts(messageVersion); connection.getContext().executeInputMessageStrategy(ctx, connection, message); return; } else if (message instanceof OpenMessage) { message = new OpenMessageLegacyBuilder(((OpenMessage) message)).build(); } } } this.strategy.onInputMessage(ctx, connection, message); } }
Context { public void executeInputMessageStrategy(ChannelHandlerContext ctx, SxpConnection connection, Notification message) throws ErrorMessageReceivedException, ErrorMessageException, UpdateMessageConnectionStateException { if (isOpenRespMessage(message)) { Version negotiatedVersion = extractVersion(message); if (isVersionMismatch(negotiatedVersion)) { LOG.info("{} SXP version negotiated to {} from {}", connection, negotiatedVersion, version); connection.setBehaviorContexts(negotiatedVersion); connection.getContext().executeInputMessageStrategy(ctx, connection, message); return; } } else if (isOpenMessage(message)) { Version messageVersion = extractVersion(message); if (!messageVersion.equals(version)) { if (connection.getVersion().equals(Version.Version1)) { MessageDecoder.sendErrorMessage(ctx, new ErrorMessageException(ErrorCodeNonExtended.VersionMismatch, null), connection); connection.setStateOff(ctx); return; } else if (messageVersion.compareTo(version) < 0) { LOG.info("{} SXP version dropping version down from {} to {}", connection, version, messageVersion); connection.setBehaviorContexts(messageVersion); connection.getContext().executeInputMessageStrategy(ctx, connection, message); return; } else if (message instanceof OpenMessage) { message = new OpenMessageLegacyBuilder(((OpenMessage) message)).build(); } } } this.strategy.onInputMessage(ctx, connection, message); } Context(SxpNode owner, Version version); }
Context { public void executeInputMessageStrategy(ChannelHandlerContext ctx, SxpConnection connection, Notification message) throws ErrorMessageReceivedException, ErrorMessageException, UpdateMessageConnectionStateException { if (isOpenRespMessage(message)) { Version negotiatedVersion = extractVersion(message); if (isVersionMismatch(negotiatedVersion)) { LOG.info("{} SXP version negotiated to {} from {}", connection, negotiatedVersion, version); connection.setBehaviorContexts(negotiatedVersion); connection.getContext().executeInputMessageStrategy(ctx, connection, message); return; } } else if (isOpenMessage(message)) { Version messageVersion = extractVersion(message); if (!messageVersion.equals(version)) { if (connection.getVersion().equals(Version.Version1)) { MessageDecoder.sendErrorMessage(ctx, new ErrorMessageException(ErrorCodeNonExtended.VersionMismatch, null), connection); connection.setStateOff(ctx); return; } else if (messageVersion.compareTo(version) < 0) { LOG.info("{} SXP version dropping version down from {} to {}", connection, version, messageVersion); connection.setBehaviorContexts(messageVersion); connection.getContext().executeInputMessageStrategy(ctx, connection, message); return; } else if (message instanceof OpenMessage) { message = new OpenMessageLegacyBuilder(((OpenMessage) message)).build(); } } } this.strategy.onInputMessage(ctx, connection, message); } Context(SxpNode owner, Version version); void executeChannelActivationStrategy(ChannelHandlerContext ctx, SxpConnection connection); void executeChannelInactivationStrategy(ChannelHandlerContext ctx, SxpConnection connection); void executeExceptionCaughtStrategy(ChannelHandlerContext ctx, SxpConnection connection); void executeInputMessageStrategy(ChannelHandlerContext ctx, SxpConnection connection, Notification message); Notification executeParseInput(ByteBuf request); ByteBuf executeUpdateMessageStrategy(SxpConnection connection,
            List<T> deleteBindings, List<T> addBindings, SxpBindingFilter bindingFilter); SxpNode getOwner(); Version getVersion(); }
Context { public void executeInputMessageStrategy(ChannelHandlerContext ctx, SxpConnection connection, Notification message) throws ErrorMessageReceivedException, ErrorMessageException, UpdateMessageConnectionStateException { if (isOpenRespMessage(message)) { Version negotiatedVersion = extractVersion(message); if (isVersionMismatch(negotiatedVersion)) { LOG.info("{} SXP version negotiated to {} from {}", connection, negotiatedVersion, version); connection.setBehaviorContexts(negotiatedVersion); connection.getContext().executeInputMessageStrategy(ctx, connection, message); return; } } else if (isOpenMessage(message)) { Version messageVersion = extractVersion(message); if (!messageVersion.equals(version)) { if (connection.getVersion().equals(Version.Version1)) { MessageDecoder.sendErrorMessage(ctx, new ErrorMessageException(ErrorCodeNonExtended.VersionMismatch, null), connection); connection.setStateOff(ctx); return; } else if (messageVersion.compareTo(version) < 0) { LOG.info("{} SXP version dropping version down from {} to {}", connection, version, messageVersion); connection.setBehaviorContexts(messageVersion); connection.getContext().executeInputMessageStrategy(ctx, connection, message); return; } else if (message instanceof OpenMessage) { message = new OpenMessageLegacyBuilder(((OpenMessage) message)).build(); } } } this.strategy.onInputMessage(ctx, connection, message); } Context(SxpNode owner, Version version); void executeChannelActivationStrategy(ChannelHandlerContext ctx, SxpConnection connection); void executeChannelInactivationStrategy(ChannelHandlerContext ctx, SxpConnection connection); void executeExceptionCaughtStrategy(ChannelHandlerContext ctx, SxpConnection connection); void executeInputMessageStrategy(ChannelHandlerContext ctx, SxpConnection connection, Notification message); Notification executeParseInput(ByteBuf request); ByteBuf executeUpdateMessageStrategy(SxpConnection connection,
            List<T> deleteBindings, List<T> addBindings, SxpBindingFilter bindingFilter); SxpNode getOwner(); Version getVersion();  }