@Test public void test_getDepartments() { Department department1 = new Department().builder().id(1L).code("100").name("account").active(true).tenantId("default").build(); Department department2 = new Department().builder().id(2L).code("200").name("hr").active(true).tenantId("default").build(); List<Department> departments = new ArrayList<>(); departments.add(department1); departments.add(department2); ResponseInfo responseInfo = new ResponseInfo("emp", "1.0", "2017-01-18T07:18:23.130Z", "uief87324", "20170310130900", "200"); DepartmentResponse departmentResponse = new DepartmentResponse().builder().department(departments).responseInfo(responseInfo).build(); List<Long> ids = new ArrayList<>(); ids.add(1L); ids.add(2L); String tenantId = "default"; RequestInfo requestInfo = new RequestInfo().builder().apiId("emp").build(); RequestInfoWrapper requestInfoWrapper = new RequestInfoWrapper().builder().requestInfo(requestInfo).build(); when(restTemplate.postForObject(any(URI.class), Matchers.<HttpEntity<?>>any(), Matchers.any(Class.class))).thenReturn(departmentResponse); List<Department> result = departmentService.getDepartments("code", tenantId, requestInfoWrapper); assertThat(result).isEqualTo(departments); }
public List<Department> getDepartments(String code, String tenantId, RequestInfoWrapper requestInfoWrapper) { URI url = null; DepartmentResponse departmentResponse = null; try { url = new URI(propertiesManager.getCommonMastersServiceHost() + propertiesManager.getCommonMastersServiceBasePath() + propertiesManager.getCommonMastersServiceDepartmentsSearch() + "?tenantId=" + tenantId + "&code=" + code); log.debug(url.toString()); departmentResponse = restTemplate.postForObject(url, getRequestInfoAsHttpEntity(requestInfoWrapper), DepartmentResponse.class); } catch (Exception e) { log.error("Following exception occurred while accessing Department API : " + e.getMessage()); return null; } return departmentResponse.getDepartment(); }
DepartmentService { public List<Department> getDepartments(String code, String tenantId, RequestInfoWrapper requestInfoWrapper) { URI url = null; DepartmentResponse departmentResponse = null; try { url = new URI(propertiesManager.getCommonMastersServiceHost() + propertiesManager.getCommonMastersServiceBasePath() + propertiesManager.getCommonMastersServiceDepartmentsSearch() + "?tenantId=" + tenantId + "&code=" + code); log.debug(url.toString()); departmentResponse = restTemplate.postForObject(url, getRequestInfoAsHttpEntity(requestInfoWrapper), DepartmentResponse.class); } catch (Exception e) { log.error("Following exception occurred while accessing Department API : " + e.getMessage()); return null; } return departmentResponse.getDepartment(); } }
DepartmentService { public List<Department> getDepartments(String code, String tenantId, RequestInfoWrapper requestInfoWrapper) { URI url = null; DepartmentResponse departmentResponse = null; try { url = new URI(propertiesManager.getCommonMastersServiceHost() + propertiesManager.getCommonMastersServiceBasePath() + propertiesManager.getCommonMastersServiceDepartmentsSearch() + "?tenantId=" + tenantId + "&code=" + code); log.debug(url.toString()); departmentResponse = restTemplate.postForObject(url, getRequestInfoAsHttpEntity(requestInfoWrapper), DepartmentResponse.class); } catch (Exception e) { log.error("Following exception occurred while accessing Department API : " + e.getMessage()); return null; } return departmentResponse.getDepartment(); }  }
DepartmentService { public List<Department> getDepartments(String code, String tenantId, RequestInfoWrapper requestInfoWrapper) { URI url = null; DepartmentResponse departmentResponse = null; try { url = new URI(propertiesManager.getCommonMastersServiceHost() + propertiesManager.getCommonMastersServiceBasePath() + propertiesManager.getCommonMastersServiceDepartmentsSearch() + "?tenantId=" + tenantId + "&code=" + code); log.debug(url.toString()); departmentResponse = restTemplate.postForObject(url, getRequestInfoAsHttpEntity(requestInfoWrapper), DepartmentResponse.class); } catch (Exception e) { log.error("Following exception occurred while accessing Department API : " + e.getMessage()); return null; } return departmentResponse.getDepartment(); }  List<Department> getDepartments(String code, String tenantId, RequestInfoWrapper requestInfoWrapper); List<Department> getDepartmentList(String tenantId, RequestInfoWrapper requestInfoWrapper); Department getDepartmentByCode(String code, String tenantId, RequestInfoWrapper requestInfoWrapper); }
DepartmentService { public List<Department> getDepartments(String code, String tenantId, RequestInfoWrapper requestInfoWrapper) { URI url = null; DepartmentResponse departmentResponse = null; try { url = new URI(propertiesManager.getCommonMastersServiceHost() + propertiesManager.getCommonMastersServiceBasePath() + propertiesManager.getCommonMastersServiceDepartmentsSearch() + "?tenantId=" + tenantId + "&code=" + code); log.debug(url.toString()); departmentResponse = restTemplate.postForObject(url, getRequestInfoAsHttpEntity(requestInfoWrapper), DepartmentResponse.class); } catch (Exception e) { log.error("Following exception occurred while accessing Department API : " + e.getMessage()); return null; } return departmentResponse.getDepartment(); }  List<Department> getDepartments(String code, String tenantId, RequestInfoWrapper requestInfoWrapper); List<Department> getDepartmentList(String tenantId, RequestInfoWrapper requestInfoWrapper); Department getDepartmentByCode(String code, String tenantId, RequestInfoWrapper requestInfoWrapper);  }