test_class.file: dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/LocalHostPermitHandlerTest.java
test_class.identifier: LocalHostPermitHandlerTest
test_case.body: @Test
      public void testHandlerAdded() throws Exception {
          ChannelHandlerContext context = mock(ChannelHandlerContext.class);
          Channel channel = mock(Channel.class);
          when(context.channel()).thenReturn(channel);
          InetAddress addr = mock(InetAddress.class);
          when(addr.isLoopbackAddress()).thenReturn(false);
          InetSocketAddress address = new InetSocketAddress(addr, 12345);
          when(channel.remoteAddress()).thenReturn(address);
          ChannelFuture future = mock(ChannelFuture.class);
          when(context.writeAndFlush(any(ByteBuf.class))).thenReturn(future);
          LocalHostPermitHandler handler = new LocalHostPermitHandler(false);
          handler.handlerAdded(context);
          ArgumentCaptor<ByteBuf> captor = ArgumentCaptor.forClass(ByteBuf.class);
          verify(context).writeAndFlush(captor.capture());
          assertThat(new String(captor.getValue().array()), containsString("Foreign Ip Not Permitted"));
          verify(future).addListener(ChannelFutureListener.CLOSE);
      }
test_case.class_method_signature: LocalHostPermitHandlerTest.testHandlerAdded()
test_case.full_signature: @Test public void testHandlerAdded()
test_case.identifier: testHandlerAdded
test_case.invocations: mock mock thenReturn when channel mock thenReturn when isLoopbackAddress thenReturn when remoteAddress mock thenReturn when writeAndFlush any handlerAdded forClass writeAndFlush verify capture assertThat array getValue containsString addListener verify
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testHandlerAdded()
focal_class.declarator: acceptForeignIp
focal_class.modifier: private
focal_class.original_string: private  boolean acceptForeignIp;
focal_class.type: boolean
focal_class.var_name: acceptForeignIp
focal_class.file: dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/LocalHostPermitHandler.java
focal_class.identifier: LocalHostPermitHandler
focal_class.class_method_signature: LocalHostPermitHandler.LocalHostPermitHandler(boolean acceptForeignIp)
focal_class.full_signature: public  LocalHostPermitHandler(boolean acceptForeignIp)
focal_class.identifier: LocalHostPermitHandler
focal_class.modifiers: public
focal_class.parameters: (boolean acceptForeignIp)
focal_class.signature:  LocalHostPermitHandler(boolean acceptForeignIp)
focal_class.class_method_signature: LocalHostPermitHandler.handlerAdded(ChannelHandlerContext ctx)
focal_class.full_signature: @Override public void handlerAdded(ChannelHandlerContext ctx)
focal_class.identifier: handlerAdded
focal_class.modifiers: @Override public
focal_class.parameters: (ChannelHandlerContext ctx)
focal_class.return: void
focal_class.signature: void handlerAdded(ChannelHandlerContext ctx)
focal_class.superclass: extends ChannelHandlerAdapter
focal_method.body: @Override
      public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
          if (!acceptForeignIp) {
              if (!((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().isLoopbackAddress()) {
                  ByteBuf cb = Unpooled.wrappedBuffer((QosConstants.BR_STR + "Foreign Ip Not Permitted."
                          + QosConstants.BR_STR).getBytes());
                  ctx.writeAndFlush(cb).addListener(ChannelFutureListener.CLOSE);
              }
          }
      }
focal_method.class_method_signature: LocalHostPermitHandler.handlerAdded(ChannelHandlerContext ctx)
focal_method.full_signature: @Override public void handlerAdded(ChannelHandlerContext ctx)
focal_method.identifier: handlerAdded
focal_method.invocations: isLoopbackAddress getAddress remoteAddress channel wrappedBuffer getBytes addListener writeAndFlush
focal_method.modifiers: @Override public
focal_method.parameters: (ChannelHandlerContext ctx)
focal_method.return: void
focal_method.signature: void handlerAdded(ChannelHandlerContext ctx)