Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test assertions #80

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
39 changes: 35 additions & 4 deletions src/test/java/org/typesense/api/CollectionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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());
}
}
14 changes: 7 additions & 7 deletions src/test/java/org/typesense/api/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -37,7 +37,7 @@ public class Helper {
List<Node> 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);
}
Expand Down Expand Up @@ -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")));

Expand Down