package org.ovirt.engine.api.restapi.resource; import javax.ws.rs.WebApplicationException; import org.junit.Test; import org.ovirt.engine.api.model.Role; import org.ovirt.engine.core.common.businessentities.RoleType; import org.ovirt.engine.core.common.queries.IdQueryParameters; import org.ovirt.engine.core.common.queries.VdcQueryType; public abstract class AbstractBackendRoleResourceTest extends AbstractBackendSubResourceTest<Role, org.ovirt.engine.core.common.businessentities.Role, BackendRoleResource> { public AbstractBackendRoleResourceTest(BackendRoleResource roleResource) { super(roleResource); } @Test public void testBadGuid() throws Exception { try { new BackendRoleResource("foo", null); fail("expected WebApplicationException"); } catch (WebApplicationException wae) { verifyNotFoundException(wae); } } @Test public void testGetNotFound() throws Exception { setUriInfo(setUpBasicUriExpectations()); setUpGetEntityExpectations(true); try { resource.get(); fail("expected WebApplicationException"); } catch (WebApplicationException wae) { verifyNotFoundException(wae); } } @Test public void testGet() throws Exception { setUriInfo(setUpBasicUriExpectations()); setUpGetEntityExpectations(); verifyModel(resource.get(), 0); } protected void setUpGetEntityExpectations() throws Exception { setUpGetEntityExpectations(false); } protected void setUpGetEntityExpectations(boolean notFound) throws Exception { setUpGetEntityExpectations(VdcQueryType.GetRoleById, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, notFound ? null : getEntity(0)); } @Override protected org.ovirt.engine.core.common.businessentities.Role getEntity(int index) { org.ovirt.engine.core.common.businessentities.Role role = new org.ovirt.engine.core.common.businessentities.Role(); role.setId(GUIDS[index]); role.setName(NAMES[index]); role.setDescription(DESCRIPTIONS[index]); role.setReadonly(false); role.setType(RoleType.ADMIN); return role; } @Override protected void verifyModel(Role model, int index) { super.verifyModel(model, index); assertTrue(model.isMutable()); assertTrue(model.isAdministrative()); } }