From be98c20ae4db727e2f52e43d90548d01727d6aca Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 12 Oct 2011 19:29:48 +0000 Subject: [PATCH] Fix the blog integration get json, and add unit tests for that part of the blog REST api git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31192 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/repository/blogs/blog.lib.ftl | 4 +- .../web/scripts/blogs/BlogServiceTest.java | 61 ++++++++++++++++++- .../repo/web/scripts/blogs/blog/BlogGet.java | 5 +- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/blog.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/blog.lib.ftl index 5596a3a10c..510b6240ee 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/blog.lib.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/blog.lib.ftl @@ -5,7 +5,7 @@ <#escape x as jsonUtils.encodeJSONString(x)> { "qnamePath": "${item.qnamePath}", - "url": "blog/node/${item.nodeRef?replace('://', '/')}", + "detailsUrl": "blog/node/${item.nodeRef?replace('://', '/')}", "blogPostsUrl": "blog/node/${item.nodeRef?replace('://', '/')}/posts", "type": "${item.properties["blg:blogImplementation"]!''}", "id": "${item.properties["blg:id"]!'0'}", @@ -22,4 +22,4 @@ } } - \ No newline at end of file + diff --git a/source/java/org/alfresco/repo/web/scripts/blogs/BlogServiceTest.java b/source/java/org/alfresco/repo/web/scripts/blogs/BlogServiceTest.java index 62b143dd0b..155dda151a 100644 --- a/source/java/org/alfresco/repo/web/scripts/blogs/BlogServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/blogs/BlogServiceTest.java @@ -50,8 +50,6 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response; /** * Unit Test to test Blog Web Script API * - * TODO Add unit tests for the Blog Integration part - * * @author mruflin */ public class BlogServiceTest extends BaseWebScriptTest @@ -70,7 +68,8 @@ public class BlogServiceTest extends BaseWebScriptTest private static final String COMPONENT_BLOG = "blog"; private static final String URL_BLOG_POST = "/api/blog/post/site/" + SITE_SHORT_NAME_BLOG + "/" + COMPONENT_BLOG + "/"; - private static final String URL_BLOG_POSTS = "/api/blog/site/" + SITE_SHORT_NAME_BLOG + "/" + COMPONENT_BLOG + "/posts"; + private static final String URL_BLOG_CORE = "/api/blog/site/" + SITE_SHORT_NAME_BLOG + "/" + COMPONENT_BLOG; + private static final String URL_BLOG_POSTS = URL_BLOG_CORE + "/posts"; private static final String URL_MY_DRAFT_BLOG_POSTS = "/api/blog/site/" + SITE_SHORT_NAME_BLOG + "/" + COMPONENT_BLOG + "/posts/mydrafts"; private static final String URL_MY_PUBLISHED_BLOG_POSTS = "/api/blog/site/" + SITE_SHORT_NAME_BLOG + @@ -712,6 +711,62 @@ public class BlogServiceTest extends BaseWebScriptTest assertEquals("new title", commentTwoUpdated.getString("title")); assertEquals("new content", commentTwoUpdated.getString("content")); } + + /** + * You can attach information to the blog container relating + * to integration with external blogs. + * This tests that feature + */ + public void testBlogIntegration() throws Exception + { + // Try to fetch the details on a new site + Response response = sendRequest(new GetRequest(URL_BLOG_CORE), 200); + String json = response.getContentAsString(); + JSONObject result = new JSONObject(json); + + assertEquals("No item in:\n"+json, true, result.has("item")); + JSONObject item = result.getJSONObject("item"); + + assertEquals("Missing key in: " + item, true, item.has("qnamePath")); + assertEquals("Missing key in: " + item, true, item.has("detailsUrl")); + assertEquals("Missing key in: " + item, true, item.has("blogPostsUrl")); + + // Blog properties are empty to start + assertEquals("", item.getString("type")); + assertEquals("", item.getString("name")); + assertEquals("", item.getString("description")); + assertEquals("", item.getString("url")); + assertEquals("", item.getString("username")); + assertEquals("", item.getString("password")); + + + // Have it updated + JSONObject blog = new JSONObject(); + blog.put("blogType", "wordpress"); + blog.put("blogName", "A Blog!"); + blog.put("username", "guest"); + sendRequest(new PutRequest(URL_BLOG_CORE, blog.toString(), "application/json"), Status.STATUS_OK); + + // Check again now + response = sendRequest(new GetRequest(URL_BLOG_CORE), 200); + json = response.getContentAsString(); + result = new JSONObject(json); + + assertEquals("No item in:\n"+json, true, result.has("item")); + item = result.getJSONObject("item"); + + assertEquals("Missing key in: " + item, true, item.has("qnamePath")); + assertEquals("Missing key in: " + item, true, item.has("detailsUrl")); + assertEquals("Missing key in: " + item, true, item.has("blogPostsUrl")); + + // Blog properties should now be set + assertEquals("wordpress", item.getString("type")); + assertEquals("A Blog!", item.getString("name")); + assertEquals("", item.getString("description")); + assertEquals("", item.getString("url")); + assertEquals("guest", item.getString("username")); + assertEquals("", item.getString("password")); + } /** * Does some stress tests. diff --git a/source/java/org/alfresco/repo/web/scripts/blogs/blog/BlogGet.java b/source/java/org/alfresco/repo/web/scripts/blogs/blog/BlogGet.java index 6858a97ad5..8dfc0c9afd 100644 --- a/source/java/org/alfresco/repo/web/scripts/blogs/blog/BlogGet.java +++ b/source/java/org/alfresco/repo/web/scripts/blogs/blog/BlogGet.java @@ -64,9 +64,10 @@ public class BlogGet extends AbstractBlogWebScript } // Build the response + // (For now, we just supply the noderef, but when we have a + // proper blog details object we'll use that) Map model = new HashMap(); - model.put(POST, blog); - model.put(ITEM, blog.getNodeRef()); + model.put(ITEM, containerNodeRef); return model; }