From c7c14a4b6758e3266241178f71f2514dc24d29df Mon Sep 17 00:00:00 2001 From: Stephane Epardaud Date: Wed, 14 Apr 2021 16:02:29 +0200 Subject: [PATCH] WIP test for #16399 --- .../mongodb/panache/bugs/Bug16399Entity.java | 51 +++++++++++++++++++ .../panache/MongodbPanacheResourceTest.java | 8 +++ 2 files changed, 59 insertions(+) create mode 100644 integration-tests/mongodb-panache/src/main/java/io/quarkus/it/mongodb/panache/bugs/Bug16399Entity.java diff --git a/integration-tests/mongodb-panache/src/main/java/io/quarkus/it/mongodb/panache/bugs/Bug16399Entity.java b/integration-tests/mongodb-panache/src/main/java/io/quarkus/it/mongodb/panache/bugs/Bug16399Entity.java new file mode 100644 index 0000000000000..d781e9ca574c3 --- /dev/null +++ b/integration-tests/mongodb-panache/src/main/java/io/quarkus/it/mongodb/panache/bugs/Bug16399Entity.java @@ -0,0 +1,51 @@ +package io.quarkus.it.mongodb.panache.bugs; + +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.bson.codecs.pojo.annotations.BsonId; +import org.bson.codecs.pojo.annotations.BsonIgnore; +import org.bson.codecs.pojo.annotations.BsonProperty; + +import io.quarkus.mongodb.panache.PanacheMongoEntityBase; + +//@MongoEntity(collection = "Bug16399") +public class Bug16399Entity extends PanacheMongoEntityBase { + @BsonId + @BsonProperty("_id") + // @Schema(example = "516448966") + public Long id = -1L; + + @BsonProperty("last_activity") + public LocalDateTime lastActivity = LocalDateTime.now(); + + @BsonIgnore + //TROUBLE METHOD CAUSES ERROR + public Bug16399Entity setLastActivity(final LocalDateTime... lastActivities) { + setLastActivity(Arrays.stream(lastActivities).max(LocalDateTime::compareTo).orElse(getTimeLastYear())); + return this; + } + + private LocalDateTime getTimeLastYear() { + return null; + } + + public LocalDateTime getLastActivity() { + return lastActivity; + } + + public Bug16399Entity setLastActivity(final LocalDateTime lastActivity) { + this.lastActivity = lastActivity; + return this; + } + + public static List dbFindById(final Iterable entities) { + if (entities.iterator().hasNext()) { + return find("_id in ?1", entities).list(); + } + return Collections.emptyList(); + } + +} diff --git a/integration-tests/mongodb-panache/src/test/java/io/quarkus/it/mongodb/panache/MongodbPanacheResourceTest.java b/integration-tests/mongodb-panache/src/test/java/io/quarkus/it/mongodb/panache/MongodbPanacheResourceTest.java index cef77a352c734..5c8a0e113e017 100644 --- a/integration-tests/mongodb-panache/src/test/java/io/quarkus/it/mongodb/panache/MongodbPanacheResourceTest.java +++ b/integration-tests/mongodb-panache/src/test/java/io/quarkus/it/mongodb/panache/MongodbPanacheResourceTest.java @@ -21,6 +21,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import io.quarkus.it.mongodb.panache.book.BookDetail; +import io.quarkus.it.mongodb.panache.bugs.Bug16399Entity; import io.quarkus.it.mongodb.panache.person.Person; import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; @@ -389,4 +390,11 @@ public void testMoreRepositoryFunctionalities() { public void testBug13301() { get("/bugs/13301").then().statusCode(200); } + + @Test + public void testBug16399() { + Bug16399Entity entity = new Bug16399Entity(); + entity.persist(); + Bug16399Entity.dbFindById(Arrays.asList(entity.id)); + } }