@Test(timeout=5000)
public void testCheckHttpsStrictAndNotProvided() throws Exception {

  HttpServletResponse resp = Mockito.mock(HttpServletResponse.class);
  StringWriter sw = new StringWriter();
  Mockito.when(resp.getWriter()).thenReturn(new PrintWriter(sw));
  YarnConfiguration conf = new YarnConfiguration();
  final URI httpLink = new URI("http://foo.com");
  final URI httpsLink = new URI("https://foo.com");
  // NONE policy
  conf.set(YarnConfiguration.RM_APPLICATION_HTTPS_POLICY, "NONE");
  assertFalse(WebAppProxyServlet.checkHttpsStrictAndNotProvided(
      resp, httpsLink, conf));
  assertEquals("", sw.toString());
  Mockito.verify(resp, Mockito.times(0)).setContentType(Mockito.any());
  assertFalse(WebAppProxyServlet.checkHttpsStrictAndNotProvided(
      resp, httpLink, conf));
  assertEquals("", sw.toString());
  Mockito.verify(resp, Mockito.times(0)).setContentType(Mockito.any());
  // LENIENT policy
  conf.set(YarnConfiguration.RM_APPLICATION_HTTPS_POLICY, "LENIENT");
  assertFalse(WebAppProxyServlet.checkHttpsStrictAndNotProvided(
      resp, httpsLink, conf));
  assertEquals("", sw.toString());
  Mockito.verify(resp, Mockito.times(0)).setContentType(Mockito.any());
  assertFalse(WebAppProxyServlet.checkHttpsStrictAndNotProvided(
      resp, httpLink, conf));
  assertEquals("", sw.toString());
  Mockito.verify(resp, Mockito.times(0)).setContentType(Mockito.any());
  // STRICT policy
  conf.set(YarnConfiguration.RM_APPLICATION_HTTPS_POLICY, "STRICT");
  assertFalse(WebAppProxyServlet.checkHttpsStrictAndNotProvided(
      resp, httpsLink, conf));
  assertEquals("", sw.toString());
  Mockito.verify(resp, Mockito.times(0)).setContentType(Mockito.any());
  assertTrue(WebAppProxyServlet.checkHttpsStrictAndNotProvided(
      resp, httpLink, conf));
  String s = sw.toString();
  assertTrue("Was expecting an HTML page explaining that an HTTPS tracking" +
      " url must be used but found " + s, s.contains("HTTPS must be used"));
  Mockito.verify(resp, Mockito.times(1)).setContentType(MimeType.HTML);
}