mirror of
https://github.com/Alfresco/SearchServices.git
synced 2026-09-16 18:12:56 +00:00
Merge branch 'master' into searchbcr
src/main/java/org/alfresco/rest/search/RestResultSetContextModel.java
This commit is contained in:
@@ -14,6 +14,7 @@ import org.alfresco.utility.data.DataLink;
|
||||
import org.alfresco.utility.data.DataSite;
|
||||
import org.alfresco.utility.data.DataUser;
|
||||
import org.alfresco.utility.data.DataWorkflow;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.network.ServerHealth;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -63,11 +64,14 @@ public abstract class RestTest extends AbstractTestNGSpringContextTests
|
||||
@Autowired
|
||||
protected WorkflowService workflow;
|
||||
|
||||
protected SiteModel testSite;
|
||||
|
||||
@BeforeSuite(alwaysRun = true)
|
||||
public void checkServerHealth() throws Exception
|
||||
{
|
||||
super.springTestContextPrepareTestInstance();
|
||||
serverHealth.assertServerIsOnline();
|
||||
testSite = dataSite.createPublicRandomSite();
|
||||
}
|
||||
|
||||
@BeforeMethod(alwaysRun=true)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.alfresco.rest.aos;
|
||||
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.rest.core.RestRequest;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class AosApiTest extends RestTest
|
||||
{
|
||||
/*
|
||||
* @author: Catalin Gornea
|
||||
*
|
||||
* simple test for demo purposes on how to use Aos with Rest
|
||||
*/
|
||||
@Test(enabled=false)
|
||||
public void assertResponsIsSuccesufulWhenGetRootDirectory() throws Exception
|
||||
{
|
||||
restClient.authenticateUser(dataUser.getAdminUser()).withAosAPI();
|
||||
RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "");
|
||||
restClient.process(request);
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.alfresco.rest.cmis;
|
||||
|
||||
import org.alfresco.dataprep.CMISUtil.DocumentType;
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.rest.core.RestResponse;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class CmisBrowserTest extends RestTest
|
||||
{
|
||||
/*
|
||||
* @author: Paul Brodner
|
||||
* simple test for demo purposes on how to use CMIS browser binding with Rest
|
||||
*/
|
||||
@Test(enabled=false)
|
||||
public void assertContentDispositionHeaderOnCmisFile() throws Exception
|
||||
{
|
||||
FileModel document = dataContent.usingUser(dataUser.getAdminUser())
|
||||
.usingSite(testSite).createContent(DocumentType.HTML);
|
||||
|
||||
RestResponse response = restClient.authenticateUser(dataUser.getAdminUser()).withCMISApi().getRootObjectByID(document);
|
||||
response.assertThat().header("Content-Disposition", String.format("attachment; filename=%s", document.getName()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -154,9 +154,9 @@ public class AddCommentsFullTests extends RestTest
|
||||
restClient.processModel(RestCommentModel.class, request);
|
||||
|
||||
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
|
||||
restClient.assertLastError().getErrorKey().contains("Unrecognized field \"content2\"");
|
||||
restClient.assertLastError().containsSummary("Unrecognized field \"content2\"");
|
||||
restClient.assertLastError().getDescriptionURL().contains("https://api-explorer.alfresco.com");
|
||||
restClient.assertLastError().getStackTrace().contains("For security reasons the stack trace is no longer displayed, but the property is kept for previous versions");
|
||||
restClient.assertLastError().containsErrorKey(String.format(RestErrorModel.UNRECOGNIZED_FIELD, "content2"));
|
||||
restClient.assertLastError().containsSummary(String.format(RestErrorModel.UNRECOGNIZED_FIELD, "content2"));
|
||||
restClient.assertLastError().descriptionURLIs(RestErrorModel.RESTAPIEXPLORER);
|
||||
restClient.assertLastError().stackTraceIs(RestErrorModel.STACKTRACE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,9 +207,9 @@ public class GetCommentsFullTests extends RestTest
|
||||
|
||||
restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).usingParams("maxItems=0").getNodeComments();
|
||||
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS);
|
||||
restClient.assertLastError().getErrorKey().contains("Only positive values supported for maxItems.");
|
||||
restClient.assertLastError().containsSummary("Only positive values supported for maxItems.");
|
||||
restClient.assertLastError().getDescriptionURL().contains("https://api-explorer.alfresco.com");
|
||||
restClient.assertLastError().getStackTrace().contains("For security reasons the stack trace is no longer displayed, but the property is kept for previous versions");
|
||||
restClient.assertLastError().containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS);
|
||||
restClient.assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS);
|
||||
restClient.assertLastError().descriptionURLIs(RestErrorModel.RESTAPIEXPLORER);
|
||||
restClient.assertLastError().stackTraceIs(RestErrorModel.STACKTRACE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.alfresco.rest.nodes;
|
||||
|
||||
import org.alfresco.dataprep.CMISUtil.DocumentType;
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
import org.alfresco.utility.model.FileType;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.alfresco.utility.report.Bug;
|
||||
import org.alfresco.utility.testrail.ExecutionType;
|
||||
import org.alfresco.utility.testrail.annotation.TestRail;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
/**
|
||||
*
|
||||
* @author mpopa
|
||||
*
|
||||
*/
|
||||
public class NodesContentTests extends RestTest
|
||||
{
|
||||
private UserModel user1, user2;
|
||||
private SiteModel site1, site2;
|
||||
private FileModel file1;
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void dataPreparation() throws Exception
|
||||
{
|
||||
user1 = dataUser.createRandomTestUser();
|
||||
user2 = dataUser.createRandomTestUser();
|
||||
site1 = dataSite.usingUser(user1).createPublicRandomSite();
|
||||
site2 = dataSite.usingUser(user2).createPublicRandomSite();
|
||||
file1 = dataContent.usingUser(user1).usingSite(site1).createContent(DocumentType.TEXT_PLAIN);
|
||||
}
|
||||
|
||||
@TestRail(section = { TestGroup.REST_API,TestGroup.NODES }, executionType = ExecutionType.SANITY,
|
||||
description = "Verify file name in Content-Disposition header")
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY})
|
||||
public void checkFileNameWithRegularCharsInHeader() throws Exception
|
||||
{
|
||||
restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("attachment=false").getNodeContent();
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
restClient.assertHeaderValueContains("Content-Disposition", String.format("filename=\"%s\"", file1.getName()));
|
||||
}
|
||||
|
||||
@Bug(id="REPO-2112")
|
||||
@TestRail(section = { TestGroup.REST_API,TestGroup.NODES }, executionType = ExecutionType.REGRESSION,
|
||||
description = "Verify file name with special chars is escaped in Content-Disposition header")
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.CORE})
|
||||
public void checkFileNameWithSpecialCharsInHeader() throws Exception
|
||||
{
|
||||
char c1 = 127;
|
||||
char c2 = 31;
|
||||
char c3 = 256;
|
||||
FileModel file = dataContent.usingUser(user2).usingSite(site2).createContent(new FileModel("\ntest\"" + c1 + c2 + c3, FileType.TEXT_PLAIN));
|
||||
restClient.authenticateUser(user2).withCoreAPI().usingNode(file).usingParams("attachment=false").getNodeContent();
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
restClient.assertHeaderValueContains("Content-Disposition","filename=\" test .txt\"");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package org.alfresco.rest.renditions;
|
||||
|
||||
import org.alfresco.dataprep.CMISUtil.DocumentType;
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.rest.exception.JsonToModelConversionException;
|
||||
import org.alfresco.rest.model.RestNodeModel;
|
||||
import org.alfresco.utility.Utility;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
import org.alfresco.utility.model.FolderModel;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.alfresco.utility.report.Bug;
|
||||
import org.alfresco.utility.testrail.ExecutionType;
|
||||
import org.alfresco.utility.testrail.annotation.TestRail;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Handles tests related to POST api-explorer/#!/renditions
|
||||
* @author Cristina Axinte
|
||||
*
|
||||
*/
|
||||
public class CreateRenditionTests extends RestTest
|
||||
{
|
||||
private UserModel adminUser, user;
|
||||
private SiteModel site;
|
||||
private FileModel document;
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void dataPreparation() throws Exception
|
||||
{
|
||||
adminUser = dataUser.getAdminUser();
|
||||
user = dataUser.createRandomTestUser();
|
||||
site = dataSite.usingUser(user).createPublicRandomSite();
|
||||
}
|
||||
|
||||
@BeforeMethod(alwaysRun = true)
|
||||
public void createDocument() throws Exception
|
||||
{
|
||||
document = dataContent.usingUser(user).usingSite(site).createContent(DocumentType.TEXT_PLAIN);
|
||||
}
|
||||
|
||||
@Bug(id = "REPO-2042", description = "Should fail only on MAC OS System and Linux" )
|
||||
@TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY,
|
||||
description = "Verify admin user creates rendition with Rest API and status code is 202")
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY })
|
||||
public void adminCanCreateRenditionToExistingNode() throws JsonToModelConversionException, Exception
|
||||
{
|
||||
restClient.authenticateUser(adminUser).withCoreAPI().usingNode(document).createNodeRendition("pdf");
|
||||
restClient.assertStatusCodeIs(HttpStatus.ACCEPTED);
|
||||
|
||||
restClient.withCoreAPI().usingNode(document).getNodeRendition("pdf")
|
||||
.assertThat().field("status").is("CREATED");
|
||||
}
|
||||
|
||||
@Bug(id = "REPO-2042", description = "Should fail only on MAC OS System and Linux" )
|
||||
@TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY,
|
||||
description = "Verify user that created the document can also creates 'pdf' rendition for it with Rest API and status code is 202")
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY })
|
||||
public void userThatCreatedFileCanCreatePdfRenditionForIt() throws JsonToModelConversionException, Exception
|
||||
{
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(document).createNodeRendition("pdf");
|
||||
restClient.assertStatusCodeIs(HttpStatus.ACCEPTED);
|
||||
|
||||
restClient.withCoreAPI().usingNode(document).getNodeRendition("pdf")
|
||||
.assertThat().field("status").is("CREATED");
|
||||
}
|
||||
|
||||
@Bug(id = "REPO-2042", description = "Should fail only on MAC OS System and Linux" )
|
||||
@TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY,
|
||||
description = "Verify user that created the document can also creates 'doclib' rendition for it with Rest API and status code is 202")
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY })
|
||||
public void userThatCreatedFileCanCreateDoclibRenditionForIt() throws JsonToModelConversionException, Exception
|
||||
{
|
||||
FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||
restClient.authenticateUser(user)
|
||||
.configureRequestSpec()
|
||||
.addMultiPart("filedata", Utility.getResourceTestDataFile("my-file.tif"));
|
||||
|
||||
RestNodeModel fileNode = restClient.authenticateUser(user).withCoreAPI().usingResource(folder).createNode();
|
||||
restClient.assertStatusCodeIs(HttpStatus.CREATED);
|
||||
document = new FileModel("my-file.tif");
|
||||
document.setCmisLocation(folder.getCmisLocation() + "/my-file.tif");
|
||||
document.setNodeRef(fileNode.getId());
|
||||
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(document).createNodeRendition("doclib");
|
||||
restClient.assertStatusCodeIs(HttpStatus.ACCEPTED);
|
||||
|
||||
restClient.withCoreAPI().usingNode(document).getNodeRendition("doclib")
|
||||
.assertThat().field("status").is("CREATED");
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import org.testng.annotations.BeforeClass;
|
||||
* <ul>
|
||||
* <li>Preparing the data to index.
|
||||
* <li>Preparing search requests.
|
||||
*
|
||||
* @author Michael Suzuki
|
||||
*
|
||||
*/
|
||||
@@ -61,17 +62,15 @@ public class AbstractSearchTest extends RestTest
|
||||
*/
|
||||
nodesBuilder = restClient.authenticateUser(userModel).withCoreAPI().usingNode(ContentModel.my()).defineNodes();
|
||||
FolderModel folder = new FolderModel(SEARCH_DATA_SAMPLE_FOLDER);
|
||||
dataContent.usingSite(siteModel).createFolder(folder);
|
||||
dataContent.usingUser(userModel).usingSite(siteModel).createFolder(folder);
|
||||
//Create files
|
||||
file = new FileModel("pangram.txt", FileType.TEXT_PLAIN, "The quick brown fox jumps over the lazy dog");
|
||||
file2 = new FileModel("cars.txt", FileType.TEXT_PLAIN, "The landrover discovery is not a sports car");
|
||||
ContentModel cm = new ContentModel();
|
||||
cm.setCmisLocation(folder.getCmisLocation());
|
||||
cm.setName(folder.getName());
|
||||
dataContent.usingSite(siteModel).usingResource(cm).createContent(file);
|
||||
dataContent.usingSite(siteModel).usingResource(cm).createContent(file2);
|
||||
|
||||
Utility.waitToLoopTime(60);
|
||||
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(cm).createContent(file);
|
||||
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(cm).createContent(file2);
|
||||
}
|
||||
/**
|
||||
* Helper method which create an http post request to Search API end point.
|
||||
|
||||
@@ -18,8 +18,13 @@
|
||||
*/
|
||||
package org.alfresco.rest.search;
|
||||
|
||||
import org.alfresco.utility.model.ContentModel;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
import org.alfresco.utility.model.FileType;
|
||||
import org.alfresco.utility.model.FolderModel;
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
@@ -29,28 +34,123 @@ import org.testng.annotations.Test;
|
||||
*/
|
||||
public class FingerPrintTest extends AbstractSearchTest
|
||||
{
|
||||
// Disabled until solr4 resolution @Test(groups={TestGroup.SEARCH, TestGroup.REST_API})
|
||||
private FileModel file1,file2,file3,file4;
|
||||
@BeforeClass
|
||||
public void indexSimilarFile() throws Exception
|
||||
{
|
||||
adminUserModel = dataUser.getAdminUser();
|
||||
userModel = dataUser.createRandomTestUser();
|
||||
siteModel = dataSite.usingUser(userModel).createPublicRandomSite();
|
||||
/*
|
||||
* Create the following file structure for preconditions :
|
||||
* |- folder
|
||||
* |-- fox.txt
|
||||
*/
|
||||
nodesBuilder = restClient.authenticateUser(userModel).withCoreAPI().usingNode(ContentModel.my()).defineNodes();
|
||||
FolderModel folder = new FolderModel(SEARCH_DATA_SAMPLE_FOLDER);
|
||||
dataContent.usingUser(userModel).usingSite(siteModel).createFolder(folder);
|
||||
file1 = new FileModel("pangram-banana.txt", FileType.TEXT_PLAIN, "The quick brown fox jumps over the lazy banana");
|
||||
file2 = new FileModel("pangram-taco.txt", FileType.TEXT_PLAIN, "The quick brown fox jumps over the lazy dog that ate the taco");
|
||||
file3 = new FileModel("pangram-cat.txt", FileType.TEXT_PLAIN, "The quick brown fox jumps over the lazy cat");
|
||||
file4 = new FileModel("dog.txt", FileType.TEXT_PLAIN, "The quick brown fox ate the lazy dog");
|
||||
ContentModel cm = new ContentModel();
|
||||
cm.setCmisLocation(folder.getCmisLocation());
|
||||
cm.setName(folder.getName());
|
||||
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(cm).createContent(file1);
|
||||
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(cm).createContent(file2);
|
||||
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(cm).createContent(file3);
|
||||
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(cm).createContent(file4);
|
||||
Thread.sleep(35000);//Allow indexing to complete.
|
||||
}
|
||||
/**
|
||||
* Search similar document based on document finger print.
|
||||
* The data prep should have loaded a file
|
||||
* identical to the one loaded as part of this test.
|
||||
* The data prep should have loaded 2 files which one is similar
|
||||
* to the files loaded as part of this test.
|
||||
* Note that for fingerprint to work it need a 5 word sequence.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test(groups= {TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1})
|
||||
public void search() throws Exception
|
||||
{
|
||||
String uuid = file.getNodeRefWithoutVersion();
|
||||
String uuid = file1.getNodeRefWithoutVersion();
|
||||
Assert.assertNotNull(uuid);
|
||||
SearchResponse response = query(uuid);
|
||||
int count = response.getEntries().size();
|
||||
String fingerprint = String.format("FINGERPRINT:%s", uuid);
|
||||
Thread.sleep(25000);//Allow indexing to complete.
|
||||
response = query(fingerprint);
|
||||
count = response.getEntries().size();
|
||||
SearchResponse response = query(fingerprint);
|
||||
int count = response.getEntries().size();
|
||||
Assert.assertTrue(count > 1);
|
||||
for(SearchNodeModel m :response.getEntries())
|
||||
{
|
||||
m.getModel().assertThat().field("name").contains("pangram.txt");
|
||||
String match = m.getModel().getName();
|
||||
switch (match)
|
||||
{
|
||||
case "pangram.txt":
|
||||
break;
|
||||
case "pangram-banana.txt":
|
||||
break;
|
||||
case "pangram-taco.txt":
|
||||
break;
|
||||
case "pangram-cat.txt":
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Not a match to an expected file: " + m.getModel().getName());
|
||||
}
|
||||
m.getModel().assertThat().field("name").isNot("dog.txt");
|
||||
m.getModel().assertThat().field("name").isNot("cars.txt");
|
||||
}
|
||||
}
|
||||
@Test(groups= {TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1})
|
||||
public void searchSimilar() throws Exception
|
||||
{
|
||||
String uuid = file2.getNodeRefWithoutVersion();
|
||||
Assert.assertNotNull(uuid);
|
||||
// In the response eneity there is a score of each doc, change below threshold to bring more like or less.
|
||||
String fingerprint = String.format("FINGERPRINT:%s_68", uuid);
|
||||
SearchResponse response = query(fingerprint);
|
||||
int count = response.getEntries().size();
|
||||
Assert.assertTrue(count > 1);
|
||||
for(SearchNodeModel m :response.getEntries())
|
||||
{
|
||||
switch (m.getModel().getName())
|
||||
{
|
||||
case "pangram.txt":
|
||||
break;
|
||||
case "pangram-taco.txt":
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Not a match to an expected file: " + m.getModel().getName());
|
||||
}
|
||||
m.getModel().assertThat().field("name").isNot("pangram-banana.txt");
|
||||
m.getModel().assertThat().field("name").isNot("pangram-cat.txt");
|
||||
m.getModel().assertThat().field("name").isNot("dog.txt");
|
||||
m.getModel().assertThat().field("name").isNot("cars.txt");
|
||||
}
|
||||
}
|
||||
@Test(groups= {TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1})
|
||||
public void searchSimilar67Percent() throws Exception
|
||||
{
|
||||
String uuid = file2.getNodeRefWithoutVersion();
|
||||
Assert.assertNotNull(uuid);
|
||||
String fingerprint = String.format("FINGERPRINT:%s_68", uuid);
|
||||
SearchResponse response = query(fingerprint);
|
||||
int count = response.getEntries().size();
|
||||
Assert.assertTrue(count > 1);
|
||||
for(SearchNodeModel m :response.getEntries())
|
||||
{
|
||||
switch (m.getModel().getName())
|
||||
{
|
||||
case "pangram.txt":
|
||||
break;
|
||||
case "pangram-taco.txt":
|
||||
break;
|
||||
case "pangram-cat.txt":
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Not a match to an expected file: " + m.getModel().getName());
|
||||
}
|
||||
m.getModel().assertThat().field("name").isNot("pangram-banana.txt");
|
||||
m.getModel().assertThat().field("name").isNot("dog.txt");
|
||||
m.getModel().assertThat().field("name").isNot("cars.txt");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.rest.search;
|
||||
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests the search functionality using an ancestor path.
|
||||
* Using the category as an example, it is a node that is located
|
||||
* in root/rootCategory/classifiable. We now provide the ability to search by path
|
||||
* so that we can return all the child elements of our target path.
|
||||
* A search on root/rootCategory/classifiable should return Regions, Languages
|
||||
* as they are the child elements of the given path.
|
||||
*
|
||||
* @author Michael Suzuki
|
||||
*
|
||||
*/
|
||||
public class SearchAPATHTest extends AbstractSearchTest
|
||||
{
|
||||
|
||||
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ASS_1})
|
||||
/**
|
||||
* {
|
||||
* "query": {
|
||||
* "query": "name:*"
|
||||
* },
|
||||
* "facetFields": {
|
||||
* "facets": [
|
||||
* {"field": "APATH", "prefix": "0" }
|
||||
* ]
|
||||
* }
|
||||
* }
|
||||
* Expected result
|
||||
* entries[],
|
||||
* "pagination": {
|
||||
* "maxItems": 100,
|
||||
* "hasMoreItems": true,
|
||||
* "totalItems": 914,
|
||||
* "count": 100,
|
||||
* "skipCount": 0
|
||||
* },
|
||||
* "context": {
|
||||
* "facetsFields": [{
|
||||
* "buckets": [
|
||||
* {
|
||||
* "count": 913,
|
||||
* "label": "0/5c09534f-3ca2-4272-bc25-064a7c1762b4"
|
||||
* },
|
||||
* {
|
||||
* "count": 2,
|
||||
* "label": "0/"
|
||||
* }
|
||||
* ],
|
||||
* "label": "APATH"
|
||||
* }],
|
||||
* "consistency": {"lastTxId": 89}
|
||||
* }
|
||||
*}}
|
||||
*
|
||||
*/
|
||||
public void searchLevel0() throws Exception
|
||||
{
|
||||
SearchRequest searchQuery = new SearchRequest();
|
||||
RestRequestQueryModel queryReq = new RestRequestQueryModel();
|
||||
queryReq.setQuery("name:*");
|
||||
searchQuery.setQuery(queryReq);
|
||||
|
||||
RestRequestFacetFieldsModel facetFields = new RestRequestFacetFieldsModel();
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
list.add(new FacetFieldQuery("APATH","0"));
|
||||
facetFields.setFacets(list);
|
||||
searchQuery.setFacetFields(facetFields);
|
||||
SearchResponse response = query(searchQuery);
|
||||
RestResultBucketsModel fresponse = response.getContext().getFacetFields().get(0);
|
||||
fresponse.assertThat().field("buckets").isNotEmpty();
|
||||
Assert.assertEquals(2,fresponse.getBuckets().size());
|
||||
fresponse.getBuckets().get(0).assertThat().field("label").contains("0/");
|
||||
fresponse.getBuckets().get(1).assertThat().field("label").is("0/");
|
||||
}
|
||||
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ASS_1})
|
||||
public void searchLevel0andIncludeSubLevel1() throws Exception
|
||||
{
|
||||
SearchRequest searchQuery = new SearchRequest();
|
||||
RestRequestQueryModel queryReq = new RestRequestQueryModel();
|
||||
queryReq.setQuery("name:*");
|
||||
searchQuery.setQuery(queryReq);
|
||||
|
||||
RestRequestFacetFieldsModel facetFields = new RestRequestFacetFieldsModel();
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
list.add(new FacetFieldQuery("APATH","1"));
|
||||
facetFields.setFacets(list);
|
||||
searchQuery.setFacetFields(facetFields);
|
||||
SearchResponse response = query(searchQuery);
|
||||
RestResultBucketsModel fresponse = response.getContext().getFacetFields().get(0);
|
||||
Assert.assertEquals(4,fresponse.getBuckets().size());
|
||||
fresponse.getBuckets().get(0).assertThat().field("label").contains("1/");
|
||||
}
|
||||
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ASS_1})
|
||||
public void searchLevel2() throws Exception
|
||||
{
|
||||
SearchRequest searchQuery = new SearchRequest();
|
||||
RestRequestQueryModel queryReq = new RestRequestQueryModel();
|
||||
queryReq.setQuery("name:*");
|
||||
searchQuery.setQuery(queryReq);
|
||||
|
||||
RestRequestFacetFieldsModel facetFields = new RestRequestFacetFieldsModel();
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
list.add(new FacetFieldQuery("APATH","1/"));
|
||||
facetFields.setFacets(list);
|
||||
searchQuery.setFacetFields(facetFields);
|
||||
|
||||
SearchResponse response = query(searchQuery);
|
||||
RestResultBucketsModel fresponse = response.getContext().getFacetFields().get(0);
|
||||
String path = fresponse.getBuckets().get(0).getLabel().replace("1/", "2/");
|
||||
list.remove(0);
|
||||
list.add(new FacetFieldQuery("APATH", path));
|
||||
|
||||
facetFields.setFacets(list);
|
||||
searchQuery.setFacetFields(facetFields);
|
||||
response = query(searchQuery);
|
||||
fresponse = response.getContext().getFacetFields().get(0);
|
||||
Assert.assertEquals(fresponse.getBuckets().size(),3);
|
||||
fresponse.getBuckets().get(0).assertThat().field("label").contains("2/");
|
||||
fresponse.getBuckets().get(0).assertThat().field("label").contains(path);
|
||||
/**
|
||||
* To return the contents of the path and its sub directory change the prefix
|
||||
* Below 2/path/path -> will return whats in path/path only
|
||||
* if 3/path/path -> will return contents from path/path/path
|
||||
* @throws Exception
|
||||
*/
|
||||
searchQuery = new SearchRequest();
|
||||
queryReq = new RestRequestQueryModel();
|
||||
queryReq.setQuery("name:*");
|
||||
searchQuery.setQuery(queryReq);
|
||||
facetFields = new RestRequestFacetFieldsModel();
|
||||
list.remove(0);
|
||||
list.add(new FacetFieldQuery("APATH",path.replace("2/", "3/")));
|
||||
facetFields.setFacets(list);
|
||||
searchQuery.setFacetFields(facetFields);
|
||||
response = query(searchQuery);
|
||||
fresponse = response.getContext().getFacetFields().get(0);
|
||||
System.out.println(response);
|
||||
Assert.assertTrue(fresponse.getBuckets().size() > 5);
|
||||
fresponse.getBuckets().get(0).assertThat().field("label").contains("3/");
|
||||
}
|
||||
}
|
||||
@@ -20,32 +20,100 @@ package org.alfresco.rest.search;
|
||||
|
||||
import org.alfresco.rest.model.RestRequestSpellcheckModel;
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.junit.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Search end point Public API test with spell checking enabled.
|
||||
* @author Michael Suzuki
|
||||
*
|
||||
*5
|
||||
*/
|
||||
public class SearchSpellCheckTest extends AbstractSearchTest
|
||||
{
|
||||
// @Test(groups={TestGroup.SEARCH, TestGroup.REST_API})
|
||||
/**
|
||||
* Perform the below query
|
||||
* {
|
||||
* "spellcheck" : { },
|
||||
* "query" : {
|
||||
* "userQuery" : "alfrezco",
|
||||
* "query" : "cm:title:alfrezco"
|
||||
* }
|
||||
* to yeild the following result.
|
||||
* {
|
||||
* "list": {
|
||||
* "pagination": {
|
||||
* "count": 22,
|
||||
* "hasMoreItems": false,
|
||||
* "totalItems": 22,
|
||||
* "skipCount": 0,
|
||||
* "maxItems": 100
|
||||
* },
|
||||
* "context": {
|
||||
* "spellCheck": {
|
||||
* "type": "searchInsteadFor",
|
||||
* "suggestions": [
|
||||
* "alfresco"
|
||||
* ]
|
||||
* }
|
||||
* },
|
||||
* "entries": [...]
|
||||
* }
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API})
|
||||
public void searchMissSpelled() throws Exception
|
||||
{
|
||||
|
||||
SearchResponse nodes = query("carz");
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
nodes.assertThat().entriesListIsEmpty();
|
||||
|
||||
SearchRequest searchReq = new SearchRequest();
|
||||
RestRequestQueryModel queryReq = new RestRequestQueryModel();
|
||||
queryReq.setQuery("cm:content:carz");
|
||||
queryReq.setUserQuery("carz");
|
||||
queryReq.setQuery("cm:title:alfrezco");
|
||||
queryReq.setUserQuery("alfrezco");
|
||||
searchReq.setQuery(queryReq);
|
||||
searchReq.setSpellcheck(new RestRequestSpellcheckModel());
|
||||
nodes = query(searchReq);
|
||||
assertResponse(query(searchReq));
|
||||
}
|
||||
private void assertResponse(SearchResponse nodes) throws Exception
|
||||
{
|
||||
nodes.assertThat().entriesListIsNotEmpty();
|
||||
nodes.getContext().assertThat().field("spellCheck").isNotEmpty();
|
||||
nodes.getContext().getSpellCheck().assertThat().field("suggestions").contains("alfresco");
|
||||
}
|
||||
@Test
|
||||
/**
|
||||
* Perform alternative way by setting the value in spellcheck object.
|
||||
*
|
||||
* {
|
||||
* "query": {
|
||||
* "query": "cm:title:alfrezco",
|
||||
* "language": "afts"
|
||||
* },
|
||||
* "spellcheck": {"query": "alfrezco"}
|
||||
* }
|
||||
* @throws Exception
|
||||
*/
|
||||
public void searchMissSpelledVersion2() throws Exception
|
||||
{
|
||||
SearchRequest searchReq = new SearchRequest();
|
||||
RestRequestQueryModel queryReq = new RestRequestQueryModel();
|
||||
queryReq.setQuery("cm:title:alfrezco");
|
||||
searchReq.setQuery(queryReq);
|
||||
|
||||
RestRequestSpellcheckModel spellCheck = new RestRequestSpellcheckModel();
|
||||
spellCheck.setQuery("alfrezco");
|
||||
searchReq.setSpellcheck(spellCheck);
|
||||
assertResponse(query(searchReq));
|
||||
}
|
||||
@Test
|
||||
public void searchWithSpellcheckerAndCorrectSpelling() throws Exception
|
||||
{
|
||||
SearchRequest searchReq = new SearchRequest();
|
||||
RestRequestQueryModel queryReq = new RestRequestQueryModel();
|
||||
queryReq.setQuery("cm:title:alfresco");
|
||||
queryReq.setUserQuery("alfresco");
|
||||
searchReq.setQuery(queryReq);
|
||||
searchReq.setSpellcheck(new RestRequestSpellcheckModel());
|
||||
SearchResponse res = query(searchReq);
|
||||
Assert.assertNull(res.getContext());
|
||||
res.assertThat().entriesListIsNotEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ package org.alfresco.rest.search;
|
||||
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class DeleteDeploymentSanityTests extends RestTest
|
||||
deployment = allDeployments.getDeploymentByName("customWorkflowExtentionForRest.bpmn");
|
||||
|
||||
RestProcessDefinitionModel processDefinitionAssociated =
|
||||
restClient.withWorkflowAPI().getAllProcessDefinitions().getProcessDefinitionByDeploymentId(deployment.getId());
|
||||
restClient.withWorkflowAPI().getAllProcessDefinitions().getProcessDefinitionById(deployment.getId());
|
||||
|
||||
RestProcessModel addedProcess =
|
||||
restClient.withWorkflowAPI().addProcess(processDefinitionAssociated.getName(), adminUser, false, CMISUtil.Priority.Normal);
|
||||
|
||||
+9
-7
@@ -33,8 +33,9 @@ public class GetProcessDefinitionImageCoreTests extends RestTest
|
||||
public void getProcessDefinitionImageUsingInvalidProcessDefinitionId() throws Exception
|
||||
{
|
||||
restClient.authenticateUser(adminUser);
|
||||
randomProcessDefinition = restClient.withWorkflowAPI().getAllProcessDefinitions().getOneRandomEntry();
|
||||
randomProcessDefinition.onModel().setId("invalidID");
|
||||
randomProcessDefinition = restClient.withWorkflowAPI().getAllProcessDefinitions().getOneRandomEntry().onModel();
|
||||
randomProcessDefinition.setId("invalidID");
|
||||
|
||||
restClient.withWorkflowAPI()
|
||||
.usingProcessDefinitions(randomProcessDefinition).getProcessDefinitionImage();
|
||||
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND)
|
||||
@@ -47,23 +48,24 @@ public class GetProcessDefinitionImageCoreTests extends RestTest
|
||||
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION },
|
||||
executionType = ExecutionType.REGRESSION,
|
||||
description = "Verify network admin is able to get a process definition image using REST API and status code is OK (200)")
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.CORE, TestGroup.NETWORKS })
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.CORE, TestGroup.NETWORKS})
|
||||
@Bug(id = "MNT-17243")
|
||||
public void networkAdminGetProcessDefinitionImage() throws Exception
|
||||
{
|
||||
adminTenantUser = UserModel.getAdminTenantUser();
|
||||
restClient.authenticateUser(adminUser)
|
||||
.usingTenant().createTenant(adminTenantUser);
|
||||
randomProcessDefinition = restClient.authenticateUser(adminTenantUser).withWorkflowAPI().getAllProcessDefinitions().getOneRandomEntry();
|
||||
|
||||
randomProcessDefinition = restClient.authenticateUser(adminTenantUser).withWorkflowAPI().getAllProcessDefinitions().getOneRandomEntry().onModel();
|
||||
restClient.withWorkflowAPI().usingProcessDefinitions(randomProcessDefinition).getProcessDefinitionImage()
|
||||
.assertResponseContainsImage();
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION },
|
||||
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESS_DEFINITION },
|
||||
executionType = ExecutionType.REGRESSION,
|
||||
description = "Verify network user is able to get a process definition image using REST API and status code is OK (200)")
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.CORE, TestGroup.NETWORKS })
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.CORE, TestGroup.NETWORKS})
|
||||
@Bug(id = "MNT-17243")
|
||||
public void networkUserGetProcessDefinitionImage() throws Exception
|
||||
{
|
||||
@@ -72,7 +74,7 @@ public class GetProcessDefinitionImageCoreTests extends RestTest
|
||||
.usingTenant().createTenant(adminTenantUser);
|
||||
UserModel tenantUser = dataUser.usingUser(adminTenantUser).createUserWithTenant("uTenant");
|
||||
randomProcessDefinition = restClient.authenticateUser(adminTenantUser).withWorkflowAPI()
|
||||
.getAllProcessDefinitions().getOneRandomEntry();
|
||||
.getAllProcessDefinitions().getOneRandomEntry().onModel();
|
||||
restClient.authenticateUser(tenantUser).withWorkflowAPI()
|
||||
.usingProcessDefinitions(randomProcessDefinition).getProcessDefinitionImage()
|
||||
.assertResponseContainsImage();
|
||||
|
||||
+4
-4
@@ -34,8 +34,8 @@ public class GetProcessDefinitionImageFullTests extends RestTest
|
||||
public void getProcessDefinitionImageUsingEmptyProcessDefinitionId() throws Exception
|
||||
{
|
||||
restClient.authenticateUser(adminUser);
|
||||
randomProcessDefinition = restClient.withWorkflowAPI().getAllProcessDefinitions().getOneRandomEntry();
|
||||
randomProcessDefinition.onModel().setId("");
|
||||
randomProcessDefinition = restClient.withWorkflowAPI().getAllProcessDefinitions().getOneRandomEntry().onModel();
|
||||
randomProcessDefinition.setId("");
|
||||
restClient.withWorkflowAPI()
|
||||
.usingProcessDefinitions(randomProcessDefinition).getProcessDefinitionImage();
|
||||
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
|
||||
@@ -53,10 +53,10 @@ public class GetProcessDefinitionImageFullTests extends RestTest
|
||||
restClient.usingTenant().createTenant(adminTenantUser2);
|
||||
|
||||
RestProcessDefinitionModel randomProcessDefinition = restClient.authenticateUser(adminTenantUser1).withWorkflowAPI()
|
||||
.getAllProcessDefinitions().getOneRandomEntry();
|
||||
.getAllProcessDefinitions().getOneRandomEntry().onModel();
|
||||
restClient.authenticateUser(adminTenantUser2).withWorkflowAPI()
|
||||
.usingProcessDefinitions(randomProcessDefinition).getProcessDefinitionImage();
|
||||
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND)
|
||||
.assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, randomProcessDefinition.onModel().getId()));
|
||||
.assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, randomProcessDefinition.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ public class GetProcessDefinitionImageSanityTests extends RestTest
|
||||
{
|
||||
testUser = dataUser.createRandomTestUser();
|
||||
restClient.authenticateUser(dataUser.getAdminUser());
|
||||
randomProcessDefinition = restClient.withWorkflowAPI().getAllProcessDefinitions().getOneRandomEntry();
|
||||
randomProcessDefinition = restClient.withWorkflowAPI().getAllProcessDefinitions().getOneRandomEntry().onModel();
|
||||
}
|
||||
|
||||
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, executionType = ExecutionType.SANITY,
|
||||
|
||||
@@ -43,7 +43,7 @@ public class DeleteProcessFullTests extends RestTest
|
||||
restClient.withWorkflowAPI().usingProcess(process).deleteProcess();
|
||||
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError()
|
||||
.containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY)
|
||||
.containsSummary(String.format("%s: %s ", "The entity with id" , process.getId(), RestErrorModel.ENTITY_NOT_FOUND))
|
||||
.containsSummary(String.format(RestErrorModel.ENTITY_WAS_NOT_FOUND, process.getId()))
|
||||
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
|
||||
.stackTraceIs(RestErrorModel.STACKTRACE);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.testng.annotations.Test;
|
||||
|
||||
public class GetTaskItemsSanityTests extends RestTest
|
||||
{
|
||||
private UserModel userModel, userWhoStartsTask, assignee, adminTenantUser, tenantUser, tenantUserAssignee;
|
||||
private UserModel userModel, userWhoStartsTask, assignee;
|
||||
private SiteModel siteModel;
|
||||
private FileModel fileModel, document1;
|
||||
private TaskModel taskModel;
|
||||
|
||||
+1
-3
@@ -27,9 +27,7 @@ public class UpdateTaskVariableSanityTests extends RestTest
|
||||
private SiteModel siteModel;
|
||||
private FileModel fileModel;
|
||||
private UserModel assigneeUser;
|
||||
private TaskModel taskModel, tenantTask;
|
||||
|
||||
private UserModel adminTenantUser, tenantUser, tenantUserAssignee;
|
||||
private TaskModel taskModel;
|
||||
|
||||
private RestVariableModel taskVariable;
|
||||
private RestVariableModel variableModel;
|
||||
|
||||
Reference in New Issue
Block a user