@Test
public void testLogQueryRequestBasicCredentialsNotInConfig() throws Exception {

  LoggingCookieStore.INSTANCE.getCookiesMap().clear();
  final String expectedClusterName = "my-test-cluster";
  EasyMockSupport mockSupport =
    new EasyMockSupport();
  CredentialStoreService credentialStoreServiceMock =
    mockSupport.createMock(CredentialStoreService.class);
  Cluster clusterMock =
    mockSupport.createMock(Cluster.class);
  LoggingRequestHelperImpl.NetworkConnection networkConnectionMock =
    mockSupport.createMock(LoggingRequestHelperImpl.NetworkConnection.class);
  Config adminPropertiesConfigMock =
    mockSupport.createMock(Config.class);
  Capture<HttpURLConnection> captureURLConnection = EasyMock.newCapture();
  Capture<HttpURLConnection> captureURLConnectionForAuthentication = EasyMock.newCapture();
  expect(clusterMock.getDesiredConfigByType("logsearch-admin-json")).andReturn(adminPropertiesConfigMock).atLeastOnce();
  expect(clusterMock.getClusterName()).andReturn(expectedClusterName).atLeastOnce();
  expect(adminPropertiesConfigMock.getProperties()).andReturn(Collections.<String, String>emptyMap()).atLeastOnce();
  expect(networkConnectionMock.readQueryResponseFromServer(capture(captureURLConnection))).andReturn(new StringBuffer(TEST_JSON_INPUT_TWO_LIST_ENTRIES)).atLeastOnce();
  // the credential store service should be consulted in this case, in order
  // to attempt to obtain the LogSearch credential from the store
  expect(credentialStoreServiceMock.getCredential(expectedClusterName, "logsearch.admin.credential")).andReturn(new PrincipalKeyCredential(EXPECTED_USER_NAME, EXPECTED_ADMIN_PASSWORD)).atLeastOnce();
  // expect that basic authentication is setup, with the expected encoded credentials
  networkConnectionMock.setupBasicAuthentication(capture(captureURLConnectionForAuthentication), eq(EXPECTED_ENCODED_CREDENTIALS));
  mockSupport.replayAll();
  LoggingRequestHelper helper =
    new LoggingRequestHelperImpl(EXPECTED_HOST_NAME, EXPECTED_PORT_NUMBER, EXPECTED_PROTOCOL, credentialStoreServiceMock, clusterMock, networkConnectionMock);
  // invoke query request
  LogQueryResponse result =
    helper.sendQueryRequest(Collections.<String,String>emptyMap());
  // verify that the HttpURLConnection was created with the proper values
  HttpURLConnection httpURLConnection =
    captureURLConnection.getValue();
  assertEquals("URLConnection did not have the correct hostname information",
    EXPECTED_HOST_NAME, httpURLConnection.getURL().getHost());
  assertEquals("URLConnection did not have the correct port information",
    EXPECTED_PORT_NUMBER, httpURLConnection.getURL().getPort() + "");
  assertEquals("URLConnection did not have the expected http protocol scheme",
    "http", httpURLConnection.getURL().getProtocol());
  assertEquals("URLConnection did not have the expected method set",
    "GET", httpURLConnection.getRequestMethod());
  assertSame("HttpUrlConnection instances passed into NetworkConnection mock should have been the same instance",
    httpURLConnection, captureURLConnectionForAuthentication.getValue());
  assertNotNull("Response object should not be null",
    result);
  // verify that the JSON response returned from the simulated server
  // is parsed properly, and has the expected values
  assertEquals("startIndex not parsed properly",
    "0", result.getStartIndex());
  assertEquals("pageSize not parsed properly",
    "5", result.getPageSize());
  assertEquals("totalCount not parsed properly",
    "10452", result.getTotalCount());
  assertEquals("resultSize not parsed properly",
    "5", result.getResultSize());
  assertEquals("queryTimeMS not parsed properly",
    "1458148754113", result.getQueryTimeMS());
  assertEquals("incorrect number of LogLineResult items parsed",
    2, result.getListOfResults().size());
  List<LogLineResult> listOfLineResults =
    result.getListOfResults();
  verifyFirstLine(listOfLineResults);
  verifySecondLine(listOfLineResults);
  mockSupport.verifyAll();
}