There is a client-server application.
For testing the server, I used an in-memory database, but with testing the client, I had problems.
It connects to the server using RestTemplate , therefore, I can only test the client when the server is running, and this is probably not entirely correct. And then, the client is tested in my case on a working database, and not on in-memory, this is definitely not good.
How should I test the client side?
Here, for example, I have a method in the client's Service Layer:
public class WebAppDepartmentsService { private final String HOST_URL = "http://localhost:8080/server/departments"; @Override public void delete(String departmentName){ RestTemplate restTemplate = new RestTemplate(); String uri = "/remove/department/{departmentName}"; Map<String, String> map = new HashMap<>(); map.put("departmentName", departmentName); restTemplate.postForLocation(HOST_URL + uri, Department.class, map); } } And now it is tested like this:
public class WebAppDepartmentsServiceTest { @Test public void testDelete(){ departmentService = new WebAppDepartmentsService(); departmentService.delete("QA"); List<Department> departments = departmentService.getAll(); assertEquals(5, departments.size()); } } PS If possible, I would like a specific test example for the delete(); method I presented delete();