@Test
  public void conversionWithGoodInputTest() throws RestServiceException, CertificateException, SSLException {
    // headers
    HttpHeaders headers = new DefaultHttpHeaders(false);
    headers.add(HttpHeaderNames.CONTENT_LENGTH, new Random().nextInt(Integer.MAX_VALUE));
    headers.add("headerKey", "headerValue1");
    headers.add("headerKey", "headerValue2");
    headers.add("overLoadedKey", "headerOverloadedValue");
    headers.add("paramNoValueInUriButValueInHeader", "paramValueInHeader");

    // params
    Map<String, List<String>> params = new HashMap<String, List<String>>();
    List<String> values = new ArrayList<String>(2);
    values.add("paramValue1");
    values.add("paramValue2");
    params.put("paramKey", values);
    values = new ArrayList<String>(1);
    values.add("paramOverloadedValue");
    params.put("overLoadedKey", values);
    params.put("paramNoValue", null);
    params.put("paramNoValueInUriButValueInHeader", null);
    params.put(DENYLISTED_QUERY_PARAM, values);

    StringBuilder uriAttachmentBuilder = new StringBuilder("?");
    for (Map.Entry<String, List<String>> param : params.entrySet()) {
      if (param.getValue() != null) {
        for (String value : param.getValue()) {
          uriAttachmentBuilder.append(param.getKey()).append("=").append(value).append("&");
        }
      } else {
        uriAttachmentBuilder.append(param.getKey()).append("&");
      }
    }
    uriAttachmentBuilder.deleteCharAt(uriAttachmentBuilder.length() - 1);
    String uriAttachment = uriAttachmentBuilder.toString();

    NettyRequest nettyRequest;
    String uri;
    Set<Cookie> cookies = new HashSet<>();
    Cookie httpCookie = new DefaultCookie("CookieKey1", "CookieValue1");
    cookies.add(httpCookie);
    httpCookie = new DefaultCookie("CookieKey2", "CookieValue2");
    cookies.add(httpCookie);
    headers.add(RestUtils.Headers.COOKIE, getCookiesHeaderValue(cookies));

    for (MockChannel channel : Arrays.asList(new MockChannel(), new MockChannel().addSslHandlerToPipeline())) {
      uri = "/GET" + uriAttachment;
      nettyRequest = createNettyRequest(HttpMethod.GET, uri, headers, channel);
      validateRequest(nettyRequest, RestMethod.GET, uri, headers, params, cookies, channel);
      closeRequestAndValidate(nettyRequest, channel);

      RecvByteBufAllocator savedAllocator = channel.config().getRecvByteBufAllocator();
      int[] bufferWatermarks = {-1, 0, 1, DEFAULT_WATERMARK};
      for (int bufferWatermark : bufferWatermarks) {
        NettyRequest.bufferWatermark = bufferWatermark;
        uri = "/POST" + uriAttachment;
        nettyRequest = createNettyRequest(HttpMethod.POST, uri, headers, channel);
        validateRequest(nettyRequest, RestMethod.POST, uri, headers, params, cookies, channel);
        if (bufferWatermark > 0) {
          assertTrue("RecvAllocator should have changed",
              channel.config().getRecvByteBufAllocator() instanceof DefaultMaxBytesRecvByteBufAllocator);
        } else {
          assertEquals("RecvAllocator not as expected", savedAllocator, channel.config().getRecvByteBufAllocator());
        }
        closeRequestAndValidate(nettyRequest, channel);
        assertEquals("Allocator not as expected", savedAllocator, channel.config().getRecvByteBufAllocator());
      }

      for (int bufferWatermark : bufferWatermarks) {
        NettyRequest.bufferWatermark = bufferWatermark;
        uri = "/PUT" + uriAttachment;
        nettyRequest = createNettyRequest(HttpMethod.PUT, uri, headers, channel);
        validateRequest(nettyRequest, RestMethod.PUT, uri, headers, params, cookies, channel);
        if (bufferWatermark > 0) {
          assertTrue("RecvAllocator should have changed",
              channel.config().getRecvByteBufAllocator() instanceof DefaultMaxBytesRecvByteBufAllocator);
        } else {
          assertEquals("RecvAllocator not as expected", savedAllocator, channel.config().getRecvByteBufAllocator());
        }
        closeRequestAndValidate(nettyRequest, channel);
        assertEquals("Allocator not as expected", savedAllocator, channel.config().getRecvByteBufAllocator());
      }

      NettyRequest.bufferWatermark = DEFAULT_WATERMARK;

      uri = "/DELETE" + uriAttachment;
      nettyRequest = createNettyRequest(HttpMethod.DELETE, uri, headers, channel);
      validateRequest(nettyRequest, RestMethod.DELETE, uri, headers, params, cookies, channel);
      closeRequestAndValidate(nettyRequest, channel);

      uri = "/HEAD" + uriAttachment;
      nettyRequest = createNettyRequest(HttpMethod.HEAD, uri, headers, channel);
      validateRequest(nettyRequest, RestMethod.HEAD, uri, headers, params, cookies, channel);
      closeRequestAndValidate(nettyRequest, channel);

      uri = "/OPTIONS" + uriAttachment;
      nettyRequest = createNettyRequest(HttpMethod.OPTIONS, uri, headers, channel);
      validateRequest(nettyRequest, RestMethod.OPTIONS, uri, headers, params, cookies, channel);
      closeRequestAndValidate(nettyRequest, channel);
    }
  }
Tests conversion of {@link HttpRequest} to {@link NettyRequest} given good input.
@throws RestServiceException
ambry-rest/src/test/java/com/github/ambry/rest/NettyRequestTest.java