Skip to content
Snippets Groups Projects
Commit 8d387871 authored by Andrej Šimurka's avatar Andrej Šimurka
Browse files

Race and season jpa repository tests

parent 3244966b
No related branches found
No related tags found
2 merge requests!60Docker,!5221 race jpa tests
Pipeline #
......@@ -48,6 +48,11 @@
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>3.0.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>17</maven.compiler.source>
......
package cz.muni.pa165.race.rest;
import cz.muni.pa165.race.data.model.Race;
import cz.muni.pa165.race.data.repository.RaceRepository;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.test.context.junit4.SpringRunner;
@DataJpaTest
public class RaceRepositoryTest {
@Autowired
private TestEntityManager entityManager;
@Autowired
private RaceRepository raceRepository;
@Test
public void saveTest() {
Race race = RaceTestUtil.getDaoRace();
Race saved = raceRepository.save(race);
Assertions.assertEquals(race, saved);
Assertions.assertEquals(entityManager.find(Race.class, 1L).getId(), 1);
}
@Test
public void getSavedEntityTest() {
Race race = RaceTestUtil.getDaoRace();
Race saved = raceRepository.save(race);
var savedId = saved.getId();
Race found = raceRepository.findById(savedId).get();
Assertions.assertAll(
() -> assertEquals(found.getRaceInfo().getName(), race.getRaceInfo().getName()),
() -> assertEquals(found.getRaceInfo().getLocation(), race.getRaceInfo().getLocation()),
() -> assertEquals(found.getRaceInfo().getPrizePool(), race.getRaceInfo().getPrizePool()),
() -> assertEquals(found.getDriver1().getDriverId(), race.getDriver1().getDriverId()),
() -> assertEquals(found.getDriver1().getCarId(), race.getDriver1().getCarId()),
() -> assertEquals(found.getDriver1().getFinalPosition(), race.getDriver1().getFinalPosition()),
() -> assertEquals(found.getDriver2().getDriverId(), race.getDriver2().getDriverId()),
() -> assertEquals(found.getDriver2().getCarId(), race.getDriver2().getCarId()),
() -> assertEquals(found.getDriver2().getFinalPosition(), race.getDriver2().getFinalPosition()));
}
}
package cz.muni.pa165.race.rest;
import cz.muni.pa165.race.data.model.Season;
import cz.muni.pa165.race.data.repository.SeasonRepository;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
@DataJpaTest
public class SeasonRepositoryTest {
@Autowired
private TestEntityManager entityManager;
@Autowired
private SeasonRepository seasonRepository;
@Test
public void saveTest() {
Season season = SeasonTestUtil.getDaoSeason();
Season saved = seasonRepository.save(season);
Assertions.assertEquals(season, saved);
Assertions.assertEquals(entityManager.find(Season.class, 1L).getId(), 1);
}
@Test
public void getSavedEntityTest() {
Season season = SeasonTestUtil.getDaoSeason();
Season saved = seasonRepository.save(season);
var savedId = saved.getId();
Season found = seasonRepository.findById(savedId).get();
Assertions.assertAll(
() -> assertEquals(found.getSeasonYear(), season.getSeasonYear()),
() -> assertEquals(found.getRaces(), season.getRaces())
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment