test_class.file: dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/HttpProcessHandlerTest.java
test_class.identifier: HttpProcessHandlerTest
test_case.body: @Test
      public void test2() throws Exception {
          ChannelHandlerContext context = mock(ChannelHandlerContext.class);
          ChannelFuture future = mock(ChannelFuture.class);
          when(context.writeAndFlush(any(FullHttpResponse.class))).thenReturn(future);
          HttpRequest message = Mockito.mock(HttpRequest.class);
          when(message.getUri()).thenReturn("localhost:80/greeting");
          when(message.getMethod()).thenReturn(HttpMethod.GET);
          HttpProcessHandler handler = new HttpProcessHandler();
          handler.channelRead0(context, message);
          verify(future).addListener(ChannelFutureListener.CLOSE);
          ArgumentCaptor<FullHttpResponse> captor = ArgumentCaptor.forClass(FullHttpResponse.class);
          verify(context).writeAndFlush(captor.capture());
          FullHttpResponse response = captor.getValue();
          assertThat(response.getStatus().code(), equalTo(200));
      }
test_case.class_method_signature: HttpProcessHandlerTest.test2()
test_case.full_signature: @Test public void test2()
test_case.identifier: test2
test_case.invocations: mock mock thenReturn when writeAndFlush any mock thenReturn when getUri thenReturn when getMethod channelRead0 addListener verify forClass writeAndFlush verify capture getValue assertThat code getStatus equalTo
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void test2()
focal_class.declarator: log = LoggerFactory.getLogger(HttpProcessHandler.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = LoggerFactory.getLogger(HttpProcessHandler.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: commandExecutor = new DefaultCommandExecutor()
focal_class.modifier: private static
focal_class.original_string: private static CommandExecutor commandExecutor = new DefaultCommandExecutor();
focal_class.type: CommandExecutor
focal_class.var_name: commandExecutor
focal_class.file: dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/HttpProcessHandler.java
focal_class.identifier: HttpProcessHandler
focal_class.class_method_signature: HttpProcessHandler.channelRead0(ChannelHandlerContext ctx, HttpRequest msg)
focal_class.full_signature: @Override protected void channelRead0(ChannelHandlerContext ctx, HttpRequest msg)
focal_class.identifier: channelRead0
focal_class.modifiers: @Override protected
focal_class.parameters: (ChannelHandlerContext ctx, HttpRequest msg)
focal_class.return: void
focal_class.signature: void channelRead0(ChannelHandlerContext ctx, HttpRequest msg)
focal_class.class_method_signature: HttpProcessHandler.http200(String result)
focal_class.full_signature: private static final FullHttpResponse http200(String result)
focal_class.identifier: http200
focal_class.modifiers: private static final
focal_class.parameters: (String result)
focal_class.return: FullHttpResponse
focal_class.signature: FullHttpResponse http200(String result)
focal_class.class_method_signature: HttpProcessHandler.http404()
focal_class.full_signature: private static final FullHttpResponse http404()
focal_class.identifier: http404
focal_class.modifiers: private static final
focal_class.parameters: ()
focal_class.return: FullHttpResponse
focal_class.signature: FullHttpResponse http404()
focal_class.class_method_signature: HttpProcessHandler.http500(String errorMessage)
focal_class.full_signature: private static final FullHttpResponse http500(String errorMessage)
focal_class.identifier: http500
focal_class.modifiers: private static final
focal_class.parameters: (String errorMessage)
focal_class.return: FullHttpResponse
focal_class.signature: FullHttpResponse http500(String errorMessage)
focal_class.superclass: extends SimpleChannelInboundHandler<HttpRequest>
focal_method.body: @Override
      protected void channelRead0(ChannelHandlerContext ctx, HttpRequest msg) throws Exception {
          CommandContext commandContext = HttpCommandDecoder.decode(msg);
          // return 404 when fail to construct command context
          if (commandContext == null) {
              log.warn("can not found commandContext url: " + msg.getUri());
              FullHttpResponse response = http404();
              ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
          } else {
              commandContext.setRemote(ctx.channel());
              try {
                  String result = commandExecutor.execute(commandContext);
                  FullHttpResponse response = http200(result);
                  ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
              } catch (NoSuchCommandException ex) {
                  log.error("can not find commandContext: " + commandContext, ex);
                  FullHttpResponse response = http404();
                  ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
              } catch (Exception qosEx) {
                  log.error("execute commandContext: " + commandContext + " got exception", qosEx);
                  FullHttpResponse response = http500(qosEx.getMessage());
                  ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
              }
          }
      }
focal_method.class_method_signature: HttpProcessHandler.channelRead0(ChannelHandlerContext ctx, HttpRequest msg)
focal_method.full_signature: @Override protected void channelRead0(ChannelHandlerContext ctx, HttpRequest msg)
focal_method.identifier: channelRead0
focal_method.invocations: decode warn getUri http404 addListener writeAndFlush setRemote channel execute http200 addListener writeAndFlush error http404 addListener writeAndFlush error http500 getMessage addListener writeAndFlush
focal_method.modifiers: @Override protected
focal_method.parameters: (ChannelHandlerContext ctx, HttpRequest msg)
focal_method.return: void
focal_method.signature: void channelRead0(ChannelHandlerContext ctx, HttpRequest msg)