diff --git a/docker-compose.yml b/docker-compose.yml index 32d3daf..78551b3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: "3" services: typesense: - image: typesense/typesense:0.24.1 + image: typesense/typesense:27.1 container_name: "typesense" ports: - "8108:8108" diff --git a/src/test/java/org/typesense/api/CollectionsTest.java b/src/test/java/org/typesense/api/CollectionsTest.java index 24e7fed..4a4d82f 100644 --- a/src/test/java/org/typesense/api/CollectionsTest.java +++ b/src/test/java/org/typesense/api/CollectionsTest.java @@ -7,6 +7,9 @@ import java.util.ArrayList; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + class CollectionsTest { @@ -32,18 +35,31 @@ void testRetrieveAllCollections() throws Exception { CollectionResponse[] collectionResponses = client.collections().retrieve(); for(CollectionResponse c:collectionResponses) System.out.println(c); + + assertNotNull(collectionResponses); + assertEquals(1, collectionResponses.length); } @Test void testRetrieveSingleCollection() throws Exception { helper.createTestCollection(); - System.out.println(client.collections("books").retrieve()); + CollectionResponse books = client.collections("books").retrieve(); + System.out.println(books); + + assertNotNull(books); + assertEquals("books", books.getName()); + assertEquals(0, books.getNumDocuments()); } @Test void testDeleteCollection() throws Exception { helper.createTestCollection(); - System.out.println(client.collections("books").delete()); + CollectionResponse books = client.collections("books").delete(); + System.out.println(books); + + assertNotNull(books); + assertEquals("books", books.getName()); + assertEquals(0, books.getNumDocuments()); } @Test @@ -59,6 +75,11 @@ void testCreateCollection() throws Exception { CollectionResponse cr = client.collections().create(collectionSchema); System.out.println(cr); + + assertNotNull(cr); + assertEquals("Countries", cr.getName()); + assertEquals(0, cr.getNumDocuments()); + assertEquals(3, cr.getFields().size()); } @Test @@ -76,7 +97,17 @@ void testCreateCollectionWithModel() throws Exception { CollectionSchema collectionSchema = new CollectionSchema(); collectionSchema.name("titles").fields(fields); - //CollectionResponse cr = client.collections().create(collectionSchema); - //System.out.println(cr); + CollectionResponse cr = client.collections().create(collectionSchema); + System.out.println(cr); + + assertNotNull(cr); + assertEquals("titles", cr.getName()); + assertEquals(0, cr.getNumDocuments()); + assertEquals(2, cr.getFields().size()); + FieldEmbed fieldEmbed = cr.getFields().stream().filter(f -> f.getName().equals("embedding")).map(Field::getEmbed) + .findFirst() + .orElse(null); + assertNotNull(fieldEmbed); + assertEquals("ts/e5-small", fieldEmbed.getModelConfig().getModelName()); } } \ No newline at end of file diff --git a/src/test/java/org/typesense/api/Helper.java b/src/test/java/org/typesense/api/Helper.java index de910e3..aef471b 100644 --- a/src/test/java/org/typesense/api/Helper.java +++ b/src/test/java/org/typesense/api/Helper.java @@ -2,7 +2,7 @@ import java.time.Duration; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -37,7 +37,7 @@ public class Helper { List nodes = new ArrayList<>(); nodes.add(new Node("http", "localhost", "8108")); - Configuration configuration = new Configuration(nodes, Duration.ofSeconds(3), "xyz"); + Configuration configuration = new Configuration(nodes, Duration.ofSeconds(5), "xyz"); this.client = new Client(configuration); } @@ -117,11 +117,11 @@ public void createTestAnalyticsRule() throws Exception { .type(AnalyticsRuleUpsertSchema.TypeEnum.NOHITS_QUERIES) .params(new AnalyticsRuleParameters() .source(new AnalyticsRuleParametersSource() - .collections(Arrays.asList("books")) - .events(Arrays.asList( - new AnalyticsRuleParametersSourceEvents() - .type("search") - .name("products_search_event")))) + .collections(Collections.singletonList("books")) + .events(Collections.singletonList( + new AnalyticsRuleParametersSourceEvents() + .type("search") + .name("products_search_event")))) .destination(new AnalyticsRuleParametersDestination() .collection("queries")));