ProfileRepository { @RequestMapping("/clients/{hwAddress}/devices") public ResponseEntity<List<Device>> getDevices(@PathVariable("hwAddress") String hwAddress) { final Optional<org.openthinclient.common.model.Client> opt = findClient(hwAddress); if (!opt.isPresent()) { return notFound(); } final org.openthinclient.common.model.Client client = opt.get(); final List<Device> res = Stream.concat( client.getDevices().stream(), client.getHardwareType().getDevices().stream() ) .map((source) -> mapper.translate(client.getRealm(), source)).collect(Collectors.toList()); return ResponseEntity.ok(res); } @Autowired  ProfileRepository(ClientService clientService, UserService userService, HardwareTypeService hardwareTypeService); @RequestMapping("/clients/{hwAddress}") ResponseEntity<Client> getClient(@PathVariable("hwAddress") String hwAddress); @RequestMapping("/clients") ResponseEntity<List<Client>> getClients(); @RequestMapping("/clients/{hwAddress}/devices") ResponseEntity<List<Device>> getDevices(@PathVariable("hwAddress") String hwAddress); @RequestMapping("/clients/{hwAddress}/applications") ResponseEntity<List<Application>> getApplications(@PathVariable("hwAddress") String hwAddress); @RequestMapping("/clients/{hwAddress}/printers") ResponseEntity<List<Printer>> getPrinters(@PathVariable("hwAddress") String hwAddress); @RequestMapping("/users/{sAMAccountName}/applications") ResponseEntity<List<Application>> getApplicationByUser(@PathVariable("sAMAccountName") String sAMAccountName); @RequestMapping("/users/{sAMAccountName}/printers") ResponseEntity<List<Printer>> getPrinterByUser(@PathVariable("sAMAccountName") String sAMAccountName); @GetMapping("/hardware-type/{name}") ResponseEntity<org.openthinclient.api.rest.model.HardwareType> getHardwareType(@PathVariable("name") String name);  }
@Test public void testGetDevices() throws Exception { final Client client = new Client(); final HardwareType hwType = new HardwareType(); hwType.setName("SomeSimpleHardwareType"); hwType.setValue("key", "value-1"); hwType.setDevices(new HashSet<>()); hwType.getDevices().add(createDevice("device 2")); hwType.setSchema(schemaProvider.getSchema(HardwareType.class, null)); client.setHardwareType(hwType); client.setDevices(new HashSet<>()); client.getDevices().add(createDevice("device 1")); client.setSchema(schemaProvider.getSchema(Client.class, null)); Mockito.when(clientService.findByHwAddress("00:11:22:33:44:55:66:77")).thenReturn(java.util.Collections.singleton(client)); final ProfileRepository repo = new ProfileRepository(clientService, userService, hardwareTypeService); final List<org.openthinclient.api.rest.model.Device> actualDevices = repo.getDevices("00:11:22:33:44:55:66:77").getBody(); assertThat(actualDevices, contains(profileWithName("device 1"), profileWithName("device 2"))); }