Search in sources :

Example 11 with MorphiaView

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

the class MorphiaViewDaoTest method testUpdateViewExistingCode.

@Test
public void testUpdateViewExistingCode() {
    MorphiaView view = prepareView();
    datastore.save(viewDao.databaseCollection(), view);
    MorphiaView view2 = prepareView();
    view2.setCode(CODE2);
    view2.setName(NAME2);
    datastore.save(viewDao.databaseCollection(), view2);
    view2.setCode(CODE);
    assertThatThrownBy(() -> viewDao.updateView(view2.getId(), view2)).isInstanceOf(DuplicateKeyException.class);
}
Also used : MorphiaView(io.lumeer.storage.mongodb.model.MorphiaView) Test(org.junit.Test)

Example 12 with MorphiaView

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

the class MorphiaViewDaoTest method testUpdateViewCode.

@Test
public void testUpdateViewCode() {
    MorphiaView view = prepareView();
    String id = datastore.save(viewDao.databaseCollection(), view).getId().toString();
    assertThat(id).isNotNull().isNotEmpty();
    view.setCode(CODE2);
    viewDao.updateView(id, view);
    MorphiaView storedView = datastore.get(viewDao.databaseCollection(), MorphiaView.class, new ObjectId(id));
    assertThat(storedView).isNotNull();
    assertThat(storedView.getCode()).isEqualTo(CODE2);
}
Also used : ObjectId(org.bson.types.ObjectId) MorphiaView(io.lumeer.storage.mongodb.model.MorphiaView) Test(org.junit.Test)

Example 13 with MorphiaView

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

the class MorphiaViewDaoTest method testCreateViewExistingCode.

@Test
public void testCreateViewExistingCode() {
    MorphiaView view = prepareView();
    datastore.save(viewDao.databaseCollection(), view);
    MorphiaView view2 = prepareView();
    view2.setName(NAME2);
    assertThatThrownBy(() -> viewDao.createView(view2)).isInstanceOf(DuplicateKeyException.class);
}
Also used : MorphiaView(io.lumeer.storage.mongodb.model.MorphiaView) Test(org.junit.Test)

Example 14 with MorphiaView

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

the class MorphiaViewDaoTest method testCreateView.

@Test
public void testCreateView() {
    MorphiaView view = prepareView();
    String id = viewDao.createView(view).getId();
    assertThat(id).isNotNull().isNotEmpty();
    assertThat(ObjectId.isValid(id)).isTrue();
    MorphiaView storedView = datastore.get(viewDao.databaseCollection(), MorphiaView.class, new ObjectId(id));
    assertThat(storedView).isNotNull();
    assertThat(storedView.getCode()).isEqualTo(CODE);
    assertThat(storedView.getName()).isEqualTo(NAME);
    assertThat(storedView.getColor()).isEqualTo(COLOR);
    assertThat(storedView.getIcon()).isEqualTo(ICON);
    assertThat(storedView.getPermissions()).isEqualTo(PERMISSIONS);
    assertThat(storedView.getQuery()).isEqualTo(QUERY);
    assertThat(storedView.getPerspective()).isEqualTo(PERSPECTIVE);
    assertThat(storedView.getConfig()).isEqualTo(CONFIG);
}
Also used : ObjectId(org.bson.types.ObjectId) MorphiaView(io.lumeer.storage.mongodb.model.MorphiaView) Test(org.junit.Test)

Example 15 with MorphiaView

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

the class MorphiaViewDao method createView.

public View createView(final View view) {
    MorphiaView morphiaView = new MorphiaView(view);
    datastore.insert(databaseCollection(), morphiaView);
    return morphiaView;
}
Also used : MorphiaView(io.lumeer.storage.mongodb.model.MorphiaView)

Aggregations

MorphiaView (io.lumeer.storage.mongodb.model.MorphiaView)17 Test (org.junit.Test)11 View (io.lumeer.api.model.View)4 SearchQuery (io.lumeer.storage.api.query.SearchQuery)4 ObjectId (org.bson.types.ObjectId)3 ArrayList (java.util.ArrayList)2 FindOptions (org.mongodb.morphia.query.FindOptions)2 Permission (io.lumeer.api.model.Permission)1 MorphiaPermission (io.lumeer.storage.mongodb.model.embedded.MorphiaPermission)1 MorphiaPermissions (io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions)1