DefaultSchemaRegistryClient implements ISchemaRegistryClient { @Override public void checkConnection() throws Exception { if(LOG.isDebugEnabled()) { LOG.debug("==> DefaultSchemaRegistryClient.checkConnection(): trying to connect to the SR server... "); } WebTarget webTarget = currentSchemaRegistryTargets().schemaRegistryVersion; Response responce = login.doAction(() -> webTarget.request(MediaType.APPLICATION_JSON_TYPE).get(Response.class)); if(LOG.isDebugEnabled()) { LOG.debug("DefaultSchemaRegistryClient.checkConnection(): response statusCode = " + responce.getStatus()); } if(responce.getStatus() != Response.Status.OK.getStatusCode()) { LOG.error("DefaultSchemaRegistryClient.checkConnection(): Connection failed. Response StatusCode = " + responce.getStatus()); throw new Exception("Connection failed. StatusCode = " + responce.getStatus()); } String respStr = responce.readEntity(String.class); if (!(respStr.contains("version") && respStr.contains("revision"))) { LOG.error("DefaultSchemaRegistryClient.checkConnection(): Connection failed. Bad response body."); throw new Exception("Connection failed. Bad response body."); } if(LOG.isDebugEnabled()) { LOG.debug("<== DefaultSchemaRegistryClient.checkConnection(): connection test successfull "); } } DefaultSchemaRegistryClient(Map<String, ?> conf); @Override List<String> getSchemaGroups(); @Override List<String> getSchemaNames(List<String> schemaGroups); @Override List<String> getSchemaBranches(String schemaMetadataName); @Override void checkConnection();  }
@Test public void checkConnection() { try { client.checkConnection(); } catch (Exception e) { fail("No Exception should be thrown"); } }
@Test(expected = Exception.class) public void checkConnection2() throws Exception { new DefaultSchemaRegistryClient(new HashMap<>()).checkConnection(); }