@Private
  public WebApp getWebapp() {
    return this.webApp;
  }
@Test
  public void testRouterSupportCrossOrigin() throws ServletException, IOException {

    // We design test cases like this
    // We start the Router and enable the Router to support Cross-origin.
    // In the configuration, we allow example.com to access.
    // 1. We simulate example.com and get the correct response
    // 2. We simulate example.org and cannot get a response

    // Initialize RouterWeb's CrossOrigin capability
    Configuration conf = new Configuration();
    conf.setBoolean(YarnConfiguration.ROUTER_WEBAPP_ENABLE_CORS_FILTER, true);
    conf.set("hadoop.http.filter.initializers", HttpCrossOriginFilterInitializer.class.getName());
    conf.set(HttpCrossOriginFilterInitializer.PREFIX + CrossOriginFilter.ALLOWED_ORIGINS,
        "example.com");
    conf.set(HttpCrossOriginFilterInitializer.PREFIX + CrossOriginFilter.ALLOWED_HEADERS,
        "X-Requested-With,Accept");
    conf.set(HttpCrossOriginFilterInitializer.PREFIX + CrossOriginFilter.ALLOWED_METHODS,
        "GET,POST");

    // Start the router
    Router router = new Router();
    router.init(conf);
    router.start();
    router.getServices();

    // Get assigned to Filter.
    // The name of the filter is "Cross Origin Filter",
    // which is specified in HttpCrossOriginFilterInitializer.
    WebApp webApp = router.getWebapp();
    HttpServer2 httpServer2 = webApp.getHttpServer();
    WebAppContext webAppContext = httpServer2.getWebAppContext();
    ServletHandler servletHandler = webAppContext.getServletHandler();
    FilterHolder holder = servletHandler.getFilter("Cross Origin Filter");
    CrossOriginFilter filter = (CrossOriginFilter) holder.getFilter();

    // 1. Simulate [example.com] for access
    HttpServletRequest mockReq = Mockito.mock(HttpServletRequest.class);
    Mockito.when(mockReq.getHeader("Origin")).thenReturn("example.com");
    Mockito.when(mockReq.getHeader("Access-Control-Request-Method")).thenReturn("GET");
    Mockito.when(mockReq.getHeader("Access-Control-Request-Headers"))
        .thenReturn("X-Requested-With");

    // Objects to verify interactions based on request
    HttpServletResponseForRouterTest mockRes = new HttpServletResponseForRouterTest();
    FilterChain mockChain = Mockito.mock(FilterChain.class);

    // Object under test
    filter.doFilter(mockReq, mockRes, mockChain);

    // Why is 5, because when Filter passes,
    // CrossOriginFilter will set 5 values to Map
    Assert.assertEquals(5, mockRes.getHeaders().size());
    String allowResult = mockRes.getHeader("Access-Control-Allow-Credentials");
    Assert.assertEquals("true", allowResult);

    // 2. Simulate [example.org] for access
    HttpServletRequest mockReq2 = Mockito.mock(HttpServletRequest.class);
    Mockito.when(mockReq2.getHeader("Origin")).thenReturn("example.org");
    Mockito.when(mockReq2.getHeader("Access-Control-Request-Method")).thenReturn("GET");
    Mockito.when(mockReq2.getHeader("Access-Control-Request-Headers"))
        .thenReturn("X-Requested-With");

    // Objects to verify interactions based on request
    HttpServletResponseForRouterTest mockRes2 = new HttpServletResponseForRouterTest();
    FilterChain mockChain2 = Mockito.mock(FilterChain.class);

    // Object under test
    filter.doFilter(mockReq2, mockRes2, mockChain2);

    // Why is 0, because when the Filter fails,
    // CrossOriginFilter will not set any value
    Assert.assertEquals(0, mockRes2.getHeaders().size());

    router.stop();
  }