incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1539035 - /sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateUserTest.java
Date Tue, 05 Nov 2013 15:38:43 GMT
Author: bdelacretaz
Date: Tue Nov  5 15:38:42 2013
New Revision: 1539035

URL: http://svn.apache.org/r1539035
Log:
SLING-3143 - Use JackrabbitOnly category to disable tests that fail on Oak

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

Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateUserTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateUserTest.java?rev=1539035&r1=1539034&r2=1539035&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateUserTest.java
(original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateUserTest.java
Tue Nov  5 15:38:42 2013
@@ -16,6 +16,10 @@
  */
 package org.apache.sling.launchpad.webapp.integrationtest.userManager;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
@@ -28,23 +32,36 @@ import org.apache.commons.httpclient.Nam
 import org.apache.commons.httpclient.UsernamePasswordCredentials;
 import org.apache.sling.commons.json.JSONException;
 import org.apache.sling.commons.json.JSONObject;
+import org.apache.sling.commons.testing.integration.HttpTest;
+import org.apache.sling.commons.testing.junit.categories.JackrabbitOnly;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
 
 /**
  * Tests for the 'createUser' Sling Post Operation
  */
-public class CreateUserTest extends UserManagerTestUtil {
+public class CreateUserTest {
     private static Random random = new Random(System.currentTimeMillis());
     private String testUserId;
+    
+    private final UserManagerTestUtil H = new UserManagerTestUtil(); 
 
-	@Override
-	public void tearDown() throws Exception {
+    @Before
+    public void setup() throws Exception {
+        H.setUp();
+    }
+    
+	@After
+	public void cleanup() throws Exception {
 		if (testUserId != null) {
 			//remove the test user if it exists.
-			String postUrl = HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".delete.html";
+			String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".delete.html";
 			List<NameValuePair> postParams = new ArrayList<NameValuePair>();
-			assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
+			H.assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
 		}
-		super.tearDown();
+		H.tearDown();
 	}
 
 	/*
@@ -55,21 +72,22 @@ public class CreateUserTest extends User
 		   <input type="submit" value="Submit" />
 		</form>
 	 */
+	@Test 
 	public void testCreateUser() throws IOException, JSONException {
 	    testUserId = "testUser" + random.nextInt() + System.currentTimeMillis();
-        String postUrl = HTTP_BASE_URL + "/system/userManager/user.create.html";
+        String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
 		final List<NameValuePair> postParams = new ArrayList<NameValuePair>();
 		postParams.add(new NameValuePair(":name", testUserId));
 		postParams.add(new NameValuePair("marker", testUserId));
 		postParams.add(new NameValuePair("pwd", "testPwd"));
 		postParams.add(new NameValuePair("pwdConfirm", "testPwd"));
 		final Credentials creds = new UsernamePasswordCredentials("admin", "admin");
-		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
+		H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams,
null);
 
 		{
 	        // fetch the user profile json to verify the settings
-	        final String getUrl = HTTP_BASE_URL + "/system/userManager/user/" + testUserId +
".json";
-	        final String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null,
HttpServletResponse.SC_OK);
+	        final String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId
+ ".json";
+	        final String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON,
null, HttpServletResponse.SC_OK);
 	        assertNotNull(json);
 	        final JSONObject jsonObj = new JSONObject(json);
 	        assertEquals(testUserId, jsonObj.getString("marker"));
@@ -81,34 +99,37 @@ public class CreateUserTest extends User
         {
             // fetch the session info to verify that the user can log in
             final Credentials newUserCreds = new UsernamePasswordCredentials(testUserId,
"testPwd");
-            final String getUrl = HTTP_BASE_URL + "/system/sling/info.sessionInfo.json";
-            final String json = getAuthenticatedContent(newUserCreds, getUrl, CONTENT_TYPE_JSON,
null, HttpServletResponse.SC_OK);
+            final String getUrl = HttpTest.HTTP_BASE_URL + "/system/sling/info.sessionInfo.json";
+            final String json = H.getAuthenticatedContent(newUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON,
null, HttpServletResponse.SC_OK);
             assertNotNull(json);
             final JSONObject jsonObj = new JSONObject(json);
             assertEquals(testUserId, jsonObj.getString("userID"));
         }
 	}
 
+	@Test 
 	public void testCreateUserMissingUserId() throws IOException {
-        String postUrl = HTTP_BASE_URL + "/system/userManager/user.create.html";
+        String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
 
 		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
 		Credentials creds = new UsernamePasswordCredentials("admin", "admin");
-		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
postParams, null);
+		H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
postParams, null);
 	}
 
+	@Test 
 	public void testCreateUserMissingPwd() throws IOException {
-        String postUrl = HTTP_BASE_URL + "/system/userManager/user.create.html";
+        String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
 
         String userId = "testUser" + random.nextInt();
 		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
 		postParams.add(new NameValuePair(":name", userId));
 		Credentials creds = new UsernamePasswordCredentials("admin", "admin");
-		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
postParams, null);
+		H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
postParams, null);
 	}
 
+	@Test 
 	public void testCreateUserWrongConfirmPwd() throws IOException {
-        String postUrl = HTTP_BASE_URL + "/system/userManager/user.create.html";
+        String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
 
         String userId = "testUser" + random.nextInt();
 		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
@@ -116,11 +137,12 @@ public class CreateUserTest extends User
 		postParams.add(new NameValuePair("pwd", "testPwd"));
 		postParams.add(new NameValuePair("pwdConfirm", "testPwd2"));
 		Credentials creds = new UsernamePasswordCredentials("admin", "admin");
-		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
postParams, null);
+		H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
postParams, null);
 	}
 
+	@Test 
 	public void testCreateUserUserAlreadyExists() throws IOException {
-        String postUrl = HTTP_BASE_URL + "/system/userManager/user.create.html";
+        String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
 
 		testUserId = "testUser" + random.nextInt();
 		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
@@ -128,10 +150,10 @@ public class CreateUserTest extends User
 		postParams.add(new NameValuePair("pwd", "testPwd"));
 		postParams.add(new NameValuePair("pwdConfirm", "testPwd"));
 		Credentials creds = new UsernamePasswordCredentials("admin", "admin");
-		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
+		H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams,
null);
 
 		//post the same info again, should fail
-		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
postParams, null);
+		H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
postParams, null);
 	}
 
 	/*
@@ -144,8 +166,9 @@ public class CreateUserTest extends User
 	   <input type="submit" value="Submit" />
 	</form>
 	*/
+	@Test 
 	public void testCreateUserWithExtraProperties() throws IOException, JSONException {
-        String postUrl = HTTP_BASE_URL + "/system/userManager/user.create.html";
+        String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
 
 		testUserId = "testUser" + random.nextInt();
 		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
@@ -156,11 +179,11 @@ public class CreateUserTest extends User
 		postParams.add(new NameValuePair("displayName", "My Test User"));
 		postParams.add(new NameValuePair("url", "http://www.apache.org"));
 		Credentials creds = new UsernamePasswordCredentials("admin", "admin");
-		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
+		H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams,
null);
 
 		//fetch the user profile json to verify the settings
-		String getUrl = HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".json";
-		String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
+		String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".json";
+		String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null,
HttpServletResponse.SC_OK);
 		assertNotNull(json);
 		JSONObject jsonObj = new JSONObject(json);
 		assertEquals(testUserId, jsonObj.getString("marker"));
@@ -175,8 +198,9 @@ public class CreateUserTest extends User
 	 * Test for SLING-1642 to verify that user self-registration by the anonymous
 	 * user is not allowed by default.
 	 */
+	@Test 
 	public void testAnonymousSelfRegistrationDisabled() throws IOException {
-        String postUrl = HTTP_BASE_URL + "/system/userManager/user.create.html";
+        String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
 
 		String userId = "testUser" + random.nextInt();
 		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
@@ -184,16 +208,17 @@ public class CreateUserTest extends User
 		postParams.add(new NameValuePair("pwd", "testPwd"));
 		postParams.add(new NameValuePair("pwdConfirm", "testPwd"));
 		//user create without logging in as a privileged user should return a 500 error
-		httpClient.getState().clearCredentials();
-		assertPostStatus(postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, null);
+		H.getHttpClient().getState().clearCredentials();
+		H.assertPostStatus(postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, null);
 	}
 	
 	
 	/**
 	 * Test for SLING-1677
 	 */
+	@Test 
 	public void testCreateUserResponseAsJSON() throws IOException, JSONException {
-        String postUrl = HTTP_BASE_URL + "/system/userManager/user.create.json";
+        String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.json";
 
 		testUserId = "testUser" + random.nextInt();
 		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
@@ -202,7 +227,7 @@ public class CreateUserTest extends User
 		postParams.add(new NameValuePair("pwd", "testPwd"));
 		postParams.add(new NameValuePair("pwdConfirm", "testPwd"));
 		Credentials creds = new UsernamePasswordCredentials("admin", "admin");
-		String json = getAuthenticatedPostContent(creds, postUrl, CONTENT_TYPE_JSON, postParams,
HttpServletResponse.SC_OK);
+		String json = H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON,
postParams, HttpServletResponse.SC_OK);
 
 		//make sure the json response can be parsed as a JSON object
 		JSONObject jsonObj = new JSONObject(json);
@@ -213,11 +238,13 @@ public class CreateUserTest extends User
 	 * Test for SLING-2070 to verify that members of the UserAdmin group
 	 * can create users.
 	 */
+	@Test 
+    @Category(JackrabbitOnly.class) // TODO: fails on Oak
 	public void testCreateUserAsUserAdminGroupMember() throws IOException {
-		testUserId = createTestUser();
-		addUserToUserAdminGroup(testUserId);
+		testUserId = H.createTestUser();
+		H.addUserToUserAdminGroup(testUserId);
 		
-        String postUrl = HTTP_BASE_URL + "/system/userManager/user.create.html";
+        String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
 
 		String userId = "testUser" + random.nextInt();
 		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
@@ -227,7 +254,7 @@ public class CreateUserTest extends User
 
 		Credentials creds = new UsernamePasswordCredentials(testUserId, "testPwd");
 		final String msg = "Expecting user " + testUserId + " to be able to create another user";
-		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, msg);
+		H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams,
msg);
 	}
 	
 }



Mime
View raw message