#104 test refactoring
This commit is contained in:
parent
11cab955b4
commit
00c5d5f755
@ -234,8 +234,6 @@ public class ConferenceDto {
|
|||||||
Objects.equals(title, that.title) &&
|
Objects.equals(title, that.title) &&
|
||||||
Objects.equals(description, that.description) &&
|
Objects.equals(description, that.description) &&
|
||||||
Objects.equals(url, that.url) &&
|
Objects.equals(url, that.url) &&
|
||||||
Objects.equals(beginDate, that.beginDate) &&
|
|
||||||
Objects.equals(endDate, that.endDate) &&
|
|
||||||
Objects.equals(deadlines, that.deadlines) &&
|
Objects.equals(deadlines, that.deadlines) &&
|
||||||
Objects.equals(removedDeadlineIds, that.removedDeadlineIds) &&
|
Objects.equals(removedDeadlineIds, that.removedDeadlineIds) &&
|
||||||
Objects.equals(userIds, that.userIds) &&
|
Objects.equals(userIds, that.userIds) &&
|
||||||
|
@ -64,7 +64,7 @@ public class ConferenceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceDto getExistConferenceById(Integer id) {
|
public ConferenceDto getExistConferenceById(Integer id) {
|
||||||
ConferenceDto conferenceDto = findOneDto(id);
|
ConferenceDto conferenceDto = new ConferenceDto(conferenceRepository.findOne(id));
|
||||||
conferenceDto.setNotSelectedPapers(getNotSelectPapers(conferenceDto.getPaperIds()));
|
conferenceDto.setNotSelectedPapers(getNotSelectPapers(conferenceDto.getPaperIds()));
|
||||||
conferenceDto.setDisabledTakePart(isCurrentUserParticipant(conferenceDto.getUsers()));
|
conferenceDto.setDisabledTakePart(isCurrentUserParticipant(conferenceDto.getUsers()));
|
||||||
return conferenceDto;
|
return conferenceDto;
|
||||||
@ -72,7 +72,7 @@ public class ConferenceService {
|
|||||||
|
|
||||||
public ConferenceDto getNewConference() {
|
public ConferenceDto getNewConference() {
|
||||||
ConferenceDto conferenceDto = new ConferenceDto();
|
ConferenceDto conferenceDto = new ConferenceDto();
|
||||||
conferenceDto.setNotSelectedPapers(getNotSelectPapers(new ArrayList<Integer>()));
|
conferenceDto.setNotSelectedPapers(getNotSelectPapers(new ArrayList<>()));
|
||||||
return conferenceDto;
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,10 +87,6 @@ public class ConferenceService {
|
|||||||
return conferences;
|
return conferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceDto findOneDto(Integer id) {
|
|
||||||
return new ConferenceDto(conferenceRepository.findOne(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(ConferenceDto conferenceDto) throws IOException {
|
public void save(ConferenceDto conferenceDto) throws IOException {
|
||||||
if (isEmpty(conferenceDto.getId())) {
|
if (isEmpty(conferenceDto.getId())) {
|
||||||
create(conferenceDto);
|
create(conferenceDto);
|
||||||
@ -127,44 +123,51 @@ public class ConferenceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Integer conferenceId) {
|
public boolean delete(Integer conferenceId) {
|
||||||
if (conferenceRepository.exists(conferenceId)) {
|
if (conferenceRepository.exists(conferenceId)) {
|
||||||
conferenceRepository.delete(conferenceId);
|
conferenceRepository.delete(conferenceId);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDeadline(ConferenceDto conferenceDto) {
|
public ConferenceDto addDeadline(ConferenceDto conferenceDto) {
|
||||||
conferenceDto.getDeadlines().add(new Deadline());
|
conferenceDto.getDeadlines().add(new Deadline());
|
||||||
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void removeDeadline(ConferenceDto conferenceDto, Integer deadlineIndex) throws IOException {
|
public ConferenceDto removeDeadline(ConferenceDto conferenceDto, Integer deadlineIndex) throws IOException {
|
||||||
if (conferenceDto.getDeadlines().get(deadlineIndex).getId() != null) {
|
if (conferenceDto.getDeadlines().get(deadlineIndex).getId() != null) {
|
||||||
conferenceDto.getRemovedDeadlineIds().add(conferenceDto.getDeadlines().get(deadlineIndex).getId());
|
conferenceDto.getRemovedDeadlineIds().add(conferenceDto.getDeadlines().get(deadlineIndex).getId());
|
||||||
}
|
}
|
||||||
conferenceDto.getDeadlines().remove((int) deadlineIndex);
|
conferenceDto.getDeadlines().remove((int) deadlineIndex);
|
||||||
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPaper(ConferenceDto conferenceDto) {
|
public ConferenceDto addPaper(ConferenceDto conferenceDto) {
|
||||||
Paper paper = new Paper();
|
Paper paper = new Paper();
|
||||||
paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle() + "_" + (new Date()).getTime());
|
paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle() + "_" + (new Date()).getTime());
|
||||||
paper.setStatus(Paper.PaperStatus.DRAFT);
|
paper.setStatus(Paper.PaperStatus.DRAFT);
|
||||||
conferenceDto.getPapers().add(paper);
|
conferenceDto.getPapers().add(paper);
|
||||||
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePaper(ConferenceDto conferenceDto, Integer paperIndex) throws IOException {
|
public ConferenceDto removePaper(ConferenceDto conferenceDto, Integer paperIndex) throws IOException {
|
||||||
Paper removedPaper = conferenceDto.getPapers().remove((int) paperIndex);
|
Paper removedPaper = conferenceDto.getPapers().remove((int) paperIndex);
|
||||||
if (removedPaper.getId() != null) {
|
if (removedPaper.getId() != null) {
|
||||||
conferenceDto.getNotSelectedPapers().add(removedPaper);
|
conferenceDto.getNotSelectedPapers().add(removedPaper);
|
||||||
}
|
}
|
||||||
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void takePart(ConferenceDto conferenceDto) throws IOException {
|
public ConferenceDto takePart(ConferenceDto conferenceDto) throws IOException {
|
||||||
conferenceDto.getUsers().add(new ConferenceUser(userService.getCurrentUser()));
|
conferenceDto.getUsers().add(new ConferenceUser(userService.getCurrentUser()));
|
||||||
conferenceDto.setDisabledTakePart(true);
|
conferenceDto.setDisabledTakePart(true);
|
||||||
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> getNotSelectPapers(List<Integer> paperIds) {
|
private List<Paper> getNotSelectPapers(List<Integer> paperIds) {
|
||||||
return paperService.findAllNotSelect(paperIds);
|
return paperService.findAllNotSelect(paperIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +183,7 @@ public class ConferenceService {
|
|||||||
return Arrays.asList(ConferenceUser.Deposit.values());
|
return Arrays.asList(ConferenceUser.Deposit.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException {
|
private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException {
|
||||||
conference.setTitle(conferenceDto.getTitle());
|
conference.setTitle(conferenceDto.getTitle());
|
||||||
conference.setDescription(conferenceDto.getDescription());
|
conference.setDescription(conferenceDto.getDescription());
|
||||||
conference.setUrl(conferenceDto.getUrl());
|
conference.setUrl(conferenceDto.getUrl());
|
||||||
@ -198,7 +201,7 @@ public class ConferenceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isCurrentUserParticipant(List<ConferenceUser> conferenceUsers) {
|
private boolean isCurrentUserParticipant(List<ConferenceUser> conferenceUsers) {
|
||||||
return conferenceUsers.stream().anyMatch(participant -> participant.getUser().equals(userService.getCurrentUser()));
|
return conferenceUsers.stream().anyMatch(participant -> participant.getUser().equals(userService.getCurrentUser()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +216,7 @@ public class ConferenceService {
|
|||||||
return convert(findAllActive(), ConferenceDto::new);
|
return convert(findAllActive(), ConferenceDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Conference> findAllActive() {
|
private List<Conference> findAllActive() {
|
||||||
return conferenceRepository.findAllActive(new Date());
|
return conferenceRepository.findAllActive(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +230,7 @@ public class ConferenceService {
|
|||||||
conferenceRepository.updatePingConference(conferenceDto.getId());
|
conferenceRepository.updatePingConference(conferenceDto.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Conference findOne(Integer conferenceId) {
|
private Conference findOne(Integer conferenceId) {
|
||||||
return conferenceRepository.findOne(conferenceId);
|
return conferenceRepository.findOne(conferenceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +256,7 @@ public class ConferenceService {
|
|||||||
modelMap.addAttribute("offshoreSales", offshoreSales);
|
modelMap.addAttribute("offshoreSales", offshoreSales);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendNotificationAfterUpdateDeadlines(Conference conference, List<Deadline> oldDeadlines) {
|
private void sendNotificationAfterUpdateDeadlines(Conference conference, List<Deadline> oldDeadlines) {
|
||||||
if (oldDeadlines.size() != conference.getDeadlines().size()) {
|
if (oldDeadlines.size() != conference.getDeadlines().size()) {
|
||||||
conferenceNotificationService.updateDeadlineNotification(conference);
|
conferenceNotificationService.updateDeadlineNotification(conference);
|
||||||
return;
|
return;
|
||||||
@ -267,7 +270,7 @@ public class ConferenceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Deadline copyDeadline(Deadline oldDeadline) {
|
private Deadline copyDeadline(Deadline oldDeadline) {
|
||||||
Deadline newDeadline = new Deadline(oldDeadline.getDate(), oldDeadline.getDescription());
|
Deadline newDeadline = new Deadline(oldDeadline.getDate(), oldDeadline.getDescription());
|
||||||
newDeadline.setId(oldDeadline.getId());
|
newDeadline.setId(oldDeadline.getId());
|
||||||
return newDeadline;
|
return newDeadline;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package conference.module_test;
|
package ru.ulstu.conference.service;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -11,9 +11,6 @@ import ru.ulstu.conference.model.Conference;
|
|||||||
import ru.ulstu.conference.model.ConferenceDto;
|
import ru.ulstu.conference.model.ConferenceDto;
|
||||||
import ru.ulstu.conference.model.ConferenceUser;
|
import ru.ulstu.conference.model.ConferenceUser;
|
||||||
import ru.ulstu.conference.repository.ConferenceRepository;
|
import ru.ulstu.conference.repository.ConferenceRepository;
|
||||||
import ru.ulstu.conference.service.ConferenceNotificationService;
|
|
||||||
import ru.ulstu.conference.service.ConferenceService;
|
|
||||||
import ru.ulstu.conference.service.ConferenceUserService;
|
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
@ -24,11 +21,12 @@ import ru.ulstu.user.service.UserService;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
@ -126,28 +124,82 @@ public class ConferenceServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindAllConferences() {
|
public void getExistConferenceById() {
|
||||||
|
when(conferenceRepository.findOne(1)).thenReturn(conferenceWithId);
|
||||||
|
when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers);
|
||||||
|
when(userService.getCurrentUser()).thenReturn(user);
|
||||||
|
conferenceDto.setDisabledTakePart(true);
|
||||||
|
assertEquals(conferenceDto, conferenceService.getExistConferenceById(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getNewConference() {
|
||||||
|
ConferenceDto newConferenceDto = new ConferenceDto();
|
||||||
|
newConferenceDto.setNotSelectedPapers(papers);
|
||||||
|
when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers);
|
||||||
|
assertEquals(newConferenceDto, conferenceService.getNewConference());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findAll() {
|
||||||
when(conferenceRepository.findAll(new Sort(Sort.Direction.DESC, "beginDate"))).thenReturn(conferences);
|
when(conferenceRepository.findAll(new Sort(Sort.Direction.DESC, "beginDate"))).thenReturn(conferences);
|
||||||
assertEquals(conferences, conferenceService.findAll());
|
assertEquals(conferences, conferenceService.findAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCopyFromDto() throws IOException {
|
public void create() throws IOException {
|
||||||
when(paperService.findPaperById(paperWithId.getId())).thenReturn(paperWithId);
|
when(paperService.findPaperById(paperWithId.getId())).thenReturn(paperWithId);
|
||||||
when(paperService.create(paperWithoutId)).thenReturn(paperWithoutId);
|
when(paperService.create(paperWithoutId)).thenReturn(paperWithoutId);
|
||||||
when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines);
|
when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines);
|
||||||
when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers);
|
when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers);
|
||||||
assertEquals(conferenceWithoutId, conferenceService.copyFromDto(new Conference(), conferenceDto));
|
when(conferenceRepository.save(new Conference())).thenReturn(conferenceWithId);
|
||||||
|
assertEquals(conferenceWithId.getId(), conferenceService.create(conferenceDto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsCurrentUserParticipant() throws IOException {
|
public void update() throws IOException {
|
||||||
|
when(conferenceRepository.findOne(1)).thenReturn(conferenceWithId);
|
||||||
|
when(paperService.findPaperById(paperWithId.getId())).thenReturn(paperWithId);
|
||||||
|
when(paperService.create(paperWithoutId)).thenReturn(paperWithoutId);
|
||||||
|
when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines);
|
||||||
|
when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers);
|
||||||
|
when(conferenceRepository.save(new Conference())).thenReturn(conferenceWithId);
|
||||||
|
assertEquals(conferenceWithId.getId(), conferenceService.create(conferenceDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void delete() {
|
||||||
|
when(conferenceRepository.exists(1)).thenReturn(true);
|
||||||
|
assertTrue(conferenceService.delete(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addDeadline() {
|
||||||
|
ConferenceDto newConferenceDto = conferenceService.addDeadline(conferenceDto);
|
||||||
|
assertEquals(conferenceDto, newConferenceDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeDeadline() throws IOException {
|
||||||
|
ConferenceDto newConferenceDto = conferenceService.removeDeadline(conferenceDto, 0);
|
||||||
|
assertEquals(conferenceDto, newConferenceDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addPaper() {
|
||||||
when(userService.getCurrentUser()).thenReturn(user);
|
when(userService.getCurrentUser()).thenReturn(user);
|
||||||
assertEquals(true, conferenceService.isCurrentUserParticipant(conferenceUsers));
|
ConferenceDto newConferenceDto = conferenceService.addPaper(conferenceDto);
|
||||||
|
assertEquals(conferenceDto, newConferenceDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTakePart() throws IOException {
|
public void removePaper() throws IOException {
|
||||||
|
ConferenceDto newConferenceDto = conferenceService.removePaper(conferenceDto, 0);
|
||||||
|
assertEquals(conferenceDto, newConferenceDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
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);
|
conferenceService.takePart(newConferenceDto);
|
||||||
@ -155,18 +207,31 @@ public class ConferenceServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindOneDto() throws IOException {
|
public void getAllUsers() {
|
||||||
when(conferenceRepository.findOne(1)).thenReturn(conferenceWithId);
|
List<User> users = Collections.singletonList(user);
|
||||||
assertEquals(conferenceDto, conferenceService.findOneDto(1));
|
when(userService.findAll()).thenReturn(users);
|
||||||
|
assertEquals(users, conferenceService.getAllUsers());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void filter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate() throws IOException {
|
public void isAttachedToConference() {
|
||||||
when(paperService.findPaperById(paperWithId.getId())).thenReturn(paperWithId);
|
|
||||||
when(paperService.create(paperWithoutId)).thenReturn(paperWithoutId);
|
|
||||||
when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines);
|
|
||||||
when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers);
|
|
||||||
when(conferenceRepository.save(conferenceWithoutId)).thenReturn(conferenceWithoutId);
|
|
||||||
assertNull(conferenceService.create(conferenceDto));
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
|
public void ping() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkEmptyFieldsOfDeadline() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void filterEmptyDeadlines() {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user