@Test public void getServiceCenterInstances(@Injectable HttpTransport httpTransport) throws RemoteOperationException, RemoteServerUnavailableException { final int expectedCode = 200; Response response = new Response(); response.setStatusCode(expectedCode); String responseString = "{\n" + " \"instances\": [\n" + " {\n" + " \"instanceId\": \"111\",\n" + " \"serviceId\": \"222\",\n" + " \"version\": \"0.1\",\n" + " \"hostName\": \"string\",\n" + " \"endpoints\": [\n" + " \"string\"\n" + " ],\n" + " \"status\": \"UP\",\n" + " \"timestamp\": \"212121212121\",\n" + " \"modTimestamp\": \"432432432432\"\n" + " }\n" + " ]\n" + "}"; response.setContent(responseString); new Expectations() { { Deencapsulation.newUninitializedInstance(DefaultHttpTransport.class); result = httpTransport; httpTransport.sendGetRequest(anyString); result = response; } }; ServiceCombClient serviceCombClient = new ServiceCombClient(url, httpTransport); MicroserviceInstancesResponse actual = serviceCombClient .getServiceCenterInstances(); Assert.assertNotNull(actual); Assert.assertEquals(actual.getInstances().size(), 1); Assert.assertEquals(actual.getInstances().get(0).getServiceId(), "222"); Assert.assertEquals(actual.getInstances().get(0).getInstanceId(), "111"); }
public MicroserviceInstancesResponse getServiceCenterInstances() throws RemoteOperationException { Response response = new Response(); try { String formatUrl = buildURI("/registry/health"); response = httpTransport.sendGetRequest(formatUrl); if (response.getStatusCode() == HttpStatus.SC_OK) { MicroserviceInstancesResponse result = JsonUtils.OBJ_MAPPER .readValue(response.getContent(), MicroserviceInstancesResponse.class); LOGGER.info("getServiceCenterInstances result=" + result); return result; } throw new RemoteOperationException( "read response failed. status:" + response.getStatusCode() + "; message:" + response .getStatusMessage() + "; content:" + response.getContent()); } catch (URISyntaxException e) { throw new RemoteOperationException("build url failed.", e); } catch (IOException | RemoteServerUnavailableException e) { throw new RemoteOperationException("read response failed. " + response, e); } }
ServiceCombClient { public MicroserviceInstancesResponse getServiceCenterInstances() throws RemoteOperationException { Response response = new Response(); try { String formatUrl = buildURI("/registry/health"); response = httpTransport.sendGetRequest(formatUrl); if (response.getStatusCode() == HttpStatus.SC_OK) { MicroserviceInstancesResponse result = JsonUtils.OBJ_MAPPER .readValue(response.getContent(), MicroserviceInstancesResponse.class); LOGGER.info("getServiceCenterInstances result=" + result); return result; } throw new RemoteOperationException( "read response failed. status:" + response.getStatusCode() + "; message:" + response .getStatusMessage() + "; content:" + response.getContent()); } catch (URISyntaxException e) { throw new RemoteOperationException("build url failed.", e); } catch (IOException | RemoteServerUnavailableException e) { throw new RemoteOperationException("read response failed. " + response, e); } } }
ServiceCombClient { public MicroserviceInstancesResponse getServiceCenterInstances() throws RemoteOperationException { Response response = new Response(); try { String formatUrl = buildURI("/registry/health"); response = httpTransport.sendGetRequest(formatUrl); if (response.getStatusCode() == HttpStatus.SC_OK) { MicroserviceInstancesResponse result = JsonUtils.OBJ_MAPPER .readValue(response.getContent(), MicroserviceInstancesResponse.class); LOGGER.info("getServiceCenterInstances result=" + result); return result; } throw new RemoteOperationException( "read response failed. status:" + response.getStatusCode() + "; message:" + response .getStatusMessage() + "; content:" + response.getContent()); } catch (URISyntaxException e) { throw new RemoteOperationException("build url failed.", e); } catch (IOException | RemoteServerUnavailableException e) { throw new RemoteOperationException("read response failed. " + response, e); } } ServiceCombClient(String urls, HttpTransport httpTransport); }
ServiceCombClient { public MicroserviceInstancesResponse getServiceCenterInstances() throws RemoteOperationException { Response response = new Response(); try { String formatUrl = buildURI("/registry/health"); response = httpTransport.sendGetRequest(formatUrl); if (response.getStatusCode() == HttpStatus.SC_OK) { MicroserviceInstancesResponse result = JsonUtils.OBJ_MAPPER .readValue(response.getContent(), MicroserviceInstancesResponse.class); LOGGER.info("getServiceCenterInstances result=" + result); return result; } throw new RemoteOperationException( "read response failed. status:" + response.getStatusCode() + "; message:" + response .getStatusMessage() + "; content:" + response.getContent()); } catch (URISyntaxException e) { throw new RemoteOperationException("build url failed.", e); } catch (IOException | RemoteServerUnavailableException e) { throw new RemoteOperationException("read response failed. " + response, e); } } ServiceCombClient(String urls, HttpTransport httpTransport); void autoDiscovery(boolean autoDiscovery); MicroserviceInstancesResponse getServiceCenterInstances(); String registerMicroservice(Microservice microservice); String getServiceId(Microservice microservice); SchemaResponse getSchemas(String serviceId); String registerInstance(MicroserviceInstance microserviceInstance); boolean deRegisterInstance(String serviceId, String instanceId); List<ServiceInstance> getInstances(Microservice microservice, String revision); MicroserviceInstanceSingleResponse getInstance(String serviceId, String instanceId); HeardBeatStatus heartbeat(HeartbeatRequest heartbeatRequest); boolean updateInstanceStatus(String serviceId, String instanceId, String status); MicroserviceResponse getServices(); boolean registerSchema(String microserviceId, String schemaId, String schemaContent); static String calcSchemaSummary(String schemaContent); void toggle(); String getUrl(); }
ServiceCombClient { public MicroserviceInstancesResponse getServiceCenterInstances() throws RemoteOperationException { Response response = new Response(); try { String formatUrl = buildURI("/registry/health"); response = httpTransport.sendGetRequest(formatUrl); if (response.getStatusCode() == HttpStatus.SC_OK) { MicroserviceInstancesResponse result = JsonUtils.OBJ_MAPPER .readValue(response.getContent(), MicroserviceInstancesResponse.class); LOGGER.info("getServiceCenterInstances result=" + result); return result; } throw new RemoteOperationException( "read response failed. status:" + response.getStatusCode() + "; message:" + response .getStatusMessage() + "; content:" + response.getContent()); } catch (URISyntaxException e) { throw new RemoteOperationException("build url failed.", e); } catch (IOException | RemoteServerUnavailableException e) { throw new RemoteOperationException("read response failed. " + response, e); } } ServiceCombClient(String urls, HttpTransport httpTransport); void autoDiscovery(boolean autoDiscovery); MicroserviceInstancesResponse getServiceCenterInstances(); String registerMicroservice(Microservice microservice); String getServiceId(Microservice microservice); SchemaResponse getSchemas(String serviceId); String registerInstance(MicroserviceInstance microserviceInstance); boolean deRegisterInstance(String serviceId, String instanceId); List<ServiceInstance> getInstances(Microservice microservice, String revision); MicroserviceInstanceSingleResponse getInstance(String serviceId, String instanceId); HeardBeatStatus heartbeat(HeartbeatRequest heartbeatRequest); boolean updateInstanceStatus(String serviceId, String instanceId, String status); MicroserviceResponse getServices(); boolean registerSchema(String microserviceId, String schemaId, String schemaContent); static String calcSchemaSummary(String schemaContent); void toggle(); String getUrl(); static String INSTANCE_STATUS; static String ZONE; }