Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)

101325: Merge RA-SPRINT2 to HEAD-BUG-FIX (5.1)
      100313: RA-62: moved AdvancedSearchTest to share-services project.
      Have also marked it @Ignore, since:
      - it doesn't pass when I run this manually on HEAD-BUG-FIX
      - it isn't included in a TestSuite there so doesn't get run on bamboo anyway
      - the test would get run in share-services, as we don't require suites there for a test to get run


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@101467 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tatyana Valkevych
2015-04-08 16:18:46 +00:00
parent b45f81630a
commit 1b72cf11d5

View File

@@ -1,145 +0,0 @@
package org.alfresco.repo.web.scripts.search;
import java.io.IOException;
import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
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.search.SearchService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.transaction.TransactionService;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
public class AdvancedSearchTest extends BaseWebScriptTest
{
private static final String TEST_FILE_NAME1 = "qwe iop.txt";
private static final String TEST_FILE_NAME2 = "qwe yu iop.txt";
private static final String TEST_IN_SITES_FILE_NAME = "qwesiteiop";
private static final String SEARCH_NAME = "qwe iop";
private static final String SEARCH_IN_SITES = "qwesiteiop";
private static final String TEST_FOLDER = "test_folder-" + System.currentTimeMillis();
private TransactionService transactionService;
private NodeService nodeService;
private FileFolderService fileFolderService;
private SearchService searchService;
private NamespaceService namespaceService;
private AuthenticationComponent authenticationComponent;
private NodeRef testNodeRef1;
private NodeRef testNodeRef2;
private NodeRef folderNodeRef;
private NodeRef rootNodeRef;
@Override
protected void setUp() throws Exception
{
super.setUp();
this.transactionService = (TransactionService) getServer().getApplicationContext().getBean("TransactionService");
this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
this.fileFolderService = (FileFolderService)getServer().getApplicationContext().getBean("FileFolderService");
this.authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean("authenticationComponent");
this.searchService = (SearchService) getServer().getApplicationContext().getBean("SearchService");
this.namespaceService = (NamespaceService) getServer().getApplicationContext().getBean("namespaceService");
this.authenticationComponent.setSystemUserAsCurrentUser();
this.rootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
List<NodeRef> results = searchService.selectNodes(this.rootNodeRef, "/app:company_home", null, namespaceService, false);
if (results.size() == 0)
{
throw new AlfrescoRuntimeException("Can't find /app:company_home");
}
NodeRef companyHomeNodeRef = results.get(0);
folderNodeRef = fileFolderService.create(companyHomeNodeRef, TEST_FOLDER, ContentModel.TYPE_FOLDER).getNodeRef();
testNodeRef1 = fileFolderService.create(folderNodeRef, TEST_FILE_NAME1, ContentModel.TYPE_CONTENT).getNodeRef();
testNodeRef2 = fileFolderService.create(folderNodeRef, TEST_FILE_NAME2, ContentModel.TYPE_CONTENT).getNodeRef();
assertNotNull(testNodeRef1);
assertNotNull(testNodeRef2);
}
private void deleteNodeIfExists(NodeRef nodeRef)
{
if (nodeService.exists(nodeRef))
{
nodeService.deleteNode(nodeRef);
}
}
@Override
protected void tearDown() throws Exception
{
super.tearDown();
RetryingTransactionCallback<Void> deleteCallback = new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
deleteNodeIfExists(testNodeRef1);
deleteNodeIfExists(testNodeRef2);
deleteNodeIfExists(folderNodeRef);
return null;
}
};
this.transactionService.getRetryingTransactionHelper().doInTransaction(deleteCallback);
this.authenticationComponent.clearCurrentSecurityContext();
}
public void testSearchFile() throws IOException, JSONException
{
//Name search without quotes
String url = "/slingshot/search?site=&term=&tag=&maxResults=251&sort=&query={\"prop_cm_name\":\"" + SEARCH_NAME + "\",\"datatype\":\"cm:content\"}&repo=true&rootNode=alfresco://company/home";
Response res = sendRequest(new GetRequest(url), Status.STATUS_OK);
JSONObject result = new JSONObject(res.getContentAsString());
assertEquals(2, result.getInt("totalRecords"));
url = "/slingshot/search?site=&term=&tag=&maxResults=251&sort=&query={\"prop_cm_name\":\"\\\"" + SEARCH_NAME + "\\\"\",\"datatype\":\"cm:content\"}&repo=true&rootNode=alfresco://company/home";
res = sendRequest(new GetRequest(url), Status.STATUS_OK);
result = new JSONObject(res.getContentAsString());
assertEquals(1, result.getInt("totalRecords"));
}
public void testSearchInSites() throws IOException, JSONException
{
List<NodeRef> results = searchService.selectNodes(this.rootNodeRef, "/app:company_home/st:sites", null, namespaceService, false);
if (results.size() == 0)
{
throw new AlfrescoRuntimeException("Can't find /app:company_home/st:sites");
}
NodeRef sitesNodeRef = results.get(0);
long time = System.currentTimeMillis();
NodeRef sitefolderNodeRef = fileFolderService.create(sitesNodeRef, TEST_FOLDER, ContentModel.TYPE_FOLDER).getNodeRef();
NodeRef nodeRef = fileFolderService.create(sitefolderNodeRef, TEST_IN_SITES_FILE_NAME + time, ContentModel.TYPE_CONTENT).getNodeRef();
// String url = "/slingshot/search?site=&term=" + SEARCH_NAME + "&tag=&maxResults=251&sort=&query=&repo=false&rootNode=alfresco%3A%2F%2Fcompany%2Fhome&pageSize=50&startIndex=0";
String url = "/slingshot/search?site=&term=&tag=&maxResults=251&sort=&query={\"prop_cm_name\":\"" + SEARCH_IN_SITES + time + "\",\"datatype\":\"cm:content\"}&repo=true&rootNode=alfresco://company/home";
Response res = sendRequest(new GetRequest(url), Status.STATUS_OK);
JSONObject result = new JSONObject(res.getContentAsString());
assertEquals(1, result.getInt("totalRecords"));
deleteNodeIfExists(nodeRef);
deleteNodeIfExists(sitefolderNodeRef);
}
}