@Test public void testChannelActive() throws Exception { when(connection.isStateOn()).thenReturn(false); when(connection.getMode()).thenReturn(ConnectionMode.Speaker); decoder.channelActive(channelHandlerContext); verify(connection).addChannelHandlerContext(any(ChannelHandlerContext.class)); when(connection.getMode()).thenReturn(ConnectionMode.Both); when(connection.isStateOn(ArgumentMatchers.any(ChannelHandlerContextType.class))).thenReturn(true); decoder.channelActive(channelHandlerContext); verify(connection, times(2)).addChannelHandlerContext(any(ChannelHandlerContext.class)); when(connection.isStateOn(ArgumentMatchers.any(ChannelHandlerContextType.class))).thenReturn(false); decoder.channelActive(channelHandlerContext); verify(connection, times(3)).addChannelHandlerContext(any(ChannelHandlerContext.class)); decoder = MessageDecoder.createServerProfile(sxpNode); decoder.channelActive(channelHandlerContext); verify(connection, times(4)).addChannelHandlerContext(any(ChannelHandlerContext.class)); when(sxpNode.getConnection(any(SocketAddress.class))).thenReturn(null); decoder.channelActive(channelHandlerContext); verify(channelHandlerContext, times(1)).close(); when(connection.isStateOn()).thenReturn(true); decoder.channelActive(channelHandlerContext); verify(channelHandlerContext, times(2)).close(); }
@Override public void channelActive(ChannelHandlerContext ctx) throws SocketAddressNotRecognizedException { LOG.info("Channel active for context {}", ctx); Channel channel = ctx.channel(); SocketAddress remoteAddr = channel.remoteAddress(); SxpConnection connection = owner.getConnection(remoteAddr); if (connection == null) { LOG.warn(getLogMessage(owner, ctx, "Channel activation")); ctx.close(); return; } if (profile.equals(Profile.SERVER)) { connection.setInetSocketAddresses(channel.localAddress()); connection.addChannelHandlerContext(ctx); return; } connection.setInetSocketAddresses(channel.localAddress()); connection.addChannelHandlerContext(ctx); connection.getContext().executeChannelActivationStrategy(ctx, connection); }
MessageDecoder extends SimpleChannelInboundHandler<ByteBuf> { @Override public void channelActive(ChannelHandlerContext ctx) throws SocketAddressNotRecognizedException { LOG.info("Channel active for context {}", ctx); Channel channel = ctx.channel(); SocketAddress remoteAddr = channel.remoteAddress(); SxpConnection connection = owner.getConnection(remoteAddr); if (connection == null) { LOG.warn(getLogMessage(owner, ctx, "Channel activation")); ctx.close(); return; } if (profile.equals(Profile.SERVER)) { connection.setInetSocketAddresses(channel.localAddress()); connection.addChannelHandlerContext(ctx); return; } connection.setInetSocketAddresses(channel.localAddress()); connection.addChannelHandlerContext(ctx); connection.getContext().executeChannelActivationStrategy(ctx, connection); } }
MessageDecoder extends SimpleChannelInboundHandler<ByteBuf> { @Override public void channelActive(ChannelHandlerContext ctx) throws SocketAddressNotRecognizedException { LOG.info("Channel active for context {}", ctx); Channel channel = ctx.channel(); SocketAddress remoteAddr = channel.remoteAddress(); SxpConnection connection = owner.getConnection(remoteAddr); if (connection == null) { LOG.warn(getLogMessage(owner, ctx, "Channel activation")); ctx.close(); return; } if (profile.equals(Profile.SERVER)) { connection.setInetSocketAddresses(channel.localAddress()); connection.addChannelHandlerContext(ctx); return; } connection.setInetSocketAddresses(channel.localAddress()); connection.addChannelHandlerContext(ctx); connection.getContext().executeChannelActivationStrategy(ctx, connection); } private  MessageDecoder(SxpNode owner, Profile profile); }
MessageDecoder extends SimpleChannelInboundHandler<ByteBuf> { @Override public void channelActive(ChannelHandlerContext ctx) throws SocketAddressNotRecognizedException { LOG.info("Channel active for context {}", ctx); Channel channel = ctx.channel(); SocketAddress remoteAddr = channel.remoteAddress(); SxpConnection connection = owner.getConnection(remoteAddr); if (connection == null) { LOG.warn(getLogMessage(owner, ctx, "Channel activation")); ctx.close(); return; } if (profile.equals(Profile.SERVER)) { connection.setInetSocketAddresses(channel.localAddress()); connection.addChannelHandlerContext(ctx); return; } connection.setInetSocketAddresses(channel.localAddress()); connection.addChannelHandlerContext(ctx); connection.getContext().executeChannelActivationStrategy(ctx, connection); } private  MessageDecoder(SxpNode owner, Profile profile); static ChannelInboundHandler createClientProfile(SxpNode owner); static ChannelInboundHandler createServerProfile(SxpNode owner); static void sendErrorMessage(ChannelHandlerContext ctx, ErrorMessageException messageValidationException,
            SxpConnection connection); @Override void channelActive(ChannelHandlerContext ctx); @Override void channelInactive(ChannelHandlerContext ctx); @Override void channelRead0(ChannelHandlerContext ctx, ByteBuf message); @Override void channelReadComplete(ChannelHandlerContext ctx); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause); }
MessageDecoder extends SimpleChannelInboundHandler<ByteBuf> { @Override public void channelActive(ChannelHandlerContext ctx) throws SocketAddressNotRecognizedException { LOG.info("Channel active for context {}", ctx); Channel channel = ctx.channel(); SocketAddress remoteAddr = channel.remoteAddress(); SxpConnection connection = owner.getConnection(remoteAddr); if (connection == null) { LOG.warn(getLogMessage(owner, ctx, "Channel activation")); ctx.close(); return; } if (profile.equals(Profile.SERVER)) { connection.setInetSocketAddresses(channel.localAddress()); connection.addChannelHandlerContext(ctx); return; } connection.setInetSocketAddresses(channel.localAddress()); connection.addChannelHandlerContext(ctx); connection.getContext().executeChannelActivationStrategy(ctx, connection); } private  MessageDecoder(SxpNode owner, Profile profile); static ChannelInboundHandler createClientProfile(SxpNode owner); static ChannelInboundHandler createServerProfile(SxpNode owner); static void sendErrorMessage(ChannelHandlerContext ctx, ErrorMessageException messageValidationException,
            SxpConnection connection); @Override void channelActive(ChannelHandlerContext ctx); @Override void channelInactive(ChannelHandlerContext ctx); @Override void channelRead0(ChannelHandlerContext ctx, ByteBuf message); @Override void channelReadComplete(ChannelHandlerContext ctx); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause);  }