You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by cs...@apache.org on 2013/01/31 13:17:47 UTC
svn commit: r1440928 - in
/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest:
AbstractTest.java ReportTestITCase.java RoleTestITCase.java
Author: cschneider
Date: Thu Jan 31 12:17:46 2013
New Revision: 1440928
URL: http://svn.apache.org/viewvc?rev=1440928&view=rev
Log:
SYNCOPE-231 Fixing RoleTest
Modified:
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ReportTestITCase.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java?rev=1440928&r1=1440927&r2=1440928&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java Thu Jan 31 12:17:46 2013
@@ -25,7 +25,6 @@ import java.util.List;
import java.util.UUID;
import javax.sql.DataSource;
-import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
@@ -71,6 +70,7 @@ import org.apache.syncope.common.service
import org.apache.syncope.common.services.SchemaService.SchemaType;
import org.apache.syncope.common.to.AbstractSchemaTO;
import org.apache.syncope.common.to.AttributeTO;
+import org.apache.syncope.common.to.RoleTO;
import org.apache.syncope.common.to.UserTO;
import org.apache.syncope.common.types.AttributableType;
import org.apache.syncope.common.validation.SyncopeClientErrorHandler;
@@ -329,6 +329,12 @@ public abstract class AbstractTest {
protected UserTO createUser(final UserTO userTO) {
Response response = userService.create(userTO);
+ if (response.getStatus() != HttpStatus.SC_CREATED) {
+ Exception ex = clientExceptionMapper.fromResponse(response);
+ if (ex != null) {
+ throw (RuntimeException) ex;
+ }
+ }
return response.readEntity(UserTO.class);
}
@@ -357,4 +363,16 @@ public abstract class AbstractTest {
}
return response;
}
+
+ protected RoleTO createRole(RoleService roleService, RoleTO newRoleTO) {
+ Response response = roleService.create(newRoleTO);
+ if (response.getStatus() != org.apache.http.HttpStatus.SC_CREATED) {
+ Exception ex = clientExceptionMapper.fromResponse(response);
+ if (ex != null) {
+ throw (RuntimeException) ex;
+ }
+ }
+ return getObject(response, RoleTO.class, roleService);
+ }
+
}
Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ReportTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ReportTestITCase.java?rev=1440928&r1=1440927&r2=1440928&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ReportTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ReportTestITCase.java Thu Jan 31 12:17:46 2013
@@ -30,7 +30,6 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Set;
-import java.util.UUID;
import javax.ws.rs.core.Response;
Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java?rev=1440928&r1=1440927&r2=1440928&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java Thu Jan 31 12:17:46 2013
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertNul
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.security.AccessControlException;
import java.util.ArrayList;
import java.util.List;
@@ -78,14 +79,12 @@ public class RoleTestITCase extends Abst
RoleTO newRoleTO = new RoleTO();
newRoleTO.addAttribute(attributeTO("attr1", "value1"));
- Throwable t = null;
try {
- roleService.create(newRoleTO);
+ createRole(roleService, newRoleTO);
fail();
} catch (SyncopeClientCompositeErrorException sccee) {
- t = sccee.getException(SyncopeClientExceptionType.InvalidSyncopeRole);
+ assertNotNull(sccee.getException(SyncopeClientExceptionType.InvalidSyncopeRole));
}
- assertNotNull(t);
}
@Test
@@ -94,8 +93,7 @@ public class RoleTestITCase extends Abst
roleTO.addVirtualAttribute(attributeTO("rvirtualdata", "rvirtualvalue"));
roleTO.setRoleOwner(8L);
- Response response = roleService.create(roleTO);
- roleTO = getObject(response, RoleTO.class, roleService);
+ roleTO = createRole(roleService, roleTO);
assertNotNull(roleTO);
assertNotNull(roleTO.getVirtualAttributeMap());
@@ -124,8 +122,7 @@ public class RoleTestITCase extends Abst
roleTO.setParent(8L);
roleTO.setPasswordPolicy(4L);
- Response response = roleService.create(roleTO);
- RoleTO actual = getObject(response, RoleTO.class, roleService);
+ RoleTO actual = createRole(roleService, roleTO);
assertNotNull(actual);
actual = roleService.read(actual.getId());
@@ -143,7 +140,7 @@ public class RoleTestITCase extends Abst
}
RoleTO roleTO = new RoleTO();
- roleTO.setName("toBeDeleted");
+ roleTO.setName("toBeDeleted" + getUUIDString());
roleTO.setParent(8L);
roleTO.addResource("resource-ldap");
@@ -216,9 +213,8 @@ public class RoleTestITCase extends Abst
@Test
public void update() {
- RoleTO roleTO = buildRoleTO("latestRole");
- Response response = roleService.create(roleTO);
- roleTO = getObject(response, RoleTO.class, roleService);
+ RoleTO roleTO = buildRoleTO("latestRole" + getUUIDString());
+ roleTO = createRole(roleService, roleTO);
assertEquals(1, roleTO.getAttributes().size());
@@ -252,11 +248,10 @@ public class RoleTestITCase extends Abst
@Test
public void updateRemovingVirAttribute() {
- RoleTO roleTO = buildBasicRoleTO("withvirtual");
+ RoleTO roleTO = buildBasicRoleTO("withvirtual" + getUUIDString());
roleTO.addVirtualAttribute(attributeTO("rvirtualdata", null));
- Response response = roleService.create(roleTO);
- roleTO = getObject(response, RoleTO.class, roleService);
+ roleTO = createRole(roleService, roleTO);
assertNotNull(roleTO);
assertEquals(1, roleTO.getVirtualAttributes().size());
@@ -273,11 +268,10 @@ public class RoleTestITCase extends Abst
@Test
public void updateRemovingDerAttribute() {
- RoleTO roleTO = buildBasicRoleTO("withderived");
+ RoleTO roleTO = buildBasicRoleTO("withderived" + getUUIDString());
roleTO.addDerivedAttribute(attributeTO("rderivedschema", null));
- Response response = roleService.create(roleTO);
- roleTO = getObject(response, RoleTO.class, roleService);
+ roleTO = createRole(roleService, roleTO);
assertNotNull(roleTO);
assertEquals(1, roleTO.getDerivedAttributes().size());
@@ -310,6 +304,8 @@ public class RoleTestITCase extends Abst
fail();
} catch (HttpStatusCodeException e) {
assertEquals(HttpStatus.FORBIDDEN, e.getStatusCode());
+ } catch (AccessControlException e) {
+ assertNotNull(e);
}
// 4. update as user5, owner of role 7 because owner of role 6 with
@@ -331,8 +327,7 @@ public class RoleTestITCase extends Abst
String roleName = "torename" + getUUIDString();
roleTO.setName(roleName);
- Response response = roleService.create(roleTO);
- RoleTO actual = getObject(response, RoleTO.class, roleService);
+ RoleTO actual = createRole(roleService, roleTO);
assertNotNull(actual);
assertEquals(roleName, actual.getName());
@@ -356,8 +351,7 @@ public class RoleTestITCase extends Abst
roleTO.addEntitlement("USER_READ");
roleTO.addEntitlement("SCHEMA_READ");
- Response response = roleService.create(roleTO);
- roleTO = getObject(response, RoleTO.class, roleService);
+ roleTO = createRole(roleService, roleTO);
assertNotNull(roleTO);
assertNotNull(roleTO.getEntitlements());
assertFalse(roleTO.getEntitlements().isEmpty());