public void singlePUT() throws Exception {
Structure st=StructureCache.getStructureByVelocityVarName("webPageContent");
Host demo=APILocator.getHostAPI().findByName("demo.dotcms.com", APILocator.getUserAPI().getSystemUser(), false);
User sysuser=APILocator.getUserAPI().getSystemUser();
String demoId=demo.getIdentifier();
ClientResponse response=
contRes.path("/publish/1").type(MediaType.APPLICATION_JSON_TYPE)
.header(authheader, authvalue).put(ClientResponse.class,
new JSONObject()
.put("stInode", st.getInode())
.put("languageId", 1)
.put("title", "Test content from ContentResourceTest")
.put("body", "this is an example text")
.put("contentHost", demoId).toString());
Assert.assertEquals(200, response.getStatus());
Assert.assertTrue(response.getLocation().toString().contains("/api/content/inode/"));
String location=response.getLocation().toString();
String inode=location.substring(location.lastIndexOf("/")+1);
Contentlet cont=APILocator.getContentletAPI().find(inode, sysuser, false);
Assert.assertNotNull(cont);
Assert.assertTrue(InodeUtils.isSet(cont.getIdentifier()));
Assert.assertEquals(demoId, cont.getHost());
Assert.assertEquals(st.getInode(), cont.getStructureInode());
Assert.assertEquals(1,cont.getLanguageId());
Assert.assertEquals("Test content from ContentResourceTest",cont.getStringProperty("title"));
Assert.assertEquals("this is an example text",cont.getStringProperty("body"));
Assert.assertTrue(cont.isLive());
// testing other host_or_folder formats: folderId
Folder folder=APILocator.getFolderAPI().findFolderByPath("/home", demo, sysuser, false);
response=contRes.path("/publish/1").type(MediaType.APPLICATION_JSON_TYPE)
.header(authheader, authvalue).put(ClientResponse.class,
new JSONObject()
.put("stInode", st.getInode())
.put("languageId", 1)
.put("title", "test content with folderid")
.put("body", "this is an example text")
.put("contentHost", folder.getInode()).toString());
location=response.getLocation().toString();
inode=location.substring(location.lastIndexOf("/")+1);
cont=APILocator.getContentletAPI().find(inode, sysuser, false);
Assert.assertEquals(folder.getInode(), cont.getFolder());
Assert.assertTrue(cont.isLive());
// testing other host_or_folder formats: hostname
response=contRes.path("/publish/1").type(MediaType.APPLICATION_JSON_TYPE)
.header(authheader, authvalue).put(ClientResponse.class,
new JSONObject()
.put("stInode", st.getInode())
.put("languageId", 1)
.put("title", "Test content from ContentResourceTest folderId")
.put("body", "this is an example text")
.put("contentHost", "demo.dotcms.com").toString());
location=response.getLocation().toString();
inode=location.substring(location.lastIndexOf("/")+1);
cont=APILocator.getContentletAPI().find(inode, sysuser, false);
Assert.assertEquals(demoId, cont.getHost());
Assert.assertTrue(cont.isLive());
// testing other host_or_folder formats: hostname:path
response=contRes.path("/justsave/1").type(MediaType.APPLICATION_JSON_TYPE)
.header(authheader, authvalue).put(ClientResponse.class,
new JSONObject()
.put("stInode", st.getInode())
.put("languageId", 1)
.put("title", "Test content from ContentResourceTest folderId")
.put("body", "this is an example text")
.put("contentHost", "demo.dotcms.com:/home").toString());
location=response.getLocation().toString();
inode=location.substring(location.lastIndexOf("/")+1);
cont=APILocator.getContentletAPI().find(inode, sysuser, false);
Assert.assertEquals(folder.getInode(), cont.getFolder());
Assert.assertFalse(cont.isLive());
// testing XML
response=contRes.path("/publish/1").type(MediaType.APPLICATION_XML_TYPE)
.header(authheader, authvalue).put(ClientResponse.class,
"<content>" +
"<stInode>" +st.getInode() + "</stInode>"+
"<languageId>1</languageId>"+
"<title>Test content from ContentResourceTest XML</title>"+
"<body>this is an example text XML</body>"+
"<contentHost>"+demoId+"</contentHost>"+
"</content>");
Assert.assertEquals(200, response.getStatus());
Assert.assertTrue(response.getLocation().toString().contains("/api/content/inode/"));
location=response.getLocation().toString();
inode=location.substring(location.lastIndexOf("/")+1);
cont=APILocator.getContentletAPI().find(inode, sysuser, false);
Assert.assertNotNull(cont);
Assert.assertTrue(InodeUtils.isSet(cont.getIdentifier()));
Assert.assertEquals(demoId, cont.getHost());
Assert.assertEquals(st.getInode(), cont.getStructureInode());
Assert.assertEquals(1,cont.getLanguageId());
Assert.assertEquals("Test content from ContentResourceTest XML",cont.getStringProperty("title"));
Assert.assertEquals("this is an example text XML",cont.getStringProperty("body"));
Assert.assertTrue(cont.isLive());
// testing form-urlencoded
String title="Test content from ContentResourceTest FORM "+UUIDGenerator.generateUuid();
String body="this is an example text FORM "+UUIDGenerator.generateUuid();
response=contRes.path("/publish/1").type(MediaType.APPLICATION_FORM_URLENCODED_TYPE)
.header(authheader, authvalue).put(ClientResponse.class,
"stInode=" +st.getInode() + "&"+
"languageId=1&"+
"title="+URLEncoder.encode(title, "UTF-8")+"&"+
"body="+URLEncoder.encode(body, "UTF-8")+"&"+
"contentHost="+demoId);
Assert.assertEquals(200, response.getStatus());
Assert.assertTrue(response.getLocation().toString().contains("/api/content/inode/"));
location=response.getLocation().toString();
inode=location.substring(location.lastIndexOf("/")+1);
Assert.assertEquals(inode, response.getHeaders().getFirst("inode")); // validate consistency of inode header
cont=APILocator.getContentletAPI().find(inode, sysuser, false);
Assert.assertNotNull(cont);
Assert.assertTrue(InodeUtils.isSet(cont.getIdentifier()));
Assert.assertEquals(cont.getIdentifier(), response.getHeaders().getFirst("identifier")); // consistency of identifier header
Assert.assertEquals(demoId, cont.getHost());
Assert.assertEquals(st.getInode(), cont.getStructureInode());
Assert.assertEquals(1,cont.getLanguageId());
Assert.assertEquals(title,cont.getStringProperty("title"));
Assert.assertEquals(body,cont.getStringProperty("body"));