Пофиксил тесты
This commit is contained in:
parent
17f70e4061
commit
0fa5ae0f6c
BIN
demo/data.mv.db
BIN
demo/data.mv.db
Binary file not shown.
@ -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());
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user