diff --git a/source/java/org/alfresco/repo/web/scripts/activities/SiteActivitySystemTest.java b/source/java/org/alfresco/repo/web/scripts/activities/SiteActivitySystemTest.java index ea9785e445..0cdf3ee608 100644 --- a/source/java/org/alfresco/repo/web/scripts/activities/SiteActivitySystemTest.java +++ b/source/java/org/alfresco/repo/web/scripts/activities/SiteActivitySystemTest.java @@ -34,17 +34,16 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; -import java.util.Date; import junit.framework.TestCase; import org.alfresco.repo.site.SiteModel; import org.alfresco.repo.web.scripts.activities.feed.UserFeedRetrieverWebScript; import org.alfresco.util.Base64; -import org.alfresco.util.ISO8601DateFormat; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONArray; +import org.json.JSONException; import org.json.JSONObject; /** @@ -59,12 +58,6 @@ public class SiteActivitySystemTest extends TestCase // TODO - use test property file private static final String REPO = "http://localhost:8080/alfresco"; - // web service (SOAP) - temporary (see below) - private static final String WEBSERVICE_ENDPOINT = REPO + "/api"; - - private static final String URL_AUTH = "/AuthenticationService"; - private static final String URL_ADMIN = "/AdministrationService"; - // web script (REST) private static final String WEBSCRIPT_ENDPOINT = REPO + "/service"; @@ -72,6 +65,9 @@ public class SiteActivitySystemTest extends TestCase private static final String URL_SITES = "/api/sites"; private static final String URL_MEMBERSHIPS = "/memberships"; + // Person Service part-URLs + private static final String URL_PEOPLE = "/api/people"; + // Activity Service part-URLs private static final String URL_ACTIVITIES = "/api/activities"; private static final String URL_SITE_FEED = "/feed/site"; @@ -130,10 +126,13 @@ public class SiteActivitySystemTest extends TestCase // pre-create users - createUser(user1, USER_PW); - createUser(user2, USER_PW); - createUser(user3, USER_PW); - createUser(user4, USER_PW); + String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, ADMIN_USER, ADMIN_PW); + assertNotNull(ticket); + + createUser(ticket, user1, USER_PW); + createUser(ticket, user2, USER_PW); + createUser(ticket, user3, USER_PW); + createUser(ticket, user4, USER_PW); setup = true; } @@ -806,91 +805,25 @@ public class SiteActivitySystemTest extends TestCase return ticketResult; } - // TODO - replace with Create Person REST API when it becomes available - - protected void createUser(String username, String password) throws MalformedURLException, URISyntaxException, IOException + protected void createUser(String ticket, String username, String password) throws JSONException, IOException, URISyntaxException { - String ticket = webServiceStartSession(ADMIN_USER, ADMIN_PW); - webServiceCreateUser(username, password, ticket); - webServiceEndSession(ticket); - } - - private String webServiceStartSession(String username, String password) throws MalformedURLException, URISyntaxException, IOException - { - String soapCall = - ""+ - ""+ - ""+ - ""+username+""+ - ""+password+""+ - ""; + // Build the JSON person object + JSONObject person = new JSONObject(); + person.put("userName", username); + person.put("firstName", "first"); + person.put("lastName", "last"); + person.put("email", "email@email.com"); + person.put("password", password); - String response = callInOutWeb(WEBSERVICE_ENDPOINT + URL_AUTH, "POST", null, soapCall, "text/xml; charset=utf-8", "\"http://www.alfresco.org/ws/service/authentication/1.0/startSession\""); + String url = WEBSCRIPT_ENDPOINT + URL_PEOPLE; + String response = callPostWebScript(url, ticket, person.toString()); - String ticket = null; - - if (response != null) + if (logger.isDebugEnabled()) { - int idx1 = response.indexOf(""); - if (idx1 != -1) - { - int idx2 = response.indexOf(""); - if (idx2 != -1) - { - ticket = response.substring(idx1+"".length(), idx2); - } - } + logger.debug("addPerson: " + username); + logger.debug("--------------"); + logger.debug(url); + logger.debug(response); } - - return ticket; - } - - private void webServiceCreateUser(String username, String password, String ticket) throws MalformedURLException, URISyntaxException, IOException - { - Date now = new Date(); - String startTime = ISO8601DateFormat.format(now); - String expireTime = ISO8601DateFormat.format(new Date(now.getTime() + 5*60*1000)); - - String soapCall = - ""+ - ""+ - ""+ - ""+ - ""+startTime+""+expireTime+""+ - "ticket"+ticket+""+ - ""+ - ""+username+""+password+""+ - "{http://www.alfresco.org/model/content/1.0}homeFolder"+ - "false"+ - "workspace:////SpacesStore" + - "{http://www.alfresco.org/model/content/1.0}firstName"+ - "false"+ - ""+"FN_"+username+""+ - "{http://www.alfresco.org/model/content/1.0}middleName"+ - "false"+ - ""+ - "{http://www.alfresco.org/model/content/1.0}lastName"+ - "false" + - ""+"LN_"+username+"" + - "{http://www.alfresco.org/model/content/1.0}email"+ - "false"+ - "email1210929178773"+ - "{http://www.alfresco.org/model/content/1.0}organizationId"+ - "false"+ - "org1210929178773"; - - callInOutWeb(WEBSERVICE_ENDPOINT + URL_ADMIN, "POST", null, soapCall, "text/xml; charset=utf-8", "\"http://www.alfresco.org/ws/service/administration/1.0/createUsers\""); // ignore response - } - - private void webServiceEndSession(String ticket) throws MalformedURLException, URISyntaxException, IOException - { - String soapCall = - ""+ - ""+ - ""+ - ""+ticket+""+ - ""; - - callInOutWeb(WEBSERVICE_ENDPOINT + URL_AUTH, "POST", null, soapCall, "text/xml; charset=utf-8", "\"http://www.alfresco.org/ws/service/authentication/1.0/endSession\""); // ignore response } }