Search in sources :

Example 1 with MorphiaProject

use of io.lumeer.storage.mongodb.model.MorphiaProject in project engine by Lumeer.

the class MorphiaProjectDaoTest method testUpdateProjectCode.

@Test
public void testUpdateProjectCode() {
    MorphiaProject project = prepareProject(CODE1);
    String id = datastore.save(projectDao.databaseCollection(), project).getId().toString();
    assertThat(id).isNotNull().isNotEmpty();
    project.setCode(CODE2);
    projectDao.updateProject(id, project);
    MorphiaProject storedProject = datastore.get(projectDao.databaseCollection(), MorphiaProject.class, new ObjectId(id));
    assertThat(storedProject).isNotNull();
    assertThat(storedProject.getCode()).isEqualTo(CODE2);
}
Also used : ObjectId(org.bson.types.ObjectId) MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Test(org.junit.Test)

Example 2 with MorphiaProject

use of io.lumeer.storage.mongodb.model.MorphiaProject in project engine by Lumeer.

the class MorphiaProjectDaoTest method testGetProjectsGroupRole.

@Test
public void testGetProjectsGroupRole() {
    MorphiaProject project = prepareProject(CODE1);
    datastore.save(projectDao.databaseCollection(), project);
    MorphiaProject project2 = prepareProject(CODE2);
    datastore.save(projectDao.databaseCollection(), project2);
    DatabaseQuery query = DatabaseQuery.createBuilder(USER2).groups(Collections.singleton(GROUP)).build();
    List<Project> projects = projectDao.getProjects(query);
    assertThat(projects).extracting(Project::getCode).containsOnly(CODE1, CODE2);
}
Also used : MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Project(io.lumeer.api.model.Project) DatabaseQuery(io.lumeer.storage.api.query.DatabaseQuery) MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Test(org.junit.Test)

Example 3 with MorphiaProject

use of io.lumeer.storage.mongodb.model.MorphiaProject in project engine by Lumeer.

the class MorphiaProjectDaoTest method testUpdateProjectExistingCode.

@Test
public void testUpdateProjectExistingCode() {
    MorphiaProject project = prepareProject(CODE1);
    datastore.save(projectDao.databaseCollection(), project);
    MorphiaProject project2 = prepareProject(CODE2);
    datastore.save(projectDao.databaseCollection(), project2);
    project2.setCode(CODE1);
    assertThatThrownBy(() -> projectDao.updateProject(project2.getId(), project2)).isInstanceOf(DuplicateKeyException.class);
}
Also used : MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Test(org.junit.Test)

Example 4 with MorphiaProject

use of io.lumeer.storage.mongodb.model.MorphiaProject in project engine by Lumeer.

the class MorphiaProjectDaoTest method testDeleteProject.

@Test
public void testDeleteProject() {
    MorphiaProject project = prepareProject(CODE1);
    datastore.save(projectDao.databaseCollection(), project);
    assertThat(project.getId()).isNotNull();
    projectDao.deleteProject(project.getId());
    Project storedProject = datastore.get(projectDao.databaseCollection(), MorphiaProject.class, new ObjectId(project.getId()));
    assertThat(storedProject).isNull();
}
Also used : MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Project(io.lumeer.api.model.Project) ObjectId(org.bson.types.ObjectId) MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Test(org.junit.Test)

Example 5 with MorphiaProject

use of io.lumeer.storage.mongodb.model.MorphiaProject in project engine by Lumeer.

the class MorphiaProjectDaoTest method testGetProjectByCode.

@Test
public void testGetProjectByCode() {
    MorphiaProject project = prepareProject(CODE1);
    datastore.save(projectDao.databaseCollection(), project);
    MorphiaProject storedProject = (MorphiaProject) projectDao.getProjectByCode(CODE1);
    assertThat(storedProject).isNotNull();
    assertThat(storedProject.getId()).isNotNull().isNotEmpty();
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(storedProject.getCode()).isEqualTo(CODE1);
    assertions.assertThat(storedProject.getName()).isEqualTo(NAME);
    assertions.assertThat(storedProject.getColor()).isEqualTo(COLOR);
    assertions.assertThat(storedProject.getIcon()).isEqualTo(ICON);
    assertions.assertThat(storedProject.getPermissions()).isEqualTo(PERMISSIONS);
    assertions.assertAll();
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Test(org.junit.Test)

Aggregations

MorphiaProject (io.lumeer.storage.mongodb.model.MorphiaProject)15 Test (org.junit.Test)9 Project (io.lumeer.api.model.Project)6 ObjectId (org.bson.types.ObjectId)4 DatabaseQuery (io.lumeer.storage.api.query.DatabaseQuery)3 MorphiaPermissions (io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions)3 Organization (io.lumeer.api.model.Organization)2 User (io.lumeer.api.model.User)2 AuthenticatedUser (io.lumeer.core.AuthenticatedUser)2 MorphiaOrganization (io.lumeer.storage.mongodb.model.MorphiaOrganization)2 SoftAssertions (org.assertj.core.api.SoftAssertions)2 Before (org.junit.Before)2 Permission (io.lumeer.api.model.Permission)1 MorphiaPermission (io.lumeer.storage.mongodb.model.embedded.MorphiaPermission)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FindOptions (org.mongodb.morphia.query.FindOptions)1