Schema test
This commit is contained in:
@@ -0,0 +1,78 @@
|
|||||||
|
package me.bearns.fias;
|
||||||
|
|
||||||
|
import me.bearns.fias.domain.Addrobj;
|
||||||
|
import me.bearns.fias.domain.FiasVersion;
|
||||||
|
import me.bearns.fias.domain.House;
|
||||||
|
import me.bearns.fias.repository.AddrobjRepository;
|
||||||
|
import me.bearns.fias.repository.HouseRepository;
|
||||||
|
import org.junit.Before;
|
||||||
|
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;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
|
@ActiveProfiles("test")
|
||||||
|
@DataJpaTest
|
||||||
|
public class SchemeTest {
|
||||||
|
|
||||||
|
private final UUID aoID = UUID.randomUUID();
|
||||||
|
private final UUID firstHouseID = UUID.randomUUID();
|
||||||
|
private final UUID nextHouseID = UUID.randomUUID();
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TestEntityManager entityManager;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AddrobjRepository addrobjRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private HouseRepository houseRepository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSave() {
|
||||||
|
|
||||||
|
final Addrobj addrobj = new Addrobj();
|
||||||
|
addrobj.aoid = aoID;
|
||||||
|
addrobj.aoguid = aoID;
|
||||||
|
|
||||||
|
final House firstHouse = new House();
|
||||||
|
firstHouse.houseid = firstHouseID;
|
||||||
|
firstHouse.houseguid = firstHouseID;
|
||||||
|
firstHouse.aoguid = addrobj;
|
||||||
|
|
||||||
|
final House nextHouse = new House();
|
||||||
|
nextHouse.houseid = nextHouseID;
|
||||||
|
nextHouse.houseguid = nextHouseID;
|
||||||
|
nextHouse.aoguid = addrobj;
|
||||||
|
|
||||||
|
entityManager.persist(addrobj);
|
||||||
|
entityManager.persist(firstHouse);
|
||||||
|
entityManager.persist(nextHouse);
|
||||||
|
|
||||||
|
final Optional<House> firstHouseOpt = houseRepository.findById(firstHouseID);
|
||||||
|
final Optional<House> nextHouseOpt = houseRepository.findById(nextHouseID);
|
||||||
|
|
||||||
|
assertThat(firstHouseOpt.isPresent()).isTrue();
|
||||||
|
|
||||||
|
assertThat(nextHouseOpt.isPresent()).isTrue();
|
||||||
|
|
||||||
|
final House firstHouseRet = firstHouseOpt.orElse(null);
|
||||||
|
final House nextHouseRet = nextHouseOpt.orElse(null);
|
||||||
|
|
||||||
|
assertThat(firstHouseRet).isNotNull();
|
||||||
|
assertThat(nextHouseRet).isNotNull();
|
||||||
|
|
||||||
|
final Addrobj firstAoguid = firstHouseRet.aoguid;
|
||||||
|
final Addrobj nextAoguid = nextHouseRet.aoguid;
|
||||||
|
|
||||||
|
assertThat(firstAoguid.aoguid).isEqualByComparingTo(nextAoguid.aoguid);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user