diff --git a/avni-server-api/src/main/java/org/avni/server/util/ObjectMapperSingleton.java b/avni-server-api/src/main/java/org/avni/server/util/ObjectMapperSingleton.java index 06b93d2f7..2772a7045 100644 --- a/avni-server-api/src/main/java/org/avni/server/util/ObjectMapperSingleton.java +++ b/avni-server-api/src/main/java/org/avni/server/util/ObjectMapperSingleton.java @@ -2,12 +2,14 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.joda.JodaModule; public final class ObjectMapperSingleton { private static final ObjectMapper objectMapper = new ObjectMapper() .registerModule(new JodaModule()) - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); private ObjectMapperSingleton() { } diff --git a/avni-server-api/src/test/java/org/avni/server/dao/UserRepositoryTest.java b/avni-server-api/src/test/java/org/avni/server/dao/UserRepositoryTest.java index 7888ee5e6..f483eb1f8 100644 --- a/avni-server-api/src/test/java/org/avni/server/dao/UserRepositoryTest.java +++ b/avni-server-api/src/test/java/org/avni/server/dao/UserRepositoryTest.java @@ -2,17 +2,22 @@ import jakarta.transaction.Transactional; import org.avni.server.common.AbstractControllerIntegrationTest; +import org.avni.server.domain.User; import org.avni.server.domain.accessControl.PrivilegeType; +import org.avni.server.domain.factory.UserBuilder; import org.avni.server.framework.security.UserContextHolder; +import org.joda.time.DateTime; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.jdbc.Sql; +import static junit.framework.TestCase.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +@Sql(value = {"/tear-down.sql"}, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql({"/test-data.sql"}) -@Transactional +@Sql(value = {"/tear-down.sql"}, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) public class UserRepositoryTest extends AbstractControllerIntegrationTest { @Autowired private UserRepository userRepository; @@ -34,4 +39,17 @@ public void hasNoSubjectPrivilege() { setUser("user-no-access"); assertFalse(userRepository.hasSubjectPrivilege(PrivilegeType.ViewSubject.name(), 1, UserContextHolder.getUser().getId())); } + + @Test + @Transactional + public void loadingAndSavingUserShouldNotChangeModifiedAudit() throws InterruptedException { + User defaultSuperAdmin = userRepository.getDefaultSuperAdmin(); + User user1 = new UserBuilder().withDefaultValuesForNewEntity().userName("user@example").withAuditUser(defaultSuperAdmin).build(); + user1 = userRepository.save(user1); + DateTime lastModifiedDateTime = user1.getLastModifiedDateTime(); + Thread.sleep(1); + userRepository.save(user1); + User loaded = userRepository.findOne(user1.getId()); + assertEquals(lastModifiedDateTime, loaded.getLastModifiedDateTime()); + } } diff --git a/avni-server-api/src/test/java/org/avni/server/service/OrganisationConfigServiceTest.java b/avni-server-api/src/test/java/org/avni/server/service/OrganisationConfigServiceTest.java index 2160d86ff..b8a4e7ab8 100644 --- a/avni-server-api/src/test/java/org/avni/server/service/OrganisationConfigServiceTest.java +++ b/avni-server-api/src/test/java/org/avni/server/service/OrganisationConfigServiceTest.java @@ -9,8 +9,6 @@ import org.avni.server.domain.UserContext; import org.avni.server.framework.security.UserContextHolder; import org.junit.Test; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import java.util.Optional; diff --git a/avni-server-api/src/test/java/org/avni/server/service/sync/ResetSyncServiceIntegrationTest.java b/avni-server-api/src/test/java/org/avni/server/service/sync/ResetSyncServiceIntegrationTest.java index f712361c2..22db7e86f 100644 --- a/avni-server-api/src/test/java/org/avni/server/service/sync/ResetSyncServiceIntegrationTest.java +++ b/avni-server-api/src/test/java/org/avni/server/service/sync/ResetSyncServiceIntegrationTest.java @@ -1,6 +1,5 @@ package org.avni.server.service.sync; -import jakarta.transaction.Transactional; import org.avni.server.common.AbstractControllerIntegrationTest; import org.avni.server.dao.LocationRepository; import org.avni.server.dao.UserRepository;