@Test public void getInstance(@Injectable Boolean autoDiscovery, @Injectable HttpTransport httpTransport) throws ServiceCombException, IOException { final int expectedCode = 200; Response response = new Response(); response.setStatusCode(expectedCode); String responseString = "{\n" + " \"instance\": {\n" + " \"instanceId\": \"2\",\n" + " \"serviceId\": \"1\",\n" + " \"version\": \"string\",\n" + " \"hostName\": \"string\",\n" + " \"endpoints\": [\n" + " \"string\"\n" + " ],\n" + " \"status\": \"UP\",\n" + " \"timestamp\": \"string\",\n" + " \"modTimestamp\": \"string\"\n" + " }\n" + "}"; response.setContent(responseString); new Expectations() { { Deencapsulation.newUninitializedInstance(DefaultHttpTransport.class); result = httpTransport; httpTransport.sendGetRequest(anyString); result = response; } }; ServiceCombClient serviceCombClient = new ServiceCombClient(url, httpTransport); MicroserviceInstanceSingleResponse actual = serviceCombClient.getInstance("1", "2"); Assert.assertEquals("1", actual.getInstance().getServiceId()); }
public MicroserviceInstanceSingleResponse getInstance(String serviceId, String instanceId) throws ServiceCombException { MicroserviceInstanceSingleResponse result = null; Response response = null; try { response = httpTransport .sendGetRequest( buildURI("/registry/microservices/" + serviceId + "/instances/" + instanceId)); if (response.getStatusCode() == HttpStatus.SC_OK) { LOGGER.info(response.getContent()); result = JsonUtils.OBJ_MAPPER .readValue(response.getContent(), MicroserviceInstanceSingleResponse.class); } else { 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 e) { throw new RemoteOperationException("read response failed. " + response, e); } return result; }
ServiceCombClient { public MicroserviceInstanceSingleResponse getInstance(String serviceId, String instanceId) throws ServiceCombException { MicroserviceInstanceSingleResponse result = null; Response response = null; try { response = httpTransport .sendGetRequest( buildURI("/registry/microservices/" + serviceId + "/instances/" + instanceId)); if (response.getStatusCode() == HttpStatus.SC_OK) { LOGGER.info(response.getContent()); result = JsonUtils.OBJ_MAPPER .readValue(response.getContent(), MicroserviceInstanceSingleResponse.class); } else { 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 e) { throw new RemoteOperationException("read response failed. " + response, e); } return result; } }
ServiceCombClient { public MicroserviceInstanceSingleResponse getInstance(String serviceId, String instanceId) throws ServiceCombException { MicroserviceInstanceSingleResponse result = null; Response response = null; try { response = httpTransport .sendGetRequest( buildURI("/registry/microservices/" + serviceId + "/instances/" + instanceId)); if (response.getStatusCode() == HttpStatus.SC_OK) { LOGGER.info(response.getContent()); result = JsonUtils.OBJ_MAPPER .readValue(response.getContent(), MicroserviceInstanceSingleResponse.class); } else { 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 e) { throw new RemoteOperationException("read response failed. " + response, e); } return result; } ServiceCombClient(String urls, HttpTransport httpTransport); }
ServiceCombClient { public MicroserviceInstanceSingleResponse getInstance(String serviceId, String instanceId) throws ServiceCombException { MicroserviceInstanceSingleResponse result = null; Response response = null; try { response = httpTransport .sendGetRequest( buildURI("/registry/microservices/" + serviceId + "/instances/" + instanceId)); if (response.getStatusCode() == HttpStatus.SC_OK) { LOGGER.info(response.getContent()); result = JsonUtils.OBJ_MAPPER .readValue(response.getContent(), MicroserviceInstanceSingleResponse.class); } else { 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 e) { throw new RemoteOperationException("read response failed. " + response, e); } return result; } 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 MicroserviceInstanceSingleResponse getInstance(String serviceId, String instanceId) throws ServiceCombException { MicroserviceInstanceSingleResponse result = null; Response response = null; try { response = httpTransport .sendGetRequest( buildURI("/registry/microservices/" + serviceId + "/instances/" + instanceId)); if (response.getStatusCode() == HttpStatus.SC_OK) { LOGGER.info(response.getContent()); result = JsonUtils.OBJ_MAPPER .readValue(response.getContent(), MicroserviceInstanceSingleResponse.class); } else { 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 e) { throw new RemoteOperationException("read response failed. " + response, e); } return result; } 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; }