diff --git a/e2e-test/src/main/resources/model/search-2139-model.xml b/e2e-test/src/main/resources/model/search-2139-model.xml new file mode 100644 index 000000000..76555ed20 --- /dev/null +++ b/e2e-test/src/main/resources/model/search-2139-model.xml @@ -0,0 +1,144 @@ + + + Administrator + + + + + + + + + + + content + + + alltypecontent + d:content + false + + BOTH + + + + + + + + + text + + + mltextLOVPartial + d:mltext + false + + BOTH + true + + + + textPatternUnique + d:text + false + + FALSE + false + + + + mltextFree + d:mltext + false + + TRUE + false + + + + textLOVPartial + d:text + false + + BOTH + true + + + + mltextPatternUnique + d:mltext + false + + FALSE + false + + + + mltextPatternMany + d:mltext + false + + BOTH + false + + + + textLOVWhole + d:text + false + + FALSE + true + + + + mltextNone + d:mltext + false + + TRUE + + + + textNone + d:text + false + + TRUE + + + + textFree + d:text + false + + TRUE + false + + + + mltextLOVWhole + d:mltext + false + + FALSE + true + + + + textPatternMany + d:text + false + + BOTH + false + + + + + + + + + \ No newline at end of file diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java new file mode 100644 index 000000000..bae7bd1ca --- /dev/null +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/FieldDefinitionTest.java @@ -0,0 +1,175 @@ +package org.alfresco.test.search.functional.searchServices.search; + +import org.alfresco.rest.search.SearchResponse; +import org.alfresco.utility.data.CustomObjectTypeProperties; +import org.alfresco.utility.model.FileModel; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * A test for fields defined in the solr schema + * Based on https://issues.alfresco.com/jira/browse/SEARCH-2139 + */ +public class FieldDefinitionTest extends AbstractSearchServicesE2ETest { + + private FileModel File1, File2; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + dataContent.usingAdmin().deployContentModel("model/search-2139-model.xml"); + + File1 = new FileModel("standard-file1.txt"); + + dataContent.usingUser(testUser).usingSite(testSite).createCustomContent(File1, "cmis:document", new CustomObjectTypeProperties()); + + cmisApi.authenticateUser(testUser).usingResource(File1).addSecondaryTypes("P:allfieldtypes:text") + .updateProperty("allfieldtypes:mltextLOVPartial", "file1") + .updateProperty("allfieldtypes:textPatternUnique", "file2") + .updateProperty("allfieldtypes:mltextFree", "file3") + .updateProperty("allfieldtypes:textLOVPartial", "file4"); + + File2 = new FileModel("standard-file2.txt"); + + dataContent.usingUser(testUser).usingSite(testSite).createCustomContent(File2, "cmis:document", new CustomObjectTypeProperties()); + + cmisApi.authenticateUser(testUser).usingResource(File2).addSecondaryTypes("P:allfieldtypes:text") + .updateProperty("allfieldtypes:textFree", "text field definition test") + .updateProperty("allfieldtypes:textPatternMany", "mltext field definition test") + .updateProperty("allfieldtypes:textLOVWhole", "text field not tokenised") + .updateProperty("allfieldtypes:mltextLOVWhole", "mltext field not tokenised"); + + waitForMetadataIndexing(File1.getName(), true); + waitForMetadataIndexing(File2.getName(), true); + } + + // A test to test the text field in the solr schema, using a single word + @Test(priority = 1) + public void testTextField() + { + SearchResponse response = queryAsUser(testUser, "allfieldtypes_textPatternUnique:file2"); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 1); + + response = queryAsUser(testUser, "allfieldtypes_textLOVPartial:file4"); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 1); + } + + // A test to test the mltext field in the solr schema, using a single word + @Test(priority = 2) + public void testmlTextField() + { + SearchResponse response = queryAsUser(testUser, "allfieldtypes_mltextLOVPartial:file1"); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 1); + + response = queryAsUser(testUser, "allfieldtypes_mltextFree:file3"); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 1); + } + + // A test to test the text field in the solr schema, where the field hasn't been defined + @Test(priority = 3) + public void testTextFieldNotDefined() + { + SearchResponse response = queryAsUser(testUser, "allfieldtypes_textPatternMany:file1"); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 0); + + response = queryAsUser(testUser, "allfieldtypes:textNone:file2"); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 0); + } + + // A test to test the mltext field in the solr schema, where the field hasn't been defined + @Test(priority = 4) + public void testmlTextFieldNotDefined() + { + SearchResponse response = queryAsUser(testUser, "allfieldtypes_mltextNone:file1"); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 0); + + response = queryAsUser(testUser, "allfieldtypes_mltextPatternUnique:file2"); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 0); + } + + // A test to test the tokenised text field in the solr schema + @Test(priority = 5) + public void testTextFieldTokenised() + { + SearchResponse response = queryAsUser(testUser, "allfieldtypes_textFree:\"text field definition test\""); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 1); + + response = queryAsUser(testUser, "allfieldtypes_textFree:text"); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 1); + + response = queryAsUser(testUser, "allfieldtypes_textFree:\"definition test\""); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 1); + + response = queryAsUser(testUser, "allfieldtypes_textPatternMany:definition"); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 1); + } + + // A test to test a non tokenised text field in the solr schema + @Test(priority = 6) + public void testTextFieldNotTokenised() + { + SearchResponse response = queryAsUser(testUser, "allfieldtypes_textLOVWhole:\"text field not tokenised\""); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 1); + + response = queryAsUser(testUser, "allfieldtypes_textLOVWhole:text"); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 0); + + response = queryAsUser(testUser, "allfieldtypes_textLOVWhole:\"field not\""); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 0); + } + + // A test to test the tokenised mltext field in the solr schema + @Test(priority = 7) + public void testmlTextFieldTokenised() + { + SearchResponse response = queryAsUser(testUser, "allfieldtypes_textPatternMany:\"mltext field definition test\""); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 1); + + response = queryAsUser(testUser, "allfieldtypes_textPatternMany:mltext"); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 1); + + response = queryAsUser(testUser, "allfieldtypes_textPatternMany:\"field definition\""); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 1); + + response = queryAsUser(testUser, "allfieldtypes_textPatternMany:field"); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 1); + } + + // A test to test the non tokenised mltext field in the solr schema + @Test(priority = 7) + public void testmlTextFieldNotTokenised() + { + SearchResponse response = queryAsUser(testUser, "allfieldtypes_mltextLOVWhole:\"mltext field not tokenised\""); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 1); + + response = queryAsUser(testUser, "allfieldtypes_mltextLOVWhole:mltext"); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 0); + + response = queryAsUser(testUser, "allfieldtypes_mltextLOVWhole:\"not tokenised\""); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response.getPagination().getCount(), 0); + } +}