Оно не подтгивается
This commit is contained in:
parent
f4f8b32fc7
commit
460bbb0617
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
2006
data.trace.db
Normal file
2006
data.trace.db
Normal file
File diff suppressed because it is too large
Load Diff
BIN
demo/data.mv.db
BIN
demo/data.mv.db
Binary file not shown.
@ -39,21 +39,30 @@ public class DemoApplication implements CommandLineRunner {
|
||||
|
||||
log.info("Create default users values");
|
||||
|
||||
final var user1 = userService.create(new UserEntity(null, "Oleja123", "bebrus@mail.ru", "1234"));
|
||||
final var user2 = userService.create(new UserEntity(null, "Vk1d2004", "berus@mail.ru", "4321"));
|
||||
final var user1 = userService.create(new UserEntity("Oleja123", "bebrus@mail.ru", "1234"));
|
||||
final var user2 = userService.create(new UserEntity("Vk1d2004", "berus@mail.ru", "4321"));
|
||||
|
||||
log.info("Create default groups values");
|
||||
|
||||
final var group1 = groupService.create(user1.getId(), new GroupEntity(null,user1, "1"));
|
||||
final var group2 = groupService.create(user2.getId(), new GroupEntity(null,user2, "2"));
|
||||
final var group3 = groupService.create(user1.getId(), new GroupEntity(null,user1, "3"));
|
||||
final var group1 = groupService.create(user1.getId(), new GroupEntity(user1, "1"));
|
||||
var tmp = user1.getGroups();
|
||||
final var group2 = groupService.create(user2.getId(), new GroupEntity(user2, "2"));
|
||||
final var group3 = groupService.create(user1.getId(), new GroupEntity(user1, "3"));
|
||||
|
||||
log.info("Create default members values");
|
||||
|
||||
final var member1 = memberService.create(group1.getId(), new MemberEntity(null, group1, "mem1", "handle1", "expert"));
|
||||
final var member2 = memberService.create(group1.getId(), new MemberEntity(null, group1, "mem2", "handle2", "expert"));
|
||||
final var member3 = memberService.create(group2.getId(), new MemberEntity(null, group2,"mem3", "handle3", "expert"));
|
||||
final var member1 = memberService.create(group1.getId(), new MemberEntity(group1, "mem1", "handle1", "expert"));
|
||||
final var member2 = memberService.create(group1.getId(), new MemberEntity( group1, "mem2", "handle2", "expert"));
|
||||
final var member3 = memberService.create(group2.getId(), new MemberEntity(group2,"mem3", "handle3", "expert"));
|
||||
|
||||
final var users = userService.getAll();
|
||||
|
||||
for (UserEntity userEntity : users) {
|
||||
var sz = userEntity.getGroups();
|
||||
for (GroupEntity groupEntity : sz) {
|
||||
var kz = groupEntity.getMembers();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
import com.example.demo.core.model.BaseEntity;
|
||||
import com.example.demo.members.model.MemberEntity;
|
||||
import com.example.demo.users.model.UserEntity;
|
||||
@ -11,6 +12,7 @@ import com.example.demo.users.model.UserEntity;
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
@ -19,7 +21,6 @@ import jakarta.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "groups")
|
||||
|
||||
public class GroupEntity extends BaseEntity {
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "userId", nullable = false)
|
||||
@ -33,7 +34,7 @@ public class GroupEntity extends BaseEntity {
|
||||
public GroupEntity() {
|
||||
}
|
||||
|
||||
public GroupEntity(Long id, UserEntity user, String name) {
|
||||
public GroupEntity(UserEntity user, String name) {
|
||||
this.user = user;
|
||||
this.name = name;
|
||||
}
|
||||
@ -44,6 +45,9 @@ public class GroupEntity extends BaseEntity {
|
||||
|
||||
public void setUser(UserEntity user) {
|
||||
this.user = user;
|
||||
if (!user.getGroups().contains(this)) {
|
||||
user.getGroups().add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -65,7 +69,7 @@ public class GroupEntity extends BaseEntity {
|
||||
members.add(member);
|
||||
}
|
||||
|
||||
public void delterMember(MemberEntity member) {
|
||||
public void deleteMember(MemberEntity member) {
|
||||
if (member.getGroup() != this) {
|
||||
return;
|
||||
}
|
||||
|
@ -10,7 +10,5 @@ import com.example.demo.groups.model.GroupEntity;
|
||||
import com.example.demo.groups.model.GroupEntity;
|
||||
|
||||
public interface GroupRepository extends CrudRepository<GroupEntity, Long> {
|
||||
Optional<GroupEntity> findOneById(long id);
|
||||
|
||||
List<GroupEntity> findByUserId(long userId);
|
||||
}
|
@ -28,7 +28,7 @@ public class MemberEntity extends BaseEntity {
|
||||
public MemberEntity() {
|
||||
}
|
||||
|
||||
public MemberEntity(Long id, GroupEntity group, String name, String handle, String rank) {
|
||||
public MemberEntity(GroupEntity group, String name, String handle, String rank) {
|
||||
this.group = group;
|
||||
this.name = name;
|
||||
this.handle = handle;
|
||||
@ -41,6 +41,9 @@ public class MemberEntity extends BaseEntity {
|
||||
|
||||
public void setGroup(GroupEntity group) {
|
||||
this.group = group;
|
||||
if (!group.getMembers().contains(this)) {
|
||||
group.getMembers().add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
@ -4,14 +4,13 @@ import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.GroupLayout.Group;
|
||||
|
||||
import com.example.demo.core.model.BaseEntity;
|
||||
import com.example.demo.groups.model.GroupEntity;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.OrderBy;
|
||||
import jakarta.persistence.Table;
|
||||
@ -32,7 +31,7 @@ public class UserEntity extends BaseEntity{
|
||||
public UserEntity(){
|
||||
}
|
||||
|
||||
public UserEntity(Long id, String handle, String email, String password) {
|
||||
public UserEntity(String handle, String email, String password) {
|
||||
this.handle = handle;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
@ -63,7 +62,7 @@ public class UserEntity extends BaseEntity{
|
||||
}
|
||||
|
||||
public Set<GroupEntity> getGroups() {
|
||||
return groups;
|
||||
return groups;
|
||||
}
|
||||
|
||||
public void addGroup(GroupEntity group) {
|
||||
|
@ -4,6 +4,7 @@ import java.util.Optional;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import com.example.demo.groups.model.GroupEntity;
|
||||
import com.example.demo.users.model.UserEntity;
|
||||
|
||||
public interface UserRepository extends CrudRepository<UserEntity, Long> {
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.example.demo;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -8,6 +10,7 @@ import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.error.NotFoundException;
|
||||
import com.example.demo.groups.model.GroupEntity;
|
||||
@ -18,10 +21,27 @@ import com.example.demo.users.service.UserService;
|
||||
@SpringBootTest
|
||||
@TestMethodOrder(OrderAnnotation.class)
|
||||
class GroupServiceTests {
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
private GroupEntity group;
|
||||
private UserEntity user;
|
||||
|
||||
@BeforeEach
|
||||
void createData() {
|
||||
removeData();
|
||||
|
||||
user = userService.create(new UserEntity("oleg", "tester1", "1234"));
|
||||
group = groupService.create(user.getId(), new GroupEntity(user, "group1"));
|
||||
groupService.create(user.getId(), new GroupEntity(user, "group2"));
|
||||
groupService.create(user.getId(), new GroupEntity(user, "group3"));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void removeData() {
|
||||
userService.getAll().forEach(item -> userService.delete(item.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getTest() {
|
||||
@ -29,41 +49,39 @@ class GroupServiceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createTest() {
|
||||
var user = userService.create(new UserEntity(null, "Oleja123", "bebrus@mail.ru", "1234"));
|
||||
groupService.create(user.getId(), new GroupEntity(null, user, "1"));
|
||||
final GroupEntity last = groupService.create(user.getId(), new GroupEntity(null, user, "2"));
|
||||
Assertions.assertEquals(2, groupService.getAll(1L).size());
|
||||
Assertions.assertEquals(last, groupService.get(2L));
|
||||
Assertions.assertEquals(3, groupService.getAll(user.getId()).size());
|
||||
var res = groupService.get(group.getId());
|
||||
Assertions.assertEquals(group, groupService.get(group.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void updateTest() {
|
||||
final String test = "TEST";
|
||||
final GroupEntity entity = groupService.get(2L);
|
||||
final String oldName = entity.getName();
|
||||
final GroupEntity newEntity = groupService.update(2L, new GroupEntity(null, userService.get(1L), test));
|
||||
Assertions.assertEquals(2, groupService.getAll(1L).size());
|
||||
Assertions.assertEquals(newEntity, groupService.get(2L));
|
||||
Assertions.assertNotEquals(oldName, newEntity.getName());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void deleteTest() {
|
||||
void createNullableTest() {
|
||||
final GroupEntity nullableGroup= new GroupEntity(user, null);
|
||||
Assertions.assertThrows(DataIntegrityViolationException.class, () -> groupService.create(user.getId(), nullableGroup));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void updateTest() {
|
||||
final String test = "TEST";
|
||||
groupService.delete(2L);
|
||||
Assertions.assertEquals(1, groupService.getAll(1L).size());
|
||||
final GroupEntity last = groupService.get(1L);
|
||||
Assertions.assertEquals(1L, last.getId());
|
||||
final UserEntity user = userService.get(1L);
|
||||
final GroupEntity newEntity = groupService.create(user.getId(), new GroupEntity(null, user, test));
|
||||
Assertions.assertEquals(2, groupService.getAll(1L).size());
|
||||
Assertions.assertEquals(3, newEntity.getId());
|
||||
userService.clear();
|
||||
groupService.clear();
|
||||
}
|
||||
final String oldName = group.getName();
|
||||
final GroupEntity newEntity = groupService.update(group.getId(), new GroupEntity(user, 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());
|
||||
|
||||
final GroupEntity newEntity = groupService.create(user.getId(), new GroupEntity(user, group.getName()));
|
||||
Assertions.assertEquals(3, groupService.getAll(user.getId()).size());
|
||||
Assertions.assertNotEquals(group.getId(), newEntity.getId());
|
||||
}
|
||||
}
|
@ -36,10 +36,10 @@ class MemberServiceTests {
|
||||
@Test
|
||||
@Order(1)
|
||||
void createTest() {
|
||||
var user = userService.create(new UserEntity(null, "Oleja123", "bebrus@mail.ru", "1234"));
|
||||
var group = groupService.create(user.getId(), new GroupEntity(null, user, "1"));
|
||||
memberService.create(group.getId(), new MemberEntity(null, group, "1", "1", "1"));
|
||||
var last = memberService.create(group.getId(), new MemberEntity(null, group, "2", "2", "2"));
|
||||
var user = userService.create(new UserEntity("Oleja123", "bebrus@mail.ru", "1234"));
|
||||
var group = groupService.create(user.getId(), new GroupEntity(user, "1"));
|
||||
memberService.create(group.getId(), new MemberEntity(group, "1", "1", "1"));
|
||||
var last = memberService.create(group.getId(), new MemberEntity( group, "2", "2", "2"));
|
||||
Assertions.assertEquals(2, memberService.getAll(1L).size());
|
||||
Assertions.assertEquals(last, memberService.get(2L));
|
||||
}
|
||||
@ -52,7 +52,7 @@ class MemberServiceTests {
|
||||
final String oldName = entity.getName();
|
||||
final String oldHandle = entity.getHandle();
|
||||
final String oldRank = entity.getRank();
|
||||
final MemberEntity newEntity = memberService.update(2L, new MemberEntity(null, groupService.get(1L), test,test,test));
|
||||
final MemberEntity newEntity = memberService.update(2L, new MemberEntity(groupService.get(1L), test,test,test));
|
||||
Assertions.assertEquals(2, memberService.getAll(1L).size());
|
||||
Assertions.assertEquals(newEntity, memberService.get(2L));
|
||||
Assertions.assertNotEquals(oldName, newEntity.getName());
|
||||
@ -69,7 +69,7 @@ class MemberServiceTests {
|
||||
final MemberEntity last = memberService.get(1L);
|
||||
Assertions.assertEquals(1L, last.getId());
|
||||
final GroupEntity group = groupService.get(1L);
|
||||
final MemberEntity newEntity = memberService.create(group.getId(), new MemberEntity(null, group, test,test,test));
|
||||
final MemberEntity newEntity = memberService.create(group.getId(), new MemberEntity(group, test,test,test));
|
||||
Assertions.assertEquals(2, memberService.getAll(1L).size());
|
||||
Assertions.assertEquals(3, newEntity.getId());
|
||||
userService.clear();
|
||||
|
@ -1,23 +1,36 @@
|
||||
package com.example.demo;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.error.NotFoundException;
|
||||
import com.example.demo.users.model.UserEntity;
|
||||
import com.example.demo.users.service.UserService;
|
||||
|
||||
@SpringBootTest
|
||||
@TestMethodOrder(OrderAnnotation.class)
|
||||
class UserServiceTests {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
private UserEntity user;
|
||||
|
||||
@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"));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void removeData() {
|
||||
userService.getAll().forEach(item -> userService.delete(item.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getTest() {
|
||||
@ -25,47 +38,64 @@ class UserServiceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createTest() {
|
||||
userService.create(new UserEntity(null, "Oleja123", "bebrus@mail.ru", "1234"));
|
||||
userService.create(new UserEntity(null, "Vk1d2004", "bebrus2@mail.ru", "12345"));
|
||||
final UserEntity last = userService.create(new UserEntity(null, "Cat_cheshir", "cat@mail.ru", "1234"));
|
||||
Assertions.assertEquals(3, userService.getAll().size());
|
||||
Assertions.assertEquals(last, userService.get(3L));
|
||||
Long id = user.getId();
|
||||
var res = userService.get(user.getId());
|
||||
Assertions.assertEquals(user, userService.get(user.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void updateTest() {
|
||||
final String test = "TEST";
|
||||
final UserEntity entity = userService.get(3L);
|
||||
final String oldEmail = entity.getEmail();
|
||||
final String oldHandle = entity.getHandle();
|
||||
final String oldPassword = entity.getPassword();
|
||||
final UserEntity newEntity = userService.update(3L, new UserEntity(null, test, test, test));
|
||||
Assertions.assertEquals(3, userService.getAll().size());
|
||||
Assertions.assertEquals(newEntity, userService.get(3L));
|
||||
Assertions.assertEquals(test, newEntity.getEmail());
|
||||
void createNotUniqueHandleTest() {
|
||||
final UserEntity nonUniqueHandleUser = new UserEntity("oleg", "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 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 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.getPassword());
|
||||
Assertions.assertNotEquals(oldEmail, newEntity.getEmail());
|
||||
Assertions.assertEquals(test, newEntity.getEmail());
|
||||
Assertions.assertEquals(test, newEntity.getPassword());
|
||||
Assertions.assertNotEquals(oldHandle, newEntity.getHandle());
|
||||
Assertions.assertNotEquals(oldPassword, newEntity.getPassword());
|
||||
Assertions.assertNotEquals(oldEmail, newEntity.getEmail());
|
||||
Assertions.assertNotEquals(oldPassword, newEntity.getPassword());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteTest() {
|
||||
userService.delete(user.getId());
|
||||
Assertions.assertEquals(2, userService.getAll().size());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void deleteTest() {
|
||||
userService.delete(3L);
|
||||
Assertions.assertEquals(2, userService.getAll().size());
|
||||
final UserEntity last = userService.get(2L);
|
||||
Assertions.assertEquals(2L, last.getId());
|
||||
|
||||
final UserEntity newEntity = userService.create(new UserEntity(null, "Cat_cheshir", "cat@mail.ru", "1234"));
|
||||
Assertions.assertEquals(3, userService.getAll().size());
|
||||
Assertions.assertEquals(4L, newEntity.getId());
|
||||
userService.clear();
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user