фиксы
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");
|
||||
|
||||
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();
|
||||
final var group2 = groupService.create(user2.getId(), new GroupEntity(user2, "2"));
|
||||
final var group3 = groupService.create(user1.getId(), new GroupEntity(user1, "3"));
|
||||
final var group2 = groupService.create(user2.getId(), new GroupEntity("2"));
|
||||
final var group3 = groupService.create(user1.getId(), new GroupEntity("3"));
|
||||
|
||||
log.info("Create default members values");
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
final var member1 = memberService.create(group1.getId(), new MemberEntity("mem1", "handle1", "expert"));
|
||||
final var member2 = memberService.create(group1.getId(), new MemberEntity( "mem2", "handle2", "expert"));
|
||||
final var member3 = memberService.create(group2.getId(), new MemberEntity("mem3", "handle3", "expert"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ public class GroupController {
|
||||
|
||||
private GroupEntity toEntity(GroupDto dto) {
|
||||
final GroupEntity entity = modelMapper.map(dto, GroupEntity.class);
|
||||
entity.setUser(userService.get(dto.getUserId()));
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,6 @@ import jakarta.validation.constraints.NotNull;
|
||||
public class GroupDto {
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
private Long id;
|
||||
@NotNull
|
||||
@Min(1)
|
||||
private Long userId;
|
||||
@NotBlank
|
||||
private String name;
|
||||
|
||||
@ -23,14 +20,6 @@ public class GroupDto {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -34,8 +34,7 @@ public class GroupEntity extends BaseEntity {
|
||||
public GroupEntity() {
|
||||
}
|
||||
|
||||
public GroupEntity(UserEntity user, String name) {
|
||||
this.user = user;
|
||||
public GroupEntity(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ -89,8 +88,6 @@ public class GroupEntity extends BaseEntity {
|
||||
return false;
|
||||
final GroupEntity other = (GroupEntity) obj;
|
||||
return Objects.equals(other.getId(), id)
|
||||
&& Objects.equals(other.getName(), name)
|
||||
&& Objects.equals(other.getUser(), user)
|
||||
&& Objects.equals(other.getMembers(), members);
|
||||
&& Objects.equals(other.getName(), name);
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ public class MemberController {
|
||||
|
||||
private MemberEntity toEntity(MemberDto dto) {
|
||||
final MemberEntity entity = modelMapper.map(dto, MemberEntity.class);
|
||||
entity.setGroup(groupService.get(dto.getGroupId()));
|
||||
return entity;
|
||||
}
|
||||
|
||||
@ -54,8 +53,8 @@ public class MemberController {
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public MemberDto create(@RequestBody @Valid MemberDto dto) {
|
||||
return toDto(memberService.create(dto.getGroupId(), toEntity(dto)));
|
||||
public MemberDto create(@PathVariable(name = "group") Long groupId, @RequestBody @Valid MemberDto dto) {
|
||||
return toDto(memberService.create(groupId, toEntity(dto)));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
|
@ -9,9 +9,6 @@ import jakarta.validation.constraints.NotNull;
|
||||
public class MemberDto {
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
private Long id;
|
||||
@NotNull
|
||||
@Min(1)
|
||||
private Long groupId;
|
||||
@NotBlank
|
||||
private String name;
|
||||
@NotBlank
|
||||
@ -27,14 +24,6 @@ public class MemberDto {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(Long groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public String getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.example.demo.users.model.UserEntity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
@ -28,8 +29,7 @@ public class MemberEntity extends BaseEntity {
|
||||
public MemberEntity() {
|
||||
}
|
||||
|
||||
public MemberEntity(GroupEntity group, String name, String handle, String rank) {
|
||||
this.group = group;
|
||||
public MemberEntity(String name, String handle, String rank) {
|
||||
this.name = name;
|
||||
this.handle = handle;
|
||||
this.rank = rank;
|
||||
@ -83,7 +83,6 @@ public class MemberEntity extends BaseEntity {
|
||||
return false;
|
||||
final MemberEntity other = (MemberEntity) obj;
|
||||
return Objects.equals(other.getId(), id)
|
||||
&& Objects.equals(other.getGroup(), group)
|
||||
&& Objects.equals(other.getName(), name)
|
||||
&& Objects.equals(other.getHandle(), handle)
|
||||
&& Objects.equals(other.getRank(), rank);
|
||||
|
@ -94,8 +94,7 @@ public class UserEntity extends BaseEntity{
|
||||
return Objects.equals(other.getId(), id)
|
||||
&& Objects.equals(other.getHandle(), handle)
|
||||
&& Objects.equals(other.getEmail(), email)
|
||||
&& Objects.equals(other.getPassword(), password)
|
||||
&& Objects.equals(other.getGroups(), groups);
|
||||
&& Objects.equals(other.getPassword(), password);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ class GroupServiceTests {
|
||||
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"));
|
||||
groupService.create(user.getId(), new GroupEntity("group1"));
|
||||
groupService.create(user.getId(), new GroupEntity("group2"));
|
||||
group = groupService.create(user.getId(), new GroupEntity("group3"));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@ -58,7 +58,7 @@ class GroupServiceTests {
|
||||
|
||||
@Test
|
||||
void createNullableTest() {
|
||||
final GroupEntity nullableGroup= new GroupEntity(user, null);
|
||||
final GroupEntity nullableGroup= new GroupEntity(null);
|
||||
Assertions.assertThrows(DataIntegrityViolationException.class, () -> groupService.create(user.getId(), nullableGroup));
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ class GroupServiceTests {
|
||||
void updateTest() {
|
||||
final String test = "TEST";
|
||||
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(newEntity, groupService.get(group.getId()));
|
||||
Assertions.assertEquals(test, newEntity.getName());
|
||||
@ -80,7 +80,7 @@ class GroupServiceTests {
|
||||
groupService.delete(group.getId());
|
||||
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.assertNotEquals(group.getId(), newEntity.getId());
|
||||
}
|
||||
|
@ -1,13 +1,17 @@
|
||||
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.modelmapper.spi.ValueReader.Member;
|
||||
import org.junit.jupiter.api.Order;
|
||||
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.groups.model.GroupEntity;
|
||||
@ -26,7 +30,25 @@ class MemberServiceTests {
|
||||
private GroupService groupService;
|
||||
@Autowired
|
||||
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
|
||||
void getTest() {
|
||||
@ -34,46 +56,43 @@ class MemberServiceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createTest() {
|
||||
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));
|
||||
Assertions.assertEquals(3, memberService.getAll(group.getId()).size());
|
||||
Assertions.assertEquals(member, memberService.get(member.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void updateTest() {
|
||||
final String test = "TEST";
|
||||
final MemberEntity entity = memberService.get(2L);
|
||||
final String oldName = entity.getName();
|
||||
final String oldHandle = entity.getHandle();
|
||||
final String oldRank = entity.getRank();
|
||||
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());
|
||||
Assertions.assertNotEquals(oldHandle, newEntity.getHandle());
|
||||
Assertions.assertNotEquals(oldRank, newEntity.getRank());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void deleteTest() {
|
||||
void createNullableTest() {
|
||||
final MemberEntity nullableMember= new MemberEntity(null, null, null);
|
||||
Assertions.assertThrows(DataIntegrityViolationException.class, () -> memberService.create(group.getId(), nullableMember));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void updateTest() {
|
||||
final String test = "TEST";
|
||||
memberService.delete(2L);
|
||||
Assertions.assertEquals(1, memberService.getAll(1L).size());
|
||||
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(group, test,test,test));
|
||||
Assertions.assertEquals(2, memberService.getAll(1L).size());
|
||||
Assertions.assertEquals(3, newEntity.getId());
|
||||
userService.clear();
|
||||
groupService.clear();
|
||||
memberService.clear();
|
||||
}
|
||||
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));
|
||||
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 deleteTest() {
|
||||
memberService.delete(member.getId());
|
||||
Assertions.assertEquals(2, memberService.getAll(group.getId()).size());
|
||||
|
||||
final MemberEntity newEntity = memberService.create(group.getId(), new MemberEntity(member.getName(), member.getHandle(), member.getRank()));
|
||||
Assertions.assertEquals(3, memberService.getAll(group.getId()).size());
|
||||
Assertions.assertNotEquals(member.getId(), newEntity.getId());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user