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

57027: Merged V4.2-BUG-FIX (4.2.1) to HEAD-BUG-FIX (Cloud/4.3)
      56494: Merged HEAD-BUG-FIX to V4.2-BUG-FIX (4.2.1)
         55500: <<NOT IN 4.1.6>> Merged V4.1-BUG-FIX (4.1.7) to HEAD-BUG-FIX (4.2)
            55434: Merged DEV to V4.1-BUG-FIX (4.1.7)
               54939 : MNT-9413 : NullPointerException thrown when a wiki page with a null title is renamed using Share
                  - Using wiki page name, if page title isn't provided
                  - Unit test was added


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@61660 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2014-02-11 18:41:12 +00:00
parent d51b5639d0
commit 207072be45
2 changed files with 107 additions and 41 deletions

View File

@@ -78,7 +78,7 @@ public class WikiPageMovePost extends AbstractWikiWebScript
// Have the page re-named, if possible // Have the page re-named, if possible
String oldTitle = page.getTitle(); String oldTitle = page.getTitle().length() == 0 ? pageTitle : page.getTitle();
try try
{ {
page.setTitle(newTitle); page.setTitle(newTitle);

View File

@@ -273,46 +273,62 @@ public class WikiRestApiTest extends BaseWebScriptTest
private JSONObject createOrUpdatePage(String title, String contents, String version, int expectedStatus) private JSONObject createOrUpdatePage(String title, String contents, String version, int expectedStatus)
throws Exception throws Exception
{ {
String name = title.replace(' ', '_'); return createOrUpdatePage(null, title, contents, version, expectedStatus);
}
JSONObject json = new JSONObject();
json.put("site", SITE_SHORT_NAME_WIKI); /**
json.put("title", title); * Creates a single wiki page based on the supplied details
json.put("pagecontent", contents); */
json.put("tags", ""); private JSONObject createOrUpdatePage(String pageName, String title, String contents, String version, int expectedStatus) throws Exception
json.put("page", "wiki-page"); // TODO Is this really needed? {
String name = null;
if (version == null || "force".equals(version)) if (pageName == null)
{ {
// Allow the save as-is, no versioning check name = title.replace(' ', '_');
json.put("forceSave", "true"); // Allow the save as-is }
} else
else {
{ name = pageName;
if ("none".equals(version)) }
{
// No versioning JSONObject json = new JSONObject();
} json.put("site", SITE_SHORT_NAME_WIKI);
else json.put("title", title);
{ json.put("pagecontent", contents);
json.put("currentVersion", version); json.put("tags", "");
} json.put("page", "wiki-page"); // TODO Is this really needed?
}
if (version == null || "force".equals(version))
Response response = sendRequest(new PutRequest(URL_WIKI_UPDATE + name, json.toString(), "application/json"), expectedStatus); {
if (expectedStatus == Status.STATUS_OK) // Allow the save as-is, no versioning check
{ json.put("forceSave", "true"); // Allow the save as-is
JSONObject result = new JSONObject(response.getContentAsString()); }
if (result.has("page")) else
{ {
return result.getJSONObject("page"); if ("none".equals(version))
} {
return result; // No versioning
} }
else else
{ {
return null; json.put("currentVersion", version);
} }
}
Response response = sendRequest(new PutRequest(URL_WIKI_UPDATE + name, json.toString(), "application/json"), expectedStatus);
if (expectedStatus == Status.STATUS_OK)
{
JSONObject result = new JSONObject(response.getContentAsString());
if (result.has("page"))
{
return result.getJSONObject("page");
}
return result;
}
else
{
return null;
}
} }
/** /**
@@ -549,6 +565,56 @@ public class WikiRestApiTest extends BaseWebScriptTest
assertEquals(PAGE_TITLE_ONE, page.getString("title")); assertEquals(PAGE_TITLE_ONE, page.getString("title"));
} }
public void testRenamePageWithEmptyTitle() throws Exception
{
JSONObject page;
String name = System.currentTimeMillis()+"";
String name2 = System.currentTimeMillis()+1+"";
// Create a page
page = createOrUpdatePage(name, name, null, Status.STATUS_OK);
assertEquals("Incorrect JSON: " + page.toString(), true, page.has("title"));
// Fetch it and check
page = getPage(name, Status.STATUS_OK);
assertEquals(name, page.getString("name"));
assertEquals(name, page.getString("title"));
//update title
SiteInfo site = siteService.getSite(SITE_SHORT_NAME_WIKI);
WikiPageInfo pageInfo = wikiService.getWikiPage(site.getShortName(), name);
NodeRef pageRef = pageInfo.getNodeRef();
nodeService.setProperty(pageRef, ContentModel.PROP_TITLE, "");
// Fetch it and check
page = getPage(name, Status.STATUS_OK);
JSONArray versions = page.getJSONArray("versionhistory");
int maxVersionIndex = versions.length()-1;
double vNum = Double.parseDouble(versions.getJSONObject(maxVersionIndex).getString("version"));
String newTitle =versions.getJSONObject(maxVersionIndex).getString("title");
for (int i = versions.length()-2; i>=0; i--)
{
JSONObject version = versions.getJSONObject(i);
String ver = version.getString("version");
if (Double.parseDouble(ver)>vNum)
{
maxVersionIndex = i;
vNum = Double.parseDouble(ver);
newTitle =versions.getJSONObject(maxVersionIndex).getString("title");
}
}
assertEquals(name, page.getString("name"));
assertEquals("", newTitle);
renamePage(name, name2, Status.STATUS_OK);
// Fetch it at the new address
page = getPage(name2, Status.STATUS_OK);
assertEquals(name2, page.getString("name"));
assertEquals(name2, page.getString("title"));
}
public void testVersioning() throws Exception public void testVersioning() throws Exception
{ {
WikiPageInfo wikiInfo; WikiPageInfo wikiInfo;