Skip to content

Commit

Permalink
Feature/conluz 76 (#78)
Browse files Browse the repository at this point in the history
* [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.

* [conluz-76] Implemented toString() method in class PlantId

* [conluz-76] Created test for method GetPlantRepositoryDatabase::findAll()
  • Loading branch information
viktorKhan authored Jun 12, 2024
1 parent 58d6c0e commit a654e59
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<changeSet id="add_datadis_prefix_to_supplies_fields_20240520T2300" author="Víctor Cañizares">
<renameColumn tableName="supplies" newColumnName="datadis_valid_date_from" oldColumnName="valid_date_from"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<changeSet id="add_supplies_fields_20240313T2225" author="Víctor Cañizares">
<addColumn tableName="supplies">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<changeSet id="add_supplies_shelly_fields_20240331T1710" author="Víctor Cañizares">
<addColumn tableName="supplies">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<changeSet id="add_third_party_field_to_supplies_20240520T2255" author="Víctor Cañizares">
<addColumn tableName="supplies">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<!-- Create table 'huawei_config' -->
<changeSet id="create_huawei_config" author="Víctor Cañizares">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<!-- Create table 'huawei_config' -->
<changeSet id="create_plants" author="Víctor Cañizares">
<createTable tableName="plants">
<column name="id" type="UUID">
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/db/liquibase/changelogs/init.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<!-- Create table 'config' -->
<changeSet id="create_config" author="Víctor Cañizares">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
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.24.xsd">

<changeSet id="make_plants_supply_id_not_null" author="Víctor Cañizares">
<addNotNullConstraint columnDataType="UUID"
columnName="supply_id"
tableName="plants"/>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<changeSet id="replace_user_id_by_supply_id_in_plants_table_20240520T2305" author="Víctor Cañizares">
<addColumn tableName="plants">
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Plant> 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<Plant> pagedResult = getPlantRepositoryDatabase.findAll(pagedRequest);

assertEquals(2, pagedResult.getItems().size());
}
}

0 comments on commit a654e59

Please sign in to comment.