Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: add assertions to the test
  • Loading branch information
cbot59 committed Dec 1, 2024
commit f24b241f2b6b71b5a59ccacffed1f9b0b52fdbd0
40 changes: 36 additions & 4 deletions src/test/java/org/typesense/api/CollectionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import org.typesense.model.*;

import java.util.ArrayList;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;


class CollectionsTest {
Expand All @@ -32,18 +36,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
Expand All @@ -59,6 +76,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
Expand All @@ -76,7 +98,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());
}
}