-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from jiritobias/Competition+SportEvent
Competition+sport event
- Loading branch information
Showing
6 changed files
with
191 additions
and
55 deletions.
There are no files selected for viewing
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
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
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
53 changes: 53 additions & 0 deletions
53
persistence/src/test/java/cz/fi/muni/pa165/dao/SportDaoImplTest.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 |
---|---|---|
@@ -1,8 +1,61 @@ | ||
package cz.fi.muni.pa165.dao; | ||
|
||
import cz.fi.muni.pa165.entity.Sport; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* @author Petra Halová | ||
*/ | ||
public class SportDaoImplTest extends BaseDaoImplTest { | ||
|
||
@Autowired | ||
private SportDao sportDao; | ||
|
||
private Sport sport1; | ||
private Sport sport2; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
sport1 = new Sport(); | ||
sport1.setName("Pole dance"); | ||
|
||
sport2 = new Sport(); | ||
sport2.setName("chess"); | ||
|
||
sportDao.create(sport1); | ||
sportDao.create(sport2); | ||
} | ||
|
||
@Test | ||
public void testDeleteSport() { | ||
assertThat(sportDao.findById(sport1.getId())).isNotNull(); | ||
assertThat(sportDao.findById(sport2.getId())).isNotNull(); | ||
|
||
sportDao.delete(sport1); | ||
|
||
assertThat(sportDao.findById(sport2.getId())).isNotNull(); | ||
assertThat(sportDao.findById(sport1.getId())).isNull(); | ||
} | ||
|
||
@Test | ||
public void testFindAllSports(){ | ||
assertThat(sportDao.findAll()) | ||
.usingFieldByFieldElementComparator() | ||
.containsOnly(sport1,sport2); | ||
|
||
sportDao.delete(sport1); | ||
sportDao.delete(sport2); | ||
assertThat(sportDao.findAll()).isEmpty(); | ||
} | ||
|
||
@Test | ||
public void testFindById(){ | ||
Long id = sport1.getId(); | ||
assertThat(sportDao.findById(id)) | ||
.isEqualToComparingFieldByField(sport1); | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
persistence/src/test/java/cz/fi/muni/pa165/dao/UserDaoImplTest.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,128 @@ | ||
package cz.fi.muni.pa165.dao; | ||
|
||
import cz.fi.muni.pa165.entity.Competition; | ||
import cz.fi.muni.pa165.entity.Sport; | ||
import cz.fi.muni.pa165.entity.User; | ||
import cz.fi.muni.pa165.enums.Gendre; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.Assert; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
import java.util.Set; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
/** | ||
* @author jiritobias, Petra Halová | ||
*/ | ||
public class UserDaoImplTest extends BaseDaoImplTest { | ||
|
||
@Qualifier("userDaoImpl") | ||
@Autowired | ||
private UserDao userDao; | ||
|
||
@Autowired | ||
private CompetitionDao competitionDao; | ||
|
||
@Autowired | ||
private SportDao sportDao; | ||
|
||
private User user1; | ||
private User user2; | ||
|
||
@BeforeMethod | ||
public void createUsers() { | ||
user1 = new User(); | ||
user1.setAddress("addres"); | ||
user1.setEmail("fake@gmail.com"); | ||
user1.setFirstname("Honza"); | ||
user1.setLastname("Novotny"); | ||
user1.setGendre(Gendre.MAN); | ||
user1.setPasswordHash("1"); | ||
userDao.create(user1); | ||
|
||
user2 = new User(); | ||
user2.setAddress("addres"); | ||
user2.setEmail("fireandblood@gmail.com"); | ||
user2.setFirstname("Daenerys"); | ||
user2.setLastname("Targaryen"); | ||
user2.setGendre(Gendre.WOMAN); | ||
user2.setPasswordHash("2"); | ||
userDao.create(user2); | ||
} | ||
|
||
private Competition createCompetition(String nameOfSport){ | ||
Sport sport = new Sport(); | ||
sport.setName(nameOfSport); | ||
sportDao.create(sport); | ||
|
||
Competition competition = new Competition(); | ||
competition.setSport(sport); | ||
competitionDao.create(competition); | ||
return competition; | ||
} | ||
|
||
@Test | ||
public void findAll() { | ||
Assertions.assertThat(userDao.findAll()) | ||
.usingFieldByFieldElementComparator() | ||
.containsOnly(user1,user2); | ||
} | ||
|
||
@Test | ||
public void findByGendre() { | ||
Assertions.assertThat(userDao.findByGendre(Gendre.MAN)) | ||
.usingFieldByFieldElementComparator() | ||
.containsOnly(user1); | ||
|
||
Assertions.assertThat(userDao.findByGendre(Gendre.WOMAN)) | ||
.usingFieldByFieldElementComparator() | ||
.containsOnly(user2); | ||
} | ||
|
||
@Test | ||
public void testCreateUser(){ | ||
Long userId = user1.getId(); | ||
Assert.assertNotNull(userId); | ||
|
||
Assertions.assertThat(userDao.findById(userId)) | ||
.isEqualToComparingFieldByField(user1); | ||
} | ||
|
||
@Test | ||
public void testDeleteUser(){ | ||
Assertions.assertThat(userDao.findById(user1.getId())).isNotNull(); | ||
Assertions.assertThat(userDao.findById(user2.getId())).isNotNull(); | ||
|
||
userDao.delete(user1); | ||
Assertions.assertThat(userDao.findById(user2.getId())).isNotNull(); | ||
Assertions.assertThat(userDao.findById(user1.getId())).isNull(); | ||
} | ||
|
||
@Test | ||
public void testAddToCompetition(){ | ||
Competition competition = createCompetition("Flying on dragons"); | ||
user2.addToCompetition(competition); | ||
|
||
Set<Competition> competitions = user2.getCompetitions(); | ||
assertEquals(competitions.size(),1); | ||
assertTrue(competitions.contains(competition)); | ||
} | ||
|
||
@Test | ||
public void testRemoveFromCompetition(){ | ||
Competition competition1 = createCompetition("Flying on dragons"); | ||
Competition competition2 = createCompetition("Burning"); | ||
|
||
user2.addToCompetition(competition1); | ||
user2.addToCompetition(competition2); | ||
|
||
user2.removeFromCompetition(competition1); | ||
Set<Competition> competitions = user2.getCompetitions(); | ||
assertEquals(competitions.size(),1); | ||
assertTrue(competitions.contains(competition2)); | ||
} | ||
} |
54 changes: 0 additions & 54 deletions
54
persistence/src/test/java/cz/fi/muni/pa165/dao/UserDaoTest.java
This file was deleted.
Oops, something went wrong.