@Test public void test_should_fail_when_tenant_id_null() throws Exception { server.expect(once(), requestTo("http: .andExpect(method(HttpMethod.POST)) .andRespond(withSuccess(resources.getFileContents("failureTenantResponse.json"), MediaType.APPLICATION_JSON_UTF8)); final City city = tenantRepository.fetchTenantByCode(null); server.verify(); assertNull(city); }
public City fetchTenantByCode(String tenant) { String url = this.tenantServiceHost + "tenant/v1/tenant/_search?code=" + tenant; final RequestInfoBody requestInfoBody = new RequestInfoBody(RequestInfo.builder().build()); final HttpEntity<RequestInfoBody> request = new HttpEntity<>(requestInfoBody); TenantResponse tr = restTemplate.postForObject(url, request, TenantResponse.class); if (!CollectionUtils.isEmpty(tr.getTenant())) return tr.getTenant().get(0).getCity(); else return null; }
TenantRepository { public City fetchTenantByCode(String tenant) { String url = this.tenantServiceHost + "tenant/v1/tenant/_search?code=" + tenant; final RequestInfoBody requestInfoBody = new RequestInfoBody(RequestInfo.builder().build()); final HttpEntity<RequestInfoBody> request = new HttpEntity<>(requestInfoBody); TenantResponse tr = restTemplate.postForObject(url, request, TenantResponse.class); if (!CollectionUtils.isEmpty(tr.getTenant())) return tr.getTenant().get(0).getCity(); else return null; } }
TenantRepository { public City fetchTenantByCode(String tenant) { String url = this.tenantServiceHost + "tenant/v1/tenant/_search?code=" + tenant; final RequestInfoBody requestInfoBody = new RequestInfoBody(RequestInfo.builder().build()); final HttpEntity<RequestInfoBody> request = new HttpEntity<>(requestInfoBody); TenantResponse tr = restTemplate.postForObject(url, request, TenantResponse.class); if (!CollectionUtils.isEmpty(tr.getTenant())) return tr.getTenant().get(0).getCity(); else return null; } TenantRepository(RestTemplate restTemplate, @Value("${egov.services.tenant.host}") String tenantServiceHost); }
TenantRepository { public City fetchTenantByCode(String tenant) { String url = this.tenantServiceHost + "tenant/v1/tenant/_search?code=" + tenant; final RequestInfoBody requestInfoBody = new RequestInfoBody(RequestInfo.builder().build()); final HttpEntity<RequestInfoBody> request = new HttpEntity<>(requestInfoBody); TenantResponse tr = restTemplate.postForObject(url, request, TenantResponse.class); if (!CollectionUtils.isEmpty(tr.getTenant())) return tr.getTenant().get(0).getCity(); else return null; } TenantRepository(RestTemplate restTemplate, @Value("${egov.services.tenant.host}") String tenantServiceHost); City fetchTenantByCode(String tenant); }
TenantRepository { public City fetchTenantByCode(String tenant) { String url = this.tenantServiceHost + "tenant/v1/tenant/_search?code=" + tenant; final RequestInfoBody requestInfoBody = new RequestInfoBody(RequestInfo.builder().build()); final HttpEntity<RequestInfoBody> request = new HttpEntity<>(requestInfoBody); TenantResponse tr = restTemplate.postForObject(url, request, TenantResponse.class); if (!CollectionUtils.isEmpty(tr.getTenant())) return tr.getTenant().get(0).getCity(); else return null; } TenantRepository(RestTemplate restTemplate, @Value("${egov.services.tenant.host}") String tenantServiceHost); City fetchTenantByCode(String tenant);  }