Search in sources :

Example 36 with PermissionService

use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-core-public by MangoAutomation.

the class RoleInheritanceTest method test3.

/**
 * Test a slightly more complex tree hierarchy with multiple inheritance
 *
 * <pre>{@code
 *               gasTechnician   -> gasRead   <- gasEdit   <- gasAdmin
 * technician -> solidTechnician -> solidRead <- solidEdit <- solidAdmin <- admin
 *               fluidTechnician -> fluidRead <- fluidEdit <- fluidAdmin
 * }</pre>
 */
@Test
public void test3() {
    PermissionService service = Common.getBean(PermissionService.class);
    // Fluid roles
    RoleVOHierarchy fluidRead = createRoleVOHierarchy("fluidRead", "fluidRead");
    MangoPermission fluidReadPermission = MangoPermission.requireAnyRole(fluidRead.getRole());
    RoleVOHierarchy fluidEdit = createRoleVOHierarchy("fluidEdit", "fluidEdit", fluidRead);
    MangoPermission fluidEditPermission = MangoPermission.requireAnyRole(fluidEdit.getRole());
    RoleVOHierarchy fluidTechnician = createRoleVOHierarchy("fluidTechnician", "fluidTechnician", fluidRead);
    RoleVOHierarchy fluidAdmin = createRoleVOHierarchy("fluidAdmin", "fluidAdmin", fluidEdit);
    // Solid roles
    RoleVOHierarchy solidRead = createRoleVOHierarchy("solidRead", "solidRead");
    MangoPermission solidReadPermission = MangoPermission.requireAnyRole(solidRead.getRole());
    RoleVOHierarchy solidEdit = createRoleVOHierarchy("solidEdit", "solidEdit", solidRead);
    MangoPermission solidEditPermission = MangoPermission.requireAnyRole(solidEdit.getRole());
    RoleVOHierarchy solidTechnician = createRoleVOHierarchy("solidTechnician", "solidTechnician", solidRead);
    RoleVOHierarchy solidAdmin = createRoleVOHierarchy("solidAdmin", "solidAdmin", solidEdit);
    // Gas roles
    RoleVOHierarchy gasRead = createRoleVOHierarchy("gasRead", "gasRead");
    MangoPermission gasReadPermission = MangoPermission.requireAnyRole(gasRead.getRole());
    RoleVOHierarchy gasEdit = createRoleVOHierarchy("gasEdit", "gasEdit", gasRead);
    MangoPermission gasEditPermission = MangoPermission.requireAnyRole(gasEdit.getRole());
    RoleVOHierarchy gasTechnician = createRoleVOHierarchy("gasTechnician", "gasTechnician", gasRead);
    RoleVOHierarchy gasAdmin = createRoleVOHierarchy("gasAdmin", "gasAdmin", gasEdit);
    RoleVOHierarchy technician = createRoleVOHierarchy("technician", "technician", fluidTechnician, solidTechnician, gasTechnician);
    RoleVOHierarchy admin = createRoleVOHierarchy("admin", "admin", fluidAdmin, solidAdmin, gasAdmin);
    // Who can read fluid
    assertTrue(service.hasPermission(createPermissionHolder(fluidRead), fluidReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(fluidEdit), fluidReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(fluidTechnician), fluidReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(fluidAdmin), fluidReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(technician), fluidReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(admin), fluidReadPermission));
    // Who cannot read fluid
    assertFalse(service.hasPermission(createPermissionHolder(gasRead), fluidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasEdit), fluidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasTechnician), fluidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasAdmin), fluidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidRead), fluidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidEdit), fluidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidTechnician), fluidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidAdmin), fluidReadPermission));
    // Who can edit fluid
    assertTrue(service.hasPermission(createPermissionHolder(fluidEdit), fluidEditPermission));
    assertTrue(service.hasPermission(createPermissionHolder(fluidAdmin), fluidEditPermission));
    assertTrue(service.hasPermission(createPermissionHolder(admin), fluidEditPermission));
    // Who cannot edit fluid
    assertFalse(service.hasPermission(createPermissionHolder(fluidRead), fluidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasRead), fluidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasEdit), fluidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasTechnician), fluidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidRead), fluidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidEdit), fluidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidTechnician), fluidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(technician), fluidEditPermission));
    // Who can read solid
    assertTrue(service.hasPermission(createPermissionHolder(solidRead), solidReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(solidEdit), solidReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(solidTechnician), solidReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(solidAdmin), solidReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(technician), solidReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(admin), solidReadPermission));
    // Who cannot read solid
    assertFalse(service.hasPermission(createPermissionHolder(gasRead), solidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasEdit), solidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasTechnician), solidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasAdmin), solidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidRead), solidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidEdit), solidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidTechnician), solidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidAdmin), solidReadPermission));
    // Who can edit solid
    assertTrue(service.hasPermission(createPermissionHolder(solidEdit), solidEditPermission));
    assertTrue(service.hasPermission(createPermissionHolder(solidAdmin), solidEditPermission));
    assertTrue(service.hasPermission(createPermissionHolder(admin), solidEditPermission));
    // Who cannot edit solid
    assertFalse(service.hasPermission(createPermissionHolder(solidRead), solidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasRead), solidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasEdit), solidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasTechnician), solidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidRead), solidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidEdit), solidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidTechnician), solidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(technician), solidEditPermission));
    // Who can read gas
    assertTrue(service.hasPermission(createPermissionHolder(gasRead), gasReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(gasEdit), gasReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(gasTechnician), gasReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(gasAdmin), gasReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(technician), gasReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(admin), gasReadPermission));
    // Who cannot read gas
    assertFalse(service.hasPermission(createPermissionHolder(solidRead), gasReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidEdit), gasReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidTechnician), gasReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidAdmin), gasReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidRead), gasReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidEdit), gasReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidTechnician), gasReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidAdmin), gasReadPermission));
    // Who can edit gas
    assertTrue(service.hasPermission(createPermissionHolder(gasEdit), gasEditPermission));
    assertTrue(service.hasPermission(createPermissionHolder(gasAdmin), gasEditPermission));
    assertTrue(service.hasPermission(createPermissionHolder(admin), gasEditPermission));
    // Who cannot edit gas
    assertFalse(service.hasPermission(createPermissionHolder(gasRead), gasEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidRead), gasEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidEdit), gasEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidTechnician), gasEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidRead), gasEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidEdit), gasEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidTechnician), gasEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(technician), gasEditPermission));
}
Also used : PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) Test(org.junit.Test)

Example 37 with PermissionService

use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-core-public by MangoAutomation.

the class PermissionPersistenceTest method testAndPermission.

@Test
public void testAndPermission() {
    PermissionService service = Common.getBean(PermissionService.class);
    // Create some roles
    Set<Role> roles = this.createRoles(2).stream().map(r -> r.getRole()).collect(Collectors.toSet());
    // insert the permission
    MangoPermission permission = service.findOrCreate(MangoPermission.requireAllRoles(roles));
    MangoPermission read = service.get(permission.getId());
    assertEquals(1, read.getRoles().size());
    Iterator<Set<Role>> it = read.getRoles().iterator();
    assertEquals(2, it.next().size());
}
Also used : PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) Role(com.serotonin.m2m2.vo.role.Role) Role(com.serotonin.m2m2.vo.role.Role) Iterator(java.util.Iterator) Common(com.serotonin.m2m2.Common) DatabaseProxy(com.serotonin.m2m2.db.DatabaseProxy) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) RoleDao(com.serotonin.m2m2.db.dao.RoleDao) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) List(java.util.List) MangoTestBase(com.serotonin.m2m2.MangoTestBase) DSLContext(org.jooq.DSLContext) Assert.assertEquals(org.junit.Assert.assertEquals) PermissionsMinterms(com.infiniteautomation.mango.db.tables.PermissionsMinterms) PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) Set(java.util.Set) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 38 with PermissionService

use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-core-public by MangoAutomation.

the class RoleInheritanceTest method test1.

/**
 * Test a straight hierarchy with only single inheritance
 *
 * <pre>{@code
 * admin -> supervisor -> edit -> read
 * }</pre>
 */
@Test
public void test1() {
    PermissionService service = Common.getBean(PermissionService.class);
    // Lowest level
    RoleVOHierarchy read = createRoleVOHierarchy("read", "read");
    MangoPermission readPermission = MangoPermission.requireAnyRole(read.getRole());
    RoleVOHierarchy edit = createRoleVOHierarchy("edit", "edit", read);
    MangoPermission editPermission = MangoPermission.requireAnyRole(edit.getRole());
    RoleVOHierarchy supervisor = createRoleVOHierarchy("supervisor", "supervisor", edit);
    MangoPermission supervisorPermission = MangoPermission.requireAnyRole(supervisor.getRole());
    RoleVOHierarchy admin = createRoleVOHierarchy("admin", "admin", supervisor);
    MangoPermission adminPermission = MangoPermission.requireAnyRole(admin.getRole());
    // What admin can do
    assertTrue(service.hasPermission(createPermissionHolder(admin), readPermission));
    assertTrue(service.hasPermission(createPermissionHolder(admin), editPermission));
    assertTrue(service.hasPermission(createPermissionHolder(admin), supervisorPermission));
    assertTrue(service.hasPermission(createPermissionHolder(admin), adminPermission));
    // What supervisor can do
    assertTrue(service.hasPermission(createPermissionHolder(supervisor), readPermission));
    assertTrue(service.hasPermission(createPermissionHolder(supervisor), editPermission));
    assertTrue(service.hasPermission(createPermissionHolder(supervisor), supervisorPermission));
    assertFalse(service.hasPermission(createPermissionHolder(supervisor), adminPermission));
    // What edit can do
    assertTrue(service.hasPermission(createPermissionHolder(edit), readPermission));
    assertTrue(service.hasPermission(createPermissionHolder(edit), editPermission));
    assertFalse(service.hasPermission(createPermissionHolder(edit), supervisorPermission));
    assertFalse(service.hasPermission(createPermissionHolder(edit), adminPermission));
    // What read can do
    assertTrue(service.hasPermission(createPermissionHolder(read), readPermission));
    assertFalse(service.hasPermission(createPermissionHolder(read), editPermission));
    assertFalse(service.hasPermission(createPermissionHolder(read), supervisorPermission));
    assertFalse(service.hasPermission(createPermissionHolder(read), adminPermission));
}
Also used : PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) Test(org.junit.Test)

Example 39 with PermissionService

use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-core-public by MangoAutomation.

the class RoleInheritanceTest method test2.

/**
 * Test a tree hierarchy with multiple inheritance
 *
 * <pre>{@code
 *            -> gasTechnician   -> gasEdit   -> gasRead
 * technician -> solidTechnician -> solidEdit -> solidRead
 *            -> fluidTechnician -> fluidEdit -> fluidRead
 * }</pre>
 */
@Test
public void test2() {
    PermissionService service = Common.getBean(PermissionService.class);
    RoleVOHierarchy fluidRead = createRoleVOHierarchy("fluidRead", "fluidRead");
    MangoPermission fluidReadPermission = MangoPermission.requireAnyRole(fluidRead.getRole());
    RoleVOHierarchy fluidEdit = createRoleVOHierarchy("fluidEdit", "fluidEdit", fluidRead);
    MangoPermission fluidEditPermission = MangoPermission.requireAnyRole(fluidEdit.getRole());
    RoleVOHierarchy solidRead = createRoleVOHierarchy("solidRead", "solidRead");
    MangoPermission solidReadPermission = MangoPermission.requireAnyRole(solidRead.getRole());
    RoleVOHierarchy solidEdit = createRoleVOHierarchy("solidEdit", "solidEdit", solidRead);
    MangoPermission solidEditPermission = MangoPermission.requireAnyRole(solidEdit.getRole());
    RoleVOHierarchy gasRead = createRoleVOHierarchy("gasRead", "gasRead");
    MangoPermission gasReadPermission = MangoPermission.requireAnyRole(gasRead.getRole());
    RoleVOHierarchy gasEdit = createRoleVOHierarchy("gasEdit", "gasEdit", gasRead);
    MangoPermission gasEditPermission = MangoPermission.requireAnyRole(gasEdit.getRole());
    RoleVOHierarchy fluidTechnician = createRoleVOHierarchy("fluidTechnician", "fluidTechnician", fluidEdit);
    RoleVOHierarchy solidTechnician = createRoleVOHierarchy("solidTechnician", "solidTechnician", solidEdit);
    RoleVOHierarchy gasTechnician = createRoleVOHierarchy("gasTechnician", "gasTechnician", gasEdit);
    RoleVOHierarchy technician = createRoleVOHierarchy("technician", "technician", fluidTechnician, solidTechnician, gasTechnician);
    // Who can read fluid
    assertTrue(service.hasPermission(createPermissionHolder(fluidRead), fluidReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(fluidEdit), fluidReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(fluidTechnician), fluidReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(technician), fluidReadPermission));
    // Who can edit fluid
    assertTrue(service.hasPermission(createPermissionHolder(fluidEdit), fluidEditPermission));
    assertTrue(service.hasPermission(createPermissionHolder(fluidTechnician), fluidEditPermission));
    assertTrue(service.hasPermission(createPermissionHolder(technician), fluidEditPermission));
    // Who cannot read fluid
    assertFalse(service.hasPermission(createPermissionHolder(gasRead), fluidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasEdit), fluidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasTechnician), fluidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidRead), fluidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidEdit), fluidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidTechnician), fluidReadPermission));
    // Who cannot edit fluid
    assertFalse(service.hasPermission(createPermissionHolder(fluidRead), fluidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasRead), fluidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasEdit), fluidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasTechnician), fluidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidRead), fluidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidEdit), fluidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidTechnician), fluidEditPermission));
    // Who can read solid
    assertTrue(service.hasPermission(createPermissionHolder(solidRead), solidReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(solidEdit), solidReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(solidTechnician), solidReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(technician), solidReadPermission));
    // Who can edit solid
    assertTrue(service.hasPermission(createPermissionHolder(solidEdit), solidEditPermission));
    assertTrue(service.hasPermission(createPermissionHolder(solidTechnician), solidEditPermission));
    assertTrue(service.hasPermission(createPermissionHolder(technician), solidEditPermission));
    // Who cannot read solid
    assertFalse(service.hasPermission(createPermissionHolder(gasRead), solidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasEdit), solidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasTechnician), solidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidRead), solidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidEdit), solidReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidTechnician), solidReadPermission));
    // Who cannot edit solid
    assertFalse(service.hasPermission(createPermissionHolder(solidRead), solidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasRead), solidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasEdit), solidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(gasTechnician), solidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidRead), solidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidEdit), solidEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidTechnician), solidEditPermission));
    // Who can read gas
    assertTrue(service.hasPermission(createPermissionHolder(gasRead), gasReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(gasEdit), gasReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(gasTechnician), gasReadPermission));
    assertTrue(service.hasPermission(createPermissionHolder(technician), gasReadPermission));
    // Who can edit gas
    assertTrue(service.hasPermission(createPermissionHolder(gasEdit), gasEditPermission));
    assertTrue(service.hasPermission(createPermissionHolder(gasTechnician), gasEditPermission));
    assertTrue(service.hasPermission(createPermissionHolder(technician), gasEditPermission));
    // Who cannot read gas
    assertFalse(service.hasPermission(createPermissionHolder(fluidRead), gasReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidEdit), gasReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidTechnician), gasReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidRead), gasReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidEdit), gasReadPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidTechnician), gasReadPermission));
    // Who cannot edit gas
    assertFalse(service.hasPermission(createPermissionHolder(gasRead), gasEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidRead), gasEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidEdit), gasEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(fluidTechnician), gasEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidRead), gasEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidEdit), gasEditPermission));
    assertFalse(service.hasPermission(createPermissionHolder(solidTechnician), gasEditPermission));
}
Also used : PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) Test(org.junit.Test)

Example 40 with PermissionService

use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-core-public by MangoAutomation.

the class LazyFieldJsonTest method testLazyPermissionInObject.

@Test
public void testLazyPermissionInObject() {
    RoleService roleService = Common.getBean(RoleService.class);
    PermissionService permissionService = Common.getBean(PermissionService.class);
    Role role1 = roleService.insert(new RoleVO(Common.NEW_ID, "XID-1", "Role 1")).getRole();
    Role role2 = roleService.insert(new RoleVO(Common.NEW_ID, "XID-2", "Role 2")).getRole();
    LazyContainer container = new LazyContainer();
    container.supplyPermission(() -> MangoPermission.builder().minterm(role1, role2).build());
    try (StringWriter stringWriter = new StringWriter()) {
        JsonWriter writer = new JsonWriter(Common.JSON_CONTEXT, stringWriter);
        JsonTypeWriter typeWriter = new JsonTypeWriter(Common.JSON_CONTEXT);
        JsonValue value = typeWriter.writeObject(container);
        writer.setPrettyIndent(0);
        writer.setPrettyOutput(true);
        writer.writeObject(value);
        String json = stringWriter.toString();
        JsonTypeReader typeReader = new JsonTypeReader(json);
        JsonValue read = typeReader.read();
        JsonObject root = read.toJsonObject();
        JsonReader reader = new JsonReader(Common.JSON_CONTEXT, root);
        ImportContext context = new ImportContext(reader, new ProcessResult(), Common.getTranslations());
        LazyContainer readContainer = new LazyContainer();
        context.getReader().readInto(readContainer, root);
        assertEquals(container.getPermission(), readContainer.getPermission());
    } catch (IOException | JsonException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : JsonException(com.serotonin.json.JsonException) JsonValue(com.serotonin.json.type.JsonValue) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) JsonObject(com.serotonin.json.type.JsonObject) IOException(java.io.IOException) JsonWriter(com.serotonin.json.JsonWriter) JsonTypeWriter(com.serotonin.json.type.JsonTypeWriter) PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) Role(com.serotonin.m2m2.vo.role.Role) ImportContext(com.infiniteautomation.mango.emport.ImportContext) RoleVO(com.serotonin.m2m2.vo.role.RoleVO) RoleService(com.infiniteautomation.mango.spring.service.RoleService) StringWriter(java.io.StringWriter) JsonReader(com.serotonin.json.JsonReader) JsonTypeReader(com.serotonin.json.type.JsonTypeReader) Test(org.junit.Test)

Aggregations

PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)47 Test (org.junit.Test)32 Role (com.serotonin.m2m2.vo.role.Role)25 Set (java.util.Set)19 HashSet (java.util.HashSet)17 Common (com.serotonin.m2m2.Common)14 DatabaseProxy (com.serotonin.m2m2.db.DatabaseProxy)14 List (java.util.List)13 MangoTestBase (com.serotonin.m2m2.MangoTestBase)12 Collectors (java.util.stream.Collectors)12 PermissionsMinterms (com.infiniteautomation.mango.db.tables.PermissionsMinterms)10 DataSourceService (com.infiniteautomation.mango.spring.service.DataSourceService)10 RoleDao (com.serotonin.m2m2.db.dao.RoleDao)10 MockDataSourceVO (com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO)10 Iterator (java.util.Iterator)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 MutableObject (org.apache.commons.lang3.mutable.MutableObject)10 DSLContext (org.jooq.DSLContext)10 Assert.assertEquals (org.junit.Assert.assertEquals)10 Assert.assertTrue (org.junit.Assert.assertTrue)10