Commit 400ee397 authored by Adrián Piaček's avatar Adrián Piaček
Browse files

Uncommenting tests

parent f9934b48
Pipeline #141884 passed with stage
in 1 minute and 4 seconds
......@@ -111,6 +111,12 @@
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -8,7 +8,7 @@
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
<property name="hibernate.dialect" value="org.hibernate.dialect.DerbyTenSevenDialect" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="true"/>
</properties>
......
......@@ -10,11 +10,15 @@ import cz.muni.fi.pa165.entity.TournamentEntity;
import cz.muni.fi.pa165.enums.CountryEnum;
import cz.muni.fi.pa165.enums.TournamentFormat;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.annotations.Test;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
......@@ -34,20 +38,20 @@ public class MatchDaoTest extends AbstractTransactionalTestNGSpringContextTests
@Autowired
private TeamDao teamDao;
// EntityManagerFactory emf = Persistence.createEntityManagerFactory("default");
//
// @AfterEach
// void afterEach(){
// EntityManager em = null;
// try {
// em = emf.createEntityManager();
// em.getTransaction().begin();
// em.createQuery("delete from MatchEntity").executeUpdate();
// em.getTransaction().commit();
// } finally {
// if (em != null) em.close();
// }
// }
EntityManagerFactory emf = Persistence.createEntityManagerFactory("default");
@AfterEach
void afterEach(){
EntityManager em = null;
try {
em = emf.createEntityManager();
em.getTransaction().begin();
em.createQuery("delete from MatchEntity").executeUpdate();
em.getTransaction().commit();
} finally {
if (em != null) em.close();
}
}
@Test
void create() {
......
......@@ -4,6 +4,7 @@ import cz.muni.fi.pa165.PersistenceSampleApplicationContext;
import cz.muni.fi.pa165.dao.person.PersonDao;
import cz.muni.fi.pa165.entity.PersonEntity;
import cz.muni.fi.pa165.enums.CountryEnum;
import org.junit.jupiter.api.AfterEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
......@@ -27,22 +28,22 @@ public class PersonDaoTest extends AbstractTransactionalTestNGSpringContextTests
@Autowired
private PersonDao personDao;
// EntityManagerFactory managerFactory = Persistence.createEntityManagerFactory("default");
//
// @AfterEach
// void afterEach() {
// EntityManager manager = null;
// try {
// manager = managerFactory.createEntityManager();
// manager.getTransaction().begin();
// manager.createQuery("delete from PersonEntity ").executeUpdate();
// manager.getTransaction().commit();
// } finally {
// if (manager != null) {
// manager.close();
// }
// }
// }
EntityManagerFactory managerFactory = Persistence.createEntityManagerFactory("default");
@AfterEach
void afterEach() {
EntityManager manager = null;
try {
manager = managerFactory.createEntityManager();
manager.getTransaction().begin();
manager.createQuery("delete from PersonEntity ").executeUpdate();
manager.getTransaction().commit();
} finally {
if (manager != null) {
manager.close();
}
}
}
@Test
void create() {
......
......@@ -3,11 +3,15 @@ package cz.muni.fi.pa165.dao;
import cz.muni.fi.pa165.PersistenceSampleApplicationContext;
import cz.muni.fi.pa165.dao.player.PlayerDao;
import cz.muni.fi.pa165.entity.PlayerEntity;
import org.junit.jupiter.api.AfterEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.annotations.Test;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -21,7 +25,22 @@ public class PlayerDaoTest extends AbstractTransactionalTestNGSpringContextTests
@Autowired
private PlayerDao playerDao;
EntityManagerFactory managerFactory = Persistence.createEntityManagerFactory("default");
@AfterEach
void afterEach() {
EntityManager manager = null;
try {
manager = managerFactory.createEntityManager();
manager.getTransaction().begin();
manager.createQuery("delete from PersonEntity ").executeUpdate();
manager.getTransaction().commit();
} finally {
if (manager != null) {
manager.close();
}
}
}
@Test
void create() {
PlayerEntity player = new PlayerEntity("Johan");
......
......@@ -5,11 +5,15 @@ import cz.muni.fi.pa165.dao.teamCoach.TeamCoachDao;
import cz.muni.fi.pa165.entity.TeamCoachEntity;
import cz.muni.fi.pa165.enums.CountryEnum;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.annotations.Test;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.util.UUID;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
......@@ -23,6 +27,22 @@ public class TeamCoachDaoTest extends AbstractTransactionalTestNGSpringContextTe
@Autowired
private TeamCoachDao coachDao;
EntityManagerFactory managerFactory = Persistence.createEntityManagerFactory("default");
@AfterEach
void afterEach() {
EntityManager manager = null;
try {
manager = managerFactory.createEntityManager();
manager.getTransaction().begin();
manager.createQuery("delete from PersonEntity ").executeUpdate();
manager.getTransaction().commit();
} finally {
if (manager != null) {
manager.close();
}
}
}
@Test
void create() {
TeamCoachEntity coach = new TeamCoachEntity("AutistaCoach");
......
......@@ -6,11 +6,15 @@ import cz.muni.fi.pa165.entity.TeamCoachEntity;
import cz.muni.fi.pa165.entity.TeamEntity;
import cz.muni.fi.pa165.enums.CountryEnum;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.annotations.Test;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
......@@ -26,6 +30,22 @@ public class TeamDaoTest extends AbstractTransactionalTestNGSpringContextTests {
@Autowired
private TeamDao teamDao;
EntityManagerFactory managerFactory = Persistence.createEntityManagerFactory("default");
@AfterEach
void afterEach() {
EntityManager manager = null;
try {
manager = managerFactory.createEntityManager();
manager.getTransaction().begin();
manager.createQuery("delete from PersonEntity ").executeUpdate();
manager.getTransaction().commit();
} finally {
if (manager != null) {
manager.close();
}
}
}
@Test
void create() {
......
......@@ -6,11 +6,15 @@ import cz.muni.fi.pa165.entity.TournamentEntity;
import cz.muni.fi.pa165.enums.CountryEnum;
import cz.muni.fi.pa165.enums.TournamentFormat;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.annotations.Test;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.util.UUID;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
......@@ -24,6 +28,22 @@ public class TournamentDaoTest extends AbstractTransactionalTestNGSpringContextT
@Autowired
private TournamentDao tournamentDao;
EntityManagerFactory managerFactory = Persistence.createEntityManagerFactory("default");
@AfterEach
void afterEach() {
EntityManager manager = null;
try {
manager = managerFactory.createEntityManager();
manager.getTransaction().begin();
manager.createQuery("delete from PersonEntity ").executeUpdate();
manager.getTransaction().commit();
} finally {
if (manager != null) {
manager.close();
}
}
}
@Test
void create() {
......
......@@ -5,11 +5,15 @@ import cz.muni.fi.pa165.dao.tournamentOrganizer.TournamentOrganizerDao;
import cz.muni.fi.pa165.entity.TournamentOrganizerEntity;
import cz.muni.fi.pa165.enums.CountryEnum;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.annotations.Test;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.util.UUID;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
......@@ -23,6 +27,22 @@ public class TournamentOrganizerDaoTest extends AbstractTransactionalTestNGSprin
@Autowired
private TournamentOrganizerDao tournamentOrganizerDao;
EntityManagerFactory managerFactory = Persistence.createEntityManagerFactory("default");
@AfterEach
void afterEach() {
EntityManager manager = null;
try {
manager = managerFactory.createEntityManager();
manager.getTransaction().begin();
manager.createQuery("delete from PersonEntity ").executeUpdate();
manager.getTransaction().commit();
} finally {
if (manager != null) {
manager.close();
}
}
}
@Test
void create() {
......
//package cz.muni.fi.pa165.entity;
//
//import cz.muni.fi.pa165.enums.CountryEnum;
//import cz.muni.fi.pa165.enums.TournamentFormat;
//import org.junit.jupiter.api.AfterAll;
//import org.junit.jupiter.api.Assertions;
//import org.junit.jupiter.api.BeforeAll;
//import org.junit.jupiter.api.Test;
//import org.junit.jupiter.api.TestInstance;
//import javax.persistence.EntityManager;
//import javax.persistence.EntityManagerFactory;
//import javax.persistence.Persistence;
//import java.util.HashSet;
//import java.util.List;
//
///**
// * @author Adrian Piacek
// */
//@TestInstance(TestInstance.Lifecycle.PER_CLASS)
//public class MatchEntityTest {
// private final EntityManagerFactory emf = Persistence.createEntityManagerFactory("default");
//
// private MatchEntity matchA, matchB, matchC;
// private TeamEntity teamA,teamB,teamC,teamD,teamE,teamF;
// private PlayerEntity playerA,playerB,playerC,playerD,playerE,playerF;
// private TournamentEntity tournamentA;
//
// @BeforeAll
// void init(){
// matchA = new MatchEntity();
// matchB = new MatchEntity();
// matchC = new MatchEntity();
//
// teamA = new TeamEntity();
// teamB = new TeamEntity();
// teamC = new TeamEntity();
// teamD = new TeamEntity();
// teamE = new TeamEntity();
// teamF = new TeamEntity();
// teamA.setName("A");
// teamB.setName("B");
// teamC.setName("C");
// teamD.setName("D");
// teamE.setName("E");
// teamF.setName("F");
//
// playerA = new PlayerEntity("A");
// playerB = new PlayerEntity("B");
// playerC = new PlayerEntity("C");
// playerD = new PlayerEntity("D");
// playerE = new PlayerEntity("E");
// playerF = new PlayerEntity("F");
//
// matchA.setTeams(new HashSet<>(List.of(teamA, teamB)));
// matchB.setTeams(new HashSet<>(List.of(teamC, teamD, teamE)));
// matchC.setTeams(new HashSet<>(List.of(teamA, teamC, teamF)));
//
// teamA.setMatches(new HashSet<>(List.of(matchA, matchC)));
// teamB.setMatches(new HashSet<>(List.of(matchA)));
// teamC.setMatches(new HashSet<>(List.of(matchB,matchC)));
// teamD.setMatches(new HashSet<>(List.of(matchB)));
// teamE.setMatches(new HashSet<>(List.of(matchB)));
// teamF.setMatches(new HashSet<>(List.of(matchC)));
//
// tournamentA = new TournamentEntity("Osaka", CountryEnum.SLOVAKIA, 1000, TournamentFormat.DEFAULT, 10);
// matchA.setTournament(tournamentA);
// matchB.setTournament(tournamentA);
// tournamentA.setMatches(new HashSet<>(List.of(matchA, matchB)));
//
// matchA.setPlayers(new HashSet<>(List.of(playerA,playerB,playerC,playerD,playerE,playerF)));
// matchB.setPlayers(new HashSet<>(List.of(playerA,playerB,playerC,playerD)));
// matchC.setPlayers(new HashSet<>(List.of(playerB,playerD,playerE,playerF)));
// playerA.setMatches(new HashSet<>(List.of(matchA, matchB)));
// playerB.setMatches(new HashSet<>(List.of(matchA, matchB, matchC)));
// playerC.setMatches(new HashSet<>(List.of(matchA, matchB)));
// playerD.setMatches(new HashSet<>(List.of(matchA, matchB, matchC)));
// playerE.setMatches(new HashSet<>(List.of(matchA, matchC)));
// playerF.setMatches(new HashSet<>(List.of(matchA, matchC)));
//
// EntityManager em = emf.createEntityManager();
// try{
// em.getTransaction().begin();
// em.persist(matchA);
// em.persist(matchB);
// em.persist(matchC);
//
// em.persist(teamA);
// em.persist(teamB);
// em.persist(teamC);
// em.persist(teamD);
// em.persist(teamE);
// em.persist(teamF);
//
// em.persist(playerA);
// em.persist(playerB);
// em.persist(playerC);
// em.persist(playerD);
// em.persist(playerE);
// em.persist(playerF);
//
// em.persist(tournamentA);
// em.getTransaction().commit();
// } finally {
// if (em != null) em.close();
// }
// }
//
// @Test
// void attributesTests(){
// MatchEntity match;
// EntityManager em1 = null;
// try {
// em1 = emf.createEntityManager();
// em1.getTransaction().begin();
// match = em1.find(MatchEntity.class, matchA.getId());
// Assertions.assertEquals(match.getId(), matchA.getId());
// em1.getTransaction().commit();
// } finally {
// if (em1 != null) em1.close();
// }
// }
//
// /**
// * Testing relationships between TournamentEntity and MatchEntity
// * Tests whether match assignment to tournament corresponds to the correct tournament.
// * Tests whether tournament consists of corresponding matches.
// */
// @Test
// void relationshipTestTournament(){
// MatchEntity match;
// TournamentEntity tournament;
// EntityManager em1 = null;
// try {
// em1 = emf.createEntityManager();
// em1.getTransaction().begin();
// match = em1.find(MatchEntity.class, matchA.getId());
// Assertions.assertEquals(match.getTournament(), tournamentA);
//
// tournament = em1.find(TournamentEntity.class, tournamentA.getId());
// Assertions.assertEquals(tournament.getMatches(), new HashSet<>(List.of(matchA, matchB)));
// match = em1.find(MatchEntity.class, matchB.getId());
// Assertions.assertEquals(match.getTournament(), tournamentA);
//
// em1.getTransaction().commit();
// } finally {
// if (em1 != null) em1.close();
// }
// }
//
// @Test
// void relationshipTestTeam(){
// MatchEntity match;
// TeamEntity team;
// EntityManager em1 = null;
// try {
// em1 = emf.createEntityManager();
// em1.getTransaction().begin();
// match = em1.find(MatchEntity.class, matchA.getId());
// Assertions.assertEquals(match.getTeams(), new HashSet<>(List.of(teamA,teamB)));
//
// match = em1.find(MatchEntity.class, matchB.getId());
// Assertions.assertEquals(match.getTeams(), new HashSet<>(List.of(teamC, teamD, teamE)));
//
// match = em1.find(MatchEntity.class, matchC.getId());
// Assertions.assertEquals(match.getTeams(), new HashSet<>(List.of(teamA, teamC, teamF)));
//
// team = em1.find(TeamEntity.class, teamB.getId());
// Assertions.assertEquals(team.getMatches(), new HashSet<>(List.of(matchA)));
//
// team = em1.find(TeamEntity.class, teamA.getId());
// Assertions.assertEquals(team.getMatches(), new HashSet<>(List.of(matchA, matchC)));
//
// team = em1.find(TeamEntity.class, teamC.getId());
// Assertions.assertEquals(team.getMatches(), new HashSet<>(List.of(matchB,matchC)));
// em1.getTransaction().commit();
// } finally {
// if (em1 != null) em1.close();
// }
// }
//
// /**
// * Testing relationships between PlayerEntity and MatchEntity
// * Tests whether match assignment of Players is corresponding to the default list of players for the tournament.
// * Tests whether player is assigned to the corresponding match as planned.
// */
// @Test
// void relationshipTestPlayers(){
// MatchEntity match;
// PlayerEntity player;
// EntityManager em1 = null;
// try {
// em1 = emf.createEntityManager();
// em1.getTransaction().begin();
// match = em1.find(MatchEntity.class, matchA.getId());
// Assertions.assertEquals(match.getPlayers(),
// new HashSet<>(List.of(playerA,playerB,playerC,playerD,playerE,playerF)));
//
// match = em1.find(MatchEntity.class, matchB.getId());
// Assertions.assertEquals(match.getPlayers(),
// new HashSet<>(List.of(playerA,playerB,playerC,playerD)));
//
// match = em1.find(MatchEntity.class, matchC.getId());
// Assertions.assertEquals(match.getPlayers(),
// new HashSet<>(List.of(playerB,playerD,playerE,playerF)));
//
// player = em1.find(PlayerEntity.class, playerA.getId());
// Assertions.assertEquals(player.getMatches(), new HashSet<>(List.of(matchA, matchB)));
//
// player = em1.find(PlayerEntity.class, playerB.getId());
// Assertions.assertEquals(player.getMatches(), new HashSet<>(List.of(matchA, matchB, matchC)));
//
// player = em1.find(PlayerEntity.class, playerD.getId());
// Assertions.assertEquals(player.getMatches(), new HashSet<>(List.of(matchA, matchB, matchC)));
//
// player = em1.find(PlayerEntity.class, playerF.getId());
// Assertions.assertEquals(player.getMatches(), new HashSet<>(List.of(matchA, matchC)));
//
// em1.getTransaction().commit();
// } finally {
// if (em1 != null) em1.close();
// }
// }
//
// @AfterAll
// public void afterAll() {
// EntityManager em = null;
// try {
// em = emf.createEntityManager();
// em.getTransaction().begin();
// em.createQuery("delete from MatchEntity").executeUpdate();
// em.createQuery("delete from TeamEntity").executeUpdate();
// em.createQuery("delete from TournamentEntity").executeUpdate();
// em.createQuery("delete from PlayerEntity").executeUpdate();
// em.getTransaction().commit();
// } finally {
// if (em != null) {
// em.close();
// }
// }
// }
//}
package cz.muni.fi.pa165.entity;
import cz.muni.fi.pa165.enums.CountryEnum;
import cz.muni.fi.pa165.enums.TournamentFormat;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.util.HashSet;
import java.util.List;
/**
* @author Adrian Piacek
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class MatchEntityTest {
private final EntityManagerFactory emf = Persistence.createEntityManagerFactory("default");