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());