|
| 1 | +package bio.overture.ego.service; |
| 2 | + |
| 3 | +import bio.overture.ego.model.entity.User; |
| 4 | +import bio.overture.ego.model.enums.UserType; |
| 5 | +import bio.overture.ego.utils.EntityGenerator; |
| 6 | +import lombok.extern.slf4j.Slf4j; |
| 7 | +import lombok.val; |
| 8 | +import org.junit.Assert; |
| 9 | +import org.junit.Test; |
| 10 | +import org.junit.runner.RunWith; |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; |
| 12 | +import org.springframework.boot.test.context.SpringBootTest; |
| 13 | +import org.springframework.test.context.ActiveProfiles; |
| 14 | +import org.springframework.test.context.TestPropertySource; |
| 15 | +import org.springframework.test.context.junit4.SpringRunner; |
| 16 | +import org.springframework.transaction.annotation.Transactional; |
| 17 | + |
| 18 | +@Slf4j |
| 19 | +@SpringBootTest |
| 20 | +@RunWith(SpringRunner.class) |
| 21 | +@ActiveProfiles("test") |
| 22 | +@TestPropertySource(properties = "default.user.firstUserAsAdmin=true") |
| 23 | +@Transactional |
| 24 | +public class FirstUserAsAdminTest { |
| 25 | + |
| 26 | + @Autowired private UserService userService; |
| 27 | + @Autowired private EntityGenerator entityGenerator; |
| 28 | + |
| 29 | + @Test |
| 30 | + public void testOnlyFirstUserShouldBeAdminByDefault() { |
| 31 | + userService.getRepository().deleteAll(); |
| 32 | + val usersCount = userService.countAll(); |
| 33 | + Assert.assertEquals(0, usersCount); |
| 34 | + User u = entityGenerator.setupUser("First User", UserType.USER); |
| 35 | + val user = userService.findById(u.getId()).get(); |
| 36 | + Assert.assertEquals(user.getType(), UserType.ADMIN); |
| 37 | + |
| 38 | + // add another user make sure they don't get ADMIN type |
| 39 | + User u2 = entityGenerator.setupUser("Second User", UserType.USER); |
| 40 | + val user2 = userService.findById(u2.getId()).get(); |
| 41 | + Assert.assertEquals(user2.getType(), UserType.USER); |
| 42 | + } |
| 43 | +} |
0 commit comments