diff options
author | mrfoxygmfr <mrfoxygmfr@sch9.ru> | 2025-03-24 01:35:11 +0300 |
---|---|---|
committer | mrfoxygmfr <mrfoxygmfr@sch9.ru> | 2025-03-24 01:35:11 +0300 |
commit | b12c501e8e1769716da2db7ba49ee6cf88142995 (patch) | |
tree | 8d61c6eb0f1201e8970145385fd59c0ed9912158 | |
parent | eaba5c9ae0296206f8f7eeddc388519ab8ae684a (diff) |
test(db): addContact method test
-rw-r--r-- | src/test/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/PartnerDAOTest.java | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/test/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/PartnerDAOTest.java b/src/test/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/PartnerDAOTest.java index 7102025..a13b6d1 100644 --- a/src/test/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/PartnerDAOTest.java +++ b/src/test/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/PartnerDAOTest.java @@ -8,8 +8,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.crossstore.ChangeSetPersister; import org.springframework.test.context.TestPropertySource; +import org.springframework.transaction.annotation.Transactional; import ru.mrfoxygmfr.warehouse_accounting.db.dao.specs.PartnerSpecs; import ru.mrfoxygmfr.warehouse_accounting.db.models.Partner; +import ru.mrfoxygmfr.warehouse_accounting.db.models.PartnerContact; import ru.mrfoxygmfr.warehouse_accounting.db.models.PartnerType; import java.util.ArrayList; @@ -74,6 +76,22 @@ public class PartnerDAOTest { assertTrue(partnerDAO.findById(1).isEmpty()); } + @Test + void addPartnerContact() { + Partner p = partnerDAO.findById(1).orElseThrow(); + PartnerContact pc = new PartnerContact(p, "Иванов", "Иван", "Исп. директор", "+7 800 555-35-35", "ivanov@roga-kopita.ru"); + p.addContact(pc); + partnerDAO.save(p); + + Partner partner = partnerDAO.findById(1).orElseThrow(); + PartnerContact pc_found = partner.getContacts().stream().findFirst().orElseThrow(); + assertEquals(pc.getSurname(), pc_found.getSurname()); + assertEquals(pc.getName(), pc_found.getName()); + assertEquals(pc.getPosition(), pc_found.getPosition()); + assertEquals(pc.getPhone(), pc_found.getPhone()); + assertEquals(pc.getEmail(), pc_found.getEmail()); + } + @BeforeEach void beforeEach() { List<Partner> partners = new ArrayList<>(); @@ -81,7 +99,6 @@ public class PartnerDAOTest { partners.add(new Partner("ООО Поставки из Китая", "1036300882671", PartnerType.SUPPLIER, "Россия, г. Город, ул. Улица, д. 2")); partners.add(new Partner("Десяточка", "7825706086", PartnerType.ISSUER, "Россия, г. Санкт-Петербург, пр. Невский, д. 90/92")); partnerDAO.saveAll(partners); - System.out.println(partnerDAO.findAll()); } @BeforeAll @@ -89,6 +106,8 @@ public class PartnerDAOTest { void annihilation() { try (Session session = sessionFactory.openSession()) { Transaction tx = session.beginTransaction(); + session.createNativeQuery("TRUNCATE public.partner_contacts RESTART IDENTITY CASCADE;").executeUpdate(); + session.createNativeQuery("ALTER SEQUENCE partner_contacts_id_seq RESTART WITH 1;").executeUpdate(); session.createNativeQuery("TRUNCATE partners RESTART IDENTITY CASCADE;").executeUpdate(); session.createNativeQuery("ALTER SEQUENCE partners_id_seq RESTART WITH 1;").executeUpdate(); tx.commit(); |