|
| 1 | +package org.typesense.api; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import org.junit.jupiter.api.AfterEach; |
| 7 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 8 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 9 | +import org.junit.jupiter.api.BeforeEach; |
| 10 | +import org.junit.jupiter.api.Test; |
| 11 | +import org.typesense.model.StopwordsSetRetrieveSchema; |
| 12 | +import org.typesense.model.StopwordsSetSchema; |
| 13 | +import org.typesense.model.StopwordsSetUpsertSchema; |
| 14 | +import org.typesense.model.StopwordsSetsRetrieveAllSchema; |
| 15 | + |
| 16 | +public class StopwordsTest { |
| 17 | + |
| 18 | + private Client client; |
| 19 | + private Helper helper; |
| 20 | + |
| 21 | + @BeforeEach |
| 22 | + void setUp() throws Exception { |
| 23 | + helper = new Helper(); |
| 24 | + client = helper.getClient(); |
| 25 | + helper.teardown(); |
| 26 | + helper.createTestCollection(); |
| 27 | + } |
| 28 | + |
| 29 | + @AfterEach |
| 30 | + void tearDown() throws Exception { |
| 31 | + helper.teardown(); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + void testUpsert() throws Exception { |
| 36 | + List<String> stopwords = new ArrayList<>(); |
| 37 | + stopwords.add("the"); |
| 38 | + stopwords.add("of"); |
| 39 | + stopwords.add("and"); |
| 40 | + |
| 41 | + StopwordsSetUpsertSchema stopwordsSetSchema = new StopwordsSetUpsertSchema(); |
| 42 | + stopwordsSetSchema.stopwords(stopwords); |
| 43 | + |
| 44 | + client.stopwords().upsert("common-words", stopwordsSetSchema); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + void testRetrieve() throws Exception { |
| 49 | + helper.createTestStopwordsSet(); |
| 50 | + |
| 51 | + StopwordsSetRetrieveSchema result = this.client.stopwords("common-words").retrieve(); |
| 52 | + |
| 53 | + assertNotNull(result); |
| 54 | + |
| 55 | + StopwordsSetSchema set = result.getStopwords(); |
| 56 | + |
| 57 | + assertEquals("common-words", set.getId()); |
| 58 | + assertEquals(3, set.getStopwords().size()); |
| 59 | + assertEquals("and", set.getStopwords().get(0)); |
| 60 | + assertEquals("the", set.getStopwords().get(1)); |
| 61 | + assertEquals("of", set.getStopwords().get(2)); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + void testRetrieveAll() throws Exception { |
| 66 | + helper.createTestStopwordsSet(); |
| 67 | + |
| 68 | + StopwordsSetsRetrieveAllSchema result = this.client.stopwords().retrieve(); |
| 69 | + |
| 70 | + assertNotNull(result); |
| 71 | + assertEquals(1, result.getStopwords().size()); |
| 72 | + |
| 73 | + StopwordsSetSchema set = result.getStopwords().get(0); |
| 74 | + |
| 75 | + assertEquals("common-words", set.getId()); |
| 76 | + assertEquals(3, set.getStopwords().size()); |
| 77 | + assertEquals("and", set.getStopwords().get(0)); |
| 78 | + assertEquals("the", set.getStopwords().get(1)); |
| 79 | + assertEquals("of", set.getStopwords().get(2)); |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + void testDelete() throws Exception { |
| 84 | + helper.createTestStopwordsSet(); |
| 85 | + |
| 86 | + StopwordsSetSchema result = this.client.stopwords("common-words").delete(); |
| 87 | + |
| 88 | + assertNotNull(result); |
| 89 | + assertEquals("common-words", result.getId()); |
| 90 | + } |
| 91 | +} |
0 commit comments