Added tests

This commit is contained in:
Filip Izydorczyk 2021-01-05 11:44:54 +01:00
parent 0b40d3729c
commit 463af01dc6
4 changed files with 85 additions and 27 deletions

View File

@ -46,15 +46,20 @@ public class AssignmentService {
return this.repo.save(assignment);
}
/*
* getCommisionAssignments Return id of the commision
/**
* gets list of assignments of given commision
*
* @param com Commision to get assinments from
* @return list of assignments
*/
public List<Assignment> getCommisionAssignments(Commision com) {
return this.repo.getByCommision(com.getId());
}
/*
* getAssignmentsAmmount Return count assignments ammount
/**
* get ammount of all assignments (not only for selected commision)
*
* @return long - ammount of assingments
*/
public long getAssignmentsAmmount() {
return this.repo.count();

View File

@ -12,7 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Service of CommisionService which can save commision, get user's commisions, get newest user's commision, get ammount of commisions.
* Service of CommisionService which can save commision, get user's commisions,
* get newest user's commision, get ammount of commisions.
*/
@Service
@ -25,12 +26,6 @@ public class CommisionService {
public CommisionService() {
}
/*
* save
*
* @param commision which assignment should be save in service
* @return commision
*/
public Commision save(Commision commision) {
Optional<Commision> lastCommision = this.getNewestCommision(commision.getCommisionOwner());
if (lastCommision.isPresent()) {
@ -45,25 +40,31 @@ public class CommisionService {
}
/*
* getUsersCommisions
* Return given users id
/**
* gets user commisions
*
* @param user owner of commisions
* @return list of user commisions
*/
public List<Commision> getUsersCommisions(User user) {
return this.repo.getUsers(user.getId());
}
/*
* getNewestCommision
* Return the newest commision of the user
/**
* get newest commision ov given user
*
* @param user owener of commision we attemp to get
* @return optional if commition was found
*/
public Optional<Commision> getNewestCommision(User user) {
return this.repo.getNewestCommision(user.getId()).stream().findFirst();
}
/*
* getCommisionsAmmount
* Return ammount of commisions
/**
* get ammpounts of commisions
*
* @return long - ammounts of commisions (all even from history, not only
* cutrrent one)
*/
public long getCommisionsAmmount() {
return this.repo.count();

View File

@ -1,6 +1,5 @@
package com.plannaplan.entities;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.sql.Date;
@ -141,22 +140,50 @@ public class AppConfigTest {
@Test
public void shouldReturnFirstStartDatesCorns() {
assertFalse(false);
final Date firtstTourStart = Date.valueOf("2020-11-12");
final Date firtstTourEnd = Date.valueOf("2020-11-13");
final Date secondTourStart = Date.valueOf("2020-11-14");
final Date secondTourEnd = Date.valueOf("2020-11-15");
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
new TourData(secondTourStart, secondTourEnd));
assertTrue(config.getFirstTourStartCron().getExpression().equals("0 0 0 12 11 ?"));
}
@Test
public void shouldReturnSecondStartDatesCorns() {
assertFalse(false);
final Date firtstTourStart = Date.valueOf("2020-11-12");
final Date firtstTourEnd = Date.valueOf("2020-11-13");
final Date secondTourStart = Date.valueOf("2020-11-14");
final Date secondTourEnd = Date.valueOf("2020-11-15");
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
new TourData(secondTourStart, secondTourEnd));
assertTrue(config.getSecondTourStartCron().getExpression().equals("0 0 0 14 11 ?"));
}
@Test
public void shouldReturnFirstEndDatesCorns() {
assertFalse(false);
final Date firtstTourStart = Date.valueOf("2020-11-12");
final Date firtstTourEnd = Date.valueOf("2020-11-13");
final Date secondTourStart = Date.valueOf("2020-11-14");
final Date secondTourEnd = Date.valueOf("2020-11-15");
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
new TourData(secondTourStart, secondTourEnd));
assertTrue(config.getFirstTourEndCron().getExpression().equals("0 0 0 13 11 ?"));
}
@Test
public void shouldReturnSecondEndDatesCorns() {
assertFalse(false);
final Date firtstTourStart = Date.valueOf("2020-11-12");
final Date firtstTourEnd = Date.valueOf("2020-11-13");
final Date secondTourStart = Date.valueOf("2020-11-14");
final Date secondTourEnd = Date.valueOf("2020-11-15");
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
new TourData(secondTourStart, secondTourEnd));
assertTrue(config.getSecondTourEndCron().getExpression().equals("0 0 0 15 11 ?"));
}
}

View File

@ -10,8 +10,11 @@ import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertTrue;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.sql.Date;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ScheduledFuture;
import com.plannaplan.TestApplication;
import com.plannaplan.entities.AppConfig;
@ -46,6 +49,9 @@ public class ConfiguratorServiceTest {
@Autowired
private AppConfigRepository appConfigRepo;
@Autowired
private EventService eventService;
@Test
public void shouldImportDataToDataBase() {
final InputStream inputStream = getClass().getClassLoader()
@ -102,8 +108,27 @@ public class ConfiguratorServiceTest {
}
@Test
public void shlouldScheduleTaskWhenSetTourDate() {
assertTrue(false);
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
public void shlouldScheduleTaskWhenSetTourDate()
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
final InputStream inputStream = getClass().getClassLoader()
.getResourceAsStream(TestApplication.TEST_CONFIG_FILE);
final ConfigData data = new ConfigData(
new TourData(new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis() + 86400000)),
new TourData(new Date(System.currentTimeMillis() + 86400000),
new Date(System.currentTimeMillis() + 2 * 86400000)),
inputStream);
this.configuratorService.config(data);
final Field reader = EventService.class.getDeclaredField("jobsMap");
reader.setAccessible(true);
@SuppressWarnings("unchecked")
final Map<Integer, ScheduledFuture<?>> map = (Map<Integer, ScheduledFuture<?>>) reader.get(this.eventService);
assertTrue(map.size() == 2);
assertTrue(map.get(EventService.FIRST_TOUR_SCHEDULE).isDone() == false);
assertTrue(map.get(EventService.SECOND_TOUR_SCHEDULE).isDone() == false);
}
}