### Question:
ConnectionCheck { public CheckResult checkURI(String uri) { final String notSensitiveUri = uri .replace(config.getAdminToken(), "__APIM_ADMIN_TOKEN___") .replace(config.getBackendToken(), "___APIM_BACKEND_TOKEN___"); final String checkName = "checkURI" + " " + notSensitiveUri; if(emergencyModeState.isEmergencyMode()) { return new CheckResult(checkName, Status.UP, "unchecked - emergency mode"); } HttpURLConnection conn = null; try { conn = createConnection(uri); final int responseCode = conn.getResponseCode(); if (Response.Status.Family.familyOf(responseCode) == Response.Status.Family.SUCCESSFUL) { return new CheckResult(checkName, Status.UP, createMessageFromConn(conn)); } else { return new CheckResult(checkName, Status.DOWN, createMessageFromConn(conn)); } } catch (IOException e) { LOG.info(APIM_1001.pattern(), notSensitiveUri, e); return new CheckResult(checkName, Status.DOWN, e.getMessage()); } finally { if (conn != null) { conn.disconnect(); } } } ConnectionCheck(ApimAdapterConfig config, EmergencyModeState emergencyModeState, int connectionTimeoutMillis, int readTimeoutMillis);  ConnectionCheck(ApimAdapterConfig config, EmergencyModeState emergencyModeState); CheckResult checkURIfor401or403(String uri); CheckResult checkURI(String uri); CheckResult checkThreeScaleAdmin(); CheckResult checkThreeScaleBackend();  }### Answer:
@Test public void checkURI() { ConnectionCheck connectionCheck = new ConnectionCheck(apimAdapterConfig, emergencyModeState); CheckResult check200 = connectionCheck.checkURI(baseUrl + "/admin/api/services/.*/proxy/mapping_rules.json.*"); CheckResult check400 = connectionCheck.checkURI(baseUrl + "/YouShallNotPass"); CheckResult check500 = connectionCheck.checkURI(baseUrl + "/misterStarkIDontFeelSoGood"); assertTrue(check200.isUp()); assertEquals(Status.UP, check200.getStatus()); assertFalse(check400.isUp()); assertEquals(Status.DOWN, check400.getStatus()); assertFalse(check500.isUp()); assertEquals(Status.DOWN, check500.getStatus()); }
@Test public void checkReadTimeout() { ConnectionCheck connectionCheck = new ConnectionCheck(apimAdapterConfig, emergencyModeState, 500, 500); StubGenerator.instantiateStubWith20SecondsDelay(); CheckResult check = connectionCheck.checkURI(baseUrl + "/iWillWaitHere"); assertFalse(check.isUp()); assertEquals(Status.DOWN, check.getStatus()); }
@Test public void connectionCheckTestInEmergencyMode() { EmergencyModeState emergencyModeState = new EmergencyModeState(); emergencyModeState.setConfigurationSuccessfulLoaded(ConfigType.PROXY, false); StubGenerator.instantiateStubWith20SecondsDelay(); ConnectionCheck connectionCheck = new ConnectionCheck(apimAdapterConfig, emergencyModeState); CheckResult check = connectionCheck.checkURI(baseUrl + "/iWillWaitHere"); assertTrue(check.isUp()); assertEquals(Status.UP, check.getStatus()); }