}
@Test
public void testMoveSimpleProject() throws CoreException {
// create the MetaStore
IMetaStore metaStore = OrionConfiguration.getMetaStore();
// create the user
UserInfo userInfo = new UserInfo();
userInfo.setUserName(testUserLogin);
userInfo.setFullName(testUserLogin);
metaStore.createUser(userInfo);
// create the workspace
String workspaceName = SimpleMetaStore.DEFAULT_WORKSPACE_NAME;
WorkspaceInfo workspaceInfo = new WorkspaceInfo();
workspaceInfo.setFullName(workspaceName);
workspaceInfo.setUserId(userInfo.getUniqueId());
metaStore.createWorkspace(workspaceInfo);
// create the project
String projectName = "Orion Project";
ProjectInfo projectInfo = new ProjectInfo();
projectInfo.setFullName(projectName);
projectInfo.setWorkspaceId(workspaceInfo.getUniqueId());
metaStore.createProject(projectInfo);
// create a project directory and file
IFileStore projectFolder = metaStore.getDefaultContentLocation(projectInfo);
if (!projectFolder.fetchInfo().exists()) {
projectFolder.mkdir(EFS.NONE, null);
}
assertTrue(projectFolder.fetchInfo().exists());
assertTrue(projectFolder.fetchInfo().isDirectory());
String fileName = "file.html";
IFileStore file = projectFolder.getChild(fileName);
try {
OutputStream outputStream = file.openOutputStream(EFS.NONE, null);
outputStream.write("<!doctype html>".getBytes());
outputStream.close();
} catch (IOException e) {
fail("Count not create a test file in the Orion Project:" + e.getLocalizedMessage());
}
assertTrue("the file in the project folder should exist.", file.fetchInfo().exists());
// update the project with the content location
projectInfo.setContentLocation(projectFolder.toLocalFile(EFS.NONE, null).toURI());
metaStore.updateProject(projectInfo);
// move the project by renaming the project by changing the projectName
String movedProjectName = "Moved Orion Project";
projectInfo.setFullName(movedProjectName);
// update the project
metaStore.updateProject(projectInfo);
// read the project back again
ProjectInfo readProjectInfo = metaStore.readProject(workspaceInfo.getUniqueId(), projectInfo.getFullName());
assertNotNull(readProjectInfo);
assertTrue(readProjectInfo.getFullName().equals(movedProjectName));
// verify the local project has moved
IFileStore workspaceFolder = metaStore.getWorkspaceContentLocation(workspaceInfo.getUniqueId());
projectFolder = workspaceFolder.getChild(projectName);
assertFalse("the original project folder should not exist.", projectFolder.fetchInfo().exists());
projectFolder = workspaceFolder.getChild(movedProjectName);
assertTrue("the new project folder should exist.", projectFolder.fetchInfo().exists() && projectFolder.fetchInfo().isDirectory());
file = projectFolder.getChild(fileName);