You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by as...@apache.org on 2013/01/15 10:40:58 UTC

svn commit: r1433327 - in /syncope/trunk/core/src/test/java/org/apache/syncope/core/rest: NotificationTestITCase.java RoleTestITCase.java SchemaTestITCase.java UserRequestTestITCase.java

Author: ashakirin
Date: Tue Jan 15 09:40:58 2013
New Revision: 1433327

URL: http://svn.apache.org/viewvc?rev=1433327&view=rev
Log:
[SYNCOPE-268] Make rest integration tests re-runnable

Modified:
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/NotificationTestITCase.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/NotificationTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/NotificationTestITCase.java?rev=1433327&r1=1433326&r2=1433327&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/NotificationTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/NotificationTestITCase.java Tue Jan 15 09:40:58 2013
@@ -59,34 +59,13 @@ public class NotificationTestITCase exte
 
     @Test
     public void create() {
-        NotificationTO notificationTO = new NotificationTO();
-        notificationTO.setTraceLevel(TraceLevel.SUMMARY);
-        notificationTO.addEvent("create");
-
-        AttributeCond fullnameLeafCond1 = new AttributeCond(AttributeCond.Type.LIKE);
-        fullnameLeafCond1.setSchema("fullname");
-        fullnameLeafCond1.setExpression("%o%");
-        AttributeCond fullnameLeafCond2 = new AttributeCond(AttributeCond.Type.LIKE);
-        fullnameLeafCond2.setSchema("fullname");
-        fullnameLeafCond2.setExpression("%i%");
-        NodeCond about = NodeCond.getAndCond(NodeCond.getLeafCond(fullnameLeafCond1),
-                NodeCond.getLeafCond(fullnameLeafCond2));
-
-        notificationTO.setAbout(about);
+        NotificationTO notificationTO = buildNotificationTO();
 
         MembershipCond membCond = new MembershipCond();
         membCond.setRoleId(7L);
         NodeCond recipients = NodeCond.getLeafCond(membCond);
-
         notificationTO.setRecipients(recipients);
 
-        notificationTO.setRecipientAttrName("email");
-        notificationTO.setRecipientAttrType(IntMappingType.UserSchema);
-
-        notificationTO.setSender("syncope@syncope.apache.org");
-        notificationTO.setSubject("Test notification");
-        notificationTO.setTemplate("test");
-
         NotificationTO actual = notificationService.create(notificationTO);
 
         assertNotNull(actual);
@@ -123,12 +102,23 @@ public class NotificationTestITCase exte
 
     @Test
     public void delete() {
-        NotificationTO deletedNotification = notificationService.delete(101L);
+    	NotificationTO notification = null;
+    	try {
+    		// Check for pre-loaded notification: must be deleted for other create tests success
+    		notification = notificationService.read(101L);	
+    	} catch (SyncopeClientCompositeErrorException e) {
+    		assertNotNull(e.getException(SyncopeClientExceptionType.NotFound));
+    		notification = buildNotificationTO();
+            notification.setSelfAsRecipient(true);
+            notification = notificationService.create(notification);
+    	}
+    	
+        NotificationTO deletedNotification = notificationService.delete(notification.getId());
         assertNotNull(deletedNotification);
 
         SyncopeClientException exception = null;
         try {
-            notificationService.read(101L);
+            notificationService.read(notification.getId());
         } catch (SyncopeClientCompositeErrorException e) {
             exception = e.getException(SyncopeClientExceptionType.NotFound);
         }
@@ -137,6 +127,25 @@ public class NotificationTestITCase exte
 
     @Test
     public void issueSYNCOPE83() {
+        NotificationTO notificationTO = buildNotificationTO();
+        notificationTO.setSelfAsRecipient(true);
+
+        NotificationTO actual = null;
+        SyncopeClientException exception = null;
+        try {
+            actual = notificationService.create(notificationTO);
+
+        } catch (SyncopeClientCompositeErrorException e) {
+            exception = e.getException(SyncopeClientExceptionType.InvalidNotification);
+        }
+        assertNull(exception);
+        assertNotNull(actual);
+        assertNotNull(actual.getId());
+        notificationTO.setId(actual.getId());
+        assertEquals(actual, notificationTO);
+    }
+
+	private NotificationTO buildNotificationTO() {
         NotificationTO notificationTO = new NotificationTO();
         notificationTO.setTraceLevel(TraceLevel.SUMMARY);
         notificationTO.addEvent("create");
@@ -155,24 +164,9 @@ public class NotificationTestITCase exte
         notificationTO.setRecipientAttrName("email");
         notificationTO.setRecipientAttrType(IntMappingType.UserSchema);
 
-        notificationTO.setSelfAsRecipient(true);
-
         notificationTO.setSender("syncope@syncope.apache.org");
-        notificationTO.setSubject("Test notification without");
+        notificationTO.setSubject("Test notification");
         notificationTO.setTemplate("test");
-
-        NotificationTO actual = null;
-        SyncopeClientException exception = null;
-        try {
-            actual = notificationService.create(notificationTO);
-
-        } catch (SyncopeClientCompositeErrorException e) {
-            exception = e.getException(SyncopeClientExceptionType.InvalidNotification);
-        }
-        assertNull(exception);
-        assertNotNull(actual);
-        assertNotNull(actual.getId());
-        notificationTO.setId(actual.getId());
-        assertEquals(actual, notificationTO);
-    }
+		return notificationTO;
+	}
 }

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=1433327&r1=1433326&r2=1433327&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 Tue Jan 15 09:40:58 2013
@@ -62,28 +62,11 @@ public class RoleTestITCase extends Abst
 
     @Test
     public void create() {
-        RoleTO roleTO = new RoleTO();
-        roleTO.setName("lastRole");
-        roleTO.setParent(8L);
-
-        // verify inheritance password and account policies
-        roleTO.setInheritAccountPolicy(false);
-        // not inherited so setter execution shouldn't be ignored
-        roleTO.setAccountPolicy(6L);
-
-        roleTO.setInheritPasswordPolicy(true);
-        // inherited so setter execution should be ignored
-        roleTO.setPasswordPolicy(2L);
-
-        roleTO.addAttribute(attributeTO("icon", "anIcon"));
-
+        RoleTO roleTO = buildRoleTO("lastRole");
         roleTO.addDerivedAttribute(attributeTO("ownerDN", null));
-
         roleTO.addVirtualAttribute(attributeTO("rvirtualdata", "rvirtualvalue"));
-
         roleTO.setRoleOwner(8L);
 
-        roleTO.addResource("resource-ldap");
 
         roleTO = roleService.create(roleTO);
         assertNotNull(roleTO);
@@ -102,7 +85,7 @@ public class RoleTestITCase extends Abst
         assertTrue(roleTO.getResources().contains("resource-ldap"));
 
         ConnObjectTO connObjectTO = resourceService.getConnector("resource-ldap", AttributableType.ROLE,
-                "lastRole");
+        		roleTO.getName());
         assertNotNull(connObjectTO);
         assertNotNull(connObjectTO.getAttributeMap().get("owner"));
     }
@@ -110,7 +93,7 @@ public class RoleTestITCase extends Abst
     @Test
     public void createWithPasswordPolicy() {
         RoleTO roleTO = new RoleTO();
-        roleTO.setName("roleWithPassword");
+        roleTO.setName("roleWithPassword" + getUUIDString());
         roleTO.setParent(8L);
         roleTO.setPasswordPolicy(4L);
 
@@ -207,23 +190,7 @@ public class RoleTestITCase extends Abst
 
     @Test
     public void update() {
-        RoleTO roleTO = new RoleTO();
-        roleTO.setName("latestRole");
-        roleTO.setParent(8L);
-
-        // verify inheritance password and account policies
-        roleTO.setInheritAccountPolicy(false);
-        // not inherited so setter execution shouldn't be ignored
-        roleTO.setAccountPolicy(6L);
-
-        roleTO.setInheritPasswordPolicy(true);
-        // inherited so setter execution should be ignored
-        roleTO.setPasswordPolicy(2L);
-
-        roleTO.addAttribute(attributeTO("icon", "anIcon"));
-
-        roleTO.addResource("resource-ldap");
-
+        RoleTO roleTO = buildRoleTO("latestRole");
         roleTO = roleService.create(roleTO);
 
         assertEquals(1, roleTO.getAttributes().size());
@@ -236,7 +203,8 @@ public class RoleTestITCase extends Abst
 
         RoleMod roleMod = new RoleMod();
         roleMod.setId(roleTO.getId());
-        roleMod.setName("finalRole");
+        String modName = "finalRole" + getUUIDString(); 
+        roleMod.setName(modName);
         roleMod.addAttributeToBeUpdated(attributeMod("show", "FALSE"));
 
         // change password policy inheritance
@@ -244,7 +212,7 @@ public class RoleTestITCase extends Abst
 
         roleTO = roleService.update(roleMod.getId(), roleMod);
 
-        assertEquals("finalRole", roleTO.getName());
+        assertEquals(modName, roleTO.getName());
         assertEquals(2, roleTO.getAttributes().size());
 
         // changes ignored because not requested (null ReferenceMod)
@@ -257,9 +225,7 @@ public class RoleTestITCase extends Abst
 
     @Test
     public void updateRemovingVirAttribute() {
-        RoleTO roleTO = new RoleTO();
-        roleTO.setName("withvirtual");
-        roleTO.setParent(8L);
+        RoleTO roleTO = buildBasicRoleTO("withvirtual");
         roleTO.addVirtualAttribute(attributeTO("rvirtualdata", null));
 
         roleTO = roleService.create(roleTO);
@@ -279,9 +245,7 @@ public class RoleTestITCase extends Abst
 
     @Test
     public void updateRemovingDerAttribute() {
-        RoleTO roleTO = new RoleTO();
-        roleTO.setName("withderived");
-        roleTO.setParent(8L);
+        RoleTO roleTO = buildBasicRoleTO("withderived");
         roleTO.addDerivedAttribute(attributeTO("rderivedschema", null));
 
         roleTO = roleService.create(roleTO);
@@ -338,36 +302,30 @@ public class RoleTestITCase extends Abst
     @Test
     public void issue178() {
         RoleTO roleTO = new RoleTO();
-        roleTO.setName("torename");
+        String roleName = "torename" + getUUIDString(); 
+        roleTO.setName(roleName);
 
         RoleTO actual = roleService.create(roleTO);
 
         assertNotNull(actual);
-        assertEquals("torename", actual.getName());
+        assertEquals(roleName, actual.getName());
         assertEquals(0L, actual.getParent());
 
         RoleMod roleMod = new RoleMod();
         roleMod.setId(actual.getId());
-        roleMod.setName("renamed");
+        String renamedRole = "renamed" + getUUIDString(); 
+        roleMod.setName(renamedRole);
 
         actual = roleService.update(roleMod.getId(), roleMod);
-        ;
 
         assertNotNull(actual);
-        assertEquals("renamed", actual.getName());
+        assertEquals(renamedRole, actual.getName());
         assertEquals(0L, actual.getParent());
     }
 
     @Test
     public void issueSYNCOPE228() {
-        RoleTO roleTO = new RoleTO();
-        roleTO.setName("issueSYNCOPE228");
-        roleTO.setParent(8L);
-        roleTO.setInheritAccountPolicy(false);
-        roleTO.setAccountPolicy(6L);
-        roleTO.setInheritPasswordPolicy(true);
-        roleTO.setPasswordPolicy(2L);
-        roleTO.addAttribute(attributeTO("icon", "anIcon"));
+        RoleTO roleTO = buildRoleTO("issueSYNCOPE228");
         roleTO.addEntitlement("USER_READ");
         roleTO.addEntitlement("SCHEMA_READ");
 
@@ -394,4 +352,30 @@ public class RoleTestITCase extends Abst
         assertNotNull(roleTO);
         assertTrue(roleTO.getEntitlements().isEmpty());
     }
+
+	private RoleTO buildBasicRoleTO(String name) {
+		RoleTO roleTO = new RoleTO();
+        roleTO.setName(name + getUUIDString());
+        roleTO.setParent(8L);
+		return roleTO;
+	}
+
+	private RoleTO buildRoleTO(String name) {
+		RoleTO roleTO = buildBasicRoleTO(name);
+
+        // verify inheritance password and account policies
+        roleTO.setInheritAccountPolicy(false);
+        // not inherited so setter execution shouldn't be ignored
+        roleTO.setAccountPolicy(6L);
+
+        roleTO.setInheritPasswordPolicy(true);
+        // inherited so setter execution should be ignored
+        roleTO.setPasswordPolicy(2L);
+
+        roleTO.addAttribute(attributeTO("icon", "anIcon"));
+
+        roleTO.addResource("resource-ldap");
+		return roleTO;
+	}
+
 }

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java?rev=1433327&r1=1433326&r2=1433327&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java Tue Jan 15 09:40:58 2013
@@ -44,10 +44,8 @@ public class SchemaTestITCase extends Ab
 
     @Test
     public void create() {
-        SchemaTO schemaTO = new SchemaTO();
-        schemaTO.setName("testAttribute");
+        SchemaTO schemaTO = buildSchemaTO("testAttribute", SchemaType.String);
         schemaTO.setMandatoryCondition("false");
-        schemaTO.setType(SchemaType.String);
 
         SchemaTO newSchemaTO = schemaService.create(AttributableType.USER, SchemaService.SchemaType.NORMAL, schemaTO);
         assertEquals(schemaTO, newSchemaTO);
@@ -115,11 +113,15 @@ public class SchemaTestITCase extends Ab
 
     @Test
     public void delete() {
-        SchemaTO deletedSchema = schemaService.delete(AttributableType.USER, SchemaService.SchemaType.NORMAL, "cool");
+        SchemaTO schemaTO = buildSchemaTO("todelete", SchemaType.String);
+        schemaTO.setMandatoryCondition("false");
+        schemaService.create(AttributableType.USER, SchemaService.SchemaType.NORMAL, schemaTO);
+
+        SchemaTO deletedSchema = schemaService.delete(AttributableType.USER, SchemaService.SchemaType.NORMAL, schemaTO.getName());
         assertNotNull(deletedSchema);
         SchemaTO firstname = null;
         try {
-            firstname = schemaService.read(AttributableType.USER, SchemaService.SchemaType.NORMAL, "cool");
+            firstname = schemaService.read(AttributableType.USER, SchemaService.SchemaType.NORMAL, schemaTO.getName());
         } catch (HttpClientErrorException e) {
             assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
         }
@@ -174,7 +176,7 @@ public class SchemaTestITCase extends Ab
         schemaTO = schemaService.create(AttributableType.USER, SchemaService.SchemaType.NORMAL, schemaTO);
         assertNotNull(schemaTO);
 
-        UserTO userTO = UserTestITCase.getSampleTO("issue258@syncope.apache.org");
+        UserTO userTO = UserTestITCase.getSampleUniqueTO();
         userTO.addAttribute(attributeTO(schemaTO.getName(), "1.2"));
 
         userTO = userService.create(userTO);
@@ -192,15 +194,13 @@ public class SchemaTestITCase extends Ab
 
     @Test
     public void issue259() {
-        SchemaTO schemaTO = new SchemaTO();
-        schemaTO.setName("schema_issue259");
+        SchemaTO schemaTO = buildSchemaTO("schema_issue259", SchemaType.Double);
         schemaTO.setUniqueConstraint(true);
-        schemaTO.setType(SchemaType.Long);
 
         schemaTO = schemaService.create(AttributableType.USER, SchemaService.SchemaType.NORMAL, schemaTO);
         assertNotNull(schemaTO);
 
-        UserTO userTO = UserTestITCase.getSampleTO("issue259@syncope.apache.org");
+        UserTO userTO = UserTestITCase.getSampleUniqueTO();
         userTO.addAttribute(attributeTO(schemaTO.getName(), "1"));
         userTO = userService.create(userTO);
         assertNotNull(userTO);
@@ -218,15 +218,13 @@ public class SchemaTestITCase extends Ab
 
     @Test
     public void issue260() {
-        SchemaTO schemaTO = new SchemaTO();
-        schemaTO.setName("schema_issue260");
-        schemaTO.setType(SchemaType.Double);
+        SchemaTO schemaTO = buildSchemaTO("schema_issue260", SchemaType.Double);
         schemaTO.setUniqueConstraint(true);
 
         schemaTO = schemaService.create(AttributableType.USER, SchemaService.SchemaType.NORMAL, schemaTO);
         assertNotNull(schemaTO);
 
-        UserTO userTO = UserTestITCase.getSampleTO("issue260@syncope.apache.org");
+        UserTO userTO = UserTestITCase.getSampleUniqueTO();
         userTO.addAttribute(attributeTO(schemaTO.getName(), "1.2"));
         userTO = userService.create(userTO);
         assertNotNull(userTO);
@@ -240,4 +238,11 @@ public class SchemaTestITCase extends Ab
             assertNotNull(sce);
         }
     }
+
+	private SchemaTO buildSchemaTO(String name, SchemaType type) {
+		SchemaTO schemaTO = new SchemaTO();
+        schemaTO.setName(name + getUUIDString());
+        schemaTO.setType(type);
+		return schemaTO;
+	}
 }

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java?rev=1433327&r1=1433326&r2=1433327&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java Tue Jan 15 09:40:58 2013
@@ -54,7 +54,7 @@ public class UserRequestTestITCase exten
         configurationTO = configurationService.create(configurationTO);
         assertNotNull(configurationTO);
 
-        UserTO userTO = UserTestITCase.getSampleTO("selfcreate@syncope.apache.org");
+        UserTO userTO = UserTestITCase.getSampleUniqueTO();
 
         // 2. get unauthorized when trying to request user create
         SyncopeClientException exception = null;
@@ -83,7 +83,7 @@ public class UserRequestTestITCase exten
         // 6. try to find user
         AttributeCond attrCond = new AttributeCond(AttributeCond.Type.EQ);
         attrCond.setSchema("userId");
-        attrCond.setExpression("selfcreate@syncope.apache.org");
+        attrCond.setExpression(userTO.getUsername());
 
         final List<UserTO> matchingUsers = userService.search(NodeCond.getLeafCond(attrCond));
         assertTrue(matchingUsers.isEmpty());
@@ -96,7 +96,7 @@ public class UserRequestTestITCase exten
     @Test
     public void update() {
         // 1. create an user (as admin)
-        UserTO userTO = UserTestITCase.getSampleTO("selfupdate@syncope.apache.org");
+        UserTO userTO = UserTestITCase.getSampleUniqueTO();
         String initialPassword = userTO.getPassword();
 
         userTO = userService.create(userTO);
@@ -152,7 +152,7 @@ public class UserRequestTestITCase exten
     @Test
     public void delete() {
         // 1. create an user (as admin)
-        UserTO userTO = UserTestITCase.getSampleTO("selfdelete@syncope.apache.org");
+        UserTO userTO = UserTestITCase.getSampleUniqueTO();
         String initialPassword = userTO.getPassword();
 
         userTO = userService.create(userTO);