@Test
  public void shouldStripHeaderWithValue() {
    request.getHeaders().put("lu", "tze");
    request.getHeaders().put("lu", "tze");

    StripHeaderBean shb = new StripHeaderBean();
    shb.setPattern("tze");
    shb.setStripType(StripType.VALUE);
    shb.setWith(With.STRING);

    config.getStripHeaders().add(shb);

    policy.apply(request, mContext, config, mRequestChain);
    policy.apply(response, mContext, config, mResponseChain);

    assertFalse(request.getHeaders().containsKey("lu"));
    assertFalse(response.getHeaders().containsKey("lu"));
  }
  @Test
  public void shouldSetHeaderOnBoth() {
    AddHeaderBean header = new AddHeaderBean();
    header.setHeaderName("Request-And-Response");
    header.setHeaderValue("Weatherwax");
    header.setOverwrite(false);
    header.setApplyTo(ApplyTo.BOTH);
    header.setValueType(ValueType.STRING);
    config.getAddHeaders().add(header);

    policy.apply(request, mContext, config, mRequestChain);

    assertEquals("Weatherwax", request.getHeaders().get("Request-And-Response"));
    assertEquals(1, request.getHeaders().size());

    policy.apply(response, mContext, config, mResponseChain);

    assertEquals("Weatherwax", response.getHeaders().get("Request-And-Response"));
    assertEquals(1, response.getHeaders().size());
  }
  @Test
  public void shouldSetHeaderOnResponse() {
    AddHeaderBean header = new AddHeaderBean();
    header.setHeaderName("X-Clacks-Overhead");
    header.setHeaderValue("GNU Terry Pratchett");
    header.setOverwrite(false);
    header.setApplyTo(ApplyTo.RESPONSE);
    header.setValueType(ValueType.STRING);
    config.getAddHeaders().add(header);

    policy.apply(response, mContext, config, mResponseChain);

    assertEquals("GNU Terry Pratchett", response.getHeaders().get("X-Clacks-Overhead"));
    assertEquals(1, response.getHeaders().size());
  }
  @Test
  public void shouldStripHeaderWithKey() {
    request.getHeaders().put("vanish", "begone");

    StripHeaderBean shb = new StripHeaderBean();
    shb.setPattern("vanish");
    shb.setStripType(StripType.KEY);
    shb.setWith(With.STRING);

    config.getStripHeaders().add(shb);

    policy.apply(request, mContext, config, mRequestChain);

    assertFalse(request.getHeaders().containsKey("vanish"));
  }
  @Test
  public void shouldStripCaseInsensitively() {
    request.getHeaders().put("lord", "Vetinari");

    StripHeaderBean shb = new StripHeaderBean();
    shb.setPattern("VETINAR\\w+");
    shb.setStripType(StripType.VALUE);
    shb.setWith(With.REGEX);

    config.getStripHeaders().add(shb);

    policy.apply(request, mContext, config, mRequestChain);

    assertFalse(request.getHeaders().containsKey("vetinari"));
    assertTrue(request.getHeaders().isEmpty());
  }
  @Test
  public void shouldStripHeaderWithRegexKey() {
    request.getHeaders().put("sybil", "ramkin");

    StripHeaderBean shb = new StripHeaderBean();
    shb.setPattern("sy.*l");
    shb.setStripType(StripType.KEY);
    shb.setWith(With.REGEX);

    config.getStripHeaders().add(shb);

    policy.apply(request, mContext, config, mRequestChain);

    assertFalse(request.getHeaders().containsKey("sybil"));
    assertTrue(request.getHeaders().isEmpty());
  }
  @Test
  public void shouldNotOverwriteWhenFlagUnset() {
    request.getHeaders().put("X-Clacks-Overhead", "Ridcully");

    AddHeaderBean header = new AddHeaderBean();
    header.setHeaderName("X-Clacks-Overhead");
    header.setHeaderValue("GNU Terry Pratchett");
    header.setOverwrite(false);
    header.setApplyTo(ApplyTo.REQUEST);
    header.setValueType(ValueType.STRING);
    config.getAddHeaders().add(header);

    policy.apply(request, mContext, config, mRequestChain);

    assertEquals("Ridcully", request.getHeaders().get("X-Clacks-Overhead"));
    assertEquals(1, request.getHeaders().size());
  }
  @Test
  public void shouldGetValueFromSystemProperties() {
    System.setProperty("PROPERTIES_KEY", "42");

    AddHeaderBean header = spy(new AddHeaderBean());

    header.setHeaderName("the-meaning-of-life");
    header.setHeaderValue("PROPERTIES_KEY");
    header.setOverwrite(false);
    header.setApplyTo(ApplyTo.REQUEST);
    header.setValueType(ValueType.SYS);
    config.getAddHeaders().add(header);

    policy.apply(request, mContext, config, mRequestChain);

    assertEquals("42", request.getHeaders().get("the-meaning-of-life"));
    assertEquals(1, request.getHeaders().size());
  }
  @Test
  public void shouldGetValueFromEnvironment() {
    AddHeaderBean header = spy(new AddHeaderBean());

    header.setHeaderName("the-meaning-of-life");
    header.setHeaderValue("KEY_TO_THE_ENVIRONMENT");
    header.setOverwrite(false);
    header.setApplyTo(ApplyTo.REQUEST);
    header.setValueType(ValueType.ENV);
    config.getAddHeaders().add(header);

    given(header.getResolvedHeaderValue()).willReturn("42");

    policy.apply(request, mContext, config, mRequestChain);

    assertEquals("42", request.getHeaders().get("the-meaning-of-life"));
    assertEquals(1, request.getHeaders().size());
  }