фиксы
This commit is contained in:
parent
460bbb0617
commit
a7366ae96a
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
BIN
demo/data.mv.db
Normal file
BIN
demo/data.mv.db
Normal file
Binary file not shown.
1071
demo/data.trace.db
Normal file
1071
demo/data.trace.db
Normal file
File diff suppressed because it is too large
Load Diff
@ -44,25 +44,16 @@ public class DemoApplication implements CommandLineRunner {
|
|||||||
|
|
||||||
log.info("Create default groups values");
|
log.info("Create default groups values");
|
||||||
|
|
||||||
final var group1 = groupService.create(user1.getId(), new GroupEntity(user1, "1"));
|
final var group1 = groupService.create(user1.getId(), new GroupEntity("1"));
|
||||||
var tmp = user1.getGroups();
|
var tmp = user1.getGroups();
|
||||||
final var group2 = groupService.create(user2.getId(), new GroupEntity(user2, "2"));
|
final var group2 = groupService.create(user2.getId(), new GroupEntity("2"));
|
||||||
final var group3 = groupService.create(user1.getId(), new GroupEntity(user1, "3"));
|
final var group3 = groupService.create(user1.getId(), new GroupEntity("3"));
|
||||||
|
|
||||||
log.info("Create default members values");
|
log.info("Create default members values");
|
||||||
|
|
||||||
final var member1 = memberService.create(group1.getId(), new MemberEntity(group1, "mem1", "handle1", "expert"));
|
final var member1 = memberService.create(group1.getId(), new MemberEntity("mem1", "handle1", "expert"));
|
||||||
final var member2 = memberService.create(group1.getId(), new MemberEntity( group1, "mem2", "handle2", "expert"));
|
final var member2 = memberService.create(group1.getId(), new MemberEntity( "mem2", "handle2", "expert"));
|
||||||
final var member3 = memberService.create(group2.getId(), new MemberEntity(group2,"mem3", "handle3", "expert"));
|
final var member3 = memberService.create(group2.getId(), new MemberEntity("mem3", "handle3", "expert"));
|
||||||
|
|
||||||
final var users = userService.getAll();
|
|
||||||
|
|
||||||
for (UserEntity userEntity : users) {
|
|
||||||
var sz = userEntity.getGroups();
|
|
||||||
for (GroupEntity groupEntity : sz) {
|
|
||||||
var kz = groupEntity.getMembers();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,6 @@ public class GroupController {
|
|||||||
|
|
||||||
private GroupEntity toEntity(GroupDto dto) {
|
private GroupEntity toEntity(GroupDto dto) {
|
||||||
final GroupEntity entity = modelMapper.map(dto, GroupEntity.class);
|
final GroupEntity entity = modelMapper.map(dto, GroupEntity.class);
|
||||||
entity.setUser(userService.get(dto.getUserId()));
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,9 +9,6 @@ import jakarta.validation.constraints.NotNull;
|
|||||||
public class GroupDto {
|
public class GroupDto {
|
||||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
private Long id;
|
private Long id;
|
||||||
@NotNull
|
|
||||||
@Min(1)
|
|
||||||
private Long userId;
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ -23,14 +20,6 @@ public class GroupDto {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getUserId() {
|
|
||||||
return userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserId(Long userId) {
|
|
||||||
this.userId = userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,7 @@ public class GroupEntity extends BaseEntity {
|
|||||||
public GroupEntity() {
|
public GroupEntity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public GroupEntity(UserEntity user, String name) {
|
public GroupEntity(String name) {
|
||||||
this.user = user;
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,8 +88,6 @@ public class GroupEntity extends BaseEntity {
|
|||||||
return false;
|
return false;
|
||||||
final GroupEntity other = (GroupEntity) obj;
|
final GroupEntity other = (GroupEntity) obj;
|
||||||
return Objects.equals(other.getId(), id)
|
return Objects.equals(other.getId(), id)
|
||||||
&& Objects.equals(other.getName(), name)
|
&& Objects.equals(other.getName(), name);
|
||||||
&& Objects.equals(other.getUser(), user)
|
|
||||||
&& Objects.equals(other.getMembers(), members);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,6 @@ public class MemberController {
|
|||||||
|
|
||||||
private MemberEntity toEntity(MemberDto dto) {
|
private MemberEntity toEntity(MemberDto dto) {
|
||||||
final MemberEntity entity = modelMapper.map(dto, MemberEntity.class);
|
final MemberEntity entity = modelMapper.map(dto, MemberEntity.class);
|
||||||
entity.setGroup(groupService.get(dto.getGroupId()));
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,8 +53,8 @@ public class MemberController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public MemberDto create(@RequestBody @Valid MemberDto dto) {
|
public MemberDto create(@PathVariable(name = "group") Long groupId, @RequestBody @Valid MemberDto dto) {
|
||||||
return toDto(memberService.create(dto.getGroupId(), toEntity(dto)));
|
return toDto(memberService.create(groupId, toEntity(dto)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
|
@ -9,9 +9,6 @@ import jakarta.validation.constraints.NotNull;
|
|||||||
public class MemberDto {
|
public class MemberDto {
|
||||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
private Long id;
|
private Long id;
|
||||||
@NotNull
|
|
||||||
@Min(1)
|
|
||||||
private Long groupId;
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String name;
|
private String name;
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@ -27,14 +24,6 @@ public class MemberDto {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getGroupId() {
|
|
||||||
return groupId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGroupId(Long groupId) {
|
|
||||||
this.groupId = groupId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHandle() {
|
public String getHandle() {
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import com.example.demo.users.model.UserEntity;
|
|||||||
|
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
@ -28,8 +29,7 @@ public class MemberEntity extends BaseEntity {
|
|||||||
public MemberEntity() {
|
public MemberEntity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MemberEntity(GroupEntity group, String name, String handle, String rank) {
|
public MemberEntity(String name, String handle, String rank) {
|
||||||
this.group = group;
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
this.rank = rank;
|
this.rank = rank;
|
||||||
@ -83,7 +83,6 @@ public class MemberEntity extends BaseEntity {
|
|||||||
return false;
|
return false;
|
||||||
final MemberEntity other = (MemberEntity) obj;
|
final MemberEntity other = (MemberEntity) obj;
|
||||||
return Objects.equals(other.getId(), id)
|
return Objects.equals(other.getId(), id)
|
||||||
&& Objects.equals(other.getGroup(), group)
|
|
||||||
&& Objects.equals(other.getName(), name)
|
&& Objects.equals(other.getName(), name)
|
||||||
&& Objects.equals(other.getHandle(), handle)
|
&& Objects.equals(other.getHandle(), handle)
|
||||||
&& Objects.equals(other.getRank(), rank);
|
&& Objects.equals(other.getRank(), rank);
|
||||||
|
@ -94,8 +94,7 @@ public class UserEntity extends BaseEntity{
|
|||||||
return Objects.equals(other.getId(), id)
|
return Objects.equals(other.getId(), id)
|
||||||
&& Objects.equals(other.getHandle(), handle)
|
&& Objects.equals(other.getHandle(), handle)
|
||||||
&& Objects.equals(other.getEmail(), email)
|
&& Objects.equals(other.getEmail(), email)
|
||||||
&& Objects.equals(other.getPassword(), password)
|
&& Objects.equals(other.getPassword(), password);
|
||||||
&& Objects.equals(other.getGroups(), groups);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,9 @@ class GroupServiceTests {
|
|||||||
removeData();
|
removeData();
|
||||||
|
|
||||||
user = userService.create(new UserEntity("oleg", "tester1", "1234"));
|
user = userService.create(new UserEntity("oleg", "tester1", "1234"));
|
||||||
group = groupService.create(user.getId(), new GroupEntity(user, "group1"));
|
groupService.create(user.getId(), new GroupEntity("group1"));
|
||||||
groupService.create(user.getId(), new GroupEntity(user, "group2"));
|
groupService.create(user.getId(), new GroupEntity("group2"));
|
||||||
groupService.create(user.getId(), new GroupEntity(user, "group3"));
|
group = groupService.create(user.getId(), new GroupEntity("group3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
@ -58,7 +58,7 @@ class GroupServiceTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createNullableTest() {
|
void createNullableTest() {
|
||||||
final GroupEntity nullableGroup= new GroupEntity(user, null);
|
final GroupEntity nullableGroup= new GroupEntity(null);
|
||||||
Assertions.assertThrows(DataIntegrityViolationException.class, () -> groupService.create(user.getId(), nullableGroup));
|
Assertions.assertThrows(DataIntegrityViolationException.class, () -> groupService.create(user.getId(), nullableGroup));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ class GroupServiceTests {
|
|||||||
void updateTest() {
|
void updateTest() {
|
||||||
final String test = "TEST";
|
final String test = "TEST";
|
||||||
final String oldName = group.getName();
|
final String oldName = group.getName();
|
||||||
final GroupEntity newEntity = groupService.update(group.getId(), new GroupEntity(user, test));
|
final GroupEntity newEntity = groupService.update(group.getId(), new GroupEntity(test));
|
||||||
Assertions.assertEquals(3, groupService.getAll(user.getId()).size());
|
Assertions.assertEquals(3, groupService.getAll(user.getId()).size());
|
||||||
Assertions.assertEquals(newEntity, groupService.get(group.getId()));
|
Assertions.assertEquals(newEntity, groupService.get(group.getId()));
|
||||||
Assertions.assertEquals(test, newEntity.getName());
|
Assertions.assertEquals(test, newEntity.getName());
|
||||||
@ -80,7 +80,7 @@ class GroupServiceTests {
|
|||||||
groupService.delete(group.getId());
|
groupService.delete(group.getId());
|
||||||
Assertions.assertEquals(2, groupService.getAll(user.getId()).size());
|
Assertions.assertEquals(2, groupService.getAll(user.getId()).size());
|
||||||
|
|
||||||
final GroupEntity newEntity = groupService.create(user.getId(), new GroupEntity(user, group.getName()));
|
final GroupEntity newEntity = groupService.create(user.getId(), new GroupEntity(group.getName()));
|
||||||
Assertions.assertEquals(3, groupService.getAll(user.getId()).size());
|
Assertions.assertEquals(3, groupService.getAll(user.getId()).size());
|
||||||
Assertions.assertNotEquals(group.getId(), newEntity.getId());
|
Assertions.assertNotEquals(group.getId(), newEntity.getId());
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
package com.example.demo;
|
package com.example.demo;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||||
|
import org.modelmapper.spi.ValueReader.Member;
|
||||||
import org.junit.jupiter.api.Order;
|
import org.junit.jupiter.api.Order;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.security.SecurityProperties.User;
|
import org.springframework.boot.autoconfigure.security.SecurityProperties.User;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
|
|
||||||
import com.example.demo.core.error.NotFoundException;
|
import com.example.demo.core.error.NotFoundException;
|
||||||
import com.example.demo.groups.model.GroupEntity;
|
import com.example.demo.groups.model.GroupEntity;
|
||||||
@ -26,7 +30,25 @@ class MemberServiceTests {
|
|||||||
private GroupService groupService;
|
private GroupService groupService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private MemberService memberService;
|
private MemberService memberService;
|
||||||
|
private MemberEntity member;
|
||||||
|
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("group1"));
|
||||||
|
member = memberService.create(group.getId(), new MemberEntity("member1", "mem1","expert"));
|
||||||
|
memberService.create(group.getId(), new MemberEntity("member1", "mem1","expert"));
|
||||||
|
memberService.create(group.getId(), new MemberEntity("member1", "mem1","expert"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void removeData() {
|
||||||
|
userService.getAll().forEach(item -> userService.delete(item.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getTest() {
|
void getTest() {
|
||||||
@ -34,46 +56,43 @@ class MemberServiceTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
|
||||||
void createTest() {
|
void createTest() {
|
||||||
var user = userService.create(new UserEntity("Oleja123", "bebrus@mail.ru", "1234"));
|
Assertions.assertEquals(3, memberService.getAll(group.getId()).size());
|
||||||
var group = groupService.create(user.getId(), new GroupEntity(user, "1"));
|
Assertions.assertEquals(member, memberService.get(member.getId()));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createNullableTest() {
|
||||||
|
final MemberEntity nullableMember= new MemberEntity(null, null, null);
|
||||||
|
Assertions.assertThrows(DataIntegrityViolationException.class, () -> memberService.create(group.getId(), nullableMember));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
|
||||||
void updateTest() {
|
void updateTest() {
|
||||||
final String test = "TEST";
|
final String test = "TEST";
|
||||||
final MemberEntity entity = memberService.get(2L);
|
final String oldName = member.getName();
|
||||||
final String oldName = entity.getName();
|
final String oldHandle = member.getHandle();
|
||||||
final String oldHandle = entity.getHandle();
|
final String oldRank = member.getRank();
|
||||||
final String oldRank = entity.getRank();
|
final MemberEntity newEntity = memberService.update(member.getId(), new MemberEntity(test, test, test));
|
||||||
final MemberEntity newEntity = memberService.update(2L, new MemberEntity(groupService.get(1L), test,test,test));
|
Assertions.assertEquals(3, memberService.getAll(group.getId()).size());
|
||||||
Assertions.assertEquals(2, memberService.getAll(1L).size());
|
Assertions.assertEquals(newEntity, memberService.get(member.getId()));
|
||||||
Assertions.assertEquals(newEntity, memberService.get(2L));
|
Assertions.assertEquals(test, newEntity.getName());
|
||||||
|
Assertions.assertEquals(test, newEntity.getHandle());
|
||||||
|
Assertions.assertEquals(test, newEntity.getRank());
|
||||||
Assertions.assertNotEquals(oldName, newEntity.getName());
|
Assertions.assertNotEquals(oldName, newEntity.getName());
|
||||||
Assertions.assertNotEquals(oldHandle, newEntity.getHandle());
|
Assertions.assertNotEquals(oldHandle, newEntity.getHandle());
|
||||||
Assertions.assertNotEquals(oldRank, newEntity.getRank());
|
Assertions.assertNotEquals(oldRank, newEntity.getRank());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(3)
|
|
||||||
void deleteTest() {
|
void deleteTest() {
|
||||||
final String test = "TEST";
|
memberService.delete(member.getId());
|
||||||
memberService.delete(2L);
|
Assertions.assertEquals(2, memberService.getAll(group.getId()).size());
|
||||||
Assertions.assertEquals(1, memberService.getAll(1L).size());
|
|
||||||
final MemberEntity last = memberService.get(1L);
|
final MemberEntity newEntity = memberService.create(group.getId(), new MemberEntity(member.getName(), member.getHandle(), member.getRank()));
|
||||||
Assertions.assertEquals(1L, last.getId());
|
Assertions.assertEquals(3, memberService.getAll(group.getId()).size());
|
||||||
final GroupEntity group = groupService.get(1L);
|
Assertions.assertNotEquals(member.getId(), newEntity.getId());
|
||||||
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();
|
|
||||||
groupService.clear();
|
|
||||||
memberService.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user