RuntimeModelRegistryImpl implements RuntimeModelRegistry { @Override public Optional<RuntimeModel> registerFile(String fileName) { if (fileName == null || fileName.trim().isEmpty()) { logger.error("Invalid file name: {}", fileName); throw new IllegalArgumentException("Invalid file name."); } File file = new File(fileName); if (!file.exists()) { logger.error("File does not exist: {}", fileName); throw new IllegalArgumentException("File does not exist"); } if (!importValidationService.validate(fileName)) { logger.error("File does not have a valid structure: {}", fileName); throw new IllegalArgumentException("Not a valid file structure."); } try (FileInputStream fis = new FileInputStream(fileName)) { String importId = FilenameUtils.getBaseName(file.getPath()); return register(importId, fis); } catch (IOException e) { logger.error("Not able to load file {}", fileName, e); throw new IllegalArgumentException("Error loading import file: " + fileName, e); } }  @PostConstruct void init(); @Override Optional<RuntimeModel> single(); @Override Optional<RuntimeModel> get(String id); @Override Optional<RuntimeModel> registerFile(String fileName); @Override void setMode(DashbuilderRuntimeMode mode); @Override boolean isEmpty(); @Override DashbuilderRuntimeMode getMode(); @Override void remove(String modelId); Optional<RuntimeModel> register(String id, InputStream fileStream); @Override Collection<String> availableModels();  }
@Test(expected = IllegalArgumentException.class) public void testRegisterFileEmpty() { registry.registerFile(""); }
@Test(expected = IllegalArgumentException.class) public void testRegisterFileNull() { registry.registerFile(null); }
@Test(expected = IllegalArgumentException.class) public void testRegisterFileNotExist() { registry.registerFile("file"); }
@Test(expected = IllegalArgumentException.class) public void testRegisterFileInvalid() throws IOException { String file = tempFile.toString(); when(importValidationService.validate(file)).thenReturn(false); registry.registerFile(file); }