Author: cziegeler
Date: Wed Jul 13 08:21:00 2011
New Revision: 1145903

URL: http://svn.apache.org/viewvc?rev=1145903&view=rev
Log:
Don't use random id - increase the id, this avoids creating the same user/group 
twice during a run

Modified:
    
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/AbstractAuthenticatedTest.java

Modified: 
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/AbstractAuthenticatedTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/AbstractAuthenticatedTest.java?rev=1145903&r1=1145902&r2=1145903&view=diff
==============================================================================
--- 
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/AbstractAuthenticatedTest.java
 (original)
+++ 
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/AbstractAuthenticatedTest.java
 Wed Jul 13 08:21:00 2011
@@ -21,7 +21,6 @@ import java.io.InputStream;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Random;
 
 import javax.servlet.http.HttpServletResponse;
 
@@ -155,7 +154,7 @@ public abstract class AbstractAuthentica
     }
 
     /** retrieve the contents of given URL and assert its content type
-     * @param expectedContentType use CONTENT_TYPE_DONTCARE if must not be 
checked 
+     * @param expectedContentType use CONTENT_TYPE_DONTCARE if must not be 
checked
      * @throws IOException
      * @throws HttpException */
     protected String getAuthenticatedPostContent(Credentials creds, String 
url, String expectedContentType, List<NameValuePair> postParams, int 
expectedStatusCode) throws IOException {
@@ -167,7 +166,7 @@ public abstract class AbstractAuthentica
         Credentials oldCredentials = 
httpClient.getState().getCredentials(authScope);
        try {
                        httpClient.getState().setCredentials(authScope, creds);
-                       
+
                if(postParams!=null) {
                    final NameValuePair [] nvp = {};
                    post.setRequestBody(postParams.toArray(nvp));
@@ -204,19 +203,25 @@ public abstract class AbstractAuthentica
                    );
                }
                return content.toString();
-                       
+
        } finally {
                httpClient.getState().setCredentials(authScope, oldCredentials);
        }
     }
-    
 
-    private static Random random = new Random(System.currentTimeMillis());
+
+    private static long randomId = System.currentTimeMillis();
+
+    private static synchronized long getNextInt() {
+        final long val = randomId;
+        randomId++;
+        return val;
+    }
 
     protected String createTestUser() throws IOException {
         String postUrl = HTTP_BASE_URL + 
"/system/userManager/user.create.html";
 
-        String testUserId = "testUser" + random.nextInt();
+        String testUserId = "testUser" + getNextInt();
         List<NameValuePair> postParams = new ArrayList<NameValuePair>();
         postParams.add(new NameValuePair(":name", testUserId));
         postParams.add(new NameValuePair("pwd", "testPwd"));
@@ -230,7 +235,7 @@ public abstract class AbstractAuthentica
     protected String createTestGroup() throws IOException {
         String postUrl = HTTP_BASE_URL + 
"/system/userManager/group.create.html";
 
-        String testGroupId = "testGroup" + random.nextInt();
+        String testGroupId = "testGroup" + getNextInt();
         List<NameValuePair> postParams = new ArrayList<NameValuePair>();
         postParams.add(new NameValuePair(":name", testGroupId));
 


Reply via email to