1717import com .couchbase .client .core .error .DocumentNotFoundException ;
1818import com .couchbase .client .java .json .JsonObject ;
1919import org .assertj .core .api .Assertions ;
20- import org .assertj .core .api .SoftAssertions ;
2120import org .eclipse .jnosql .communication .Settings ;
2221import org .eclipse .jnosql .communication .TypeReference ;
2322import org .eclipse .jnosql .communication .keyvalue .BucketManager ;
4443
4544import static java .util .Arrays .asList ;
4645import static org .assertj .core .api .Assertions .assertThat ;
46+ import static org .assertj .core .api .SoftAssertions .assertSoftly ;
4747import static org .awaitility .Awaitility .await ;
4848import static org .eclipse .jnosql .communication .driver .IntegrationTest .MATCHES ;
4949import static org .eclipse .jnosql .communication .driver .IntegrationTest .NAMED ;
@@ -80,7 +80,7 @@ public class CouchbaseDocumentManagerTest {
8080
8181 @ BeforeEach
8282 @ AfterEach
83- void cleanUpData () throws InterruptedException {
83+ void cleanUpData () throws InterruptedException {
8484 try {
8585 keyValueEntityManagerForPerson .delete ("id" );
8686 keyValueEntityManagerForPerson .delete ("id2" );
@@ -206,11 +206,29 @@ void shouldRetrieveListDocumentList() {
206206 }
207207
208208 @ Test
209- void shouldCount () {
210- CommunicationEntity entity = getEntity ();
211- entityManager .insert (entity );
212- long counted = entityManager .count (COLLECTION_PERSON_NAME );
213- assertTrue (counted > 0 );
209+ void shouldCount () {
210+ CommunicationEntity entity = entityManager .insert (createSubdocumentList ());
211+ Element key = entity .find ("_id" ).get ();
212+ var query = select ().from (COLLECTION_APP_NAME ).where (key .name ()).eq (key .get ()).build ();
213+
214+ assertSoftly (softly -> {
215+ softly .assertThat (entityManager .count (entity .name ()))
216+ .as ("must return more than zero for person collection" )
217+ .isEqualTo (1L );
218+
219+ softly .assertThat (entityManager .count (query ))
220+ .isEqualTo (1L );
221+
222+ softly .assertThatThrownBy (()->
223+ entityManager .count ((String ) null ))
224+ .isInstanceOf (NullPointerException .class );
225+
226+ softly .assertThatThrownBy (()->
227+ entityManager .count ((SelectQuery ) null ))
228+ .isInstanceOf (NullPointerException .class );
229+
230+ });
231+
214232 }
215233
216234 private CommunicationEntity createSubdocumentList () {
@@ -277,7 +295,7 @@ void shouldInsertNull() {
277295 entity .add (Element .of ("name" , null ));
278296 CommunicationEntity documentEntity = entityManager .insert (entity );
279297 Optional <Element > name = documentEntity .find ("name" );
280- SoftAssertions . assertSoftly (soft -> {
298+ assertSoftly (soft -> {
281299 soft .assertThat (name ).isPresent ();
282300 soft .assertThat (name ).get ().extracting (Element ::name ).isEqualTo ("name" );
283301 soft .assertThat (name ).get ().extracting (Element ::get ).isNull ();
@@ -290,7 +308,7 @@ void shouldUpdateNull(){
290308 entity .add (Element .of ("name" , null ));
291309 var documentEntity = entityManager .update (entity );
292310 Optional <Element > name = documentEntity .find ("name" );
293- SoftAssertions . assertSoftly (soft -> {
311+ assertSoftly (soft -> {
294312 soft .assertThat (name ).isPresent ();
295313 soft .assertThat (name ).get ().extracting (Element ::name ).isEqualTo ("name" );
296314 soft .assertThat (name ).get ().extracting (Element ::get ).isNull ();
@@ -302,11 +320,16 @@ void shouldFindContains() {
302320 var entity = getEntity ();
303321
304322 entityManager .insert (entity );
323+
324+ await ().until (
325+ () -> !(entityManager .select (select ().from (entity .name ()).build ()).toList ().isEmpty ())
326+ );
327+
305328 var query = new MappingQuery (Collections .emptyList (), 0L , 0L , CriteriaCondition .contains (Element .of ("name" ,
306329 "lia" )), COLLECTION_PERSON_NAME , Collections .emptyList ());
307330
308331 var result = entityManager .select (query ).toList ();
309- SoftAssertions . assertSoftly (softly -> {
332+ assertSoftly (softly -> {
310333 softly .assertThat (result ).hasSize (1 );
311334 softly .assertThat (result .get (0 ).find ("name" ).orElseThrow ().get (String .class )).isEqualTo ("Poliana" );
312335 });
@@ -317,11 +340,15 @@ void shouldStartsWith() {
317340 var entity = getEntity ();
318341
319342 entityManager .insert (entity );
343+ await ().until (
344+ () -> !(entityManager .select (select ().from (entity .name ()).build ()).toList ().isEmpty ())
345+ );
346+
320347 var query = new MappingQuery (Collections .emptyList (), 0L , 0L , CriteriaCondition .startsWith (Element .of ("name" ,
321348 "Pol" )), COLLECTION_PERSON_NAME , Collections .emptyList ());
322349
323350 var result = entityManager .select (query ).toList ();
324- SoftAssertions . assertSoftly (softly -> {
351+ assertSoftly (softly -> {
325352 softly .assertThat (result ).hasSize (1 );
326353 softly .assertThat (result .get (0 ).find ("name" ).orElseThrow ().get (String .class )).isEqualTo ("Poliana" );
327354 });
@@ -332,11 +359,16 @@ void shouldEndsWith() {
332359 var entity = getEntity ();
333360
334361 entityManager .insert (entity );
362+
363+ await ().until (
364+ () -> !(entityManager .select (select ().from (entity .name ()).build ()).toList ().isEmpty ())
365+ );
366+
335367 var query = new MappingQuery (Collections .emptyList (), 0L , 0L , CriteriaCondition .endsWith (Element .of ("name" ,
336368 "ana" )), COLLECTION_PERSON_NAME , Collections .emptyList ());
337369
338370 var result = entityManager .select (query ).toList ();
339- SoftAssertions . assertSoftly (softly -> {
371+ assertSoftly (softly -> {
340372 softly .assertThat (result ).hasSize (1 );
341373 softly .assertThat (result .get (0 ).find ("name" ).orElseThrow ().get (String .class )).isEqualTo ("Poliana" );
342374 });
0 commit comments