Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)

75035: Merged WAT2 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud)
      71719: Changed the Raise event test to a POST from a GET


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@75363 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Will Abson
2014-07-01 15:10:45 +00:00
parent b35bec9108
commit 91ca9dbe23
4 changed files with 27 additions and 16 deletions

View File

@@ -1581,7 +1581,7 @@
</property> </property>
</bean> </bean>
<bean id="webscript.org.alfresco.repository.events.raiseevent.get" class="org.alfresco.repo.web.scripts.events.RaiseBrowserEventGet" <bean id="webscript.org.alfresco.repository.events.raiseevent.post" class="org.alfresco.repo.web.scripts.events.RaiseBrowserEventPost"
parent="webscript"> parent="webscript">
<property name="siteService" ref="SiteService" /> <property name="siteService" ref="SiteService" />
<property name="eventPublisher" ref="eventPublisher" /> <property name="eventPublisher" ref="eventPublisher" />

View File

@@ -41,7 +41,7 @@ import org.springframework.util.StringUtils;
* @author Gethin James * @author Gethin James
* @since 5.0 * @since 5.0
*/ */
public class RaiseBrowserEventGet extends AbstractWebScript public class RaiseBrowserEventPost extends AbstractWebScript
{ {
private EventPublisher eventPublisher; private EventPublisher eventPublisher;
private SiteService siteService; private SiteService siteService;
@@ -79,14 +79,23 @@ public class RaiseBrowserEventGet extends AbstractWebScript
action = templateVars.get("action"); action = templateVars.get("action");
} }
String attributes = req.getParameter("attributes"); String attributes = req.getContent().getContent();
if (attributes != null) if (attributes != null)
{
if (StringUtils.hasText(attributes))
{ {
if (!validJsonMap(attributes)) if (!validJsonMap(attributes))
{ {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON Object: " + attributes); throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON Object: " + attributes);
} }
} }
else
{
//No valid attributes passed in so reset it
attributes = null;
}
}
if (StringUtils.hasText(component) && StringUtils.hasText(action)) if (StringUtils.hasText(component) && StringUtils.hasText(action))
{ {

View File

@@ -35,16 +35,17 @@ import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.util.PropertyMap; import org.alfresco.util.PropertyMap;
import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
/** /**
* Tests the {@link RaiseBrowserEventGet} endpoint * Tests the {@link RaiseBrowserEventPost} endpoint
*/ */
public class RaiseEventTest extends BaseWebScriptTest public class RaiseEventTest extends BaseWebScriptTest
{ {
private static final String USER_ONE = "RaiseEventTestuser1"; private static final String USER_ONE = "RaiseEventTestuser1";
private static final String SITE_EVENTS_TEST = "RaiseEventTestSite"; private static final String SITE_EVENTS_TEST = "Site_Raise_Event_Test";
private static final String GET_URL = "/api/events/"; private static final String POST_URL = "/api/events/";
private EventPublisherForTestingOnly eventPublisher; private EventPublisherForTestingOnly eventPublisher;
private AuthenticationComponent authenticationComponent; private AuthenticationComponent authenticationComponent;
@@ -70,7 +71,7 @@ public class RaiseEventTest extends BaseWebScriptTest
SiteInfo siteInfo = this.siteService.getSite(SITE_EVENTS_TEST); SiteInfo siteInfo = this.siteService.getSite(SITE_EVENTS_TEST);
if (siteInfo == null) if (siteInfo == null)
{ {
this.siteService.createSite("RaiseEventSitePreset", SITE_EVENTS_TEST, SITE_EVENTS_TEST+" Title", "SiteDescription", SiteVisibility.PRIVATE); this.siteService.createSite("RaiseEventSitePreset", SITE_EVENTS_TEST, SITE_EVENTS_TEST+" Title", "SiteDescription", SiteVisibility.PUBLIC);
} }
createUser(USER_ONE, SiteModel.SITE_COLLABORATOR); createUser(USER_ONE, SiteModel.SITE_COLLABORATOR);
@@ -96,18 +97,19 @@ public class RaiseEventTest extends BaseWebScriptTest
} }
/** /**
* Tests GET requests to create browser events. * Tests POST requests to create browser events.
* *
* @throws Exception * @throws Exception
*/ */
public void testRaiseEvent() throws Exception public void testRaiseEvent() throws Exception
{ {
sendRequest(new GetRequest(GET_URL+"mypage/edit"), Status.STATUS_OK); sendRequest(new PostRequest(POST_URL+"mypage/edit", "", "application/json"), Status.STATUS_OK);
sendRequest(new GetRequest(GET_URL), Status.STATUS_NOT_FOUND); sendRequest(new PostRequest(POST_URL, "", "application/json"), Status.STATUS_NOT_FOUND);
sendRequest(new GetRequest(GET_URL+"mypage"), Status.STATUS_NOT_FOUND); sendRequest(new PostRequest(POST_URL+"mypage", "", "application/json"), Status.STATUS_NOT_FOUND);
sendRequest(new GetRequest(GET_URL+SITE_EVENTS_TEST+"/sitepage/view"), Status.STATUS_OK); sendRequest(new GetRequest(POST_URL+SITE_EVENTS_TEST+"/sitepage/view"), Status.STATUS_METHOD_NOT_ALLOWED);
sendRequest(new GetRequest(GET_URL+SITE_EVENTS_TEST+"/sitepage/view?attributes=xyz"), Status.STATUS_BAD_REQUEST); sendRequest(new PostRequest(POST_URL+SITE_EVENTS_TEST+"/sitepage/view", "", "application/json"), Status.STATUS_OK);
sendRequest(new GetRequest(GET_URL+SITE_EVENTS_TEST+"/specialpage/view?attributes={\"source\": \"bob\", \"target\": \"hope\"}"), Status.STATUS_OK); sendRequest(new PostRequest(POST_URL+SITE_EVENTS_TEST+"/sitepage/view", "rubbish", "application/json"), Status.STATUS_BAD_REQUEST);
sendRequest(new PostRequest(POST_URL+SITE_EVENTS_TEST+"/specialpage/view", "{\"source\": \"bob\", \"target\": \"hope\"}", "application/json"), Status.STATUS_OK);
List<BrowserEvent> browserEvents = eventPublisher.getQueueByType(BrowserEvent.class); List<BrowserEvent> browserEvents = eventPublisher.getQueueByType(BrowserEvent.class);
int found = 0; int found = 0;