-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hajekad3
committed
Jan 5, 2023
1 parent
c6eb9cb
commit 251d493
Showing
9 changed files
with
325 additions
and
1 deletion.
There are no files selected for viewing
5 changes: 4 additions & 1 deletion
5
...ad3/reservantor/CoachAcceptanceTests.java → ...ntor/Acceptance/CoachAcceptanceTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
reservantor/src/test/java/cz/cvut/fit/hajekad3/reservantor/Helper/CoachHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cz.cvut.fit.hajekad3.reservantor.Helper; | ||
|
||
import cz.cvut.fit.hajekad3.reservantor.DomainLayer.Coach; | ||
import cz.cvut.fit.hajekad3.reservantor.InterfaceLayer.Dtos.Coach.CreateCoachDto; | ||
import cz.cvut.fit.hajekad3.reservantor.InterfaceLayer.Dtos.Coach.CoachDto; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class CoachHelper { | ||
public Coach fillCoach() { | ||
Coach ret = new Coach(fillCoachDto()); | ||
|
||
return ret; | ||
} | ||
|
||
public CoachDto fillCoachDto() { | ||
CoachDto ret = new CoachDto(); | ||
|
||
ret.setId(1L); | ||
ret.setCostRate(50); | ||
ret.setTrainings(new ArrayList<>()); | ||
ret.setPassword("pass"); | ||
ret.setEmail("[email protected]"); | ||
ret.setFirstName("Jan"); | ||
ret.setSecondName("Novak"); | ||
|
||
return ret; | ||
} | ||
|
||
public CreateCoachDto fillCreateCoachDto() { | ||
CreateCoachDto ret = new CreateCoachDto(); | ||
|
||
ret.setPassword("pass"); | ||
ret.setCostRate(50); | ||
ret.setEmail("[email protected]"); | ||
ret.setFirstName("Jan"); | ||
ret.setSecondName("Novak"); | ||
|
||
return ret; | ||
} | ||
|
||
public Coach fillCoachFromCreateCoachDto() { | ||
Coach ret = fillCoach(); | ||
|
||
return ret; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
reservantor/src/test/java/cz/cvut/fit/hajekad3/reservantor/Helper/PlaceHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cz.cvut.fit.hajekad3.reservantor.Helper; | ||
|
||
import cz.cvut.fit.hajekad3.reservantor.DomainLayer.Place; | ||
import cz.cvut.fit.hajekad3.reservantor.InterfaceLayer.Dtos.Place.CreatePlaceDto; | ||
import cz.cvut.fit.hajekad3.reservantor.InterfaceLayer.Dtos.Place.PlaceDto; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class PlaceHelper { | ||
public Place fillPlace() { | ||
Place ret = new Place(fillPlaceDto()); | ||
|
||
return ret; | ||
} | ||
|
||
public PlaceDto fillPlaceDto() { | ||
PlaceDto ret = new PlaceDto(); | ||
|
||
ret.setId(1L); | ||
ret.setLatitude(50D); | ||
ret.setLongitude(50D); | ||
ret.setTrainings(new ArrayList<>()); | ||
|
||
return ret; | ||
} | ||
|
||
public CreatePlaceDto fillCreatePlaceDto() { | ||
CreatePlaceDto ret = new CreatePlaceDto(); | ||
|
||
ret.setLatitude(50D); | ||
ret.setLongitude(50D); | ||
|
||
return ret; | ||
} | ||
|
||
public Place fillPlaceFromCreatePlaceDto() { | ||
Place ret = fillPlace(); | ||
|
||
return ret; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
reservantor/src/test/java/cz/cvut/fit/hajekad3/reservantor/Helper/TraineeHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package cz.cvut.fit.hajekad3.reservantor.Helper; | ||
|
||
import cz.cvut.fit.hajekad3.reservantor.DomainLayer.Trainee; | ||
import cz.cvut.fit.hajekad3.reservantor.InterfaceLayer.Dtos.Trainee.CreateTraineeDto; | ||
import cz.cvut.fit.hajekad3.reservantor.InterfaceLayer.Dtos.Trainee.TraineeDto; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class TraineeHelper { | ||
public Trainee fillTrainee() { | ||
Trainee ret = new Trainee(fillTraineeDto()); | ||
|
||
return ret; | ||
} | ||
|
||
public TraineeDto fillTraineeDto() { | ||
TraineeDto ret = new TraineeDto(); | ||
|
||
ret.setId(1L); | ||
ret.setSkillCap(50); | ||
ret.setTrainings(new ArrayList<>()); | ||
ret.setUsername("user"); | ||
ret.setPassword("pass"); | ||
ret.setEmail("[email protected]"); | ||
ret.setFirstName("Jan"); | ||
ret.setSecondName("Novak"); | ||
|
||
return ret; | ||
} | ||
|
||
public CreateTraineeDto fillCreateTraineeDto() { | ||
CreateTraineeDto ret = new CreateTraineeDto(); | ||
|
||
ret.setSkillCap(50); | ||
ret.setUsername("user"); | ||
ret.setPassword("pass"); | ||
ret.setEmail("[email protected]"); | ||
ret.setFirstName("Jan"); | ||
ret.setSecondName("Novak"); | ||
|
||
return ret; | ||
} | ||
|
||
public Trainee fillTraineeFromCreateTraineeDto() { | ||
Trainee ret = fillTrainee(); | ||
|
||
return ret; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
reservantor/src/test/java/cz/cvut/fit/hajekad3/reservantor/Helper/TrainingHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package cz.cvut.fit.hajekad3.reservantor.Helper; | ||
|
||
import cz.cvut.fit.hajekad3.reservantor.DomainLayer.Training; | ||
import cz.cvut.fit.hajekad3.reservantor.InterfaceLayer.Dtos.Training.CreateTrainingDto; | ||
import cz.cvut.fit.hajekad3.reservantor.InterfaceLayer.Dtos.Training.TrainingDto; | ||
|
||
import java.sql.Timestamp; | ||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
|
||
public class TrainingHelper { | ||
private Timestamp now() { | ||
Calendar calendar = Calendar.getInstance(); | ||
return new Timestamp(calendar.getTimeInMillis()); | ||
} | ||
|
||
public Training fillTraining() { | ||
Training ret = new Training(fillTrainingDto()); | ||
|
||
return ret; | ||
} | ||
|
||
public TrainingDto fillTrainingDto() { | ||
TrainingDto ret = new TrainingDto(); | ||
|
||
ret.setId(1L); | ||
ret.setDateOfTraining(now().toString()); | ||
ret.setDescription("Blank"); | ||
ret.setIdCoach(1L); | ||
ret.setIdPlace(1L); | ||
ret.setParticipatingTraineesIds(new ArrayList<>()); | ||
|
||
return ret; | ||
} | ||
|
||
public CreateTrainingDto fillCreateTrainingDto() { | ||
CreateTrainingDto ret = new CreateTrainingDto(); | ||
|
||
ret.setDateOfTraining(now().toString()); | ||
ret.setDescription("Blank"); | ||
ret.setIdCoach(1L); | ||
ret.setIdPlace(1L); | ||
|
||
return ret; | ||
} | ||
|
||
public Training fillTrainingFromCreateTrainingDto() { | ||
Training ret = fillTraining(); | ||
|
||
return ret; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...ntor/src/test/java/cz/cvut/fit/hajekad3/reservantor/Integration/CoachIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package cz.cvut.fit.hajekad3.reservantor.Integration; | ||
|
||
public class CoachIntegrationTest { | ||
} |
62 changes: 62 additions & 0 deletions
62
reservantor/src/test/java/cz/cvut/fit/hajekad3/reservantor/Unit/CoachUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package cz.cvut.fit.hajekad3.reservantor.Unit; | ||
|
||
import cz.cvut.fit.hajekad3.reservantor.DomainLayer.Coach; | ||
import cz.cvut.fit.hajekad3.reservantor.DomainLayer.Trainee; | ||
import cz.cvut.fit.hajekad3.reservantor.DomainLayer.Training; | ||
import cz.cvut.fit.hajekad3.reservantor.InfrastructureLayer.Storage.Implementations.CoachRepositoryExtraMethods; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.TypedQuery; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
public class CoachUnitTest { | ||
@Mock | ||
private EntityManager entityManager; | ||
|
||
@InjectMocks | ||
private CoachRepositoryExtraMethods coachRepositoryExtraMethods; | ||
|
||
@Test | ||
public void coachHasTrainedTrainee() { | ||
// Setup | ||
Trainee trainee = new Trainee(); | ||
Coach coach = new Coach(); | ||
TypedQuery<Training> query = Mockito.mock(TypedQuery.class); | ||
Mockito.when(query.getResultList()).thenReturn(Arrays.asList(new Training())); | ||
Mockito.when(entityManager.createQuery(Mockito.anyString(), Mockito.eq(Training.class))) | ||
.thenReturn(query); | ||
|
||
// Execute | ||
boolean result = coachRepositoryExtraMethods.coachTrainedTrainee(trainee, coach); | ||
|
||
// Assert | ||
assert(result == true); | ||
} | ||
|
||
@Test | ||
public void coachHasNotTrainedTrainee() { | ||
// Setup | ||
Trainee trainee = new Trainee(); | ||
Coach coach = new Coach(); | ||
TypedQuery<Training> query = Mockito.mock(TypedQuery.class); | ||
Mockito.when(query.getResultList()).thenReturn(Collections.emptyList()); | ||
Mockito.when(entityManager.createQuery(Mockito.anyString(), Mockito.eq(Training.class))) | ||
.thenReturn(query); | ||
|
||
// Execute | ||
boolean result = coachRepositoryExtraMethods.coachTrainedTrainee(trainee, coach); | ||
|
||
// Assert | ||
assert(result == false); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
reservantor/src/test/java/cz/cvut/fit/hajekad3/reservantor/Unit/TraineeUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package cz.cvut.fit.hajekad3.reservantor.Unit; | ||
|
||
public class TraineeUnitTest { | ||
} |
62 changes: 62 additions & 0 deletions
62
reservantor/src/test/java/cz/cvut/fit/hajekad3/reservantor/Unit/TrainingUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package cz.cvut.fit.hajekad3.reservantor.Unit; | ||
|
||
import cz.cvut.fit.hajekad3.reservantor.DomainLayer.Trainee; | ||
import cz.cvut.fit.hajekad3.reservantor.InfrastructureLayer.Storage.Implementations.TraineeRepositoryExtraMethods; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
import jakarta.persistence.TypedQuery; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
public class TrainingUnitTest { | ||
@Mock | ||
private EntityManager entityManager; | ||
@InjectMocks | ||
private TraineeRepositoryExtraMethods traineeRepositoryExtraMethods; | ||
|
||
@Test | ||
public void testFindMatch() { | ||
// Setup | ||
Trainee trainee = new Trainee(); | ||
trainee.setId(1L); | ||
trainee.setSkillCap(5); | ||
|
||
Trainee matchingTrainee1 = new Trainee(); | ||
matchingTrainee1.setId(2L); | ||
matchingTrainee1.setSkillCap(4); | ||
|
||
Trainee matchingTrainee2 = new Trainee(); | ||
matchingTrainee2.setId(3L); | ||
matchingTrainee2.setSkillCap(6); | ||
|
||
Trainee nonMatchingTrainee = new Trainee(); | ||
nonMatchingTrainee.setId(4L); | ||
nonMatchingTrainee.setSkillCap(1); | ||
|
||
List<Trainee> expectedResult = Arrays.asList(matchingTrainee1, matchingTrainee2); | ||
|
||
String queryString = "SELECT DISTINCT t FROM Trainee t WHERE t.skillCap >= :traineeSkill - :range AND t.skillCap <= :traineeSkill + :range AND t.id != :traineeId"; | ||
TypedQuery<Trainee> query = Mockito.mock(TypedQuery.class); | ||
Mockito.when(query.getResultList()).thenReturn(expectedResult); | ||
Mockito.when(entityManager.createQuery(queryString, Trainee.class)).thenReturn(query); | ||
Mockito.when(query.setParameter("traineeId", trainee.getId())).thenReturn(query); | ||
Mockito.when(query.setParameter("traineeSkill", trainee.getSkillCap())).thenReturn(query); | ||
Mockito.when(query.setParameter("range", 5)).thenReturn(query); | ||
|
||
// Execute | ||
List<Trainee> result = traineeRepositoryExtraMethods.findMatch(5, trainee); | ||
|
||
// Assert | ||
assert(expectedResult == result); | ||
} | ||
} |