request.addHeader("Origin", "http://www.test.org");
request.addHeader("Access-Control-Request-Method", "PATCH");
request.addHeader("Access-Control-Request-Headers", HttpHeaders.AUTHORIZATION + ", X-Custom-Header");
request.setMethod("OPTIONS");
MockHttpServletResponse response = new MockHttpServletResponse();
//null FilterChain as chain.filter to proceed the flow is not called with preflight
filter.doFilter(request, response, null);
assertEquals("86400", response.getHeader("Access-Control-Max-Age"));
assertEquals(HttpHeaders.AUTHORIZATION + ", X-Custom-Header", response.getHeader("Access-Control-Allow-Headers"));
assertEquals("GET, OPTIONS, HEAD, PUT, PATCH, POST, DELETE", response.getHeader("Access-Control-Allow-Methods"));
assertEquals("*", response.getHeader("Access-Control-Allow-Origin"));
}