-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ACS-6125: test support for path queries against categories #2602
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
62feae6
ACS-3832: test support for parent queries against categories
Pawel-608 4aac97c
test support for path queries against categories
Pawel-608 47034d8
Update tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsear…
Pawel-608 2e1b938
Update tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsear…
Pawel-608 c565ea2
Merge branch 'master' into feature/category-path-query
Pawel-608 6eae612
test
Pawel-608 0a5bb65
test
Pawel-608 3ef2d54
pmd
Pawel-608 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
...ch/src/test/java/org/alfresco/elasticsearch/reindexing/NodeWithCategoryIndexingTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package org.alfresco.elasticsearch.reindexing; | ||
|
||
import static java.lang.String.format; | ||
|
||
import static org.alfresco.elasticsearch.SearchQueryService.req; | ||
import static org.alfresco.utility.report.log.Step.STEP; | ||
|
||
import org.alfresco.elasticsearch.reindexing.utils.Categories; | ||
import org.alfresco.rest.search.SearchRequest; | ||
import org.alfresco.utility.model.TestGroup; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* Tests verifying live indexing of secondary children and ANCESTOR index in Elasticsearch. | ||
*/ | ||
@SuppressWarnings({"PMD.JUnitTestsShouldIncludeAssert", "PMD.JUnit4TestShouldUseTestAnnotation"}) // these are testng tests and use searchQueryService.expectResultsFromQuery for assertion | ||
public class NodeWithCategoryIndexingTests extends NodesSecondaryChildrenRelatedTests | ||
{ | ||
|
||
@Autowired | ||
private Categories categories; | ||
|
||
/* | ||
A --- B (folders) | ||
\____ | ||
\ | ||
K --- L (categories) | ||
*/ | ||
@BeforeClass(alwaysRun = true) | ||
@Override | ||
public void dataPreparation() | ||
{ | ||
super.dataPreparation(); | ||
|
||
// given | ||
STEP("Create nested folders in site's Document Library."); | ||
folders().createNestedFolders(A, B); | ||
|
||
STEP("Create nested categories."); | ||
categories.createNestedCategories(K, L); | ||
|
||
STEP("Link folders to category."); | ||
folders(A).linkToCategory(categories.get(L)); | ||
} | ||
|
||
@Test(groups = TestGroup.SEARCH) | ||
public void testParentQueryAgainstCategory() | ||
{ | ||
// then | ||
STEP("Verify that searching by PARENT and category will find one descendant node: categoryL."); | ||
SearchRequest query = req("PARENT:" + categories.get(K).getId()); | ||
searchQueryService.expectResultsFromQuery(query, testUser, categories.get(L).getName()); | ||
} | ||
|
||
@Test(groups = TestGroup.SEARCH) | ||
public void testParentQueryAgainstFolder() | ||
{ | ||
// then | ||
STEP("Verify that searching by PARENT and category will find one descendant node: folderA."); | ||
SearchRequest query = req("PARENT:" + categories.get(L).getId()); | ||
searchQueryService.expectResultsFromQuery(query, testUser, folders(A).getName()); | ||
} | ||
|
||
@Test(groups = TestGroup.SEARCH) | ||
public void testParentQueryAgainstFolderAfterCategoryDeletion() | ||
{ | ||
// given | ||
STEP("Create nested folders in site's Document Library."); | ||
folders().createNestedFolders(C); | ||
|
||
STEP("Create nested categories."); | ||
categories.createNestedCategories(M); | ||
|
||
STEP("Link folders to category."); | ||
folders(C).linkToCategory(categories.get(M)); | ||
|
||
// when | ||
STEP("Verify that searching by PARENT and category will find one descendant node: folderC."); | ||
SearchRequest query = req("PARENT:" + categories.get(M).getId()); | ||
searchQueryService.expectResultsFromQuery(query, testUser, folders(C).getName()); | ||
|
||
// then | ||
STEP("Delete categoryM."); | ||
categories.delete(M); | ||
|
||
STEP("Verify that searching by PARENT and deleted category will find no descendant nodes."); | ||
searchQueryService.expectResultsFromQuery(query, testUser); | ||
} | ||
|
||
|
||
@Test(groups = TestGroup.SEARCH) | ||
public void testSearchByPath() | ||
{ | ||
// given | ||
String Kname = categories.get(K).getName(); | ||
String Lname = categories.get(L).getName(); | ||
String Aname = folders(A).getName(); | ||
|
||
// then | ||
STEP("Verify that searching by PATH and category will find: folderA"); | ||
SearchRequest query = req(format("PATH:'/cm:categoryRoot/cm:generalclassifiable/cm:%s/cm:%s/cm:%s'", Kname, Lname, Aname)); | ||
searchQueryService.expectResultsFromQuery(query, testUser, folders(A).getName()); | ||
} | ||
|
||
@Test(groups = TestGroup.SEARCH) | ||
public void ensureCategoriesAreNotTransitive_lookingForExactChildren() | ||
{ | ||
// given | ||
String Kname = categories.get(K).getName(); | ||
String Lname = categories.get(L).getName(); | ||
String Aname = folders(A).getName(); | ||
String Bname = folders(B).getName(); | ||
|
||
// then | ||
STEP("Verify that searching by PATH for nested folder will return no results (Dependency to category is not transitive)"); | ||
SearchRequest query = req(format("PATH:'/cm:categoryRoot/cm:generalclassifiable/cm:%s/cm:%s/cm:%s/cm:%s'", Kname, Lname, Aname, Bname)); | ||
searchQueryService.expectResultsFromQuery(query, testUser); | ||
} | ||
|
||
@Test(groups = TestGroup.SEARCH) | ||
public void ensureCategoriesAreNotTransitive_lookingForAllChildren() | ||
Pawel-608 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
// given | ||
String Kname = categories.get(K).getName(); | ||
String Lname = categories.get(L).getName(); | ||
|
||
// then | ||
STEP("Verify that searching by PATH and category will find: folderA"); | ||
SearchRequest query = req(format("PATH:'/cm:categoryRoot/cm:generalclassifiable/cm:%s/cm:%s//*'", Kname, Lname)); | ||
searchQueryService.expectResultsFromQuery(query, testUser, folders(A).getName()); | ||
} | ||
|
||
@Test(groups = TestGroup.SEARCH) | ||
public void ensureCategoriesAreNotTransitive_lookingForAllChildren_byParentCategory() | ||
Pawel-608 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
// given | ||
String Kname = categories.get(K).getName(); | ||
|
||
// then | ||
STEP("Verify that searching by PATH and category will find: folderA"); | ||
SearchRequest query = req(format("PATH:'/cm:categoryRoot/cm:generalclassifiable/cm:%s//*'", Kname)); | ||
searchQueryService.expectResultsFromQuery(query, testUser, categories.get(L).getName(), folders(A).getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...s-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/utils/Categories.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.alfresco.elasticsearch.reindexing.utils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.alfresco.rest.core.RestWrapper; | ||
import org.alfresco.rest.model.RestCategoryModel; | ||
import org.alfresco.utility.data.DataUser; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class Categories | ||
{ | ||
private static final String ROOT_CATEGORY_ID = "-root-"; | ||
public static final RestCategoryModel ROOT_CATEGORY = RestCategoryModel.builder() | ||
.id(ROOT_CATEGORY_ID) | ||
.create(); | ||
|
||
@Autowired | ||
private RestWrapper restClient; | ||
|
||
@Autowired | ||
private DataUser dataUser; | ||
|
||
private final Map<String, Category> categories = new HashMap<>(); | ||
|
||
public List<Category> createNestedCategories(String... nestedCategoriesNames) | ||
{ | ||
if (nestedCategoriesNames.length == 0) | ||
{ | ||
return Collections.emptyList(); | ||
} | ||
|
||
List<Category> categories = new ArrayList<>(); | ||
categories.add(new Category(restClient, dataUser.getAdminUser(), ROOT_CATEGORY, nestedCategoriesNames[0])); | ||
|
||
for (int i = 1; i < nestedCategoriesNames.length; i++) | ||
{ | ||
categories.add(categories.get(i - 1).createSubcategory(nestedCategoriesNames[i])); | ||
} | ||
|
||
categories.forEach(category -> this.categories.put(category.getName(), category)); | ||
|
||
return categories; | ||
} | ||
|
||
public Category get(String categoryName) { | ||
return categories.get(categoryName); | ||
} | ||
|
||
public void delete(String categoryName) { | ||
Category categoryToDelete = categories.remove(categoryName); | ||
|
||
restClient.authenticateUser(dataUser.getAdminUser()) | ||
.withCoreAPI() | ||
.usingCategory(categoryToDelete) | ||
.deleteCategory(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/utils/Category.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.alfresco.elasticsearch.reindexing.utils; | ||
|
||
import org.alfresco.rest.core.RestWrapper; | ||
import org.alfresco.rest.model.RestCategoryModel; | ||
import org.alfresco.utility.model.UserModel; | ||
|
||
public class Category extends RestCategoryModel | ||
{ | ||
private final RestWrapper restClient; | ||
|
||
private final UserModel user; | ||
|
||
public Category(RestWrapper restClient, UserModel user, RestCategoryModel parent, String newCategoryName) | ||
{ | ||
this.restClient = restClient; | ||
this.user = user; | ||
|
||
RestCategoryModel category = restClient.authenticateUser(user) | ||
.withCoreAPI() | ||
.usingCategory(parent) | ||
.createSingleCategory(RestCategoryModel.builder().name(newCategoryName).create()); | ||
|
||
setName(category.getName()); | ||
setCount(category.getCount()); | ||
setId(category.getId()); | ||
setPath(category.getPath()); | ||
setParentId(category.getParentId()); | ||
setHasChildren(category.getHasChildren()); | ||
} | ||
|
||
public Category createSubcategory(String subcategoryName) | ||
{ | ||
return new Category(restClient, user, this, subcategoryName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also a
expectNoResultsFromQuery
method that you can use for this.