}
@SuppressWarnings("unchecked")
@Test
public void onlyPortalAdminOrContentAdminCanSetPublishStatus() {
ContentAPI contentAPI = new ContentAPI();
contentAPI.addNewTag("testtag", helper.loginAsDeveloper());
contentAPI.setContent("content html", "testtag", true,
helper.loginAsPortalAdmin());
APIResponse response = contentAPI.getAllValidPublishedContents();
Map<String, String> all = (Map<String, String>) response.object;
assertTrue(all.containsKey("testtag"));
//set publish to false
contentAPI.setPublishStatus("testtag", false,
helper.loginAsPortalAdmin());
response = contentAPI.getAllValidPublishedContents();
all = (Map<String, String>) response.object;
assertTrue(! all.containsKey("testtag"));
//add a user as content admin
AdminAPI adminAPI = new AdminAPI();
adminAPI.addUser("contentadmin@test.com", helper.loginAsPortalAdmin());
contentAPI.assignUserAsContentAdmin("contentadmin@test.com",
"testtag", helper.loginAsPortalAdmin());
//publish to true
contentAPI.setPublishStatus("testtag", true,
helper.loginAs("contentadmin@test.com"));
response = contentAPI.getAllValidPublishedContents();
all = (Map<String, String>) response.object;
assertTrue(all.containsKey("testtag"));
//portaluser or portalreadonly should throw exception
response = contentAPI.setPublishStatus("testtag", false,
helper.loginAsPortalReadOnly());
assertTrue(response.statusCode == Status.ERROR_INSUFFICIENT_PERMISSION);
response = contentAPI.setPublishStatus("testtag", false,
helper.loginAsPortalUser());
assertTrue(response.statusCode == Status.ERROR_INSUFFICIENT_PERMISSION);
}