diff --git a/step-framework-collections/src/test/java/step/core/collections/AbstractCollectionTest.java b/step-framework-collections/src/test/java/step/core/collections/AbstractCollectionTest.java index 6416de3..57881ac 100644 --- a/step-framework-collections/src/test/java/step/core/collections/AbstractCollectionTest.java +++ b/step-framework-collections/src/test/java/step/core/collections/AbstractCollectionTest.java @@ -2,10 +2,13 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import jakarta.json.Json; import jakarta.json.JsonObject; @@ -15,6 +18,8 @@ import org.junit.Test; import step.core.accessors.AbstractIdentifiableObject; +import step.core.accessors.AbstractTrackedObject; +import step.core.accessors.AbstractUser; import step.core.accessors.DefaultJacksonMapperProvider; import step.core.collections.serialization.DottedKeyMap; import step.core.entities.Bean; @@ -614,4 +619,49 @@ public void renameCollections() { result = collection.find(Filters.empty(), null, null, null, 0).collect(Collectors.toList()); assertEquals(0, result.size()); } + + public static class TestUser extends AbstractUser { + public final String name; + + @JsonCreator + public TestUser(@JsonProperty("name") String name) { + this.name = name; + } + + @Override + public String getSessionUsername() { + return name; + } + } + + @Test + public void testAbstractTrackedObject() { + collectionFactory.getCollection("testAbstractTrackedObject", AbstractTrackedObject.class).drop(); + Collection collection = collectionFactory.getCollection("testAbstractTrackedObject", AbstractTrackedObject.class); + AbstractUser creator = new TestUser("creator"); + String creatorId = creator.getId().toHexString(); + AbstractTrackedObject abstractTrackedObject = new AbstractTrackedObject(); + abstractTrackedObject.setCreationUser(creator.getSessionUsername()); + Date now = new Date(); + abstractTrackedObject.setCreationDate(now); + abstractTrackedObject.setLastModificationUser(creator.getSessionUsername()); + abstractTrackedObject.setLastModificationDate(now); + collection.save(abstractTrackedObject); + //Search by creator name + assertTrue("Search by creator name did not find result", + collection.find(Filters.equals("creationUser", creator.getSessionUsername()), null, null, null, 0).findFirst().isPresent()); + //Search by modifier name + assertTrue("Search by modifier name did not find result", + collection.find(Filters.equals("lastModificationUser", creator.getSessionUsername()), null, null, null, 0).findFirst().isPresent()); + TestUser modifier = new TestUser("modifier"); + abstractTrackedObject.setLastModificationDate(new Date()); + abstractTrackedObject.setLastModificationUser(modifier.getSessionUsername()); + collection.save(abstractTrackedObject); + //Search by creator name + assertTrue("Search by creator name did not find result", + collection.find(Filters.equals("creationUser", creator.getSessionUsername()), null, null, null, 0).findFirst().isPresent()); + //Search by modifier name + assertTrue("Search by modifier name did not find result", + collection.find(Filters.equals("lastModificationUser", modifier.getSessionUsername()), null, null, null, 0).findFirst().isPresent()); + } }