Commit 344e3805 authored by Adrián Piaček's avatar Adrián Piaček
Browse files

Merge branch 'frontend' into 'main'

Frontend

See merge request !29
parents 2cebab23 e7cb3362
Pipeline #141928 passed with stage
in 1 minute and 40 seconds
......@@ -15,6 +15,8 @@ public class TournamentDTO extends BaseDTO {
private String city;
private String name;
private CountryEnum country;
private double prizePool;
......@@ -24,4 +26,5 @@ public class TournamentDTO extends BaseDTO {
private int teamCapacity;
private TeamEntity winner;
}
......@@ -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
......@@ -21,6 +21,9 @@ public class TournamentEntity extends BaseEntity {
@Column(nullable = false, unique = true)
private String city;
@Column(nullable = false)
private String name;
private CountryEnum country;
private double prizePool;
private TournamentFormat tournamentFormat;
......@@ -56,9 +59,10 @@ public class TournamentEntity extends BaseEntity {
public TournamentEntity() {
}
public TournamentEntity(String city, CountryEnum country,
public TournamentEntity(String name, String city, CountryEnum country,
int pricePool, TournamentFormat format, int capacity) {
this.name = name;
this.city = city;
this.country = country;
this.prizePool = pricePool;
......
......@@ -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() {
......@@ -86,7 +90,7 @@ public class MatchDaoTest extends AbstractTransactionalTestNGSpringContextTests
void update() {
MatchEntity match = new MatchEntity();
matchDao.create(match);
TournamentEntity tournament = new TournamentEntity("Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
TournamentEntity tournament = new TournamentEntity("MSI","Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
tournamentDao.create(tournament);
match.setTournament(tournament);
TeamEntity teamA = new TeamEntity();
......
......@@ -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,10 +28,26 @@ 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() {
TournamentEntity tournament = new TournamentEntity("Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
TournamentEntity tournament = new TournamentEntity("MSI","Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
tournamentDao.create(tournament);
assertThat(tournament.getId()).isNotNull();
Assertions.assertThat(tournamentDao.findAll()).hasSize(1);
......@@ -35,7 +55,7 @@ public class TournamentDaoTest extends AbstractTransactionalTestNGSpringContextT
@Test
void findByIdExisting() {
TournamentEntity tournament = new TournamentEntity("Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
TournamentEntity tournament = new TournamentEntity("MSI 2","Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
tournamentDao.create(tournament);
var find = tournamentDao.findById(tournament.getId());
assertThat(find).isEqualTo(tournament);
......@@ -52,9 +72,9 @@ public class TournamentDaoTest extends AbstractTransactionalTestNGSpringContextT
@Test
void findAll() {
TournamentEntity tournamentA =
new TournamentEntity("Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
new TournamentEntity("MSI","Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
TournamentEntity tournamentB =
new TournamentEntity("Brno", CountryEnum.CZECH_REPUBLIC, 5, TournamentFormat.DEFAULT, 15);
new TournamentEntity("MSI 2","Brno", CountryEnum.CZECH_REPUBLIC, 5, TournamentFormat.DEFAULT, 15);
tournamentDao.create(tournamentA);
tournamentDao.create(tournamentB);
Assertions.assertThat(tournamentDao.findAll()).hasSize(2);
......@@ -64,6 +84,7 @@ public class TournamentDaoTest extends AbstractTransactionalTestNGSpringContextT
void update() {
TournamentEntity tournamentEntity = new TournamentEntity();
tournamentDao.create(tournamentEntity);
tournamentEntity.setName("MSI");
tournamentEntity.setCity("Bratislava");
tournamentEntity.setPrizePool(25.0);
tournamentEntity.setTeamCapacity(7);
......@@ -74,9 +95,9 @@ public class TournamentDaoTest extends AbstractTransactionalTestNGSpringContextT
@Test
void delete() {
TournamentEntity tournamentA =
new TournamentEntity("Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
new TournamentEntity("MSI","Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
TournamentEntity tournamentB =
new TournamentEntity("Brno", CountryEnum.CZECH_REPUBLIC, 5, TournamentFormat.DEFAULT, 15);
new TournamentEntity("MSI 2","Brno", CountryEnum.CZECH_REPUBLIC, 5, TournamentFormat.DEFAULT, 15);
tournamentDao.create(tournamentA);
tournamentDao.create(tournamentB);
tournamentDao.remove(tournamentA);
......
......@@ -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();
// }