diff --git a/e2e-test/java/org/alfresco/rest/search/FingerPrintTest.java b/e2e-test/java/org/alfresco/rest/search/FingerPrintTest.java index 8396f8cc0..78a239d91 100644 --- a/e2e-test/java/org/alfresco/rest/search/FingerPrintTest.java +++ b/e2e-test/java/org/alfresco/rest/search/FingerPrintTest.java @@ -18,7 +18,14 @@ */ 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; /** * Search end point Public API test with finger print. @@ -27,28 +34,122 @@ import org.testng.Assert; */ 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}) 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}) + public void searchSimilar() 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; + 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}) + 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"); } } - }