#104 create fixed, remove update
This commit is contained in:
parent
bde9cb51fb
commit
80de18d3ee
@ -111,16 +111,16 @@ public class ConferenceService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer create(ConferenceDto conferenceDto) throws IOException {
|
public Conference create(ConferenceDto conferenceDto) throws IOException {
|
||||||
Conference newConference = copyFromDto(new Conference(), conferenceDto);
|
Conference newConference = copyFromDto(new Conference(), conferenceDto);
|
||||||
newConference = conferenceRepository.save(newConference);
|
newConference = conferenceRepository.save(newConference);
|
||||||
conferenceNotificationService.sendCreateNotification(newConference);
|
conferenceNotificationService.sendCreateNotification(newConference);
|
||||||
eventService.createFromConference(newConference);
|
eventService.createFromConference(newConference);
|
||||||
return newConference.getId();
|
return newConference;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer update(ConferenceDto conferenceDto) throws IOException {
|
public Conference update(ConferenceDto conferenceDto) throws IOException {
|
||||||
Conference conference = conferenceRepository.findOne(conferenceDto.getId());
|
Conference conference = conferenceRepository.findOne(conferenceDto.getId());
|
||||||
List<Deadline> oldDeadlines = conference.getDeadlines().stream()
|
List<Deadline> oldDeadlines = conference.getDeadlines().stream()
|
||||||
.map(this::copyDeadline)
|
.map(this::copyDeadline)
|
||||||
@ -134,7 +134,7 @@ public class ConferenceService extends BaseService {
|
|||||||
conferenceNotificationService.updateConferencesDatesNotification(conference, oldBeginDate, oldEndDate);
|
conferenceNotificationService.updateConferencesDatesNotification(conference, oldBeginDate, oldEndDate);
|
||||||
}
|
}
|
||||||
conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
|
conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
|
||||||
return conference.getId();
|
return conference;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -62,11 +62,13 @@ public class ConferenceServiceTest {
|
|||||||
@InjectMocks
|
@InjectMocks
|
||||||
ConferenceService conferenceService;
|
ConferenceService conferenceService;
|
||||||
|
|
||||||
private final Integer ID = 1;
|
private final static Integer ID = 1;
|
||||||
private final Integer INDEX = 0;
|
private final static Integer INDEX = 0;
|
||||||
private final String NAME = "Name";
|
private final static String NAME = "Name";
|
||||||
private final boolean DISABLED = true;
|
private final static String DESCRIPTION = "Desc";
|
||||||
private final Integer YEAR = 2019;
|
private final static boolean TRUE = true;
|
||||||
|
private final static Integer YEAR = 2019;
|
||||||
|
private final static Sort SORT = new Sort(Sort.Direction.DESC, "beginDate");
|
||||||
|
|
||||||
private List<Conference> conferences;
|
private List<Conference> conferences;
|
||||||
private List<Deadline> deadlines;
|
private List<Deadline> deadlines;
|
||||||
@ -86,14 +88,10 @@ public class ConferenceServiceTest {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
conferences = new ArrayList<>();
|
conferences = new ArrayList<>();
|
||||||
conferenceWithId = new Conference();
|
conferenceWithId = new Conference();
|
||||||
Conference conferenceWithoutId = new Conference();
|
|
||||||
|
|
||||||
conferenceWithId.setId(ID);
|
conferenceWithId.setId(ID);
|
||||||
conferenceWithId.setTitle(NAME);
|
conferenceWithId.setTitle(NAME);
|
||||||
conferenceWithId.setDescription("Описание");
|
conferenceWithId.setDescription(DESCRIPTION);
|
||||||
|
|
||||||
conferenceWithoutId.setTitle("Название");
|
|
||||||
conferenceWithoutId.setDescription("Описание");
|
|
||||||
|
|
||||||
paperWithId = new Paper();
|
paperWithId = new Paper();
|
||||||
paperWithId.setId(1);
|
paperWithId.setId(1);
|
||||||
@ -107,7 +105,7 @@ public class ConferenceServiceTest {
|
|||||||
papers.add(paperWithoutId);
|
papers.add(paperWithoutId);
|
||||||
|
|
||||||
deadlines = new ArrayList<>();
|
deadlines = new ArrayList<>();
|
||||||
deadline = new Deadline(new Date(), "desc");
|
deadline = new Deadline(new Date(), DESCRIPTION);
|
||||||
deadline.setId(ID);
|
deadline.setId(ID);
|
||||||
deadlines.add(deadline);
|
deadlines.add(deadline);
|
||||||
|
|
||||||
@ -121,8 +119,6 @@ public class ConferenceServiceTest {
|
|||||||
conferenceUsers = new ArrayList<>();
|
conferenceUsers = new ArrayList<>();
|
||||||
conferenceUsers.add(conferenceUser);
|
conferenceUsers.add(conferenceUser);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
conferences.add(conferenceWithId);
|
conferences.add(conferenceWithId);
|
||||||
conferenceDto = new ConferenceDto(conferenceWithId);
|
conferenceDto = new ConferenceDto(conferenceWithId);
|
||||||
}
|
}
|
||||||
@ -132,10 +128,12 @@ public class ConferenceServiceTest {
|
|||||||
when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId);
|
when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId);
|
||||||
when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers);
|
when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers);
|
||||||
when(userService.getCurrentUser()).thenReturn(user);
|
when(userService.getCurrentUser()).thenReturn(user);
|
||||||
|
|
||||||
ConferenceDto newConferenceDto = new ConferenceDto(conferenceWithId);
|
ConferenceDto newConferenceDto = new ConferenceDto(conferenceWithId);
|
||||||
newConferenceDto.setNotSelectedPapers(papers);
|
newConferenceDto.setNotSelectedPapers(papers);
|
||||||
newConferenceDto.setDisabledTakePart(!DISABLED);
|
newConferenceDto.setDisabledTakePart(!TRUE);
|
||||||
ConferenceDto result = conferenceService.getExistConferenceById(ID);
|
ConferenceDto result = conferenceService.getExistConferenceById(ID);
|
||||||
|
|
||||||
assertEquals(newConferenceDto.getId(), result.getId());
|
assertEquals(newConferenceDto.getId(), result.getId());
|
||||||
assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers());
|
assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers());
|
||||||
assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart());
|
assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart());
|
||||||
@ -144,9 +142,11 @@ public class ConferenceServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getNewConference() {
|
public void getNewConference() {
|
||||||
when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers);
|
when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers);
|
||||||
|
|
||||||
ConferenceDto newConferenceDto = new ConferenceDto();
|
ConferenceDto newConferenceDto = new ConferenceDto();
|
||||||
newConferenceDto.setNotSelectedPapers(papers);
|
newConferenceDto.setNotSelectedPapers(papers);
|
||||||
ConferenceDto result = conferenceService.getNewConference();
|
ConferenceDto result = conferenceService.getNewConference();
|
||||||
|
|
||||||
assertEquals(newConferenceDto.getId(), result.getId());
|
assertEquals(newConferenceDto.getId(), result.getId());
|
||||||
assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers());
|
assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers());
|
||||||
assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart());
|
assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart());
|
||||||
@ -154,29 +154,34 @@ public class ConferenceServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findAll() {
|
public void findAll() {
|
||||||
when(conferenceRepository.findAll(new Sort(Sort.Direction.DESC, "beginDate"))).thenReturn(conferences);
|
when(conferenceRepository.findAll(SORT)).thenReturn(conferences);
|
||||||
assertEquals(conferences, conferenceService.findAll());
|
|
||||||
|
assertEquals(Collections.singletonList(conferenceWithId), conferenceService.findAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void create() throws IOException {
|
public void create() throws IOException {
|
||||||
when(paperService.findPaperById(paperWithId.getId())).thenReturn(paperWithId);
|
when(paperService.findPaperById(ID)).thenReturn(paperWithId);
|
||||||
when(paperService.create(paperWithoutId)).thenReturn(paperWithoutId);
|
when(paperService.create(new Paper())).thenReturn(paperWithoutId);
|
||||||
when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines);
|
when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines);
|
||||||
when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers);
|
when(conferenceUserService.saveOrCreate(new ArrayList<>())).thenReturn(conferenceUsers);
|
||||||
when(conferenceRepository.save(new Conference())).thenReturn(conferenceWithId);
|
when(conferenceRepository.save(new Conference())).thenReturn(conferenceWithId);
|
||||||
assertEquals(conferenceWithId.getId(), conferenceService.create(conferenceDto));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
conferenceDto.setPapers(papers);
|
||||||
public void update() throws IOException {
|
conferenceDto.setDeadlines(deadlines);
|
||||||
when(conferenceRepository.findOne(1)).thenReturn(conferenceWithId);
|
conferenceDto.setUsers(conferenceUsers);
|
||||||
when(paperService.findPaperById(paperWithId.getId())).thenReturn(paperWithId);
|
conferenceDto.getPaperIds().add(ID);
|
||||||
when(paperService.create(paperWithoutId)).thenReturn(paperWithoutId);
|
|
||||||
when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines);
|
Conference newConference = new Conference();
|
||||||
when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers);
|
newConference.setId(ID);
|
||||||
when(conferenceRepository.save(new Conference())).thenReturn(conferenceWithId);
|
newConference.setTitle(NAME);
|
||||||
assertEquals(conferenceWithId.getId(), conferenceService.update(conferenceDto));
|
newConference.setDescription(DESCRIPTION);
|
||||||
|
newConference.setPapers(papers);
|
||||||
|
newConference.getPapers().add(paperWithId);
|
||||||
|
newConference.setDeadlines(deadlines);
|
||||||
|
newConference.setUsers(conferenceUsers);
|
||||||
|
|
||||||
|
assertEquals(newConference, conferenceService.create(conferenceDto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -191,6 +196,7 @@ 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().get(0), conferenceService.addDeadline(conferenceDto).getDeadlines().get(0));
|
assertEquals(newConferenceDto.getDeadlines().get(0), conferenceService.addDeadline(conferenceDto).getDeadlines().get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,18 +206,21 @@ public class ConferenceServiceTest {
|
|||||||
newConferenceDto.getRemovedDeadlineIds().add(ID);
|
newConferenceDto.getRemovedDeadlineIds().add(ID);
|
||||||
conferenceDto.getDeadlines().add(deadline);
|
conferenceDto.getDeadlines().add(deadline);
|
||||||
ConferenceDto result = conferenceService.removeDeadline(conferenceDto, INDEX);
|
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() {
|
||||||
|
when(userService.getCurrentUser()).thenReturn(user);
|
||||||
|
|
||||||
ConferenceDto newConferenceDto = new ConferenceDto();
|
ConferenceDto newConferenceDto = new ConferenceDto();
|
||||||
newConferenceDto.getPapers().add(paperWithoutId);
|
newConferenceDto.getPapers().add(paperWithoutId);
|
||||||
conferenceDto.getPapers().clear();
|
conferenceDto.getPapers().clear();
|
||||||
when(userService.getCurrentUser()).thenReturn(user);
|
|
||||||
ConferenceDto result = conferenceService.addPaper(conferenceDto);
|
ConferenceDto result = conferenceService.addPaper(conferenceDto);
|
||||||
result.getPapers().get(INDEX).setTitle(NAME); // приходится вручную назначать название, т.е. название зависит от даты
|
result.getPapers().get(INDEX).setTitle(NAME); // приходится вручную назначать название, т.е. название зависит от даты
|
||||||
|
|
||||||
assertEquals(newConferenceDto.getPapers(), result.getPapers());
|
assertEquals(newConferenceDto.getPapers(), result.getPapers());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,6 +232,7 @@ public class ConferenceServiceTest {
|
|||||||
conferenceDto.getPapers().add(paperWithId);
|
conferenceDto.getPapers().add(paperWithId);
|
||||||
conferenceDto.getPapers().add(paperWithoutId);
|
conferenceDto.getPapers().add(paperWithoutId);
|
||||||
ConferenceDto result = conferenceService.removePaper(conferenceDto, INDEX);
|
ConferenceDto result = conferenceService.removePaper(conferenceDto, INDEX);
|
||||||
|
|
||||||
assertEquals(newConferenceDto.getPapers(), result.getPapers());
|
assertEquals(newConferenceDto.getPapers(), result.getPapers());
|
||||||
assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers());
|
assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers());
|
||||||
}
|
}
|
||||||
@ -230,11 +240,13 @@ public class ConferenceServiceTest {
|
|||||||
@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();
|
||||||
newConferenceDto.setUsers(conferenceUsers);
|
newConferenceDto.setUsers(conferenceUsers);
|
||||||
newConferenceDto.setDisabledTakePart(DISABLED);
|
newConferenceDto.setDisabledTakePart(TRUE);
|
||||||
conferenceDto.getPapers().clear();
|
conferenceDto.getPapers().clear();
|
||||||
ConferenceDto result = conferenceService.takePart(conferenceDto);
|
ConferenceDto result = conferenceService.takePart(conferenceDto);
|
||||||
|
|
||||||
assertEquals(newConferenceDto.getUsers(), result.getUsers());
|
assertEquals(newConferenceDto.getUsers(), result.getUsers());
|
||||||
assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart());
|
assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart());
|
||||||
}
|
}
|
||||||
@ -248,17 +260,20 @@ public class ConferenceServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void filter() {
|
public void filter() {
|
||||||
|
when(userService.findById(ID)).thenReturn(user);
|
||||||
|
when(conferenceRepository.findByUserAndYear(user, YEAR)).thenReturn(conferences);
|
||||||
|
|
||||||
ConferenceFilterDto conferenceFilterDto = new ConferenceFilterDto();
|
ConferenceFilterDto conferenceFilterDto = new ConferenceFilterDto();
|
||||||
conferenceFilterDto.setFilterUserId(ID);
|
conferenceFilterDto.setFilterUserId(ID);
|
||||||
conferenceFilterDto.setYear(YEAR);
|
conferenceFilterDto.setYear(YEAR);
|
||||||
when(userService.findById(ID)).thenReturn(user);
|
|
||||||
when(conferenceRepository.findByUserAndYear(user, YEAR)).thenReturn(conferences);
|
|
||||||
assertEquals(Collections.singletonList(conferenceDto), conferenceService.filter(conferenceFilterDto));
|
assertEquals(Collections.singletonList(conferenceDto), conferenceService.filter(conferenceFilterDto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAttachedToConference() {
|
public void isAttachedToConference() {
|
||||||
when(conferenceRepository.isPaperAttached(ID)).thenReturn(true);
|
when(conferenceRepository.isPaperAttached(ID)).thenReturn(TRUE);
|
||||||
|
|
||||||
assertTrue(conferenceService.isAttachedToConference(ID));
|
assertTrue(conferenceService.isAttachedToConference(ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,6 +283,7 @@ public class ConferenceServiceTest {
|
|||||||
when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId);
|
when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId);
|
||||||
when(pingService.addPing(conferenceWithId)).thenReturn(ping);
|
when(pingService.addPing(conferenceWithId)).thenReturn(ping);
|
||||||
when(conferenceRepository.updatePingConference(ID)).thenReturn(INDEX);
|
when(conferenceRepository.updatePingConference(ID)).thenReturn(INDEX);
|
||||||
|
|
||||||
assertEquals(ping, conferenceService.ping(conferenceDto));
|
assertEquals(ping, conferenceService.ping(conferenceDto));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user