Skip to content

Commit be839c6

Browse files
committed
Create test to filter
Signed-off-by: Otavio Santana <[email protected]>
1 parent 83fd445 commit be839c6

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

mongodb-driver/src/test/java/org/eclipse/jnosql/communication/mongodb/document/MongoDBSpecificFeaturesTest.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,77 @@
1414
*/
1515
package org.eclipse.jnosql.communication.mongodb.document;
1616

17+
import com.mongodb.client.model.Filters;
18+
import jakarta.nosql.document.Document;
19+
import jakarta.nosql.document.DocumentCollectionManager;
20+
import jakarta.nosql.document.DocumentDeleteQuery;
21+
import jakarta.nosql.document.DocumentEntity;
22+
import jakarta.nosql.document.DocumentQuery;
23+
import org.eclipse.jnosql.communication.document.Documents;
24+
import org.junit.jupiter.api.Assertions;
25+
import org.junit.jupiter.api.BeforeAll;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
28+
29+
import java.io.IOException;
30+
import java.util.HashMap;
31+
import java.util.List;
32+
import java.util.Map;
33+
import java.util.Optional;
34+
import java.util.stream.Collectors;
35+
36+
import static com.mongodb.client.model.Filters.eq;
37+
import static jakarta.nosql.document.DocumentQuery.select;
38+
import static org.hamcrest.MatcherAssert.assertThat;
39+
import static org.hamcrest.Matchers.contains;
40+
import static org.junit.jupiter.api.Assertions.assertFalse;
41+
1742
public class MongoDBSpecificFeaturesTest {
43+
44+
public static final String COLLECTION_NAME = "person";
45+
private static MongoDBDocumentCollectionManager entityManager;
46+
47+
@BeforeAll
48+
public static void setUp() throws IOException {
49+
entityManager = ManagerFactorySupplier.INSTANCE.get("database");
50+
}
51+
52+
@BeforeEach
53+
public void beforeEach() {
54+
DocumentDeleteQuery.delete().from(COLLECTION_NAME).delete(entityManager);
55+
}
56+
57+
@Test
58+
public void shouldReturnErrorWhenThereIsNullParameter(){
59+
Assertions.assertThrows(NullPointerException.class,
60+
() -> entityManager.select(null, null));
61+
Assertions.assertThrows(NullPointerException.class,
62+
() -> entityManager.select(COLLECTION_NAME, null));
63+
64+
Assertions.assertThrows(NullPointerException.class,
65+
() -> entityManager.select(null, eq("name", "Poliana")));
66+
}
67+
68+
@Test
69+
public void shouldFindDocument() {
70+
DocumentEntity entity = entityManager.insert(getEntity());
71+
Optional<Document> id = entity.find("_id");
72+
73+
74+
List<DocumentEntity> entities = entityManager.select(COLLECTION_NAME,
75+
eq("name", "Poliana")).collect(Collectors.toList());
76+
assertFalse(entities.isEmpty());
77+
assertThat(entities, contains(entity));
78+
}
79+
80+
private DocumentEntity getEntity() {
81+
DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
82+
Map<String, Object> map = new HashMap<>();
83+
map.put("name", "Poliana");
84+
map.put("city", "Salvador");
85+
List<Document> documents = Documents.of(map);
86+
documents.forEach(entity::add);
87+
return entity;
88+
}
89+
1890
}

0 commit comments

Comments
 (0)