PXEConfigTFTProvider implements TFTPProvider { protected Path getTemplatePath(Client client) { final String templatePathString = Config.BootOptions.BootLoaderTemplate.get(client); Path templatePath = null; if (templatePathString != null && templatePathString.trim().length() > 0) { templatePath = tftpHome.resolve(templatePathString); if (!Files.isRegularFile(templatePath)) { LOGGER.error("Boot template is not accessible: " + templatePath); templatePath = null; } } if (templatePath == null) return fallbackTemplatePath; return templatePath; } PXEConfigTFTProvider(Path tftpHome, RealmService realmService, ClientService clientService, Path fallbackTemplatePath); long getLength(SocketAddress peer, SocketAddress local, String arg0,
                        String arg1); InputStream getStream(SocketAddress peer, SocketAddress local,
                               String prefix, String fileName); static final Pattern TEMPLATE_REPLACEMENT_PATTERN; }
@Test public void testResolveTemplateNoConfiguredTemplate() throws Exception { final PXEConfigTFTProvider provider = createProvider(); final Client client = new Client(); final Path path = provider.getTemplatePath(client); assertEquals(config.defaultTemplatePath, path); }
@Test public void testResolveTemplateWithConfiguredTemplateThatDoesNotExist() throws Exception { final PXEConfigTFTProvider provider = createProvider(); final Client client = new Client(); BootOptions.BootLoaderTemplate.set(client, "some-non-existing-template.txt"); final Path path = provider.getTemplatePath(client); assertEquals(config.defaultTemplatePath, path); }
@Test public void testResolveTemplateWithConfiguredTemplate() throws Exception { final PXEConfigTFTProvider provider = createProvider(); final Client client = new Client(); BootOptions.BootLoaderTemplate.set(client, "another-template.txt"); final Path path = provider.getTemplatePath(client); assertEquals(config.secondTemplatePath, path); }