HttpTransportFactory extends BaseHttpTransportFactory { @Override public void setConf(AbstractConfig config) { HttpTransportConfig httpConfig = (HttpTransportConfig) config; BasicHttpAuthConfig auth = (BasicHttpAuthConfig) httpConfig.getBasicHttpAuth(); if (auth != null) { byte[] encodedAuth = Base64.encodeBase64((auth.getUsername() + ":" + auth.getPassword()).getBytes()); httpConfig.addHttpHeader(HttpHeaders.AUTHORIZATION, "Basic " + new String(encodedAuth)); } super.setConf(config); }  @Override void setConf(AbstractConfig config);  }
@Test public void testBasicAuthHeaders() { HttpTransportConfig config = new HttpTransportConfig(); config.addHttpHeader("foo", "bar"); BasicHttpAuthConfig auth = new BasicHttpAuthConfig(); auth.setUsername("foo"); auth.setPassword(new StringValueConfig("bar")); config.setBasicHttpAuth(auth); HttpTransportFactory factory = spy(new HttpTransportFactory()); factory.setConf(config); ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class); verify(factory, times(1)).getClient(anyBoolean(), anyString(), captor.capture(), anyInt()); Map<String, String> expected = new HashMap<String, String>(); expected.put("foo", "bar"); expected.put("Authorization", "Basic Zm9vOmJhcg=="); assertEquals(expected, captor.getValue()); }