mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||||
{
|
{
|
||||||
"qnamePath": "${item.qnamePath}",
|
"qnamePath": "${item.qnamePath}",
|
||||||
"url": "blog/node/${item.nodeRef?replace('://', '/')}",
|
"detailsUrl": "blog/node/${item.nodeRef?replace('://', '/')}",
|
||||||
"blogPostsUrl": "blog/node/${item.nodeRef?replace('://', '/')}/posts",
|
"blogPostsUrl": "blog/node/${item.nodeRef?replace('://', '/')}/posts",
|
||||||
"type": "${item.properties["blg:blogImplementation"]!''}",
|
"type": "${item.properties["blg:blogImplementation"]!''}",
|
||||||
"id": "${item.properties["blg:id"]!'0'}",
|
"id": "${item.properties["blg:id"]!'0'}",
|
||||||
|
@@ -50,8 +50,6 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
|||||||
/**
|
/**
|
||||||
* Unit Test to test Blog Web Script API
|
* Unit Test to test Blog Web Script API
|
||||||
*
|
*
|
||||||
* TODO Add unit tests for the Blog Integration part
|
|
||||||
*
|
|
||||||
* @author mruflin
|
* @author mruflin
|
||||||
*/
|
*/
|
||||||
public class BlogServiceTest extends BaseWebScriptTest
|
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 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_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 +
|
private static final String URL_MY_DRAFT_BLOG_POSTS = "/api/blog/site/" + SITE_SHORT_NAME_BLOG +
|
||||||
"/" + COMPONENT_BLOG + "/posts/mydrafts";
|
"/" + COMPONENT_BLOG + "/posts/mydrafts";
|
||||||
private static final String URL_MY_PUBLISHED_BLOG_POSTS = "/api/blog/site/" + SITE_SHORT_NAME_BLOG +
|
private static final String URL_MY_PUBLISHED_BLOG_POSTS = "/api/blog/site/" + SITE_SHORT_NAME_BLOG +
|
||||||
@@ -713,6 +712,62 @@ public class BlogServiceTest extends BaseWebScriptTest
|
|||||||
assertEquals("new content", commentTwoUpdated.getString("content"));
|
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.
|
* Does some stress tests.
|
||||||
*
|
*
|
||||||
|
@@ -64,9 +64,10 @@ public class BlogGet extends AbstractBlogWebScript
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build the response
|
// Build the response
|
||||||
|
// (For now, we just supply the noderef, but when we have a
|
||||||
|
// proper blog details object we'll use that)
|
||||||
Map<String, Object> model = new HashMap<String, Object>();
|
Map<String, Object> model = new HashMap<String, Object>();
|
||||||
model.put(POST, blog);
|
model.put(ITEM, containerNodeRef);
|
||||||
model.put(ITEM, blog.getNodeRef());
|
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user