#104 removePaper, addPaper, takePart fixed
This commit is contained in:
parent
ce7b4c9c7a
commit
c0937d721a
@ -29,6 +29,7 @@ import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@ -264,4 +265,30 @@ public class Paper extends BaseEntity implements UserContainer {
|
||||
.findAny()
|
||||
.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);
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,9 @@ public class ConferenceServiceTest {
|
||||
ConferenceService conferenceService;
|
||||
|
||||
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<Deadline> deadlines;
|
||||
@ -76,6 +78,7 @@ public class ConferenceServiceTest {
|
||||
|
||||
private ConferenceDto conferenceDto;
|
||||
private User user;
|
||||
private Deadline deadline;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@ -83,8 +86,8 @@ public class ConferenceServiceTest {
|
||||
conferenceWithId = new Conference();
|
||||
Conference conferenceWithoutId = new Conference();
|
||||
|
||||
conferenceWithId.setId(1);
|
||||
conferenceWithId.setTitle("Название");
|
||||
conferenceWithId.setId(ID);
|
||||
conferenceWithId.setTitle(NAME);
|
||||
conferenceWithId.setDescription("Описание");
|
||||
|
||||
conferenceWithoutId.setTitle("Название");
|
||||
@ -92,37 +95,31 @@ public class ConferenceServiceTest {
|
||||
|
||||
paperWithId = new Paper();
|
||||
paperWithId.setId(1);
|
||||
paperWithId.setTitle("paperTitle");
|
||||
paperWithId.setTitle(NAME);
|
||||
|
||||
paperWithoutId = new Paper();
|
||||
paperWithoutId.setTitle("paperTitleNoId");
|
||||
paperWithoutId.setTitle(NAME);
|
||||
|
||||
papers = new ArrayList<>();
|
||||
papers.add(paperWithId);
|
||||
papers.add(paperWithoutId);
|
||||
|
||||
deadlines = new ArrayList<>();
|
||||
Deadline deadline = new Deadline(new Date(), "desc");
|
||||
deadline.setId(1);
|
||||
deadline = new Deadline(new Date(), "desc");
|
||||
deadline.setId(ID);
|
||||
deadlines.add(deadline);
|
||||
|
||||
ConferenceUser conferenceUser = new ConferenceUser();
|
||||
conferenceUser.setDeposit(ConferenceUser.Deposit.ARTICLE);
|
||||
conferenceUser.setParticipation(ConferenceUser.Participation.INTRAMURAL);
|
||||
user = new User();
|
||||
user.setFirstName("Name");
|
||||
user.setFirstName(NAME);
|
||||
conferenceUser.setUser(user);
|
||||
|
||||
conferenceUsers = new ArrayList<>();
|
||||
conferenceUsers.add(conferenceUser);
|
||||
|
||||
conferenceWithId.setPapers(papers);
|
||||
conferenceWithId.setDeadlines(deadlines);
|
||||
conferenceWithId.setUsers(conferenceUsers);
|
||||
|
||||
conferenceWithoutId.setPapers(papers);
|
||||
conferenceWithoutId.setDeadlines(deadlines);
|
||||
conferenceWithoutId.setUsers(conferenceUsers);
|
||||
|
||||
conferences.add(conferenceWithId);
|
||||
conferenceDto = new ConferenceDto(conferenceWithId);
|
||||
@ -184,37 +181,52 @@ public class ConferenceServiceTest {
|
||||
ConferenceDto newConferenceDto = new ConferenceDto();
|
||||
newConferenceDto.getDeadlines().add(new Deadline());
|
||||
conferenceDto.getDeadlines().clear();
|
||||
assertEquals(newConferenceDto.getDeadlines(), conferenceService.addDeadline(conferenceDto).getDeadlines());
|
||||
assertEquals(newConferenceDto.getDeadlines().get(0), conferenceService.addDeadline(conferenceDto).getDeadlines().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeDeadline() throws IOException {
|
||||
ConferenceDto newConferenceDto = new ConferenceDto();
|
||||
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.getRemovedDeadlineIds(), result.getRemovedDeadlineIds());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addPaper() {
|
||||
ConferenceDto newConferenceDto = new ConferenceDto();
|
||||
newConferenceDto.getPapers().add(paperWithoutId);
|
||||
conferenceDto.getPapers().clear();
|
||||
when(userService.getCurrentUser()).thenReturn(user);
|
||||
ConferenceDto newConferenceDto = conferenceService.addPaper(conferenceDto);
|
||||
assertEquals(conferenceDto, newConferenceDto);
|
||||
ConferenceDto result = conferenceService.addPaper(conferenceDto);
|
||||
result.getPapers().get(INDEX).setTitle(NAME); // приходится вручную назначать название, т.е. название зависит от даты
|
||||
assertEquals(newConferenceDto.getPapers(), result.getPapers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removePaper() throws IOException {
|
||||
ConferenceDto newConferenceDto = conferenceService.removePaper(conferenceDto, ROMOVE_INDEX);
|
||||
assertEquals(conferenceDto, newConferenceDto);
|
||||
ConferenceDto newConferenceDto = new ConferenceDto();
|
||||
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
|
||||
public void takePart() throws IOException {
|
||||
when(userService.getCurrentUser()).thenReturn(user);
|
||||
ConferenceDto newConferenceDto = new ConferenceDto();
|
||||
conferenceService.takePart(newConferenceDto);
|
||||
assertEquals(newConferenceDto.getUsers(), conferenceDto.getUsers());
|
||||
newConferenceDto.setUsers(conferenceUsers);
|
||||
newConferenceDto.setDisabledTakePart(DISABLED);
|
||||
conferenceDto.getPapers().clear();
|
||||
ConferenceDto result = conferenceService.takePart(conferenceDto);
|
||||
assertEquals(newConferenceDto.getUsers(), result.getUsers());
|
||||
assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -224,7 +236,6 @@ public class ConferenceServiceTest {
|
||||
assertEquals(users, conferenceService.getAllUsers());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void filter() {
|
||||
ConferenceFilterDto conferenceFilterDto = new ConferenceFilterDto();
|
||||
|
Loading…
Reference in New Issue
Block a user