MappedDirectoryLocalFSMountStrategy implements LocalFSMountStrategy { @Override public java.io.File getMountPath(String workspaceId) throws ServerException { if (workspaceId == null || workspaceId.isEmpty()) { throw new ServerException("Unable get mount path for virtual file system. Workspace id is not set."); } final java.io.File directory = mapping.get(workspaceId); if (directory == null) { throw new ServerException( String.format("Unable get mount path for virtual file system. Virtual file system is not configured for workspace %s.", workspaceId)); } return directory; } MappedDirectoryLocalFSMountStrategy(Map<String, java.io.File> mapping);  MappedDirectoryLocalFSMountStrategy(); @Inject private  MappedDirectoryLocalFSMountStrategy(@Named("vfs.local.directory_mapping_file") java.io.File mappingFile); @PostConstruct void start(); @PreDestroy void stop(); void loadFromPropertiesFile(java.io.File propertiesFile); void saveInPropertiesFile(java.io.File propertiesFile); @Override java.io.File getMountPath(String workspaceId); @Override java.io.File getMountPath(); void setMountPath(String workspaceId, java.io.File mountPath); void removeMountPath(String workspaceId); Map<String, java.io.File> getDirectoryMapping();  }
@Test public void getsMountPathForWorkspace() throws Exception { final String workspaceId = "ws_1"; final Map<String, java.io.File> mapping = new HashMap<>(); mapping.put(workspaceId, mountPath); final LocalFSMountStrategy mountStrategy = new MappedDirectoryLocalFSMountStrategy(mapping); assertEquals(mountPath, mountStrategy.getMountPath(workspaceId)); }
@Test(expected = ServerException.class) public void throwsExceptionIfMountPathForWorkspaceIsNotSet() throws Exception { final LocalFSMountStrategy mountStrategy = new MappedDirectoryLocalFSMountStrategy(); mountStrategy.getMountPath(workspaceId); }
@Test(expected = ServerException.class) public void throwsExceptionIfWorkspaceIdIsNull() throws Exception { final Map<String, java.io.File> mapping = new HashMap<>(); mapping.put(workspaceId, mountPath); final LocalFSMountStrategy mountStrategy = new MappedDirectoryLocalFSMountStrategy(mapping); mountStrategy.getMountPath(null); }