ProfileRepository { @RequestMapping("/clients/{hwAddress}") public ResponseEntity<Client> getClient(@PathVariable("hwAddress") String hwAddress) { Optional<org.openthinclient.common.model.Client> optional = findClient(hwAddress); if (optional.isPresent()) { org.openthinclient.common.model.Client source = optional.get(); Client client = mapper.translate(source.getRealm(), source); return ResponseEntity.ok(resolveConfiguration(source.getRealm(), client)); } return notFound(); } @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 testClientHasHardwareType() throws Exception { final Client client = new Client(); final HardwareType hwType = new HardwareType(); hwType.setName("SomeSimpleHardwareType"); hwType.setValue("Custom.third", "hardware type specific configuration property"); hwType.setValue("BootOptions.TFTPBootserver", "${myip}"); hwType.setDevices(new HashSet<>()); hwType.setSchema(schemaProvider.getSchema(HardwareType.class, null)); client.setHardwareType(hwType); client.setDevices(new HashSet<>()); 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 org.openthinclient.api.rest.model.Client actual = repo.getClient("00:11:22:33:44:55:66:77").getBody(); assertEquals("hardware type specific configuration property", actual.getConfiguration().getAdditionalProperties().get("Custom.third")); }
@Test public void testClientMergeAndResolveConfigurationHardware() throws Exception { final Client hwClient = new Client(); final HardwareType hwType = new HardwareType(); hwType.setName("SomeSimpleHardwareType"); hwType.setValue("Custom.third", "hardware type specific configuration property"); hwType.setValue("BootOptions.TFTPBootserver", "${myip}"); hwType.setValue("BootOptions.NFSRootserver", "${myip}"); hwType.setDevices(new HashSet<>()); hwType.setSchema(schemaProvider.getSchema(HardwareType.class, null)); hwClient.setHardwareType(hwType); hwClient.setDevices(new HashSet<>()); hwClient.setSchema(schemaProvider.getSchema(Client.class, null)); hwClient.setValue("BootOptions.NFSRootserver", "1.1.1.1"); Mockito.when(clientService.findByHwAddress("00:11:22:33:44:55:66:77")).thenReturn(java.util.Collections.singleton(hwClient)); ProfileRepository repo = new ProfileRepository(clientService, userService, hardwareTypeService); final org.openthinclient.api.rest.model.Client actual = repo.getClient("00:11:22:33:44:55:66:77").getBody(); assertEquals("hardware type specific configuration property", actual.getConfiguration().getAdditionalProperties().get("Custom.third")); assertEquals("${myip}", actual.getConfiguration().getAdditionalProperties().get("BootOptions.TFTPBootserver")); assertEquals("1.1.1.1", actual.getConfiguration().getAdditionalProperties().get("BootOptions.NFSRootserver")); }
@Test public void testClientMergeAndResolveConfigurationLocation() throws Exception { final Client locClient = new Client(); locClient.setName("otc-client-NA"); final Location loc = new Location(); loc.setName("North America (US)"); loc.setValue("Lang.lang", "en_US.UTF-8"); loc.setValue("Time.ntpservers", "pool.ntp.org"); loc.setValue("BootOptions.TFTPBootserver", "${myip}"); loc.setValue("BootOptions.NFSRootserver", "${myip}"); loc.setSchema(schemaProvider.getSchema(Location.class, null)); locClient.setLocation(loc); locClient.setDevices(new HashSet<>()); locClient.setSchema(schemaProvider.getSchema(Client.class, null)); Mockito.when(clientService.findByHwAddress("00:11:22:33:44:55:66:78")).thenReturn(java.util.Collections.singleton(locClient)); ProfileRepository repo = new ProfileRepository(clientService, userService, hardwareTypeService); final org.openthinclient.api.rest.model.Client locc = repo.getClient("00:11:22:33:44:55:66:78").getBody(); assertEquals("${myip}", locc.getConfiguration().getAdditionalProperties().get("BootOptions.TFTPBootserver")); assertEquals("${myip}", locc.getConfiguration().getAdditionalProperties().get("BootOptions.NFSRootserver")); }
@Test public void testClientMergeAndResolveConfigurationByRealm() throws Exception { Realm realm = new Realm(); realm.setSchema(schemaProvider.getSchema(Realm.class, null)); realm.setValue("BootOptions.TFTPBootserver", "${myip}"); realm.setValue("BootOptions.NFSRootserver", "${myip}"); realm.setValue("Directory.Primary.LDAPURLs", "ldap: final Client locClient = new Client(); locClient.setName("otc-client-NA"); locClient.setRealm(realm); final Location loc = new Location(); loc.setName("North America (US)"); loc.setValue("Lang.lang", "en_US.UTF-8"); loc.setValue("Time.ntpservers", "pool.ntp.org"); loc.setSchema(schemaProvider.getSchema(Location.class, null)); locClient.setLocation(loc); locClient.setDevices(new HashSet<>()); locClient.setSchema(schemaProvider.getSchema(Client.class, null)); LDAPConnectionDescriptor lcd = new LDAPConnectionDescriptor(); lcd.setBaseDN("dc=open+thinclient,dc=org"); lcd.setHostname("10.10.10.10"); realm.setConnectionDescriptor(lcd); Mockito.when(clientService.findByHwAddress("00:11:22:33:44:55:66:78")).thenReturn(java.util.Collections.singleton(locClient)); ProfileRepository repo = new ProfileRepository(clientService, userService, hardwareTypeService); final org.openthinclient.api.rest.model.Client locc = repo.getClient("00:11:22:33:44:55:66:78").getBody(); assertEquals("10.10.10.10", locc.getConfiguration().getAdditionalProperties().get("BootOptions.TFTPBootserver")); assertEquals("10.10.10.10", locc.getConfiguration().getAdditionalProperties().get("BootOptions.NFSRootserver")); assertEquals("ldap: assertEquals("cn=roPrincipal,ou=RealmConfiguration,dc=open+thinclient,dc=org", locc.getConfiguration().getAdditionalProperties().get("Directory.Primary.ReadOnly.Principal")); }