#104 some methods fixed

This commit is contained in:
Nightblade73 2019-05-16 15:55:29 +04:00
parent c0937d721a
commit bde9cb51fb
4 changed files with 41 additions and 21 deletions

View File

@ -16,6 +16,7 @@ import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.name.BaseService;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.service.PaperService;
import ru.ulstu.ping.model.Ping;
import ru.ulstu.ping.service.PingService;
import ru.ulstu.timeline.service.EventService;
import ru.ulstu.user.model.User;
@ -240,9 +241,10 @@ public class ConferenceService extends BaseService {
}
@Transactional
public int ping(ConferenceDto conferenceDto) throws IOException {
pingService.addPing(findOne(conferenceDto.getId()));
return conferenceRepository.updatePingConference(conferenceDto.getId());
public Ping ping(ConferenceDto conferenceDto) throws IOException {
Ping ping = pingService.addPing(findOne(conferenceDto.getId()));
conferenceRepository.updatePingConference(conferenceDto.getId());
return ping;
}
private Conference findOne(Integer conferenceId) {

View File

@ -268,9 +268,15 @@ public class Paper extends BaseEntity implements UserContainer {
@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;
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 &&

View File

@ -23,10 +23,10 @@ public class PingService {
}
@Transactional
public void addPing(Conference conference) throws IOException {
public Ping addPing(Conference conference) throws IOException {
Ping newPing = new Ping(new Date(), userService.getCurrentUser());
newPing.setConference(conference);
pingRepository.save(newPing);
return pingRepository.save(newPing);
}
public Integer countPingYesterday(Conference conference, Calendar calendar) {

View File

@ -16,6 +16,7 @@ import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.service.PaperService;
import ru.ulstu.ping.model.Ping;
import ru.ulstu.ping.service.PingService;
import ru.ulstu.timeline.service.EventService;
import ru.ulstu.user.model.User;
@ -65,6 +66,7 @@ public class ConferenceServiceTest {
private final Integer INDEX = 0;
private final String NAME = "Name";
private final boolean DISABLED = true;
private final Integer YEAR = 2019;
private List<Conference> conferences;
private List<Deadline> deadlines;
@ -127,19 +129,27 @@ public class ConferenceServiceTest {
@Test
public void getExistConferenceById() {
when(conferenceRepository.findOne(1)).thenReturn(conferenceWithId);
when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId);
when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers);
when(userService.getCurrentUser()).thenReturn(user);
conferenceDto.setDisabledTakePart(true);
assertEquals(conferenceDto, conferenceService.getExistConferenceById(1));
ConferenceDto newConferenceDto = new ConferenceDto(conferenceWithId);
newConferenceDto.setNotSelectedPapers(papers);
newConferenceDto.setDisabledTakePart(!DISABLED);
ConferenceDto result = conferenceService.getExistConferenceById(ID);
assertEquals(newConferenceDto.getId(), result.getId());
assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers());
assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart());
}
@Test
public void getNewConference() {
when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers);
ConferenceDto newConferenceDto = new ConferenceDto();
newConferenceDto.setNotSelectedPapers(papers);
when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers);
assertEquals(newConferenceDto, conferenceService.getNewConference());
ConferenceDto result = conferenceService.getNewConference();
assertEquals(newConferenceDto.getId(), result.getId());
assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers());
assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart());
}
@Test
@ -239,23 +249,25 @@ public class ConferenceServiceTest {
@Test
public void filter() {
ConferenceFilterDto conferenceFilterDto = new ConferenceFilterDto();
conferenceFilterDto.setFilterUserId(1);
conferenceFilterDto.setYear(2019);
when(userService.findById(1)).thenReturn(user);
when(conferenceRepository.findByUserAndYear(user, 2019)).thenReturn(conferences);
conferenceFilterDto.setFilterUserId(ID);
conferenceFilterDto.setYear(YEAR);
when(userService.findById(ID)).thenReturn(user);
when(conferenceRepository.findByUserAndYear(user, YEAR)).thenReturn(conferences);
assertEquals(Collections.singletonList(conferenceDto), conferenceService.filter(conferenceFilterDto));
}
@Test
public void isAttachedToConference() {
when(conferenceRepository.isPaperAttached(1)).thenReturn(true);
assertTrue(conferenceService.isAttachedToConference(1));
when(conferenceRepository.isPaperAttached(ID)).thenReturn(true);
assertTrue(conferenceService.isAttachedToConference(ID));
}
@Test
public void ping() throws IOException {
Ping ping = new Ping();
when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId);
when(conferenceRepository.updatePingConference(1)).thenReturn(1);
assertEquals(1, conferenceService.ping(conferenceDto));
when(pingService.addPing(conferenceWithId)).thenReturn(ping);
when(conferenceRepository.updatePingConference(ID)).thenReturn(INDEX);
assertEquals(ping, conferenceService.ping(conferenceDto));
}
}