Search in sources :

Example 11 with LinkInstance

use of io.lumeer.api.model.LinkInstance in project engine by Lumeer.

the class MongoLinkInstanceDaoTest method testCreateLinkInstance.

@Test
public void testCreateLinkInstance() {
    LinkInstance linkInstance = prepareLinkInstance();
    String id = linkInstanceDao.createLinkInstance(linkInstance).getId();
    assertThat(id).isNotNull().isNotEmpty();
    assertThat(ObjectId.isValid(id)).isTrue();
    LinkInstance storedLinkInstance = linkInstanceDao.getLinkInstance(id);
    assertThat(storedLinkInstance).isNotNull();
    assertThat(storedLinkInstance.getLinkTypeId()).isEqualTo(LINK_TYPE_ID1);
    assertThat(storedLinkInstance.getDocumentIds()).containsOnlyElementsOf(Arrays.asList(DOCUMENT_ID1, DOCUMENT_ID2));
    assertThat(storedLinkInstance.getData().keySet()).containsOnlyElementsOf(DATA.keySet());
}
Also used : LinkInstance(io.lumeer.api.model.LinkInstance) Test(org.junit.Test)

Example 12 with LinkInstance

use of io.lumeer.api.model.LinkInstance in project engine by Lumeer.

the class MongoLinkInstanceDaoTest method testDeleteLinkInstance.

@Test
public void testDeleteLinkInstance() {
    LinkInstance created = linkInstanceDao.createLinkInstance(prepareLinkInstance());
    assertThat(created.getId()).isNotNull();
    linkInstanceDao.deleteLinkInstance(created.getId());
    assertThatThrownBy(() -> linkInstanceDao.getLinkInstance(created.getId())).isInstanceOf(StorageException.class);
}
Also used : LinkInstance(io.lumeer.api.model.LinkInstance) Test(org.junit.Test)

Example 13 with LinkInstance

use of io.lumeer.api.model.LinkInstance in project engine by Lumeer.

the class MongoLinkInstanceDaoTest method testDeleteLinkInstancesByLinkTypeIds.

@Test
public void testDeleteLinkInstancesByLinkTypeIds() throws InterruptedException {
    linkInstanceDao.createLinkInstance(prepareLinkInstance());
    LinkInstance linkInstance2 = prepareLinkInstance();
    linkInstance2.setLinkTypeId(LINK_TYPE_ID2);
    linkInstanceDao.createLinkInstance(linkInstance2);
    LinkInstance linkInstance3 = prepareLinkInstance();
    linkInstance3.setLinkTypeId(LINK_TYPE_ID2);
    linkInstanceDao.createLinkInstance(linkInstance3);
    LinkInstance linkInstance4 = prepareLinkInstance();
    linkInstance4.setLinkTypeId(LINK_TYPE_ID3);
    String id4 = linkInstanceDao.createLinkInstance(linkInstance4).getId();
    assertThat(linkInstanceDao.databaseCollection().find().into(new ArrayList<>()).size()).isEqualTo(4);
    SearchQuery query1 = SearchQuery.createBuilder(USER).linkTypeIds(new HashSet<>(Arrays.asList(LINK_TYPE_ID1, LINK_TYPE_ID2))).build();
    linkInstanceDao.deleteLinkInstances(query1);
    List<LinkInstance> linkInstances = linkInstanceDao.databaseCollection().find().into(new ArrayList<>());
    assertThat(linkInstances).extracting("id").containsOnlyElementsOf(Collections.singletonList(id4));
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) ArrayList(java.util.ArrayList) LinkInstance(io.lumeer.api.model.LinkInstance) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with LinkInstance

use of io.lumeer.api.model.LinkInstance in project engine by Lumeer.

the class MongoLinkInstanceDaoTest method testGetLinkInstancesByDocumentIds.

@Test
public void testGetLinkInstancesByDocumentIds() {
    String id1 = linkInstanceDao.createLinkInstance(prepareLinkInstance()).getId();
    LinkInstance linkInstance2 = prepareLinkInstance();
    linkInstance2.setDocumentIds(Arrays.asList(DOCUMENT_ID2, DOCUMENT_ID3));
    String id2 = linkInstanceDao.createLinkInstance(linkInstance2).getId();
    LinkInstance linkInstance3 = prepareLinkInstance();
    linkInstance3.setDocumentIds(Arrays.asList(DOCUMENT_ID1, DOCUMENT_ID5));
    String id3 = linkInstanceDao.createLinkInstance(linkInstance3).getId();
    LinkInstance linkInstance4 = prepareLinkInstance();
    linkInstance4.setDocumentIds(Arrays.asList(DOCUMENT_ID2, DOCUMENT_ID4));
    String id4 = linkInstanceDao.createLinkInstance(linkInstance4).getId();
    SearchQuery query1 = SearchQuery.createBuilder(USER).documentIds(Collections.singleton(DOCUMENT_ID1)).build();
    List<LinkInstance> linkInstances = linkInstanceDao.getLinkInstances(query1);
    assertThat(linkInstances).extracting("id").containsOnlyElementsOf(Arrays.asList(id1, id3));
    SearchQuery query2 = SearchQuery.createBuilder(USER).documentIds(Collections.singleton(DOCUMENT_ID2)).build();
    linkInstances = linkInstanceDao.getLinkInstances(query2);
    assertThat(linkInstances).extracting("id").containsOnlyElementsOf(Arrays.asList(id1, id2, id4));
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) LinkInstance(io.lumeer.api.model.LinkInstance) Test(org.junit.Test)

Example 15 with LinkInstance

use of io.lumeer.api.model.LinkInstance in project engine by Lumeer.

the class MongoLinkInstanceDaoTest method testDeleteLinkInstancesByDocumentIds.

@Test
public void testDeleteLinkInstancesByDocumentIds() {
    linkInstanceDao.createLinkInstance(prepareLinkInstance());
    LinkInstance linkInstance2 = prepareLinkInstance();
    linkInstance2.setDocumentIds(Arrays.asList(DOCUMENT_ID2, DOCUMENT_ID3));
    linkInstanceDao.createLinkInstance(linkInstance2);
    LinkInstance linkInstance3 = prepareLinkInstance();
    linkInstance3.setDocumentIds(Arrays.asList(DOCUMENT_ID1, DOCUMENT_ID5));
    linkInstanceDao.createLinkInstance(linkInstance3);
    LinkInstance linkInstance4 = prepareLinkInstance();
    linkInstance4.setDocumentIds(Arrays.asList(DOCUMENT_ID2, DOCUMENT_ID4));
    linkInstanceDao.createLinkInstance(linkInstance4);
    assertThat(linkInstanceDao.databaseCollection().find().into(new ArrayList<>()).size()).isEqualTo(4);
    SearchQuery query1 = SearchQuery.createBuilder(USER).documentIds(Collections.singleton(DOCUMENT_ID1)).build();
    linkInstanceDao.deleteLinkInstances(query1);
    assertThat(linkInstanceDao.databaseCollection().find().into(new ArrayList<>()).size()).isEqualTo(2);
    SearchQuery query2 = SearchQuery.createBuilder(USER).documentIds(Collections.singleton(DOCUMENT_ID2)).build();
    linkInstanceDao.deleteLinkInstances(query2);
    assertThat(linkInstanceDao.databaseCollection().find().into(new ArrayList<>())).isEmpty();
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) ArrayList(java.util.ArrayList) LinkInstance(io.lumeer.api.model.LinkInstance) Test(org.junit.Test)

Aggregations

LinkInstance (io.lumeer.api.model.LinkInstance)20 Test (org.junit.Test)17 Response (javax.ws.rs.core.Response)5 SearchQuery (io.lumeer.storage.api.query.SearchQuery)4 ArrayList (java.util.ArrayList)4 Entity (javax.ws.rs.client.Entity)4 JsonQuery (io.lumeer.api.dto.JsonQuery)3 HashSet (java.util.HashSet)3 List (java.util.List)2 GenericType (javax.ws.rs.core.GenericType)2 LinkType (io.lumeer.api.model.LinkType)1 Document (org.bson.Document)1