Skip to content

Commit

Permalink
#813 - serialisation config to ignore objects or type hibernate proxy…
Browse files Browse the repository at this point in the history
… (bytebuddy)
  • Loading branch information
petmongrels committed Nov 8, 2024
1 parent 93456ed commit 599768e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 599768e

Please sign in to comment.