@Test public void getServiceId(@Injectable Boolean autoDiscovery, @Injectable HttpTransport httpTransport) throws ServiceCombException, IOException { final int expectedCode = 200; Response response = new Response(); response.setStatusCode(expectedCode); String responseString = "{\"serviceId\": \"22222\"}"; response.setContent(responseString); autoDiscovery = false; Microservice microservice = new Microservice(); new Expectations() { { Deencapsulation.newUninitializedInstance(DefaultHttpTransport.class); result = httpTransport; httpTransport.sendGetRequest(anyString); result = response; } }; ServiceCombClient serviceCombClient = new ServiceCombClient(url, httpTransport); String actual = serviceCombClient.getServiceId(microservice); Assert.assertEquals("22222", actual); }
public String getServiceId(Microservice microservice) throws ServiceCombException { Response response = null; try { String path = buildURI("/registry/existence"); response = httpTransport .sendGetRequest(addParam2URI(path, "microservice", null, microservice)); if (response.getStatusCode() == HttpStatus.SC_OK) { LOGGER.info(response.getContent()); HashMap<String, String> result = JsonUtils.OBJ_MAPPER .readValue(response.getContent(), HashMap.class); return result.get("serviceId"); } else if (response.getStatusCode() == HttpStatus.SC_BAD_REQUEST) { LOGGER.info(response.getContent()); return null; } 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); } }
ServiceCombClient { public String getServiceId(Microservice microservice) throws ServiceCombException { Response response = null; try { String path = buildURI("/registry/existence"); response = httpTransport .sendGetRequest(addParam2URI(path, "microservice", null, microservice)); if (response.getStatusCode() == HttpStatus.SC_OK) { LOGGER.info(response.getContent()); HashMap<String, String> result = JsonUtils.OBJ_MAPPER .readValue(response.getContent(), HashMap.class); return result.get("serviceId"); } else if (response.getStatusCode() == HttpStatus.SC_BAD_REQUEST) { LOGGER.info(response.getContent()); return null; } 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); } } }
ServiceCombClient { public String getServiceId(Microservice microservice) throws ServiceCombException { Response response = null; try { String path = buildURI("/registry/existence"); response = httpTransport .sendGetRequest(addParam2URI(path, "microservice", null, microservice)); if (response.getStatusCode() == HttpStatus.SC_OK) { LOGGER.info(response.getContent()); HashMap<String, String> result = JsonUtils.OBJ_MAPPER .readValue(response.getContent(), HashMap.class); return result.get("serviceId"); } else if (response.getStatusCode() == HttpStatus.SC_BAD_REQUEST) { LOGGER.info(response.getContent()); return null; } 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); } } ServiceCombClient(String urls, HttpTransport httpTransport); }
ServiceCombClient { public String getServiceId(Microservice microservice) throws ServiceCombException { Response response = null; try { String path = buildURI("/registry/existence"); response = httpTransport .sendGetRequest(addParam2URI(path, "microservice", null, microservice)); if (response.getStatusCode() == HttpStatus.SC_OK) { LOGGER.info(response.getContent()); HashMap<String, String> result = JsonUtils.OBJ_MAPPER .readValue(response.getContent(), HashMap.class); return result.get("serviceId"); } else if (response.getStatusCode() == HttpStatus.SC_BAD_REQUEST) { LOGGER.info(response.getContent()); return null; } 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); } } 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 String getServiceId(Microservice microservice) throws ServiceCombException { Response response = null; try { String path = buildURI("/registry/existence"); response = httpTransport .sendGetRequest(addParam2URI(path, "microservice", null, microservice)); if (response.getStatusCode() == HttpStatus.SC_OK) { LOGGER.info(response.getContent()); HashMap<String, String> result = JsonUtils.OBJ_MAPPER .readValue(response.getContent(), HashMap.class); return result.get("serviceId"); } else if (response.getStatusCode() == HttpStatus.SC_BAD_REQUEST) { LOGGER.info(response.getContent()); return null; } 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); } } 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; }