#104 removePaper, addPaper, takePart fixed

This commit is contained in:
Nightblade73 2019-05-16 15:35:32 +04:00
parent ce7b4c9c7a
commit c0937d721a
2 changed files with 61 additions and 23 deletions

View File

@ -29,6 +29,7 @@ import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
@ -264,4 +265,30 @@ public class Paper extends BaseEntity implements UserContainer {
.findAny() .findAny()
.isPresent(); .isPresent();
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
Paper paper = (Paper) o;
return Objects.equals(title, paper.title) &&
status == paper.status &&
type == paper.type &&
Objects.equals(deadlines, paper.deadlines) &&
Objects.equals(comment, paper.comment) &&
Objects.equals(url, paper.url) &&
Objects.equals(locked, paper.locked) &&
Objects.equals(events, paper.events) &&
Objects.equals(files, paper.files) &&
Objects.equals(authors, paper.authors) &&
Objects.equals(latexText, paper.latexText) &&
Objects.equals(conferences, paper.conferences) &&
Objects.equals(grants, paper.grants);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), title, status, type, createDate, updateDate, deadlines, comment, url, locked, events, files, authors, latexText, conferences, grants);
}
} }

View File

@ -62,7 +62,9 @@ public class ConferenceServiceTest {
ConferenceService conferenceService; ConferenceService conferenceService;
private final Integer ID = 1; private final Integer ID = 1;
private final Integer ROMOVE_INDEX = 0; private final Integer INDEX = 0;
private final String NAME = "Name";
private final boolean DISABLED = true;
private List<Conference> conferences; private List<Conference> conferences;
private List<Deadline> deadlines; private List<Deadline> deadlines;
@ -76,6 +78,7 @@ public class ConferenceServiceTest {
private ConferenceDto conferenceDto; private ConferenceDto conferenceDto;
private User user; private User user;
private Deadline deadline;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -83,8 +86,8 @@ public class ConferenceServiceTest {
conferenceWithId = new Conference(); conferenceWithId = new Conference();
Conference conferenceWithoutId = new Conference(); Conference conferenceWithoutId = new Conference();
conferenceWithId.setId(1); conferenceWithId.setId(ID);
conferenceWithId.setTitle("Название"); conferenceWithId.setTitle(NAME);
conferenceWithId.setDescription("Описание"); conferenceWithId.setDescription("Описание");
conferenceWithoutId.setTitle("Название"); conferenceWithoutId.setTitle("Название");
@ -92,37 +95,31 @@ public class ConferenceServiceTest {
paperWithId = new Paper(); paperWithId = new Paper();
paperWithId.setId(1); paperWithId.setId(1);
paperWithId.setTitle("paperTitle"); paperWithId.setTitle(NAME);
paperWithoutId = new Paper(); paperWithoutId = new Paper();
paperWithoutId.setTitle("paperTitleNoId"); paperWithoutId.setTitle(NAME);
papers = new ArrayList<>(); papers = new ArrayList<>();
papers.add(paperWithId); papers.add(paperWithId);
papers.add(paperWithoutId); papers.add(paperWithoutId);
deadlines = new ArrayList<>(); deadlines = new ArrayList<>();
Deadline deadline = new Deadline(new Date(), "desc"); deadline = new Deadline(new Date(), "desc");
deadline.setId(1); deadline.setId(ID);
deadlines.add(deadline); deadlines.add(deadline);
ConferenceUser conferenceUser = new ConferenceUser(); ConferenceUser conferenceUser = new ConferenceUser();
conferenceUser.setDeposit(ConferenceUser.Deposit.ARTICLE); conferenceUser.setDeposit(ConferenceUser.Deposit.ARTICLE);
conferenceUser.setParticipation(ConferenceUser.Participation.INTRAMURAL); conferenceUser.setParticipation(ConferenceUser.Participation.INTRAMURAL);
user = new User(); user = new User();
user.setFirstName("Name"); user.setFirstName(NAME);
conferenceUser.setUser(user); conferenceUser.setUser(user);
conferenceUsers = new ArrayList<>(); conferenceUsers = new ArrayList<>();
conferenceUsers.add(conferenceUser); conferenceUsers.add(conferenceUser);
conferenceWithId.setPapers(papers);
conferenceWithId.setDeadlines(deadlines);
conferenceWithId.setUsers(conferenceUsers);
conferenceWithoutId.setPapers(papers);
conferenceWithoutId.setDeadlines(deadlines);
conferenceWithoutId.setUsers(conferenceUsers);
conferences.add(conferenceWithId); conferences.add(conferenceWithId);
conferenceDto = new ConferenceDto(conferenceWithId); conferenceDto = new ConferenceDto(conferenceWithId);
@ -184,37 +181,52 @@ public class ConferenceServiceTest {
ConferenceDto newConferenceDto = new ConferenceDto(); ConferenceDto newConferenceDto = new ConferenceDto();
newConferenceDto.getDeadlines().add(new Deadline()); newConferenceDto.getDeadlines().add(new Deadline());
conferenceDto.getDeadlines().clear(); conferenceDto.getDeadlines().clear();
assertEquals(newConferenceDto.getDeadlines(), conferenceService.addDeadline(conferenceDto).getDeadlines()); assertEquals(newConferenceDto.getDeadlines().get(0), conferenceService.addDeadline(conferenceDto).getDeadlines().get(0));
} }
@Test @Test
public void removeDeadline() throws IOException { public void removeDeadline() throws IOException {
ConferenceDto newConferenceDto = new ConferenceDto(); ConferenceDto newConferenceDto = new ConferenceDto();
newConferenceDto.getRemovedDeadlineIds().add(ID); newConferenceDto.getRemovedDeadlineIds().add(ID);
ConferenceDto result = conferenceService.removeDeadline(conferenceDto, ROMOVE_INDEX); conferenceDto.getDeadlines().add(deadline);
ConferenceDto result = conferenceService.removeDeadline(conferenceDto, INDEX);
assertEquals(newConferenceDto.getDeadlines(), result.getDeadlines()); assertEquals(newConferenceDto.getDeadlines(), result.getDeadlines());
assertEquals(newConferenceDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds()); assertEquals(newConferenceDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds());
} }
@Test @Test
public void addPaper() { public void addPaper() {
ConferenceDto newConferenceDto = new ConferenceDto();
newConferenceDto.getPapers().add(paperWithoutId);
conferenceDto.getPapers().clear();
when(userService.getCurrentUser()).thenReturn(user); when(userService.getCurrentUser()).thenReturn(user);
ConferenceDto newConferenceDto = conferenceService.addPaper(conferenceDto); ConferenceDto result = conferenceService.addPaper(conferenceDto);
assertEquals(conferenceDto, newConferenceDto); result.getPapers().get(INDEX).setTitle(NAME); // приходится вручную назначать название, т.е. название зависит от даты
assertEquals(newConferenceDto.getPapers(), result.getPapers());
} }
@Test @Test
public void removePaper() throws IOException { public void removePaper() throws IOException {
ConferenceDto newConferenceDto = conferenceService.removePaper(conferenceDto, ROMOVE_INDEX); ConferenceDto newConferenceDto = new ConferenceDto();
assertEquals(conferenceDto, newConferenceDto); newConferenceDto.getNotSelectedPapers().add(paperWithId);
newConferenceDto.getPapers().add(paperWithoutId);
conferenceDto.getPapers().add(paperWithId);
conferenceDto.getPapers().add(paperWithoutId);
ConferenceDto result = conferenceService.removePaper(conferenceDto, INDEX);
assertEquals(newConferenceDto.getPapers(), result.getPapers());
assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers());
} }
@Test @Test
public void takePart() throws IOException { public void takePart() throws IOException {
when(userService.getCurrentUser()).thenReturn(user); when(userService.getCurrentUser()).thenReturn(user);
ConferenceDto newConferenceDto = new ConferenceDto(); ConferenceDto newConferenceDto = new ConferenceDto();
conferenceService.takePart(newConferenceDto); newConferenceDto.setUsers(conferenceUsers);
assertEquals(newConferenceDto.getUsers(), conferenceDto.getUsers()); newConferenceDto.setDisabledTakePart(DISABLED);
conferenceDto.getPapers().clear();
ConferenceDto result = conferenceService.takePart(conferenceDto);
assertEquals(newConferenceDto.getUsers(), result.getUsers());
assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart());
} }
@Test @Test
@ -224,7 +236,6 @@ public class ConferenceServiceTest {
assertEquals(users, conferenceService.getAllUsers()); assertEquals(users, conferenceService.getAllUsers());
} }
@Test @Test
public void filter() { public void filter() {
ConferenceFilterDto conferenceFilterDto = new ConferenceFilterDto(); ConferenceFilterDto conferenceFilterDto = new ConferenceFilterDto();