#104 test copy from dto method
This commit is contained in:
parent
3a9fde3404
commit
a8d987b01f
@ -181,7 +181,7 @@ public class ConferenceService {
|
|||||||
return Arrays.asList(ConferenceUser.Deposit.values());
|
return Arrays.asList(ConferenceUser.Deposit.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException {
|
public 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());
|
||||||
|
@ -5,11 +5,11 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import ru.ulstu.conference.model.Conference;
|
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.repository.ConferenceRepository;
|
import ru.ulstu.conference.repository.ConferenceRepository;
|
||||||
import ru.ulstu.conference.service.ConferenceService;
|
import ru.ulstu.conference.service.ConferenceService;
|
||||||
import ru.ulstu.conference.service.ConferenceUserService;
|
import ru.ulstu.conference.service.ConferenceUserService;
|
||||||
@ -17,12 +17,15 @@ 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;
|
||||||
import ru.ulstu.paper.service.PaperService;
|
import ru.ulstu.paper.service.PaperService;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
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.mockito.Mockito.when;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class ConferenceServiceTest {
|
public class ConferenceServiceTest {
|
||||||
@ -44,7 +47,10 @@ public class ConferenceServiceTest {
|
|||||||
|
|
||||||
private List<Conference> conferences;
|
private List<Conference> conferences;
|
||||||
private List<Deadline> deadlines;
|
private List<Deadline> deadlines;
|
||||||
|
private List<Paper> papers;
|
||||||
|
private List<ConferenceUser> conferenceUsers;
|
||||||
private Conference conference;
|
private Conference conference;
|
||||||
|
private ConferenceUser conferenceUser;
|
||||||
|
|
||||||
private Paper paperWithId;
|
private Paper paperWithId;
|
||||||
private Paper paperWithoutId;
|
private Paper paperWithoutId;
|
||||||
@ -56,11 +62,9 @@ public class ConferenceServiceTest {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
conferences = new ArrayList<>();
|
conferences = new ArrayList<>();
|
||||||
conference = new Conference();
|
conference = new Conference();
|
||||||
conference.setId(1);
|
|
||||||
conference.setTitle("Название");
|
conference.setTitle("Название");
|
||||||
conference.setDescription("Описание");
|
conference.setDescription("Описание");
|
||||||
conferences.add(conference);
|
|
||||||
conferenceDto = new ConferenceDto(conference);
|
|
||||||
|
|
||||||
paperWithId = new Paper();
|
paperWithId = new Paper();
|
||||||
paperWithId.setId(1);
|
paperWithId.setId(1);
|
||||||
@ -69,21 +73,46 @@ public class ConferenceServiceTest {
|
|||||||
paperWithoutId = new Paper();
|
paperWithoutId = new Paper();
|
||||||
paperWithoutId.setTitle("paperTitleNoId");
|
paperWithoutId.setTitle("paperTitleNoId");
|
||||||
|
|
||||||
|
papers = new ArrayList<>();
|
||||||
|
papers.add(paperWithId);
|
||||||
|
papers.add(paperWithoutId);
|
||||||
|
|
||||||
deadlines = new ArrayList<>();
|
deadlines = new ArrayList<>();
|
||||||
deadline = new Deadline(new Date(),"desc");
|
deadline = new Deadline(new Date(), "desc");
|
||||||
deadline.setId(1);
|
deadline.setId(1);
|
||||||
deadlines.add(deadline);
|
deadlines.add(deadline);
|
||||||
|
|
||||||
|
conferenceUser = new ConferenceUser();
|
||||||
|
conferenceUser.setDeposit(ConferenceUser.Deposit.ARTICLE);
|
||||||
|
conferenceUser.setParticipation(ConferenceUser.Participation.INTRAMURAL);
|
||||||
|
User user = new User();
|
||||||
|
user.setFirstName("Name");
|
||||||
|
conferenceUser.setUser(user);
|
||||||
|
|
||||||
|
conferenceUsers = new ArrayList<>();
|
||||||
|
conferenceUsers.add(conferenceUser);
|
||||||
|
|
||||||
|
conference.setPapers(papers);
|
||||||
|
conference.setDeadlines(deadlines);
|
||||||
|
conference.setUsers(conferenceUsers);
|
||||||
|
|
||||||
|
conferences.add(conference);
|
||||||
|
conferenceDto = new ConferenceDto(conference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindAllConferences() {
|
public void testFindAllConferences() {
|
||||||
Mockito.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() {
|
public void testCopyFromDto() throws IOException {
|
||||||
|
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);
|
||||||
|
assertEquals(conference, conferenceService.copyFromDto(new Conference(), conferenceDto));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user