diff --git a/demo/data.mv.db b/demo/data.mv.db index c68dd5a..ae48392 100644 Binary files a/demo/data.mv.db and b/demo/data.mv.db differ diff --git a/demo/src/test/java/com/example/demo/GroupServiceTests.java b/demo/src/test/java/com/example/demo/GroupServiceTests.java index 60f7272..97e336b 100644 --- a/demo/src/test/java/com/example/demo/GroupServiceTests.java +++ b/demo/src/test/java/com/example/demo/GroupServiceTests.java @@ -21,67 +21,67 @@ import com.example.demo.users.service.UserService; @SpringBootTest @TestMethodOrder(OrderAnnotation.class) class GroupServiceTests { - // @Autowired - // private GroupService groupService; - // @Autowired - // private UserService userService; - // private GroupEntity group; - // private UserEntity user; + @Autowired + private GroupService groupService; + @Autowired + private UserService userService; + private GroupEntity group; + private UserEntity user; - // @BeforeEach - // void createData() { - // removeData(); + @BeforeEach + void createData() { + removeData(); - // user = userService.create(new UserEntity("oleg", "tester1", "1234")); - // groupService.create(user.getId(), new GroupEntity("group1")); - // groupService.create(user.getId(), new GroupEntity("group2")); - // group = groupService.create(user.getId(), new GroupEntity("group3")); - // } + user = userService.create(new UserEntity("tester1", "1234")); + groupService.create(user.getId(), new GroupEntity("group1")); + groupService.create(user.getId(), new GroupEntity("group2")); + group = groupService.create(user.getId(), new GroupEntity("group3")); + } - // @AfterEach - // void removeData() { - // userService.getAll().forEach(item -> userService.delete(item.getId())); - // } + @AfterEach + void removeData() { + userService.getAll().forEach(item -> userService.delete(item.getId())); + } - // @Test - // void getTest() { - // Assertions.assertThrows(NotFoundException.class, () -> groupService.get(0L)); - // } + @Test + void getTest() { + Assertions.assertThrows(NotFoundException.class, () -> groupService.get(0L)); + } - // @Test - // void createTest() { - // Assertions.assertEquals(3, groupService.getAll(user.getId()).size()); - // var res = groupService.get(group.getId()); - // Assertions.assertEquals(group, groupService.get(group.getId())); - // } + @Test + void createTest() { + Assertions.assertEquals(3, groupService.getAll(user.getId()).size()); + var res = groupService.get(group.getId()); + Assertions.assertEquals(group, groupService.get(group.getId())); + } - // @Test - // void createNullableTest() { - // final GroupEntity nullableGroup= new GroupEntity(null); - // Assertions.assertThrows(DataIntegrityViolationException.class, () -> groupService.create(user.getId(), nullableGroup)); - // } + @Test + void createNullableTest() { + final GroupEntity nullableGroup= new GroupEntity(null); + Assertions.assertThrows(DataIntegrityViolationException.class, () -> groupService.create(user.getId(), nullableGroup)); + } - // @Test - // void updateTest() { - // final String test = "TEST"; - // final String oldName = group.getName(); - // final GroupEntity newEntity = groupService.update(group.getId(), new GroupEntity(test)); - // Assertions.assertEquals(3, groupService.getAll(user.getId()).size()); - // Assertions.assertEquals(newEntity, groupService.get(group.getId())); - // Assertions.assertEquals(test, newEntity.getName()); - // Assertions.assertEquals(user, newEntity.getUser()); - // Assertions.assertNotEquals(oldName, newEntity.getName()); - // } + @Test + void updateTest() { + final String test = "TEST"; + final String oldName = group.getName(); + final GroupEntity newEntity = groupService.update(group.getId(), new GroupEntity(test)); + Assertions.assertEquals(3, groupService.getAll(user.getId()).size()); + Assertions.assertEquals(newEntity, groupService.get(group.getId())); + Assertions.assertEquals(test, newEntity.getName()); + Assertions.assertEquals(user, newEntity.getUser()); + Assertions.assertNotEquals(oldName, newEntity.getName()); + } - // @Test - // void deleteTest() { - // groupService.delete(group.getId()); - // Assertions.assertEquals(2, groupService.getAll(user.getId()).size()); + @Test + void deleteTest() { + groupService.delete(group.getId()); + Assertions.assertEquals(2, groupService.getAll(user.getId()).size()); - // final GroupEntity newEntity = groupService.create(user.getId(), new GroupEntity(group.getName())); - // Assertions.assertEquals(3, groupService.getAll(user.getId()).size()); - // Assertions.assertNotEquals(group.getId(), newEntity.getId()); - // } + final GroupEntity newEntity = groupService.create(user.getId(), new GroupEntity(group.getName())); + Assertions.assertEquals(3, groupService.getAll(user.getId()).size()); + Assertions.assertNotEquals(group.getId(), newEntity.getId()); + } } \ No newline at end of file diff --git a/demo/src/test/java/com/example/demo/MemberServiceTests.java b/demo/src/test/java/com/example/demo/MemberServiceTests.java index 131e2b6..4a2b205 100644 --- a/demo/src/test/java/com/example/demo/MemberServiceTests.java +++ b/demo/src/test/java/com/example/demo/MemberServiceTests.java @@ -13,6 +13,7 @@ import org.springframework.boot.autoconfigure.security.SecurityProperties.User; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.dao.DataIntegrityViolationException; +import com.example.demo.core.configuration.Constants; import com.example.demo.core.error.NotFoundException; import com.example.demo.groups.model.GroupEntity; import com.example.demo.groups.service.GroupService; @@ -34,66 +35,66 @@ class MemberServiceTests { private GroupEntity group; private UserEntity user; - // @BeforeEach - // void createData() { - // removeData(); + @BeforeEach + void createData() { + removeData(); - // user = userService.create(new UserEntity("oleg", "tester1", "1234")); - // group = groupService.create(user.getId(), new GroupEntity("group1")); - // member = memberService.create(group.getId(), new MemberEntity("member1", "mem1","expert", 1615L)); - // memberService.create(group.getId(), new MemberEntity("member1", "mem1","expert", 1712L)); - // memberService.create(group.getId(), new MemberEntity("member1", "mem1","expert", 1651L)); - // } + user = userService.create(new UserEntity("tester1", "1234")); + group = groupService.create(user.getId(), new GroupEntity("group1")); + member = memberService.create(group.getId(), new MemberEntity("member1", "mem1","expert", 1615L)); + memberService.create(group.getId(), new MemberEntity("member1", "mem1","expert", 1712L)); + memberService.create(group.getId(), new MemberEntity("member1", "mem1","expert", 1651L)); + } - // @AfterEach - // void removeData() { - // userService.getAll().forEach(item -> userService.delete(item.getId())); - // } + @AfterEach + void removeData() { + userService.getAll().forEach(item -> userService.delete(item.getId())); + } - // @Test - // void getTest() { - // Assertions.assertThrows(NotFoundException.class, () -> memberService.get(0L)); - // } + @Test + void getTest() { + Assertions.assertThrows(NotFoundException.class, () -> memberService.get(0L)); + } - // @Test - // void createTest() { - // Assertions.assertEquals(3, memberService.getAll(group.getId()).size()); - // Assertions.assertEquals(member, memberService.get(member.getId())); - // } + @Test + void createTest() { + Assertions.assertEquals(3, memberService.getAll(group.getId(), 0, Constants.DEFUALT_PAGE_SIZE).getContent().size()); + Assertions.assertEquals(member, memberService.get(member.getId())); + } - // @Test - // void createNullableTest() { - // final MemberEntity nullableMember= new MemberEntity(null, null, null, null); - // Assertions.assertThrows(DataIntegrityViolationException.class, () -> memberService.create(group.getId(), nullableMember)); - // } + @Test + void createNullableTest() { + final MemberEntity nullableMember= new MemberEntity(null, null, null, null); + Assertions.assertThrows(DataIntegrityViolationException.class, () -> memberService.create(group.getId(), nullableMember)); + } - // @Test - // void updateTest() { - // final String test = "TEST"; - // final String oldName = member.getName(); - // final String oldHandle = member.getHandle(); - // final String oldRank = member.getRank(); - // final MemberEntity newEntity = memberService.update(member.getId(), new MemberEntity(test, test, test, null)); - // Assertions.assertEquals(3, memberService.getAll(group.getId()).size()); - // Assertions.assertEquals(newEntity, memberService.get(member.getId())); - // Assertions.assertEquals(test, newEntity.getName()); - // Assertions.assertEquals(test, newEntity.getHandle()); - // Assertions.assertEquals(test, newEntity.getRank()); - // Assertions.assertNotEquals(oldName, newEntity.getName()); - // Assertions.assertNotEquals(oldHandle, newEntity.getHandle()); - // Assertions.assertNotEquals(oldRank, newEntity.getRank()); - // } + @Test + void updateTest() { + final String test = "TEST"; + final String oldName = member.getName(); + final String oldHandle = member.getHandle(); + final String oldRank = member.getRank(); + final MemberEntity newEntity = memberService.update(member.getId(), new MemberEntity(test, test, test, null)); + Assertions.assertEquals(3, memberService.getAll(group.getId(), 0, Constants.DEFUALT_PAGE_SIZE).getContent().size()); + Assertions.assertEquals(newEntity, memberService.get(member.getId())); + Assertions.assertEquals(test, newEntity.getName()); + Assertions.assertEquals(test, newEntity.getHandle()); + Assertions.assertEquals(test, newEntity.getRank()); + Assertions.assertNotEquals(oldName, newEntity.getName()); + Assertions.assertNotEquals(oldHandle, newEntity.getHandle()); + Assertions.assertNotEquals(oldRank, newEntity.getRank()); + } - // @Test - // void deleteTest() { - // memberService.delete(member.getId()); - // Assertions.assertEquals(2, memberService.getAll(group.getId()).size()); + @Test + void deleteTest() { + memberService.delete(member.getId()); + Assertions.assertEquals(2, memberService.getAll(group.getId(), 0, Constants.DEFUALT_PAGE_SIZE).getContent().size()); - // final MemberEntity newEntity = memberService.create(group.getId(), new MemberEntity(member.getName(), member.getHandle(), member.getRank(), - // member.getRating())); - // Assertions.assertEquals(3, memberService.getAll(group.getId()).size()); - // Assertions.assertNotEquals(member.getId(), newEntity.getId()); - // } + final MemberEntity newEntity = memberService.create(group.getId(), new MemberEntity(member.getName(), member.getHandle(), member.getRank(), + member.getRating())); + Assertions.assertEquals(3, memberService.getAll(group.getId(), 0, Constants.DEFUALT_PAGE_SIZE).getContent().size()); + Assertions.assertNotEquals(member.getId(), newEntity.getId()); + } } \ No newline at end of file diff --git a/demo/src/test/java/com/example/demo/UserServiceTests.java b/demo/src/test/java/com/example/demo/UserServiceTests.java index 43cf8dd..4ba7ba4 100644 --- a/demo/src/test/java/com/example/demo/UserServiceTests.java +++ b/demo/src/test/java/com/example/demo/UserServiceTests.java @@ -14,87 +14,78 @@ import com.example.demo.users.service.UserService; @SpringBootTest class UserServiceTests { - // @Autowired - // private UserService userService; - // private UserEntity user; + @Autowired + private UserService userService; + private UserEntity user; - // @BeforeEach - // void createData() { - // removeData(); + @BeforeEach + void createData() { + removeData(); - // user = userService.create(new UserEntity("oleg", "tester1", "1234")); - // userService.create(new UserEntity("arthur", "tester2", "123")); - // userService.create(new UserEntity("egor", "tester3", "12345")); - // } + user = userService.create(new UserEntity("tester1", "1234")); + userService.create(new UserEntity("tester2", "123")); + userService.create(new UserEntity("tester3", "12345")); + } - // @AfterEach - // void removeData() { - // userService.getAll().forEach(item -> userService.delete(item.getId())); - // } + @AfterEach + void removeData() { + userService.getAll().forEach(item -> userService.delete(item.getId())); + } - // @Test - // void getTest() { - // Assertions.assertThrows(NotFoundException.class, () -> userService.get(0L)); - // } + @Test + void getTest() { + Assertions.assertThrows(NotFoundException.class, () -> userService.get(0L)); + } - // @Test - // void createTest() { - // Assertions.assertEquals(3, userService.getAll().size()); - // Long id = user.getId(); - // var res = userService.get(user.getId()); - // Assertions.assertEquals(user, userService.get(user.getId())); - // } + @Test + void createTest() { + Assertions.assertEquals(3, userService.getAll().size()); + Long id = user.getId(); + var res = userService.get(user.getId()); + Assertions.assertEquals(user, userService.get(user.getId())); + } - // @Test - // void createNotUniqueHandleTest() { - // final UserEntity nonUniqueHandleUser = new UserEntity("oleg", "tester4", "1234"); - // Assertions.assertThrows(IllegalArgumentException.class, () -> userService.create(nonUniqueHandleUser)); - // } + @Test + void createNotUniqueHandleTest() { + final UserEntity nonUniqueHandleUser = new UserEntity("tester4", "1234"); + Assertions.assertThrows(IllegalArgumentException.class, () -> userService.create(nonUniqueHandleUser)); + } - // @Test - // void createNullableHandleTest() { - // final UserEntity nullableUser = new UserEntity(null, "asads", "asdsad"); - // Assertions.assertThrows(DataIntegrityViolationException.class, () -> userService.create(nullableUser)); - // } + @Test + void createNullableHandleTest() { + final UserEntity nullableUser = new UserEntity("asads", "asdsad"); + Assertions.assertThrows(DataIntegrityViolationException.class, () -> userService.create(nullableUser)); + } - // @Test - // void createNullableEmailTest() { - // final UserEntity nullableUser = new UserEntity("asads", null, "asdsad"); - // Assertions.assertThrows(DataIntegrityViolationException.class, () -> userService.create(nullableUser)); - // } - - // @Test - // void createNullablePassswordTest() { - // final UserEntity nullableUser = new UserEntity("asads", "asads", null); - // Assertions.assertThrows(DataIntegrityViolationException.class, () -> userService.create(nullableUser)); - // } + @Test + void createNullablePassswordTest() { + final UserEntity nullableUser = new UserEntity("asads", null); + Assertions.assertThrows(DataIntegrityViolationException.class, () -> userService.create(nullableUser)); + } - // @Test - // void updateTest() { - // final String test = "TEST"; - // final String oldHandle = user.getHandle(); - // final String oldEmail = user.getEmail(); - // final String oldPassword = user.getPassword(); - // final UserEntity newEntity = userService.update(user.getId(), new UserEntity(test, test,test)); - // Assertions.assertEquals(3, userService.getAll().size()); - // Assertions.assertEquals(newEntity, userService.get(user.getId())); - // Assertions.assertEquals(test, newEntity.getHandle()); - // Assertions.assertEquals(test, newEntity.getEmail()); - // Assertions.assertEquals(test, newEntity.getPassword()); - // Assertions.assertNotEquals(oldHandle, newEntity.getHandle()); - // Assertions.assertNotEquals(oldEmail, newEntity.getEmail()); - // Assertions.assertNotEquals(oldPassword, newEntity.getPassword()); - // } + @Test + void updateTest() { + final String test = "TEST"; + final String oldHandle = user.getLogin(); + final String oldPassword = user.getPassword(); + final UserEntity newEntity = userService.update(user.getId(), new UserEntity(test,test)); + Assertions.assertEquals(3, userService.getAll().size()); + Assertions.assertEquals(newEntity, userService.get(user.getId())); + Assertions.assertEquals(test, newEntity.getLogin()); + Assertions.assertEquals(test, newEntity.getPassword()); + Assertions.assertNotEquals(oldHandle, newEntity.getLogin()); + Assertions.assertNotEquals(oldPassword, newEntity.getPassword()); + } - // @Test - // void deleteTest() { - // userService.delete(user.getId()); - // Assertions.assertEquals(2, userService.getAll().size()); + @Test + void deleteTest() { + userService.delete(user.getId()); + Assertions.assertEquals(2, userService.getAll().size()); - // final UserEntity newEntity = userService.create(new UserEntity(user.getHandle(), user.getEmail(), user.getPassword())); - // Assertions.assertEquals(3, userService.getAll().size()); - // Assertions.assertNotEquals(user.getId(), newEntity.getId()); - // } + final UserEntity newEntity = userService.create(new UserEntity(user.getLogin(), user.getPassword())); + Assertions.assertEquals(3, userService.getAll().size()); + Assertions.assertNotEquals(user.getId(), newEntity.getId()); + } }