Package org.eclipse.orion.server.core.metastore

Examples of org.eclipse.orion.server.core.metastore.IMetaStore


  }

  @Test
  public void testMoveUser() 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);

    // read the user using the cache
    UserInfo readUserInfo = metaStore.readUserByProperty(UserConstants2.USER_NAME, testUserLogin, false, false);
    assertNotNull(readUserInfo);
    assertEquals(readUserInfo.getUniqueId(), userInfo.getUniqueId());

    // 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);

    // update the content location
    IFileStore projectLocation = metaStore.getDefaultContentLocation(projectInfo);
    projectInfo.setContentLocation(projectLocation.toURI());
    metaStore.updateProject(projectInfo);

    // read the user back again
    userInfo = metaStore.readUser(testUserLogin);
    assertNotNull(userInfo);
    assertTrue(userInfo.getUserName().equals(testUserLogin));

    // move the user by changing the userName
    String newUserName = "ahunter";
    userInfo.setUserName(newUserName);

    // update the user
    metaStore.updateUser(userInfo);

    // read the user back again
    UserInfo readUserInfo2 = metaStore.readUser(newUserName);
    assertNotNull(readUserInfo2);
    assertTrue(readUserInfo2.getUserName().equals(newUserName));

    // read the user using the cache
    UserInfo readUserInfo3 = metaStore.readUserByProperty(UserConstants2.USER_NAME, testUserLogin, false, false);
    assertNull(readUserInfo3);

    // read the user using the cache
    UserInfo readUserInfo4 = metaStore.readUserByProperty(UserConstants2.USER_NAME, newUserName, false, false);
    assertNotNull(readUserInfo4);
    assertEquals(readUserInfo4.getUniqueId(), userInfo.getUniqueId());

    // read the moved workspace
    List<String> workspaceIds = userInfo.getWorkspaceIds();
    assertNotNull(workspaceIds);
    assertEquals(1, workspaceIds.size());
    String readWorkspaceId = workspaceIds.get(0);
    assertTrue(readWorkspaceId.startsWith(newUserName));
    WorkspaceInfo readWorkspaceInfo = metaStore.readWorkspace(readWorkspaceId);
    assertNotNull(readWorkspaceInfo);
    assertEquals(1, readWorkspaceInfo.getProjectNames().size());

    // read the moved project
    String readProjectName = readWorkspaceInfo.getProjectNames().get(0);
    assertEquals(readProjectName, projectName);
    ProjectInfo readProjectInfo = metaStore.readProject(readWorkspaceId, readProjectName);
    assertNotNull(readProjectInfo);
    assertEquals(readWorkspaceInfo.getUniqueId(), readProjectInfo.getWorkspaceId());
  }
View Full Code Here


  }

  @Test
  public void testReadAllUsers() throws CoreException {
    // create the MetaStore
    IMetaStore metaStore = OrionConfiguration.getMetaStore();

    // create the user
    UserInfo userInfo1 = new UserInfo();
    userInfo1.setUserName(testUserLogin);
    userInfo1.setFullName(testUserLogin);
    metaStore.createUser(userInfo1);

    // create a second user
    UserInfo userInfo2 = new UserInfo();
    userInfo2.setUserName("john");
    userInfo2.setFullName("John Doe");
    metaStore.createUser(userInfo2);

    // both user should be in the users list
    List<String> allUsers = metaStore.readAllUsers();
    assertNotNull(allUsers);
    assertTrue(allUsers.contains(userInfo1.getUniqueId()));
    assertTrue(allUsers.contains(userInfo2.getUniqueId()));
  }
View Full Code Here

    assertTrue(allUsers.contains(userInfo2.getUniqueId()));
  }

  @Test
  public void testReadCorruptedProjectJson() throws IOException, CoreException {
    IMetaStore metaStore = null;
    try {
      metaStore = OrionConfiguration.getMetaStore();
    } catch (NullPointerException e) {
      // expected when the workbench is not running
    }
    if (!(metaStore instanceof SimpleMetaStore)) {
      // the workbench is not running, just pass the test
      return;
    }

    // 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 a folder and project.json for the bad project on the filesystem
    String projectName = "Bad Project";
    File rootLocation = OrionConfiguration.getRootLocation().toLocalFile(EFS.NONE, null);
    String workspaceId = SimpleMetaStoreUtil.encodeWorkspaceId(userInfo.getUniqueId(), workspaceName);
    String encodedWorkspaceName = SimpleMetaStoreUtil.decodeWorkspaceNameFromWorkspaceId(workspaceId);
    File userMetaFolder = SimpleMetaStoreUtil.readMetaUserFolder(rootLocation, userInfo.getUniqueId());
    File workspaceMetaFolder = SimpleMetaStoreUtil.readMetaFolder(userMetaFolder, encodedWorkspaceName);

    assertTrue(SimpleMetaStoreUtil.createMetaFolder(workspaceMetaFolder, projectName));
    String corruptedProjectJson = "{\n\"OrionVersion\": 4,";
    File newFile = SimpleMetaStoreUtil.retrieveMetaFile(userMetaFolder, projectName);
    FileWriter fileWriter = new FileWriter(newFile);
    fileWriter.write(corruptedProjectJson);
    fileWriter.write("\n");
    fileWriter.flush();
    fileWriter.close();

    // read the project, should return null as the project is corrupted on disk
    ProjectInfo readProjectInfo = metaStore.readProject(workspaceInfo.getUniqueId(), projectName);
    assertNull(readProjectInfo);
  }
View Full Code Here

    assertNull(readProjectInfo);
  }

  @Test
  public void testReadCorruptedUserJson() throws IOException, CoreException {
    IMetaStore metaStore = null;
    try {
      metaStore = OrionConfiguration.getMetaStore();
    } catch (NullPointerException e) {
      // expected when the workbench is not running
    }
    if (!(metaStore instanceof SimpleMetaStore)) {
      // the workbench is not running, just pass the test
      return;
    }

    // create a folder and user.json for the bad user on the filesystem
    String baduser = testUserLogin;
    File rootLocation = OrionConfiguration.getRootLocation().toLocalFile(EFS.NONE, null);
    assertTrue(SimpleMetaStoreUtil.createMetaUserFolder(rootLocation, baduser));
    File userMetaFolder = SimpleMetaStoreUtil.readMetaUserFolder(rootLocation, baduser);
    String corruptedUserJson = "{\n\"FullName\": \"Administrator\",\n\"OrionVersion\": 4,";
    File corruptedUserFile = SimpleMetaStoreUtil.retrieveMetaFile(userMetaFolder, SimpleMetaStore.USER);
    FileWriter fileWriter = new FileWriter(corruptedUserFile);
    fileWriter.write(corruptedUserJson);
    fileWriter.write("\n");
    fileWriter.flush();
    fileWriter.close();

    // read the user, should return null as the user is corrupted on disk
    UserInfo readUserInfo = metaStore.readUser(baduser);
    assertNull(readUserInfo);

    // make sure we delete the corruptedUserFile afterwards or we break the indexer
    corruptedUserFile.delete();
    assertFalse(corruptedUserFile.exists());
View Full Code Here

    assertFalse(corruptedUserFile.exists());
  }

  @Test
  public void testReadCorruptedWorkspaceJson() throws IOException, CoreException {
    IMetaStore metaStore = null;
    try {
      metaStore = OrionConfiguration.getMetaStore();
    } catch (NullPointerException e) {
      // expected when the workbench is not running
    }
    if (!(metaStore instanceof SimpleMetaStore)) {
      // the workbench is not running, just pass the test
      return;
    }

    // create the user
    UserInfo userInfo = new UserInfo();
    userInfo.setUserName(testUserLogin);
    userInfo.setFullName(testUserLogin);
    metaStore.createUser(userInfo);

    // create a folder and workspace.json for the bad workspace on the filesystem
    File rootLocation = OrionConfiguration.getRootLocation().toLocalFile(EFS.NONE, null);
    String workspaceName = SimpleMetaStore.DEFAULT_WORKSPACE_NAME;
    String workspaceId = SimpleMetaStoreUtil.encodeWorkspaceId(userInfo.getUniqueId(), workspaceName);
    String encodedWorkspaceName = SimpleMetaStoreUtil.decodeWorkspaceNameFromWorkspaceId(workspaceId);
    File userMetaFolder = SimpleMetaStoreUtil.readMetaUserFolder(rootLocation, userInfo.getUniqueId());
    assertTrue(SimpleMetaStoreUtil.createMetaFolder(userMetaFolder, encodedWorkspaceName));
    String corruptedWorkspaceJson = "{\n\"OrionVersion\": 4,";
    File newFile = SimpleMetaStoreUtil.retrieveMetaFile(userMetaFolder, encodedWorkspaceName);
    FileWriter fileWriter = new FileWriter(newFile);
    fileWriter.write(corruptedWorkspaceJson);
    fileWriter.write("\n");
    fileWriter.flush();
    fileWriter.close();

    // read the workspace, should return null as the workspace is corrupted on disk
    WorkspaceInfo readWorkspaceInfo = metaStore.readWorkspace(workspaceId);
    assertNull(readWorkspaceInfo);
  }
View Full Code Here

  }

  @Test
  public void testReadProject() 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 projectName1 = "Orion Project";
    ProjectInfo projectInfo1 = new ProjectInfo();
    projectInfo1.setFullName(projectName1);
    try {
      projectInfo1.setContentLocation(new URI("file://root/folder/orion"));
    } catch (URISyntaxException e) {
      // should not get an exception here, simple URI
    }
    projectInfo1.setWorkspaceId(workspaceInfo.getUniqueId());
    metaStore.createProject(projectInfo1);

    // create another project
    String projectName2 = "Another Project";
    ProjectInfo projectInfo2 = new ProjectInfo();
    projectInfo2.setFullName(projectName2);
    try {
      projectInfo2.setContentLocation(new URI("file://root/folder/another"));
    } catch (URISyntaxException e) {
      // should not get an exception here, simple URI
    }
    projectInfo2.setWorkspaceId(workspaceInfo.getUniqueId());
    metaStore.createProject(projectInfo2);

    // read the workspace
    WorkspaceInfo readWorkspaceInfo = metaStore.readWorkspace(workspaceInfo.getUniqueId());
    assertNotNull(readWorkspaceInfo);
    assertEquals(readWorkspaceInfo.getFullName(), workspaceInfo.getFullName());
    assertEquals(2, readWorkspaceInfo.getProjectNames().size());
    assertTrue(readWorkspaceInfo.getProjectNames().contains(projectInfo1.getFullName()));
    assertTrue(readWorkspaceInfo.getProjectNames().contains(projectInfo2.getFullName()));

    // read the project
    ProjectInfo readProjectInfo = metaStore.readProject(workspaceInfo.getUniqueId(), projectInfo2.getFullName());
    assertNotNull(readProjectInfo);
    assertEquals(readProjectInfo.getFullName(), projectInfo2.getFullName());
  }
View Full Code Here

  }

  @Test
  public void testReadProjectThatDoesNotExist() 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 workspaceInfo1 = new WorkspaceInfo();
    workspaceInfo1.setFullName(workspaceName);
    workspaceInfo1.setUserId(userInfo.getUniqueId());
    metaStore.createWorkspace(workspaceInfo1);

    // read the project
    ProjectInfo readProjectInfo = metaStore.readProject(workspaceInfo1.getUniqueId(), "Project Zero");
    assertNull(readProjectInfo);
  }
View Full Code Here

  }

  @Test
  public void testReadProjectWithWorkspaceThatDoesNotExist() 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 id of a workspace that does not exist
    String workspaceName = SimpleMetaStore.DEFAULT_WORKSPACE_NAME;
    String workspaceId = SimpleMetaStoreUtil.encodeWorkspaceId(userInfo.getUniqueId(), workspaceName);

    // read the project
    ProjectInfo readProjectInfo = metaStore.readProject(workspaceId, "Project Zero");
    assertNull(readProjectInfo);
  }
View Full Code Here

  }

  @Test
  public void testReadUser() 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);

    // read the user
    UserInfo readUserInfo = metaStore.readUser(userInfo.getUniqueId());
    assertNotNull(readUserInfo);
    assertEquals(readUserInfo.getUniqueId(), userInfo.getUniqueId());
  }
View Full Code Here

  }

  @Test
  public void testReadUserByEmailConfirmationProperty() throws CoreException {
    // create the MetaStore
    IMetaStore metaStore = OrionConfiguration.getMetaStore();

    // create the user
    UserInfo userInfo = new UserInfo();
    userInfo.setUserName(testUserLogin);
    userInfo.setFullName(testUserLogin);
    String emailConfirmationId = "1413302977602-0.2258318922458089";
    userInfo.setProperty(UserConstants2.EMAIL_CONFIRMATION_ID, emailConfirmationId);
    metaStore.createUser(userInfo);

    // read the user back again
    UserInfo readUserInfo = metaStore.readUser(testUserLogin);
    assertNotNull(readUserInfo);
    assertEquals(testUserLogin, readUserInfo.getUserName());
    assertEquals(emailConfirmationId, readUserInfo.getProperty(UserConstants2.EMAIL_CONFIRMATION_ID));

    // update the UserInfo
    emailConfirmationId = "1381865755658-0.34789953865892875";
    userInfo.setProperty(UserConstants2.EMAIL_CONFIRMATION_ID, emailConfirmationId);

    // update the user
    metaStore.updateUser(userInfo);

    // read the user back again
    UserInfo readUserInfo2 = metaStore.readUser(testUserLogin);
    assertNotNull(readUserInfo2);
    assertEquals(testUserLogin, readUserInfo2.getUserName());
    String readEmail_confirmation = readUserInfo2.getProperty(UserConstants2.EMAIL_CONFIRMATION_ID);
    assertEquals(emailConfirmationId, readEmail_confirmation);

    // delete the email_confirmation property and update the user
    userInfo.setProperty(UserConstants2.EMAIL_CONFIRMATION_ID, null);
    metaStore.updateUser(userInfo);

    // read the user
    UserInfo readUserInfo3 = metaStore.readUser(userInfo.getUniqueId());
    assertNotNull(readUserInfo3);
    assertEquals(readUserInfo3.getUniqueId(), userInfo.getUniqueId());
    assertNull(readUserInfo3.getProperty(UserConstants2.EMAIL_CONFIRMATION_ID));

    // update the UserInfo again
    emailConfirmationId = "1381865755658-0.34789953865892875";
    userInfo.setProperty(UserConstants2.EMAIL_CONFIRMATION_ID, emailConfirmationId);

    // update the user
    metaStore.updateUser(userInfo);

    // read the user back again
    UserInfo readUserInfo4 = metaStore.readUser(testUserLogin);
    assertNotNull(readUserInfo4);
    assertEquals(testUserLogin, readUserInfo4.getUserName());
    assertEquals(emailConfirmationId, readUserInfo4.getProperty(UserConstants2.EMAIL_CONFIRMATION_ID));
  }
View Full Code Here

TOP

Related Classes of org.eclipse.orion.server.core.metastore.IMetaStore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.