Search in sources :

Example 1 with Permit

use of org.ovirt.engine.api.model.Permit in project ovirt-engine by oVirt.

the class BackendRolesResourceTest method testAddRole.

@Test
public void testAddRole() throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    setUpCreationExpectations(ActionType.AddRoleWithActionGroups, RoleWithActionGroupsParameters.class, new String[] { "Role.Id", "Role.Name" }, new Object[] { GUIDS[0], NAMES[0] }, true, true, GUIDS[0], QueryType.GetRoleById, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0));
    Role model = new Role();
    model.setName(NAMES[0]);
    model.setPermits(new Permits());
    model.getPermits().getPermits().add(new Permit());
    model.getPermits().getPermits().get(0).setId("" + ActionGroup.CREATE_VM.getId());
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Role);
    verifyModel((Role) response.getEntity(), 0);
}
Also used : Role(org.ovirt.engine.api.model.Role) Response(javax.ws.rs.core.Response) Permit(org.ovirt.engine.api.model.Permit) Permits(org.ovirt.engine.api.model.Permits) Test(org.junit.Test)

Example 2 with Permit

use of org.ovirt.engine.api.model.Permit in project ovirt-engine by oVirt.

the class PermitMapper method map.

@Mapping(from = ActionGroup.class, to = Permit.class)
public static Permit map(ActionGroup entity, Permit template) {
    Permit model = template != null ? template : new Permit();
    model.setId(Integer.toString(entity.getId()));
    model.setName(entity.name().toLowerCase());
    model.setAdministrative(entity.getRoleType() == RoleType.ADMIN);
    return model;
}
Also used : Permit(org.ovirt.engine.api.model.Permit)

Example 3 with Permit

use of org.ovirt.engine.api.model.Permit in project ovirt-engine by oVirt.

the class BackendClusterLevelsResource method makeClusterLevel.

public ClusterLevel makeClusterLevel(String version) {
    ClusterLevel level = new ClusterLevel();
    level.setId(version);
    // Not exposing CPU list filtered queries:
    if (!isFiltered()) {
        CpuTypes cpuTypes = new CpuTypes();
        for (ServerCpu serverCpu : getServerCpuList(version)) {
            CpuType cpuType = new CpuType();
            cpuType.setName(serverCpu.getCpuName());
            cpuType.setLevel(serverCpu.getLevel());
            cpuType.setArchitecture(CPUMapper.map(serverCpu.getArchitecture(), null));
            cpuTypes.getCpuTypes().add(cpuType);
        }
        level.setCpuTypes(cpuTypes);
    }
    // Add permits:
    Permits permits = new Permits();
    for (ActionGroup actionGroup : getActionGroups()) {
        Permit permit = PermitMapper.map(actionGroup, null);
        permits.getPermits().add(permit);
    }
    level.setPermits(permits);
    return LinkHelper.addLinks(level);
}
Also used : Permit(org.ovirt.engine.api.model.Permit) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) ClusterLevel(org.ovirt.engine.api.model.ClusterLevel) ServerCpu(org.ovirt.engine.core.common.businessentities.ServerCpu) CpuTypes(org.ovirt.engine.api.model.CpuTypes) CpuType(org.ovirt.engine.api.model.CpuType) Permits(org.ovirt.engine.api.model.Permits)

Example 4 with Permit

use of org.ovirt.engine.api.model.Permit in project ovirt-engine by oVirt.

the class BackendPermitsResourceTest method testAddPermit.

@Test
public void testAddPermit() throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    setUpCreationExpectations(ActionType.AttachActionGroupsToRole, ActionGroupsToRoleParameter.class, new String[] { "RoleId" }, new Object[] { GUIDS[1] }, true, true, GUIDS[2], null, null, null, null, getEntity(1));
    Permit model = new Permit();
    model.setId("1");
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Permit);
    verifyModel((Permit) response.getEntity(), 0);
}
Also used : Response(javax.ws.rs.core.Response) Permit(org.ovirt.engine.api.model.Permit) Test(org.junit.Test)

Example 5 with Permit

use of org.ovirt.engine.api.model.Permit in project ovirt-engine by oVirt.

the class BackendRolesResourceTest method testAddIncompleteParametersNoName.

@Test
public void testAddIncompleteParametersNoName() throws Exception {
    Role model = new Role();
    model.setPermits(new Permits());
    model.getPermits().getPermits().add(new Permit());
    model.getPermits().getPermits().get(0).setId("1");
    setUriInfo(setUpBasicUriExpectations());
    try {
        collection.add(model);
        fail("expected WebApplicationException on incomplete parameters");
    } catch (WebApplicationException wae) {
        verifyIncompleteException(wae, "Role", "add", "name");
    }
}
Also used : Role(org.ovirt.engine.api.model.Role) Permit(org.ovirt.engine.api.model.Permit) WebApplicationException(javax.ws.rs.WebApplicationException) Permits(org.ovirt.engine.api.model.Permits) Test(org.junit.Test)

Aggregations

Permit (org.ovirt.engine.api.model.Permit)6 Test (org.junit.Test)4 Permits (org.ovirt.engine.api.model.Permits)4 Response (javax.ws.rs.core.Response)3 Role (org.ovirt.engine.api.model.Role)3 WebApplicationException (javax.ws.rs.WebApplicationException)2 ClusterLevel (org.ovirt.engine.api.model.ClusterLevel)1 CpuType (org.ovirt.engine.api.model.CpuType)1 CpuTypes (org.ovirt.engine.api.model.CpuTypes)1 ActionGroup (org.ovirt.engine.core.common.businessentities.ActionGroup)1 ServerCpu (org.ovirt.engine.core.common.businessentities.ServerCpu)1