diff --git a/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java b/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java new file mode 100644 index 000000000..5b79f8808 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java @@ -0,0 +1,79 @@ +/* + * 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 . + */ +package org.alfresco.rest.search; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestNodeModelsCollection; +import org.alfresco.rest.model.builder.NodesBuilder; +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.SiteModel; +import org.alfresco.utility.model.UserModel; +import org.testng.annotations.BeforeClass; + +/** + * Abstract Search test. + * @author Michael Suzuki + * + */ +public class AbstractSearchTest extends RestTest +{ + protected static final String SEARCH_DATA_SAMPLE_FOLDER = "folder"; + UserModel userModel, adminUserModel; + SiteModel siteModel; + UserModel searchedUser; + NodesBuilder nodesBuilder; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + /* + * Create the following file structure for preconditions : + * |- folder + * |-- pangram.txt + * |-- cars.pdf + */ + nodesBuilder = restClient.authenticateUser(userModel).withCoreAPI().usingNode(ContentModel.my()).defineNodes(); + FolderModel folder = new FolderModel(SEARCH_DATA_SAMPLE_FOLDER); + dataContent.usingSite(siteModel).createFolder(folder); + //Create files + FileModel file = new FileModel("pangram.txt", FileType.TEXT_PLAIN, "The qucik brown fox jumps over the lazy dog"); + FileModel 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); + } + + protected RestNodeModelsCollection query(String term) throws Exception + { + return restClient.authenticateUser(userModel) + .withCoreAPI() + .usingParams("term=" + term) + .usingQueries() + .findNodes(); + } + +} diff --git a/e2e-test/java/org/alfresco/rest/search/SearchTest.java b/e2e-test/java/org/alfresco/rest/search/SearchTest.java index 0808d6d97..036ee5c97 100644 --- a/e2e-test/java/org/alfresco/rest/search/SearchTest.java +++ b/e2e-test/java/org/alfresco/rest/search/SearchTest.java @@ -18,18 +18,9 @@ */ package org.alfresco.rest.search; -import org.alfresco.rest.RestTest; import org.alfresco.rest.model.RestNodeModelsCollection; -import org.alfresco.rest.model.builder.NodesBuilder; -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.SiteModel; import org.alfresco.utility.model.TestGroup; -import org.alfresco.utility.model.UserModel; import org.springframework.http.HttpStatus; -import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; /** @@ -37,48 +28,8 @@ import org.testng.annotations.Test; * @author Michael Suzuki * */ -public class SearchTest extends RestTest +public class SearchTest extends AbstractSearchTest { - private static final String SEARCH_DATA_SAMPLE_FOLDER = "folder"; - UserModel userModel, adminUserModel; - SiteModel siteModel; - UserModel searchedUser; - NodesBuilder nodesBuilder; - - @BeforeClass(alwaysRun = true) - public void dataPreparation() throws Exception - { - adminUserModel = dataUser.getAdminUser(); - userModel = dataUser.createRandomTestUser(); - siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); - /* - * Create the following file structure for preconditions : - * |- folder - * |-- pangram.txt - * |-- cars.pdf - */ - nodesBuilder = restClient.authenticateUser(userModel).withCoreAPI().usingNode(ContentModel.my()).defineNodes(); - FolderModel folder = new FolderModel(SEARCH_DATA_SAMPLE_FOLDER); - dataContent.usingSite(siteModel).createFolder(folder); - //Create files - FileModel file = new FileModel("pangram.txt", FileType.TEXT_PLAIN, "The qucik brown fox jumps over the lazy dog"); - FileModel 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); - } - - protected RestNodeModelsCollection query(String term) throws Exception - { - return restClient.authenticateUser(userModel) - .withCoreAPI() - .usingParams("term=" + term) - .usingQueries() - .findNodes(); - } - @Test(groups={TestGroup.SEARCH}) public void searchCreatedData() throws Exception { @@ -89,4 +40,12 @@ public class SearchTest extends RestTest restClient.assertStatusCodeIs(HttpStatus.OK); nodes.assertThat().entriesListIsNotEmpty(); } + + @Test(groups={TestGroup.SEARCH}) + public void searchNonIndexedData() throws Exception + { + RestNodeModelsCollection nodes = query("yeti"); + restClient.assertStatusCodeIs(HttpStatus.OK); + nodes.assertThat().entriesListIsEmpty(); + } }