Sites collection added to person rest API, check point of tagging rest API

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10025 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2008-07-25 12:21:03 +00:00
parent 6b736cfa12
commit 5f6cb30310
17 changed files with 317 additions and 2 deletions

View File

@@ -332,4 +332,51 @@ public class SiteServiceTest extends BaseWebScriptTest
getRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO, 404);
}
public void testGetPersonSites() throws Exception
{
// Create a site
String shortName = GUID.generate();
createSite("myPreset", shortName, "myTitle", "myDescription", true, 200);
String shortName2 = GUID.generate();
createSite("myPreset", shortName2, "myTitle", "myDescription", true, 200);
MockHttpServletResponse response = getRequest("/api/people/" + USER_TWO + "/sites", 200);
JSONArray result = new JSONArray(response.getContentAsString());
assertNotNull(result);
assertEquals(0, result.length());
// Add some memeberships
JSONObject membership = new JSONObject();
membership.put("role", SiteModel.SITE_CONSUMER);
JSONObject person = new JSONObject();
person.put("userName", USER_TWO);
membership.put("person", person);
postRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, 200, membership.toString(), "application/json");
membership = new JSONObject();
membership.put("role", SiteModel.SITE_CONSUMER);
person = new JSONObject();
person.put("userName", USER_TWO);
membership.put("person", person);
postRequest(URL_SITES + "/" + shortName2 + URL_MEMBERSHIPS, 200, membership.toString(), "application/json");
response = getRequest("/api/people/" + USER_TWO + "/sites", 200);
result = new JSONArray(response.getContentAsString());
assertNotNull(result);
assertEquals(2, result.length());
response = getRequest("/api/people/" + USER_ONE + "/sites", 200);
result = new JSONArray(response.getContentAsString());
assertNotNull(result);
assertEquals(2, result.length());
response = getRequest("/api/people/" + USER_THREE + "/sites", 200);
result = new JSONArray(response.getContentAsString());
assertNotNull(result);
assertEquals(0, result.length());
}
}

View File

@@ -25,12 +25,20 @@
package org.alfresco.repo.web.scripts.tagging;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.model.Repository;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.tagging.TaggingService;
import org.alfresco.util.GUID;
import org.alfresco.util.PropertyMap;
import org.json.JSONArray;
import org.springframework.mock.web.MockHttpServletResponse;
/**
* Unit test to test tagging Web Script API
@@ -43,9 +51,20 @@ public class TaggingServiceTest extends BaseWebScriptTest
private AuthenticationComponent authenticationComponent;
private PersonService personService;
private TaggingService taggingService;
private FileFolderService fileFolderService;
private Repository repositoryHelper;
private NodeService nodeService;
private static final String TEST_USER = "TaggingServiceTestUser";
private static final String TAG_1 = "tagOneREST";
private static final String TAG_2 = "tagTwoREST";
private static final String TAG_3 = "tagThreeREST";
private static final String TAG_4 = "tagFourREST";
private static final String TAG_5 = "tagFiveREST";
private NodeRef nodeOne;
private NodeRef nodeTwo;
@Override
protected void setUp() throws Exception
@@ -55,7 +74,28 @@ public class TaggingServiceTest extends BaseWebScriptTest
this.authenticationService = (AuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
this.taggingService = (TaggingService)getServer().getApplicationContext().getBean("TaggingService");
this.taggingService = (TaggingService)getServer().getApplicationContext().getBean("TaggingService");
this.fileFolderService = (FileFolderService)getServer().getApplicationContext().getBean("FileFolderService");
this.repositoryHelper = (Repository)getServer().getApplicationContext().getBean("repositoryHelper");
this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
// Add a load of tags ready to use
this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_1);
this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_2);
this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_3);
this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_4);
this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_5);
// Create test node's
NodeRef testRoot = this.repositoryHelper.getCompanyHome();
String guid = GUID.generate();
this.nodeOne = this.fileFolderService.create(testRoot, "test_doc1" + guid + ".txt", ContentModel.TYPE_CONTENT).getNodeRef();
this.nodeTwo = this.fileFolderService.create(testRoot, "test_dco2" + guid + ".txt", ContentModel.TYPE_CONTENT).getNodeRef();
// Add tags to test nodes
this.taggingService.addTag(nodeOne, TAG_1);
this.taggingService.addTag(nodeOne, TAG_2);
this.taggingService.addTag(nodeTwo, TAG_2);
// Create users
createUser(TEST_USER);
@@ -85,10 +125,62 @@ public class TaggingServiceTest extends BaseWebScriptTest
protected void tearDown() throws Exception
{
super.tearDown();
this.authenticationComponent.setCurrentUser("admin");
this.taggingService.deleteTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_1);
this.taggingService.deleteTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_2);
this.taggingService.deleteTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_3);
this.taggingService.deleteTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_4);
this.taggingService.deleteTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_5);
this.nodeService.deleteNode(this.nodeOne);
this.nodeService.deleteNode(this.nodeTwo);
}
public void testGetTags()
throws Exception
{
MockHttpServletResponse response = getRequest("/api/tags/" + StoreRef.PROTOCOL_WORKSPACE + "/SpacesStore", 200);
JSONArray jsonArray = new JSONArray(response.getContentAsString());
assertNotNull(jsonArray);
assertEquals(5, jsonArray.length());
response = getRequest("/api/tags/" + StoreRef.PROTOCOL_WORKSPACE + "/SpacesStore?tf=one", 200);
jsonArray = new JSONArray(response.getContentAsString());
assertNotNull(jsonArray);
assertEquals(1, jsonArray.length());
response = getRequest("/api/tags/" + StoreRef.PROTOCOL_WORKSPACE + "/SpacesStore?tf=none", 200);
jsonArray = new JSONArray(response.getContentAsString());
assertNotNull(jsonArray);
assertEquals(0, jsonArray.length());
}
public void testGetNodes()
throws Exception
{
MockHttpServletResponse response = getRequest("/api/tags/" + StoreRef.PROTOCOL_WORKSPACE + "/SpacesStore/" + TAG_1 + "/nodes", 200);
JSONArray jsonArray = new JSONArray(response.getContentAsString());
assertNotNull(jsonArray);
assertEquals(1, jsonArray.length());
System.out.println(response.getContentAsString());
response = getRequest("/api/tags/" + StoreRef.PROTOCOL_WORKSPACE + "/SpacesStore/" + TAG_2 + "/nodes", 200);
jsonArray = new JSONArray(response.getContentAsString());
assertNotNull(jsonArray);
assertEquals(2, jsonArray.length());
response = getRequest("/api/tags/" + StoreRef.PROTOCOL_WORKSPACE + "/SpacesStore/jumk/nodes", 200);
jsonArray = new JSONArray(response.getContentAsString());
assertNotNull(jsonArray);
assertEquals(0, jsonArray.length());
}