mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merge from SEAMIST3
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10725 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -27,11 +27,13 @@ package org.alfresco.repo.web.scripts;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.web.scripts.TestWebScriptServer;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Base unit test class for web scripts.
|
||||
*
|
||||
@@ -56,7 +58,7 @@ public abstract class BaseWebScriptTest extends TestCase
|
||||
}
|
||||
return BaseWebScriptTest.server;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* "GET" the url and check for the expected status code
|
||||
*
|
||||
@@ -68,7 +70,7 @@ public abstract class BaseWebScriptTest extends TestCase
|
||||
protected MockHttpServletResponse getRequest(String url, int expectedStatus)
|
||||
throws IOException
|
||||
{
|
||||
return sendRequest(METHOD_GET, url, expectedStatus, null, null);
|
||||
return getRequest(url, expectedStatus, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,6 +87,21 @@ public abstract class BaseWebScriptTest extends TestCase
|
||||
return sendRequest(METHOD_DELETE, url, expectedStatus, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* "GET" the url and check for the expected status code
|
||||
*
|
||||
* @param url
|
||||
* @param expectedStatus
|
||||
* @param asUser
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
protected MockHttpServletResponse getRequest(String url, int expectedStatus, String asUser)
|
||||
throws IOException
|
||||
{
|
||||
return sendRequest(METHOD_GET, url, expectedStatus, null, null, asUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* "POST" the url and check for the expected status code
|
||||
*
|
||||
@@ -98,7 +115,22 @@ public abstract class BaseWebScriptTest extends TestCase
|
||||
protected MockHttpServletResponse postRequest(String url, int expectedStatus, String body, String contentType)
|
||||
throws IOException
|
||||
{
|
||||
return postRequest(url, expectedStatus, body.getBytes(), contentType);
|
||||
return postRequest(url, expectedStatus, body.getBytes(), contentType, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* "POST" the url and check for the expected status code
|
||||
*
|
||||
* @param url
|
||||
* @param expectedStatus
|
||||
* @param asUser
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
protected MockHttpServletResponse postRequest(String url, int expectedStatus, String body, String contentType, String asUser)
|
||||
throws IOException
|
||||
{
|
||||
return postRequest(url, expectedStatus, body.getBytes(), contentType, asUser);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,11 +144,26 @@ public abstract class BaseWebScriptTest extends TestCase
|
||||
protected MockHttpServletResponse postRequest(String url, int expectedStatus, byte[] body, String contentType)
|
||||
throws IOException
|
||||
{
|
||||
return sendRequest(METHOD_POST, url, expectedStatus, body, contentType);
|
||||
return postRequest(url, expectedStatus, body, contentType, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* "PUT" the url and check for the expected status code
|
||||
* "POST" the url and check for the expected status code
|
||||
*
|
||||
* @param url
|
||||
* @param expectedStatus
|
||||
* @param asUser
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
protected MockHttpServletResponse postRequest(String url, int expectedStatus, byte[] body, String contentType, String asUser)
|
||||
throws IOException
|
||||
{
|
||||
return sendRequest(METHOD_POST, url, expectedStatus, body, contentType, asUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send request to Test Web Script Server
|
||||
*
|
||||
* @param url
|
||||
* @param expectedStatus
|
||||
@@ -136,21 +183,34 @@ public abstract class BaseWebScriptTest extends TestCase
|
||||
* @param method
|
||||
* @param url
|
||||
* @param expectedStatus
|
||||
* @param body
|
||||
* @param contentType
|
||||
* @param asUser
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
private MockHttpServletResponse sendRequest(String method, String url, int expectedStatus, byte[] body, String contentType)
|
||||
private MockHttpServletResponse sendRequest(final String method, final String url, final int expectedStatus, final byte[] body, final String contentType, String asUser)
|
||||
throws IOException
|
||||
{
|
||||
MockHttpServletResponse response = BaseWebScriptTest.getServer().submitRequest(method, url, new HashMap<String, String>(), body, contentType);
|
||||
// send request in context of specified user
|
||||
String runAsUser = (asUser == null) ? AuthenticationUtil.getSystemUserName() : asUser;
|
||||
MockHttpServletResponse response = AuthenticationUtil.runAs(new RunAsWork<MockHttpServletResponse>()
|
||||
{
|
||||
@SuppressWarnings("synthetic-access")
|
||||
public MockHttpServletResponse doWork() throws Exception
|
||||
{
|
||||
return BaseWebScriptTest.getServer().submitRequest(method, url, new HashMap<String, String>(), body, contentType);
|
||||
}
|
||||
}, runAsUser);
|
||||
|
||||
if (expectedStatus > 0 && expectedStatus != response.getStatus())
|
||||
{
|
||||
//if (response.getStatus() == 500)
|
||||
//{
|
||||
System.out.println(response.getContentAsString());
|
||||
// System.out.println(response.getContentAsString());
|
||||
//}
|
||||
|
||||
fail("Expected status code " + expectedStatus + " , " + response.getStatus() + " was returned");
|
||||
fail("Status code " + response.getStatus() + " returned, but expected " + expectedStatus + " for " + url + " (" + method + ")");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
@@ -33,6 +33,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import org.alfresco.repo.cache.SimpleCache;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.template.CropContentMethod;
|
||||
import org.alfresco.repo.tenant.TenantDeployer;
|
||||
import org.alfresco.repo.tenant.TenantDeployerService;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
@@ -179,6 +180,7 @@ public class RepositoryContainer extends AbstractRuntimeContainer implements Ten
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.putAll(super.getTemplateParameters());
|
||||
params.put(TemplateService.KEY_IMAGE_RESOLVER, imageResolver.getImageResolver());
|
||||
params.put("cropContent", new CropContentMethod());
|
||||
addRepoParameters(params);
|
||||
return params;
|
||||
}
|
||||
|
@@ -74,6 +74,7 @@ public class TestWebScriptRepoServer extends TestWebScriptServer
|
||||
try
|
||||
{
|
||||
TestWebScriptServer testServer = getTestServer();
|
||||
AuthenticationUtil.setSystemUserAsCurrentUser();
|
||||
testServer.rep();
|
||||
}
|
||||
catch(Throwable e)
|
||||
|
Reference in New Issue
Block a user