Search in sources :

Example 21 with ConditionSortLimit

use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by infiniteautomation.

the class EventInstanceServiceTest method testQueryReadPermissionEnforcement.

@Override
@Test
public void testQueryReadPermissionEnforcement() {
    EventInstanceVO vo = newVO(editUser);
    setReadPermission(MangoPermission.requireAnyRole(editRole), vo);
    EventInstanceVO saved = service.insert(vo);
    runAs.runAs(readUser, () -> {
        ConditionSortLimit conditions = new ConditionSortLimit(null, null, 1, 0);
        AtomicInteger count = new AtomicInteger();
        getService().customizedQuery(conditions, (item) -> {
            count.getAndIncrement();
        });
        assertEquals(0, count.get());
    });
    runAs.runAs(editUser, () -> {
        Condition c = getDao().getIdField().eq(saved.getId());
        ConditionSortLimit conditions = new ConditionSortLimit(c, null, null, null);
        AtomicInteger count = new AtomicInteger();
        getService().customizedQuery(conditions, (item) -> {
            count.getAndIncrement();
            assertEquals(saved.getId(), item.getId());
        });
        assertEquals(1, count.get());
    });
}
Also used : Condition(org.jooq.Condition) EventInstanceVO(com.serotonin.m2m2.vo.event.EventInstanceVO) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit) Test(org.junit.Test)

Example 22 with ConditionSortLimit

use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by infiniteautomation.

the class AbstractBasicVOServiceWithPermissionsTestBase method testQueryEditPermissionEnforcement.

@Test
public void testQueryEditPermissionEnforcement() {
    VO vo = newVO(readUser);
    setEditPermission(MangoPermission.requireAnyRole(editRole), vo);
    VO saved = service.insert(vo);
    runAs.runAs(readUser, () -> {
        ConditionSortLimit conditions = new ConditionSortLimit(null, null, 1, 0);
        AtomicInteger count = new AtomicInteger();
        getService().customizedQuery(conditions, (item) -> {
            count.getAndIncrement();
        });
        assertEquals(0, count.get());
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractBasicVO(com.serotonin.m2m2.vo.AbstractBasicVO) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit) Test(org.junit.Test)

Example 23 with ConditionSortLimit

use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by infiniteautomation.

the class AbstractBasicVOServiceWithPermissionsTestBase method testQueryReadPermissionEnforcement.

@Test
public void testQueryReadPermissionEnforcement() {
    VO vo = newVO(editUser);
    setReadPermission(MangoPermission.requireAnyRole(editRole), vo);
    VO saved = service.insert(vo);
    runAs.runAs(readUser, () -> {
        ConditionSortLimit conditions = new ConditionSortLimit(null, null, 1, 0);
        AtomicInteger count = new AtomicInteger();
        getService().customizedQuery(conditions, (item) -> {
            count.getAndIncrement();
        });
        assertEquals(0, count.get());
    });
    runAs.runAs(editUser, () -> {
        Condition c = getDao().getIdField().eq(saved.getId());
        ConditionSortLimit conditions = new ConditionSortLimit(c, null, null, null);
        AtomicInteger count = new AtomicInteger();
        getService().customizedQuery(conditions, (item) -> {
            count.getAndIncrement();
            assertEquals(saved.getId(), item.getId());
        });
        assertEquals(1, count.get());
    });
}
Also used : Condition(org.jooq.Condition) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractBasicVO(com.serotonin.m2m2.vo.AbstractBasicVO) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit) Test(org.junit.Test)

Example 24 with ConditionSortLimit

use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by infiniteautomation.

the class AbstractBasicVOServiceWithPermissionsTestBase method testCountQueryEditPermissionEnforcement.

@Test
public void testCountQueryEditPermissionEnforcement() {
    VO vo = newVO(readUser);
    setEditPermission(MangoPermission.requireAnyRole(editRole), vo);
    service.insert(vo);
    runAs.runAs(readUser, () -> {
        ConditionSortLimit conditions = new ConditionSortLimit(null, null, null, 0);
        int count = getService().customizedCount(conditions);
        assertEquals(0, count);
    });
}
Also used : AbstractBasicVO(com.serotonin.m2m2.vo.AbstractBasicVO) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit) Test(org.junit.Test)

Example 25 with ConditionSortLimit

use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by infiniteautomation.

the class AbstractVOServiceWithPermissionsTest method queryForName.

public int queryForName(String name) {
    Condition c = getDao().getNameField().eq(name);
    ConditionSortLimit conditions = new ConditionSortLimit(c, null, null, 0);
    AtomicInteger count = new AtomicInteger();
    getService().customizedQuery(conditions, (item) -> {
        count.getAndIncrement();
        assertEquals(name, item.getName());
    });
    return count.get();
}
Also used : Condition(org.jooq.Condition) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit)

Aggregations

ConditionSortLimit (com.infiniteautomation.mango.db.query.ConditionSortLimit)35 Condition (org.jooq.Condition)14 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)10 AbstractBasicVO (com.serotonin.m2m2.vo.AbstractBasicVO)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)7 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)6 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)4 Common (com.serotonin.m2m2.Common)4 ModuleRegistry (com.serotonin.m2m2.module.ModuleRegistry)4 ApiOperation (io.swagger.annotations.ApiOperation)3 List (java.util.List)3 Record (org.jooq.Record)3 Record1 (org.jooq.Record1)3 SelectJoinStep (org.jooq.SelectJoinStep)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3