### Question:
DatadogClient extends RestTemplateWrapper implements MetricProviderClient { @Override public boolean testConnection() throws MangleException { log.debug("Validating test connection with Datadog using the specified tokens"); ResponseEntity<String> response = (ResponseEntity<String>) this .get(MetricProviderConstants.DATADOG_API_VALIDATE_API_APP_KEYS, String.class); if (StringUtils.isEmpty(response)) { throw new MangleException(ErrorCode.UNABLE_TO_CONNECT_TO_DATADOG_INSTANCE); } log.debug("Test connection completed and status: " + response.getStatusCode().value()); if (!(response.getStatusCode().value() == 200)) { throw new MangleException(ErrorCode.AUTH_FAILURE_TO_DATADOG); } return response.getStatusCode().value() == 200; } DatadogClient(DatadogConnectionProperties datadogConnectionProperties); @Override boolean testConnection();  }### Answer:
@Test(expectedExceptions = MangleException.class, description = "Validate the exception when invalid api tokens are passed") public void datadogConnectionWithNullTokens() throws MangleException { DatadogClient dgClient = new DatadogClient(new DatadogConnectionProperties()); dgClient.testConnection(); }
@Test(expectedExceptions = MangleException.class, description = "Validate the exception when null application token is specified") public void datadogConnectionWithNullAppToken() throws MangleException { DatadogConnectionProperties datadogConnectionProperties = getDatadogClientProperty(); datadogConnectionProperties.setApplicationKey(""); DatadogClient dgClient = new DatadogClient(datadogConnectionProperties); dgClient.testConnection(); }
@Test(expectedExceptions = MangleException.class, description = "Validate the exception when null datadog api instance is specified") public void datadogConnectionWithNullDatadogInstance() throws MangleException { DatadogConnectionProperties datadogConnectionProperties = getDatadogClientProperty(); datadogConnectionProperties.setUri(""); DatadogClient dgClient = new DatadogClient(datadogConnectionProperties); dgClient.testConnection(); }
@Test(expectedExceptions = MangleException.class, description = "Validate the exception when null api token is specified") public void datadogConnectionWithNullApiToken() throws MangleException { DatadogConnectionProperties datadogConnectionProperties = getDatadogClientProperty(); datadogConnectionProperties.setApiKey(""); DatadogClient dgClient = new DatadogClient(datadogConnectionProperties); dgClient.testConnection(); }
@Test(description = "Validating of Datadog test connection when invalid tokens are specified") public void dataDogConnectionWithInvalidTokends() throws MangleException { DatadogConnectionProperties datadogConnectionProperties = getDatadogClientProperty(); String expectedApiUrl = datadogConnectionProperties.getUri() + "/api/v1/validate?api_key=" + datadogConnectionProperties.getApiKey() + "&application_key=" + datadogConnectionProperties.getApplicationKey(); DatadogClient dgClient = new DatadogClient(datadogConnectionProperties); Assert.assertFalse(dgClient.testConnection()); Assert.assertEquals(dgClient.getRequestUrl(), expectedApiUrl); }