#104 add 3 more tests
This commit is contained in:
parent
888fecf687
commit
e4f5bede2a
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.Errors;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.deadline.service.DeadlineService;
|
||||
import ru.ulstu.file.model.FileDataDto;
|
||||
import ru.ulstu.file.service.FileService;
|
||||
@ -76,13 +77,11 @@ public class GrantService extends BaseService {
|
||||
this.pingService = pingService;
|
||||
}
|
||||
|
||||
//++
|
||||
public GrantDto getExistGrantById(Integer id) {
|
||||
GrantDto grantDto = new GrantDto(findById(id));
|
||||
return grantDto;
|
||||
}
|
||||
|
||||
//++
|
||||
public List<Grant> findAll() {
|
||||
return grantRepository.findAll();
|
||||
}
|
||||
@ -91,7 +90,6 @@ public class GrantService extends BaseService {
|
||||
return convert(findAll(), GrantDto::new);
|
||||
}
|
||||
|
||||
//++
|
||||
@Transactional
|
||||
public Grant create(GrantDto grantDto) throws IOException {
|
||||
Grant newGrant = copyFromDto(new Grant(), grantDto);
|
||||
@ -164,7 +162,6 @@ public class GrantService extends BaseService {
|
||||
return grant.getId();
|
||||
}
|
||||
|
||||
//++
|
||||
@Transactional
|
||||
public boolean delete(Integer grantId) throws IOException {
|
||||
Grant grant = findById(grantId);
|
||||
@ -175,30 +172,10 @@ public class GrantService extends BaseService {
|
||||
return false;
|
||||
}
|
||||
|
||||
//++
|
||||
public List<Grant.GrantStatus> getGrantStatuses() {
|
||||
return Arrays.asList(Grant.GrantStatus.values());
|
||||
}
|
||||
|
||||
// @Transactional
|
||||
// public Grant create(String title, Project projectId, Date deadlineDate, User user, Paper paper) {
|
||||
// Grant grant = new Grant();
|
||||
// grant.setTitle(title);
|
||||
// grant.setComment("Комментарий к гранту 1");
|
||||
// grant.setProject(projectId);
|
||||
// grant.setStatus(APPLICATION);
|
||||
// grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн"));
|
||||
// grant.getAuthors().add(user);
|
||||
// grant.setLeader(user);
|
||||
// grant.getPapers().add(paper);
|
||||
// grant = grantRepository.save(grant);
|
||||
//
|
||||
// eventService.createFromGrant(grant);
|
||||
// grantNotificationService.sendCreateNotification(grant);
|
||||
//
|
||||
// return grant;
|
||||
// }
|
||||
|
||||
public boolean save(GrantDto grantDto, Errors errors) throws IOException {
|
||||
grantDto.setName(grantDto.getTitle());
|
||||
filterEmptyDeadlines(grantDto);
|
||||
@ -278,26 +255,24 @@ public class GrantService extends BaseService {
|
||||
.collect(toList());
|
||||
}
|
||||
|
||||
//++
|
||||
public List<PaperDto> getGrantPapers(List<Integer> paperIds) {
|
||||
return paperService.findAllSelect(paperIds);
|
||||
}
|
||||
|
||||
//++
|
||||
public List<PaperDto> getAllUncompletedPapers() {
|
||||
return paperService.findAllNotCompleted();
|
||||
}
|
||||
|
||||
public void attachPaper(GrantDto grantDto) {
|
||||
public List<PaperDto> attachPaper(GrantDto grantDto) {
|
||||
if (!grantDto.getPaperIds().isEmpty()) {
|
||||
grantDto.getPapers().clear();
|
||||
grantDto.setPapers(getGrantPapers(grantDto.getPaperIds()));
|
||||
} else {
|
||||
grantDto.getPapers().clear();
|
||||
}
|
||||
return grantDto.getPapers();
|
||||
}
|
||||
|
||||
//++
|
||||
public GrantDto removeDeadline(GrantDto grantDto, Integer deadlineId) {
|
||||
if (grantDto.getDeadlines().get(deadlineId).getId() != null) {
|
||||
grantDto.getRemovedDeadlineIds().add(grantDto.getDeadlines().get(deadlineId).getId());
|
||||
@ -329,10 +304,11 @@ public class GrantService extends BaseService {
|
||||
.collect(toList());
|
||||
}
|
||||
|
||||
public void filterEmptyDeadlines(GrantDto grantDto) {
|
||||
public List<Deadline> filterEmptyDeadlines(GrantDto grantDto) {
|
||||
grantDto.setDeadlines(grantDto.getDeadlines().stream()
|
||||
.filter(dto -> dto.getDate() != null || !StringUtils.isEmpty(dto.getDescription()))
|
||||
.collect(Collectors.toList()));
|
||||
return grantDto.getDeadlines();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@ -354,12 +330,10 @@ public class GrantService extends BaseService {
|
||||
return grantRepository.findAllActive();
|
||||
}
|
||||
|
||||
//+
|
||||
public Grant findById(Integer id) {
|
||||
return grantRepository.findOne(id);
|
||||
}
|
||||
|
||||
//+
|
||||
@Transactional
|
||||
public void ping(int grantId) throws IOException {
|
||||
pingService.addPing(findById(grantId));
|
||||
|
@ -28,6 +28,7 @@ import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@ -103,7 +104,6 @@ public class GrantServiceTest {
|
||||
paperDto = new PaperDto(paperWithId);
|
||||
paperDtos.add(paperDto);
|
||||
|
||||
|
||||
authors = new HashSet<>();
|
||||
author = leader;
|
||||
authors.add(author);
|
||||
@ -184,7 +184,7 @@ public class GrantServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeDeadline() throws IOException {
|
||||
public void removeDeadline() {
|
||||
GrantDto newGrantDto = new GrantDto();
|
||||
newGrantDto.getRemovedDeadlineIds().add(ID);
|
||||
grantDto.getDeadlines().add(deadline);
|
||||
@ -193,23 +193,39 @@ public class GrantServiceTest {
|
||||
assertEquals(newGrantDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findById() {
|
||||
when(grantRepository.findOne(ID)).thenReturn(grantWithId);
|
||||
Grant findGrant = grantService.findById(ID);
|
||||
|
||||
// @Test
|
||||
// public void findAllDto() {
|
||||
// when(grantRepository.findAll()).thenReturn(grants);
|
||||
// List<Grant> list = convert(grants, GrantDto::new);
|
||||
// grantDtos.clear();
|
||||
// //List<GrantDto> listDto = new ArrayList<>();
|
||||
// list.forEach(grant -> {
|
||||
// GrantDto grantDto = new GrantDto(grant);
|
||||
// grantDtos.add(grantDto);
|
||||
// });
|
||||
//
|
||||
//
|
||||
// //grantDtos.forEach(grantDto -> grantDto.setTitle(StringUtils.abbreviate(grantDto.getTitle(), MAX_DISPLAY_SIZE)));
|
||||
// //List<GrantDto> result = ;
|
||||
// assertEquals(grantDtos, grantService.findAllDto());
|
||||
// }
|
||||
assertEquals(grantWithId.getId(), findGrant.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void attachPaper() {
|
||||
when(grantRepository.findOne(ID)).thenReturn(grantWithId);
|
||||
when(paperService.findAllSelect(Collections.singletonList(ID))).thenReturn(paperDtos);
|
||||
GrantDto newGrantDto = new GrantDto(grantWithId);
|
||||
|
||||
if (!newGrantDto.getPaperIds().isEmpty()) {
|
||||
newGrantDto.getPapers().clear();
|
||||
newGrantDto.setPapers(paperDtos);
|
||||
} else {
|
||||
newGrantDto.getPapers().clear();
|
||||
}
|
||||
|
||||
assertEquals(newGrantDto.getPapers(), grantService.attachPaper(grantDto));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterEmptyDeadlines() {
|
||||
when(grantRepository.findOne(ID)).thenReturn(grantWithId);
|
||||
GrantDto newGrantDto = new GrantDto(grantWithId);
|
||||
|
||||
newGrantDto.setDeadlines(newGrantDto.getDeadlines().stream()
|
||||
.filter(dto -> dto.getDate() != null || !StringUtils.isEmpty(dto.getDescription()))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
assertEquals(newGrantDto.getDeadlines(), grantService.filterEmptyDeadlines(grantDto));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user