From 046c0ff8dbf93e090fe92d26a1abaf203c7280a3 Mon Sep 17 00:00:00 2001 From: viktorKhan Date: Tue, 11 Jun 2024 23:22:38 +0200 Subject: [PATCH 1/3] [conluz-76] Created DB migration to make field supply_id from table plants not nullable. Changed the liquibase dbchangelog schema to match version of the library used, 4.24. --- .../add_datadis_prefix_to_supplies_fields.xml | 2 +- .../liquibase/changelogs/add_supplies_fields.xml | 2 +- .../changelogs/add_supplies_shelly_fields.xml | 2 +- .../add_third_party_field_to_supplies.xml | 2 +- .../changelogs/create_huawei_config_table.xml | 2 +- .../liquibase/changelogs/create_plants_table.xml | 3 +-- .../resources/db/liquibase/changelogs/init.xml | 2 +- .../changelogs/make_plants_supply_id_not_null.xml | 14 ++++++++++++++ ...eplace_user_id_by_supply_id_in_plants_table.xml | 2 +- 9 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 src/main/resources/db/liquibase/changelogs/make_plants_supply_id_not_null.xml diff --git a/src/main/resources/db/liquibase/changelogs/add_datadis_prefix_to_supplies_fields.xml b/src/main/resources/db/liquibase/changelogs/add_datadis_prefix_to_supplies_fields.xml index f3316ef..13b738a 100644 --- a/src/main/resources/db/liquibase/changelogs/add_datadis_prefix_to_supplies_fields.xml +++ b/src/main/resources/db/liquibase/changelogs/add_datadis_prefix_to_supplies_fields.xml @@ -3,7 +3,7 @@ xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog -http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd"> +http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd"> diff --git a/src/main/resources/db/liquibase/changelogs/add_supplies_fields.xml b/src/main/resources/db/liquibase/changelogs/add_supplies_fields.xml index 14fbb5f..adfa187 100644 --- a/src/main/resources/db/liquibase/changelogs/add_supplies_fields.xml +++ b/src/main/resources/db/liquibase/changelogs/add_supplies_fields.xml @@ -3,7 +3,7 @@ xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog -http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd"> +http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd"> diff --git a/src/main/resources/db/liquibase/changelogs/add_supplies_shelly_fields.xml b/src/main/resources/db/liquibase/changelogs/add_supplies_shelly_fields.xml index 2516ca6..c84d7a9 100644 --- a/src/main/resources/db/liquibase/changelogs/add_supplies_shelly_fields.xml +++ b/src/main/resources/db/liquibase/changelogs/add_supplies_shelly_fields.xml @@ -3,7 +3,7 @@ xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog -http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd"> +http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd"> diff --git a/src/main/resources/db/liquibase/changelogs/add_third_party_field_to_supplies.xml b/src/main/resources/db/liquibase/changelogs/add_third_party_field_to_supplies.xml index 8986278..188cb22 100644 --- a/src/main/resources/db/liquibase/changelogs/add_third_party_field_to_supplies.xml +++ b/src/main/resources/db/liquibase/changelogs/add_third_party_field_to_supplies.xml @@ -3,7 +3,7 @@ xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog -http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd"> +http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd"> diff --git a/src/main/resources/db/liquibase/changelogs/create_huawei_config_table.xml b/src/main/resources/db/liquibase/changelogs/create_huawei_config_table.xml index 5d3c20f..c34f478 100644 --- a/src/main/resources/db/liquibase/changelogs/create_huawei_config_table.xml +++ b/src/main/resources/db/liquibase/changelogs/create_huawei_config_table.xml @@ -3,7 +3,7 @@ xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog -http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd"> +http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd"> diff --git a/src/main/resources/db/liquibase/changelogs/create_plants_table.xml b/src/main/resources/db/liquibase/changelogs/create_plants_table.xml index 75544e1..1f0e35b 100644 --- a/src/main/resources/db/liquibase/changelogs/create_plants_table.xml +++ b/src/main/resources/db/liquibase/changelogs/create_plants_table.xml @@ -3,9 +3,8 @@ xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog -http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd"> +http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd"> - diff --git a/src/main/resources/db/liquibase/changelogs/init.xml b/src/main/resources/db/liquibase/changelogs/init.xml index 9940778..165abf2 100644 --- a/src/main/resources/db/liquibase/changelogs/init.xml +++ b/src/main/resources/db/liquibase/changelogs/init.xml @@ -3,7 +3,7 @@ xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog -http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd"> +http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd"> diff --git a/src/main/resources/db/liquibase/changelogs/make_plants_supply_id_not_null.xml b/src/main/resources/db/liquibase/changelogs/make_plants_supply_id_not_null.xml new file mode 100644 index 0000000..42289b7 --- /dev/null +++ b/src/main/resources/db/liquibase/changelogs/make_plants_supply_id_not_null.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/src/main/resources/db/liquibase/changelogs/replace_user_id_by_supply_id_in_plants_table.xml b/src/main/resources/db/liquibase/changelogs/replace_user_id_by_supply_id_in_plants_table.xml index 1bf4dfb..40346a6 100644 --- a/src/main/resources/db/liquibase/changelogs/replace_user_id_by_supply_id_in_plants_table.xml +++ b/src/main/resources/db/liquibase/changelogs/replace_user_id_by_supply_id_in_plants_table.xml @@ -3,7 +3,7 @@ xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog -http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd"> +http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd"> From 526779d42d2a0eee7f2ee4f19f8e5c2edb16214f Mon Sep 17 00:00:00 2001 From: viktorKhan Date: Tue, 11 Jun 2024 23:23:10 +0200 Subject: [PATCH 2/3] [conluz-76] Implemented toString() method in class PlantId --- .../java/org/lucoenergia/conluz/domain/shared/PlantId.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/lucoenergia/conluz/domain/shared/PlantId.java b/src/main/java/org/lucoenergia/conluz/domain/shared/PlantId.java index 0acdb6b..a07cfaf 100644 --- a/src/main/java/org/lucoenergia/conluz/domain/shared/PlantId.java +++ b/src/main/java/org/lucoenergia/conluz/domain/shared/PlantId.java @@ -17,4 +17,11 @@ public UUID getId() { public static PlantId of(UUID id) { return new PlantId(id); } + + @Override + public String toString() { + return "PlantId{" + + "id=" + id.toString() + + '}'; + } } From ca43cd774cdf8c8eb301af7596df2ffb67cfcf1c Mon Sep 17 00:00:00 2001 From: viktorKhan Date: Tue, 11 Jun 2024 23:24:11 +0200 Subject: [PATCH 3/3] [conluz-76] Created test for method GetPlantRepositoryDatabase::findAll() --- ...lantRepositoryDatabaseIntegrationTest.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/test/java/org/lucoenergia/conluz/infrastructure/production/plant/get/GetPlantRepositoryDatabaseIntegrationTest.java diff --git a/src/test/java/org/lucoenergia/conluz/infrastructure/production/plant/get/GetPlantRepositoryDatabaseIntegrationTest.java b/src/test/java/org/lucoenergia/conluz/infrastructure/production/plant/get/GetPlantRepositoryDatabaseIntegrationTest.java new file mode 100644 index 0000000..f6c923a --- /dev/null +++ b/src/test/java/org/lucoenergia/conluz/infrastructure/production/plant/get/GetPlantRepositoryDatabaseIntegrationTest.java @@ -0,0 +1,64 @@ +package org.lucoenergia.conluz.infrastructure.production.plant.get; + +import org.junit.jupiter.api.Test; +import org.lucoenergia.conluz.domain.admin.supply.Supply; +import org.lucoenergia.conluz.domain.admin.supply.SupplyMother; +import org.lucoenergia.conluz.domain.admin.supply.create.CreateSupplyRepository; +import org.lucoenergia.conluz.domain.admin.user.User; +import org.lucoenergia.conluz.domain.admin.user.UserMother; +import org.lucoenergia.conluz.domain.admin.user.create.CreateUserRepository; +import org.lucoenergia.conluz.domain.production.plant.Plant; +import org.lucoenergia.conluz.domain.production.plant.PlantMother; +import org.lucoenergia.conluz.domain.production.plant.create.CreatePlantRepository; +import org.lucoenergia.conluz.domain.shared.SupplyId; +import org.lucoenergia.conluz.domain.shared.UserId; +import org.lucoenergia.conluz.domain.shared.pagination.PagedRequest; +import org.lucoenergia.conluz.domain.shared.pagination.PagedResult; +import org.lucoenergia.conluz.infrastructure.production.plant.PlantEntity; +import org.lucoenergia.conluz.infrastructure.shared.BaseIntegrationTest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@Transactional +class GetPlantRepositoryDatabaseIntegrationTest extends BaseIntegrationTest { + + @Autowired + private GetPlantRepositoryDatabase getPlantRepositoryDatabase; + + @Autowired + private CreatePlantRepository createPlantRepository; + @Autowired + private CreateSupplyRepository createSupplyRepository; + @Autowired + private CreateUserRepository createUserRepository; + + + @Test + void testFindAllWithZeroResults() { + + PagedRequest pagedRequest = PagedRequest.of(0, 10); + PagedResult pagedResult = getPlantRepositoryDatabase.findAll(pagedRequest); + + assertEquals(0, pagedResult.getItems().size()); + } + + @Test + void testFindAllWithMoreThanOneResults() { + + User user = UserMother.randomUser(); + user = createUserRepository.create(user); + Supply supply = SupplyMother.random(user).build(); + supply = createSupplyRepository.create(supply, UserId.of(user.getId())); + Plant plantEntityOne = PlantMother.random(supply).build(); + createPlantRepository.create(plantEntityOne, SupplyId.of(supply.getId())); + Plant plantEntityTwo = PlantMother.random(supply).build(); + createPlantRepository.create(plantEntityTwo, SupplyId.of(supply.getId())); + + PagedRequest pagedRequest = PagedRequest.of(0, 10); + PagedResult pagedResult = getPlantRepositoryDatabase.findAll(pagedRequest); + + assertEquals(2, pagedResult.getItems().size()); + } +} \ No newline at end of file