From 61548ce1ee21da302a9a93e68e03b19cbb09084d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Ca=C3=B1izares=20Mata?= Date: Fri, 8 Mar 2024 17:31:00 +0100 Subject: [PATCH] =?UTF-8?q?[conluz-54]=20Renamed=20current=20id=20to=20cod?= =?UTF-8?q?e=20and=20added=20a=20new=20field=20id=20of=20ty=E2=80=A6=20(#5?= =?UTF-8?q?5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [conluz-54] Renamed current id to code and added a new field id of type UUID * [conluz-54] Adapted OAS documentation to the adition of the new code field --- .../conluz/domain/admin/supply/Supply.java | 30 ++++- .../supply/SupplyAlreadyExistsException.java | 16 +++ .../conluz/domain/shared/SupplyCode.java | 14 +++ .../conluz/domain/shared/SupplyId.java | 8 +- .../admin/supply/SupplyEntity.java | 105 ++++++++++++++---- .../admin/supply/SupplyEntityMapper.java | 1 + .../admin/supply/SupplyRepository.java | 9 +- .../admin/supply/SupplyResponse.java | 11 +- .../supply/create/CreateSupplyAssembler.java | 2 +- .../admin/supply/create/CreateSupplyBody.java | 10 +- .../supply/create/CreateSupplyController.java | 3 +- .../create/CreateSupplyRepositoryImpl.java | 19 +++- .../supply/get/GetAllSuppliesController.java | 9 +- ...GetDatadisConsumptionRepositoryInflux.java | 2 +- .../GetDatadisConsumptionRepositoryRest.java | 6 +- .../GetDailyProductionController.java | 7 +- .../GetHourlyProductionController.java | 6 +- .../GetInstantProductionController.java | 7 +- .../GetMonthlyProductionController.java | 6 +- .../GetYearlyProductionController.java | 6 +- .../web/error/SupplyExceptionHandler.java | 2 +- .../db/liquibase/changelogs/init.xml | 5 +- .../domain/admin/supply/SupplyMother.java | 11 +- .../DatadisConsumptionSyncServiceTest.java | 6 +- .../admin/supply/SupplyEntityMapperTest.java | 7 +- .../admin/supply/SupplyEntityMother.java | 27 +++++ .../create/CreateSupplyControllerTest.java | 10 +- .../create/ImportUsersControllerTest.java | 22 ++-- ...sumptionRepositoryRestIntegrationTest.java | 2 +- ...tDatadisConsumptionRepositoryRestTest.java | 4 +- ...mptionRepositoryInfluxIntegrationTest.java | 2 +- .../GetHourlyProductionControllerTest.java | 19 ++-- .../GetInstantProductionControllerTest.java | 34 ++++-- src/test/resources/{ => fixtures}/empty.csv | 0 .../resources/{ => fixtures/users}/users.csv | 0 .../{ => fixtures/users}/users_malformed.csv | 0 36 files changed, 317 insertions(+), 111 deletions(-) create mode 100644 src/main/java/org/lucoenergia/conluz/domain/admin/supply/SupplyAlreadyExistsException.java create mode 100644 src/main/java/org/lucoenergia/conluz/domain/shared/SupplyCode.java create mode 100644 src/test/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyEntityMother.java rename src/test/resources/{ => fixtures}/empty.csv (100%) rename src/test/resources/{ => fixtures/users}/users.csv (100%) rename src/test/resources/{ => fixtures/users}/users_malformed.csv (100%) diff --git a/src/main/java/org/lucoenergia/conluz/domain/admin/supply/Supply.java b/src/main/java/org/lucoenergia/conluz/domain/admin/supply/Supply.java index d543888..677aab6 100644 --- a/src/main/java/org/lucoenergia/conluz/domain/admin/supply/Supply.java +++ b/src/main/java/org/lucoenergia/conluz/domain/admin/supply/Supply.java @@ -1,16 +1,28 @@ package org.lucoenergia.conluz.domain.admin.supply; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import org.lucoenergia.conluz.domain.admin.user.User; +import org.lucoenergia.conluz.infrastructure.shared.uuid.ValidUUID; import java.time.LocalDate; +import java.util.UUID; public class Supply { - private final String id; + @NotNull + @ValidUUID + private final UUID id; + @NotBlank + private final String code; + @NotNull private User user; private final String name; + @NotBlank private final String address; + @NotNull private final Float partitionCoefficient; + @NotNull private final Boolean enabled; private final LocalDate validDateFrom; private final String distributor; @@ -19,6 +31,7 @@ public class Supply { private Supply(Builder builder) { this.id = builder.id; + this.code = builder.code; this.user = builder.user; this.name = builder.name; this.address = builder.address; @@ -31,7 +44,8 @@ private Supply(Builder builder) { } public static class Builder { - private String id; + private UUID id; + private String code; private User user; private String name; private String address; @@ -42,11 +56,16 @@ public static class Builder { private String distributorCode; private String pointType; - public Builder withId(String id) { + public Builder withId(UUID id) { this.id = id; return this; } + public Builder withCode(String code) { + this.code = code; + return this; + } + public Builder withUser(User user) { this.user = user; return this; @@ -97,9 +116,12 @@ public Supply build() { } } - public String getId() { + public UUID getId() { return id; } + public String getCode() { + return code; + } public User getUser() { return user; diff --git a/src/main/java/org/lucoenergia/conluz/domain/admin/supply/SupplyAlreadyExistsException.java b/src/main/java/org/lucoenergia/conluz/domain/admin/supply/SupplyAlreadyExistsException.java new file mode 100644 index 0000000..6412dee --- /dev/null +++ b/src/main/java/org/lucoenergia/conluz/domain/admin/supply/SupplyAlreadyExistsException.java @@ -0,0 +1,16 @@ +package org.lucoenergia.conluz.domain.admin.supply; + +import org.lucoenergia.conluz.domain.shared.SupplyCode; + +public class SupplyAlreadyExistsException extends RuntimeException { + + private final SupplyCode code; + + public SupplyAlreadyExistsException(SupplyCode code) { + this.code = code; + } + + public SupplyCode getUserId() { + return code; + } +} diff --git a/src/main/java/org/lucoenergia/conluz/domain/shared/SupplyCode.java b/src/main/java/org/lucoenergia/conluz/domain/shared/SupplyCode.java new file mode 100644 index 0000000..c288774 --- /dev/null +++ b/src/main/java/org/lucoenergia/conluz/domain/shared/SupplyCode.java @@ -0,0 +1,14 @@ +package org.lucoenergia.conluz.domain.shared; + +public class SupplyCode { + + private final String code; + + public SupplyCode(String code) { + this.code = code; + } + + public String getCode() { + return code; + } +} diff --git a/src/main/java/org/lucoenergia/conluz/domain/shared/SupplyId.java b/src/main/java/org/lucoenergia/conluz/domain/shared/SupplyId.java index 4c56977..38f5730 100644 --- a/src/main/java/org/lucoenergia/conluz/domain/shared/SupplyId.java +++ b/src/main/java/org/lucoenergia/conluz/domain/shared/SupplyId.java @@ -1,14 +1,16 @@ package org.lucoenergia.conluz.domain.shared; +import java.util.UUID; + public class SupplyId { - private final String id; + private final UUID id; - public SupplyId(String id) { + public SupplyId(UUID id) { this.id = id; } - public String getId() { + public UUID getId() { return id; } } diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyEntity.java b/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyEntity.java index d74fa48..051f349 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyEntity.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyEntity.java @@ -6,11 +6,14 @@ import jakarta.persistence.ManyToOne; import org.lucoenergia.conluz.infrastructure.admin.user.UserEntity; +import java.util.UUID; + @Entity(name = "supplies") public class SupplyEntity { @Id - private String id; + private UUID id; + private String code; @ManyToOne(fetch = FetchType.LAZY) private UserEntity user; private String name; @@ -22,22 +25,91 @@ public SupplyEntity() { enabled = true; } - public SupplyEntity(String id, String name, String address, Float partitionCoefficient, Boolean enabled) { - this.id = id; - this.name = name; - this.address = address; - this.partitionCoefficient = partitionCoefficient; - this.enabled = enabled; + public static class Builder { + private UUID id; + private String code; + private UserEntity user; + private String name; + private String address; + private Float partitionCoefficient; + private Boolean enabled; + + public Builder withId(UUID id) { + this.id = id; + return this; + } + + public Builder withCode(String code) { + this.code = code; + return this; + } + + public Builder withUser(UserEntity user) { + this.user = user; + return this; + } + + public Builder withName(String name) { + this.name = name; + return this; + } + + public Builder withAddress(String address) { + this.address = address; + return this; + } + + public Builder withPartitionCoefficient(Float partitionCoefficient) { + this.partitionCoefficient = partitionCoefficient; + return this; + } + + public Builder withEnabled(Boolean enabled) { + this.enabled = enabled; + return this; + } + + public SupplyEntity build() { + SupplyEntity entity = new SupplyEntity(); + entity.id = this.id; + entity.code = this.code; + entity.user = this.user; + entity.name = this.name; + entity.address = this.address; + entity.partitionCoefficient = this.partitionCoefficient; + entity.enabled = this.enabled; + return entity; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SupplyEntity )) return false; + return code != null && code.equals(((SupplyEntity) o).getCode()); + } + + @Override + public int hashCode() { + return getClass().hashCode(); } - public String getId() { + public UUID getId() { return id; } - public void setId(String id) { + public void setId(UUID id) { this.id = id; } + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + public String getName() { return name; } @@ -50,6 +122,7 @@ public String getAddress() { return address; } + public void setAddress(String address) { this.address = address; } @@ -77,16 +150,4 @@ public UserEntity getUser() { public void setUser(UserEntity user) { this.user = user; } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SupplyEntity )) return false; - return id != null && id.equals(((SupplyEntity) o).getId()); - } - - @Override - public int hashCode() { - return getClass().hashCode(); - } -} +} \ No newline at end of file diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyEntityMapper.java b/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyEntityMapper.java index 858a682..6922c0e 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyEntityMapper.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyEntityMapper.java @@ -11,6 +11,7 @@ public class SupplyEntityMapper extends BaseMapper { public Supply map(SupplyEntity entity) { return new Supply.Builder() .withId(entity.getId()) + .withCode(entity.getCode()) .withAddress(entity.getAddress()) .withPartitionCoefficient(entity.getPartitionCoefficient()) .withEnabled(entity.getEnabled()) diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyRepository.java b/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyRepository.java index 7257fc6..1e38ef1 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyRepository.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyRepository.java @@ -2,5 +2,12 @@ import org.springframework.data.jpa.repository.JpaRepository; -public interface SupplyRepository extends JpaRepository { +import java.util.Optional; +import java.util.UUID; + +public interface SupplyRepository extends JpaRepository { + + Optional findByCode(String code); + + int countByCode(String code); } diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyResponse.java b/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyResponse.java index 54dab61..f1e9788 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyResponse.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyResponse.java @@ -3,9 +3,12 @@ import org.lucoenergia.conluz.domain.admin.supply.Supply; import org.lucoenergia.conluz.infrastructure.admin.user.UserResponse; +import java.util.UUID; + public class SupplyResponse { - private final String id; + private final UUID id; + private final String code; private final UserResponse user; private final String name; private final String address; @@ -14,6 +17,7 @@ public class SupplyResponse { public SupplyResponse(Supply supply) { this.id = supply.getId(); + this.code = supply.getCode(); this.name = supply.getName(); this.address = supply.getAddress(); this.partitionCoefficient = supply.getPartitionCoefficient(); @@ -21,9 +25,12 @@ public SupplyResponse(Supply supply) { this.user = supply.getUser() != null ? new UserResponse(supply.getUser()) : null; } - public String getId() { + public UUID getId() { return id; } + public String getCode() { + return code; + } public UserResponse getUser() { return user; diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/create/CreateSupplyAssembler.java b/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/create/CreateSupplyAssembler.java index 51f22f2..8c1af00 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/create/CreateSupplyAssembler.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/create/CreateSupplyAssembler.java @@ -10,7 +10,7 @@ public class CreateSupplyAssembler implements Assembler 0) { + throw new SupplyAlreadyExistsException(new SupplyCode(supply.getCode())); + } + UserEntity userEntity = result.get(); - SupplyEntity supplyEntity = new SupplyEntity(supply.getId(), supply.getName(), supply.getAddress(), - supply.getPartitionCoefficient(), supply.getEnabled()); + SupplyEntity supplyEntity = new SupplyEntity.Builder() + .withId(UUID.randomUUID()) + .withCode(supply.getCode()) + .withName(supply.getName()) + .withAddress(supply.getAddress()) + .withPartitionCoefficient(supply.getPartitionCoefficient()) + .withEnabled(supply.getEnabled()) + .build(); userEntity.addSupply(supplyEntity); userRepository.save(userEntity); - Optional newSupplyEntity = supplyRepository.findById(supply.getId()); + Optional newSupplyEntity = supplyRepository.findByCode(supply.getCode()); if (newSupplyEntity.isEmpty()) { throw new SupplyCannotBeCreatedException(); } diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/get/GetAllSuppliesController.java b/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/get/GetAllSuppliesController.java index 153f9f9..cd6a89e 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/get/GetAllSuppliesController.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/admin/supply/get/GetAllSuppliesController.java @@ -60,7 +60,8 @@ public GetAllSuppliesController(GetSupplyService service) { { "items":[ { - "id":"hhtc50AmS9KRqvZuYecV", + "id":"123e4567-e89b-12d3-a456-426614174000", + "code":"hhtc50AmS9KRqvZuYecV", "user":{ "id":"e7ab39cd-9250-40a9-b829-f11f65aae27d", "personalId":"rAtjrSXAU", @@ -78,7 +79,8 @@ public GetAllSuppliesController(GetSupplyService service) { "enabled":true }, { - "id":"mbHX0arnmS4KgooidQxj", + "id":"3f4fb466-2753-4f6d-bf73-8478e876e50b", + "code":"mbHX0arnmS4KgooidQxj", "user":{ "id":"81b4de42-a49f-440f-868a-f1cf72199ae7", "personalId":"j3E44iio", @@ -96,7 +98,8 @@ public GetAllSuppliesController(GetSupplyService service) { "enabled":true }, { - "id":"6OOtEWtt4a0epeugj1y2", + "id":"785de77b-8c22-4d2f-9d12-f172113f9aa4", + "code":"6OOtEWtt4a0epeugj1y2", "user":{ "id":"e7ab39cd-9250-40a9-b829-f11f65aae27d", "personalId":"rAtjrSXAU", diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/GetDatadisConsumptionRepositoryInflux.java b/src/main/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/GetDatadisConsumptionRepositoryInflux.java index 6d48ba6..e88b826 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/GetDatadisConsumptionRepositoryInflux.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/GetDatadisConsumptionRepositoryInflux.java @@ -43,7 +43,7 @@ public List getHourlyConsumptionsByMonth(Supply supply, Month month Query query = new Query(String.format( "SELECT * FROM \"%s\" WHERE cups = '%s' AND time >= '%s' AND time <= '%s'", DatadisConfig.CONSUMPTION_KWH_MEASUREMENT, - supply.getId(), + supply.getCode(), startDate, endDate)); diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/GetDatadisConsumptionRepositoryRest.java b/src/main/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/GetDatadisConsumptionRepositoryRest.java index 6b0cb70..1ad8964 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/GetDatadisConsumptionRepositoryRest.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/GetDatadisConsumptionRepositoryRest.java @@ -55,13 +55,13 @@ public List getHourlyConsumptionsByMonth(@NotNull Supply supply, @N final OkHttpClient client = conluzRestClientBuilder.build(); - LOGGER.info("Processing supply {}", supply.getId()); + LOGGER.info("Processing supply {}", supply.getCode()); validateSupply(supply); // Create the complete URL with the query parameter final String url = UriComponentsBuilder.fromUriString(DatadisConfig.BASE_URL + GET_CONSUMPTION_DATA_PATH) - .queryParam(DatadisParams.CUPS, supply.getId()) + .queryParam(DatadisParams.CUPS, supply.getCode()) .queryParam(DatadisParams.DISTRIBUTOR_CODE, supply.getDistributorCode()) .queryParam(DatadisParams.AUTHORIZED_NIF, supply.getUser().getPersonalId()) .queryParam(DatadisParams.START_DATE, monthDate) @@ -91,7 +91,7 @@ public List getHourlyConsumptionsByMonth(@NotNull Supply supply, @N result.addAll(consumptions); } else { throw new DatadisException(String.format("Unable to get consumptions for supply with ID %s. Code %s, message: %s", - supply.getId(), response.code(), response.body() != null ? response.body().string() : response.message())); + supply.getCode(), response.code(), response.body() != null ? response.body().string() : response.message())); } } catch (IOException e) { throw new DatadisException("Unable to make the request to datadis.es", e); diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetDailyProductionController.java b/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetDailyProductionController.java index 8a2ef4c..207d908 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetDailyProductionController.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetDailyProductionController.java @@ -5,7 +5,6 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; -import org.apache.commons.lang3.StringUtils; import org.lucoenergia.conluz.domain.production.GetProductionService; import org.lucoenergia.conluz.domain.production.ProductionByTime; import org.lucoenergia.conluz.domain.shared.SupplyId; @@ -23,6 +22,8 @@ import java.time.OffsetDateTime; import java.util.List; +import java.util.Objects; +import java.util.UUID; @RestController @RequestMapping("/api/v1/production/daily") @@ -62,9 +63,9 @@ public GetDailyProductionController(GetProductionService getProductionService) { public List getDailyProduction( @RequestParam("startDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime startDate, @RequestParam("endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime endDate, - @RequestParam(required = false) String supplyId) { + @RequestParam(required = false) UUID supplyId) { - if (StringUtils.isBlank(supplyId)) { + if (Objects.isNull(supplyId)) { return getProductionService.getDailyProductionByRangeOfDates(startDate, endDate); } return getProductionService.getDailyProductionByRangeOfDatesAndSupply(startDate, endDate, diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetHourlyProductionController.java b/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetHourlyProductionController.java index a533ebe..598ddb0 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetHourlyProductionController.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetHourlyProductionController.java @@ -23,6 +23,8 @@ import java.time.OffsetDateTime; import java.util.List; +import java.util.Objects; +import java.util.UUID; @RestController @RequestMapping("/api/v1/production/hourly") @@ -62,9 +64,9 @@ public GetHourlyProductionController(GetProductionService getProductionService) public List getHourlyProduction( @RequestParam("startDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime startDate, @RequestParam("endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime endDate, - @RequestParam(required = false) String supplyId) { + @RequestParam(required = false) UUID supplyId) { - if (StringUtils.isBlank(supplyId)) { + if (Objects.isNull(supplyId)) { return getProductionService.getHourlyProductionByRangeOfDates(startDate, endDate); } return getProductionService.getHourlyProductionByRangeOfDatesAndSupply(startDate, endDate, diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetInstantProductionController.java b/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetInstantProductionController.java index 08ef0b6..5fea178 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetInstantProductionController.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetInstantProductionController.java @@ -20,6 +20,9 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.util.Objects; +import java.util.UUID; + @RestController @RequestMapping("/api/v1/production") public class GetInstantProductionController { @@ -55,8 +58,8 @@ public GetInstantProductionController(GetProductionService getProductionService) @UnauthorizedErrorResponse @BadRequestErrorResponse @InternalServerErrorResponse - public InstantProduction getInstantProduction(@RequestParam(required = false) String supplyId) { - if (StringUtils.isBlank(supplyId)) { + public InstantProduction getInstantProduction(@RequestParam(required = false) UUID supplyId) { + if (Objects.isNull(supplyId)) { return getProductionService.getInstantProduction(); } return getProductionService.getInstantProductionBySupply(new SupplyId(supplyId)); diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetMonthlyProductionController.java b/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetMonthlyProductionController.java index bc199f2..910c99c 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetMonthlyProductionController.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetMonthlyProductionController.java @@ -23,6 +23,8 @@ import java.time.OffsetDateTime; import java.util.List; +import java.util.Objects; +import java.util.UUID; @RestController @RequestMapping("/api/v1/production/monthly") @@ -62,9 +64,9 @@ public GetMonthlyProductionController(GetProductionService getProductionService) public List getMonthlyProduction( @RequestParam("startDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime startDate, @RequestParam("endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime endDate, - @RequestParam(required = false) String supplyId) { + @RequestParam(required = false) UUID supplyId) { - if (StringUtils.isBlank(supplyId)) { + if (Objects.isNull(supplyId)) { return getProductionService.getMonthlyProductionByRangeOfDates(startDate, endDate); } return getProductionService.getMonthlyProductionByRangeOfDatesAndSupply(startDate, endDate, diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetYearlyProductionController.java b/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetYearlyProductionController.java index 5695a0a..7d2ed4e 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetYearlyProductionController.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/production/GetYearlyProductionController.java @@ -23,6 +23,8 @@ import java.time.OffsetDateTime; import java.util.List; +import java.util.Objects; +import java.util.UUID; @RestController @RequestMapping("/api/v1/production/yearly") @@ -62,9 +64,9 @@ public GetYearlyProductionController(GetProductionService getProductionService) public List getYearlyProduction( @RequestParam("startDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime startDate, @RequestParam("endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime endDate, - @RequestParam(required = false) String supplyId) { + @RequestParam(required = false) UUID supplyId) { - if (StringUtils.isBlank(supplyId)) { + if (Objects.isNull(supplyId)) { return getProductionService.getYearlyProductionByRangeOfDates(startDate, endDate); } return getProductionService.getYearlyProductionByRangeOfDatesAndSupply(startDate, endDate, diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/shared/web/error/SupplyExceptionHandler.java b/src/main/java/org/lucoenergia/conluz/infrastructure/shared/web/error/SupplyExceptionHandler.java index 5a6e6cf..cd2926c 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/shared/web/error/SupplyExceptionHandler.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/shared/web/error/SupplyExceptionHandler.java @@ -22,7 +22,7 @@ public SupplyExceptionHandler(MessageSource messageSource) { @ExceptionHandler(SupplyNotFoundException.class) public ResponseEntity handleException(SupplyNotFoundException e) { - String supplyId = e.getId().getId(); + String supplyId = e.getId().getId().toString(); String message = messageSource.getMessage( "error.supply.not.found", diff --git a/src/main/resources/db/liquibase/changelogs/init.xml b/src/main/resources/db/liquibase/changelogs/init.xml index 03a6743..9940778 100644 --- a/src/main/resources/db/liquibase/changelogs/init.xml +++ b/src/main/resources/db/liquibase/changelogs/init.xml @@ -64,9 +64,12 @@ http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd"> - + + + + diff --git a/src/test/java/org/lucoenergia/conluz/domain/admin/supply/SupplyMother.java b/src/test/java/org/lucoenergia/conluz/domain/admin/supply/SupplyMother.java index 1022f6b..2e530a0 100644 --- a/src/test/java/org/lucoenergia/conluz/domain/admin/supply/SupplyMother.java +++ b/src/test/java/org/lucoenergia/conluz/domain/admin/supply/SupplyMother.java @@ -1,17 +1,22 @@ package org.lucoenergia.conluz.domain.admin.supply; import org.apache.commons.lang3.RandomStringUtils; -import org.apache.commons.lang3.RandomUtils; -import org.lucoenergia.conluz.domain.admin.supply.Supply; import org.lucoenergia.conluz.domain.admin.user.User; +import org.lucoenergia.conluz.domain.admin.user.UserMother; import java.util.Random; +import java.util.UUID; public class SupplyMother { + public static Supply random() { + return random(UserMother.randomUser()); + } + public static Supply random(User user) { return new Supply.Builder() - .withId(RandomStringUtils.random(20, true, true)) + .withId(UUID.randomUUID()) + .withCode(RandomStringUtils.random(20, true, true)) .withAddress(RandomStringUtils.random(20, true, true)) .withPartitionCoefficient(new Random().nextFloat()) .withEnabled(new Random().nextBoolean()) diff --git a/src/test/java/org/lucoenergia/conluz/domain/consumption/datadis/DatadisConsumptionSyncServiceTest.java b/src/test/java/org/lucoenergia/conluz/domain/consumption/datadis/DatadisConsumptionSyncServiceTest.java index 2b01605..e57996f 100644 --- a/src/test/java/org/lucoenergia/conluz/domain/consumption/datadis/DatadisConsumptionSyncServiceTest.java +++ b/src/test/java/org/lucoenergia/conluz/domain/consumption/datadis/DatadisConsumptionSyncServiceTest.java @@ -31,7 +31,7 @@ void testSynchronizeConsumptionsSuccessfully() { // Given User user = UserMother.randomUser(); Supply supply = new Supply.Builder() - .withId(RandomStringUtils.random(20, true, true)) + .withCode(RandomStringUtils.random(20, true, true)) .withUser(user) .withValidDateFrom(LocalDate.now().minusMonths(4)) .build(); @@ -63,7 +63,7 @@ void testSynchronizeConsumptionsWithSupplyWithNullValidDate() { // Given User user = UserMother.randomUser(); Supply supply = new Supply.Builder() - .withId(RandomStringUtils.random(20, true, true)) + .withCode(RandomStringUtils.random(20, true, true)) .withUser(user) .build(); @@ -94,7 +94,7 @@ void testSynchronizeConsumptionsSuccessfullyWithValidDateOlderThanAYear() { // Given User user = UserMother.randomUser(); Supply supply = new Supply.Builder() - .withId(RandomStringUtils.random(20, true, true)) + .withCode(RandomStringUtils.random(20, true, true)) .withUser(user) .withValidDateFrom(LocalDate.now().minusMonths(20)) .build(); diff --git a/src/test/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyEntityMapperTest.java b/src/test/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyEntityMapperTest.java index 8e2cee4..708ddfa 100644 --- a/src/test/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyEntityMapperTest.java +++ b/src/test/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyEntityMapperTest.java @@ -3,8 +3,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.lucoenergia.conluz.domain.admin.supply.Supply; -import org.lucoenergia.conluz.infrastructure.admin.supply.SupplyEntity; -import org.lucoenergia.conluz.infrastructure.admin.supply.SupplyEntityMapper; class SupplyEntityMapperTest { @@ -12,12 +10,11 @@ class SupplyEntityMapperTest { @Test void testMap() { - SupplyEntity entity = new SupplyEntity("XX000012345678901234F0RT", "My supply", - "Fake Street 123", 3.1245f, true); + SupplyEntity entity = SupplyEntityMother.random(); Supply result = mapper.map(entity); - Assertions.assertEquals(entity.getId(), result.getId()); + Assertions.assertEquals(entity.getCode(), result.getCode()); Assertions.assertEquals(entity.getName(), result.getName()); Assertions.assertEquals(entity.getAddress(), result.getAddress()); Assertions.assertEquals(entity.getPartitionCoefficient(), result.getPartitionCoefficient()); diff --git a/src/test/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyEntityMother.java b/src/test/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyEntityMother.java new file mode 100644 index 0000000..675190e --- /dev/null +++ b/src/test/java/org/lucoenergia/conluz/infrastructure/admin/supply/SupplyEntityMother.java @@ -0,0 +1,27 @@ +package org.lucoenergia.conluz.infrastructure.admin.supply; + +import org.apache.commons.lang3.RandomStringUtils; +import org.lucoenergia.conluz.domain.admin.user.UserMother; +import org.lucoenergia.conluz.infrastructure.admin.user.UserEntity; + +import java.util.Random; +import java.util.UUID; + +public class SupplyEntityMother { + + public static SupplyEntity random() { + return random(UserMother.randomUserEntity()); + } + + public static SupplyEntity random(UserEntity user) { + return new SupplyEntity.Builder() + .withId(UUID.randomUUID()) + .withCode(RandomStringUtils.random(20, true, true)) + .withAddress(RandomStringUtils.random(20, true, true)) + .withPartitionCoefficient(new Random().nextFloat()) + .withEnabled(new Random().nextBoolean()) + .withUser(user) + .withName(RandomStringUtils.random(10, true, false)) + .build(); + } +} diff --git a/src/test/java/org/lucoenergia/conluz/infrastructure/admin/supply/create/CreateSupplyControllerTest.java b/src/test/java/org/lucoenergia/conluz/infrastructure/admin/supply/create/CreateSupplyControllerTest.java index 8d8e519..e2ef04b 100644 --- a/src/test/java/org/lucoenergia/conluz/infrastructure/admin/supply/create/CreateSupplyControllerTest.java +++ b/src/test/java/org/lucoenergia/conluz/infrastructure/admin/supply/create/CreateSupplyControllerTest.java @@ -7,6 +7,7 @@ import org.lucoenergia.conluz.domain.admin.user.create.CreateUserRepository; import org.lucoenergia.conluz.domain.shared.SupplyId; import org.lucoenergia.conluz.domain.admin.user.UserMother; +import org.lucoenergia.conluz.infrastructure.admin.supply.SupplyRepository; import org.lucoenergia.conluz.infrastructure.shared.BaseControllerTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; @@ -24,7 +25,7 @@ class CreateSupplyControllerTest extends BaseControllerTest { @Autowired - private GetSupplyRepository getSupplyRepository; + private SupplyRepository supplyRepository; @Autowired private CreateUserRepository createUserRepository; @@ -38,7 +39,7 @@ void testCreateSupply() throws Exception { String body = """ { - "id": "ES0033333333333333AA0A", + "code": "ES0033333333333333AA0A", "userId": "e7ab39cd-9250-40a9-b829-f11f65aae27d", "address": "Fake Street 123", "partitionCoefficient": "3.0763" @@ -51,7 +52,8 @@ void testCreateSupply() throws Exception { .content(body)) .andDo(print()) .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value("ES0033333333333333AA0A")) + .andExpect(jsonPath("$.id").isNotEmpty()) + .andExpect(jsonPath("$.code").value("ES0033333333333333AA0A")) .andExpect(jsonPath("$.address").value("Fake Street 123")) .andExpect(jsonPath("$.partitionCoefficient").value("3.0763")) .andExpect(jsonPath("$.name").isEmpty()) @@ -65,6 +67,6 @@ void testCreateSupply() throws Exception { .andExpect(jsonPath("$.user.phoneNumber").value(user.getPhoneNumber())) .andExpect(jsonPath("$.user.enabled").value(user.isEnabled())); - Assertions.assertTrue(getSupplyRepository.existsById(new SupplyId("ES0033333333333333AA0A"))); + Assertions.assertEquals(1, supplyRepository.countByCode("ES0033333333333333AA0A")); } } diff --git a/src/test/java/org/lucoenergia/conluz/infrastructure/admin/user/create/ImportUsersControllerTest.java b/src/test/java/org/lucoenergia/conluz/infrastructure/admin/user/create/ImportUsersControllerTest.java index 1bae251..7bd0eeb 100644 --- a/src/test/java/org/lucoenergia/conluz/infrastructure/admin/user/create/ImportUsersControllerTest.java +++ b/src/test/java/org/lucoenergia/conluz/infrastructure/admin/user/create/ImportUsersControllerTest.java @@ -1,7 +1,5 @@ package org.lucoenergia.conluz.infrastructure.admin.user.create; -import org.hamcrest.Description; -import org.hamcrest.Matcher; import org.junit.jupiter.api.Test; import org.lucoenergia.conluz.infrastructure.shared.BaseControllerTest; import org.springframework.core.io.ClassPathResource; @@ -27,11 +25,11 @@ class ImportUsersControllerTest extends BaseControllerTest { @Test void testMinimumBody() throws Exception { - ClassPathResource resource = new ClassPathResource("users.csv"); + ClassPathResource resource = new ClassPathResource("fixtures/users/users.csv"); MockMultipartFile file = new MockMultipartFile( "file", - "users.csv", + "fixtures/users/users.csv", "text/csv", Files.readAllBytes(resource.getFile().toPath())); @@ -51,11 +49,11 @@ void testMinimumBody() throws Exception { @Test void testWithWrongContentType() throws Exception { - ClassPathResource resource = new ClassPathResource("users.csv"); + ClassPathResource resource = new ClassPathResource("fixtures/users/users.csv"); MockMultipartFile file = new MockMultipartFile( "file", - "users.csv", + "fixtures/users/users.csv", "text/csv", Files.readAllBytes(resource.getFile().toPath())); @@ -76,11 +74,11 @@ void testWithWrongContentType() throws Exception { @Test void testWithWrongFileMimeType() throws Exception { - ClassPathResource resource = new ClassPathResource("users.csv"); + ClassPathResource resource = new ClassPathResource("fixtures/users/users.csv"); MockMultipartFile file = new MockMultipartFile( "file", - "users.csv", + "fixtures/users/users.csv", "application/octet-stream", Files.readAllBytes(resource.getFile().toPath())); @@ -124,11 +122,11 @@ void testWithWrongFileExtension() throws Exception { @Test void testWithEmptyCsvFile() throws Exception { - ClassPathResource resource = new ClassPathResource("empty.csv"); + ClassPathResource resource = new ClassPathResource("fixtures/empty.csv"); MockMultipartFile file = new MockMultipartFile( "file", - "users.csv", + "fixtures/users/users.csv", "text/csv", Files.readAllBytes(resource.getFile().toPath())); @@ -148,11 +146,11 @@ void testWithEmptyCsvFile() throws Exception { @Test void testWithMalformedCsvFile() throws Exception { - ClassPathResource resource = new ClassPathResource("users_malformed.csv"); + ClassPathResource resource = new ClassPathResource("fixtures/users/users_malformed.csv"); MockMultipartFile file = new MockMultipartFile( "file", - "users.csv", + "fixtures/users/users.csv", "text/csv", Files.readAllBytes(resource.getFile().toPath())); diff --git a/src/test/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/GetDatadisConsumptionRepositoryRestIntegrationTest.java b/src/test/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/GetDatadisConsumptionRepositoryRestIntegrationTest.java index e9f4d9f..c6367fb 100644 --- a/src/test/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/GetDatadisConsumptionRepositoryRestIntegrationTest.java +++ b/src/test/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/GetDatadisConsumptionRepositoryRestIntegrationTest.java @@ -34,7 +34,7 @@ void testGetMonthlyConsumption() { final User user = new User.Builder().personalId(authorizedNif).build(); final Supply supply = new Supply.Builder() - .withId(cups) + .withCode(cups) .withUser(user) .withDistributorCode(distributorCode) .withPointType(pointType) diff --git a/src/test/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/GetDatadisConsumptionRepositoryRestTest.java b/src/test/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/GetDatadisConsumptionRepositoryRestTest.java index 37f2dc9..e51db61 100644 --- a/src/test/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/GetDatadisConsumptionRepositoryRestTest.java +++ b/src/test/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/GetDatadisConsumptionRepositoryRestTest.java @@ -74,7 +74,7 @@ void testGetMonthlyConsumptionWithUnsuccessfulResponseAndEmptyBody() throws IOEx // Assemble final User user = new User.Builder().personalId("authorizedNif").build(); final Supply supply = new Supply.Builder() - .withId("cups") + .withCode("cups") .withUser(user) .withDistributorCode("distributorCode") .withPointType("pointType") @@ -114,7 +114,7 @@ void testGetMonthlyConsumptionWithSuccessfulResponse() throws IOException { // Assemble final User user = new User.Builder().personalId("authorizedNif").build(); final Supply supply = new Supply.Builder() - .withId("ES0031300329693002BQ0F") + .withCode("ES0031300329693002BQ0F") .withUser(user) .withDistributorCode("distributorCode") .withPointType("pointType") diff --git a/src/test/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/PersistDatadisConsumptionRepositoryInfluxIntegrationTest.java b/src/test/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/PersistDatadisConsumptionRepositoryInfluxIntegrationTest.java index b4e501d..9c2d381 100644 --- a/src/test/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/PersistDatadisConsumptionRepositoryInfluxIntegrationTest.java +++ b/src/test/java/org/lucoenergia/conluz/infrastructure/consumption/datadis/PersistDatadisConsumptionRepositoryInfluxIntegrationTest.java @@ -28,7 +28,7 @@ void testPersistSingleConsumption() throws InterruptedException { int year = 2024; Consumption consumption = ConsumptionMother.random(); consumption.setDate(String.format("%s/%02d/01", year, month.getValue())); - Supply supply = new Supply.Builder().withId(consumption.getCups()).build(); + Supply supply = new Supply.Builder().withCode(consumption.getCups()).build(); // Act repository.persistConsumptions(Collections.singletonList(consumption)); diff --git a/src/test/java/org/lucoenergia/conluz/infrastructure/production/GetHourlyProductionControllerTest.java b/src/test/java/org/lucoenergia/conluz/infrastructure/production/GetHourlyProductionControllerTest.java index bcf6436..5d50313 100644 --- a/src/test/java/org/lucoenergia/conluz/infrastructure/production/GetHourlyProductionControllerTest.java +++ b/src/test/java/org/lucoenergia/conluz/infrastructure/production/GetHourlyProductionControllerTest.java @@ -14,6 +14,7 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; +import java.util.UUID; import static org.hamcrest.Matchers.containsString; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -75,19 +76,21 @@ void testInvalidDateFormat() throws Exception { @Test void testGetHourlyProductionBySupply() throws Exception { + SupplyId supplyId = new SupplyId(UUID.randomUUID()); + // Create some supplies supplyRepository.saveAll(Arrays.asList( - new SupplyEntity("1", "My house", "Fake street", 0.030763f, true), - new SupplyEntity("2", "The garage", "Sesame Street 666", 0.015380f, true), - new SupplyEntity("3", "My daughter's house", "Real street 22", 0.041017f, true) + new SupplyEntity.Builder().withId(supplyId.getId()).build(), + new SupplyEntity.Builder().withId(UUID.randomUUID()).build(), + new SupplyEntity.Builder().withId(UUID.randomUUID()).build() )); - SupplyId supplyId = new SupplyId("1"); + String authHeader = loginAsDefaultAdmin(); mockMvc.perform(get("/api/v1/production/hourly") .header(HttpHeaders.AUTHORIZATION, authHeader) - .queryParam("supplyId", supplyId.getId()) + .queryParam("supplyId", supplyId.getId().toString()) .queryParam("startDate", START_DATE) .queryParam("endDate", END_DATE)) .andExpect(status().isOk()) @@ -98,18 +101,18 @@ void testGetHourlyProductionBySupply() throws Exception { void testGetHourlyProductionByUnknownSupply() throws Exception { String authHeader = loginAsDefaultAdmin(); - String supplyId = "1"; + UUID supplyId = UUID.randomUUID(); mockMvc.perform(get("/api/v1/production/hourly") .header(HttpHeaders.AUTHORIZATION, authHeader) - .queryParam("supplyId", supplyId) + .queryParam("supplyId", supplyId.toString()) .queryParam("startDate", START_DATE) .queryParam("endDate", END_DATE)) .andExpect(status().isBadRequest()) .andExpect(content().string(containsString("\"traceId\":"))) .andExpect(content().string(containsString("\"timestamp\":"))) .andExpect(content().string(containsString("\"status\":400"))) - .andExpect(content().string(containsString("\"message\":\"El punto de suministro con identificador '1' no ha sido encontrado. Revise que el identificador sea correcto.\""))); + .andExpect(content().string(containsString(String.format("\"message\":\"El punto de suministro con identificador '%s' no ha sido encontrado. Revise que el identificador sea correcto.\"", supplyId)))); } @Test diff --git a/src/test/java/org/lucoenergia/conluz/infrastructure/production/GetInstantProductionControllerTest.java b/src/test/java/org/lucoenergia/conluz/infrastructure/production/GetInstantProductionControllerTest.java index 96afbee..06a17b9 100644 --- a/src/test/java/org/lucoenergia/conluz/infrastructure/production/GetInstantProductionControllerTest.java +++ b/src/test/java/org/lucoenergia/conluz/infrastructure/production/GetInstantProductionControllerTest.java @@ -2,8 +2,14 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +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.infrastructure.admin.supply.SupplyEntity; +import org.lucoenergia.conluz.infrastructure.admin.supply.SupplyEntityMother; import org.lucoenergia.conluz.infrastructure.admin.supply.SupplyRepository; +import org.lucoenergia.conluz.infrastructure.admin.user.UserEntity; +import org.lucoenergia.conluz.infrastructure.admin.user.UserRepository; import org.lucoenergia.conluz.infrastructure.shared.BaseControllerTest; import org.lucoenergia.conluz.infrastructure.shared.db.influxdb.EnergyProductionInfluxLoader; import org.lucoenergia.conluz.infrastructure.shared.db.influxdb.MockInfluxDbConfiguration; @@ -12,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.Arrays; +import java.util.UUID; import static org.hamcrest.Matchers.containsString; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -21,6 +28,8 @@ @Transactional class GetInstantProductionControllerTest extends BaseControllerTest { + @Autowired + private UserRepository userRepository; @Autowired private SupplyRepository supplyRepository; @Autowired @@ -49,19 +58,24 @@ void testGetInstantProduction() throws Exception { @Test void testGetInstantProductionBySupply() throws Exception { + UserEntity user = UserMother.randomUserEntity(); + user = userRepository.save(user); + + String authHeader = loginAsDefaultAdmin(); + UUID supplyId = UUID.randomUUID(); + SupplyEntity supplyEntity = SupplyEntityMother.random(user); + supplyEntity.setId(supplyId); + // Create some supplies supplyRepository.saveAll(Arrays.asList( - new SupplyEntity("1", "My house", "Fake street", 0.030763f, true), - new SupplyEntity("2", "The garage", "Sesame Street 666", 0.015380f, true), - new SupplyEntity("3", "My daughter's house", "Real street 22", 0.041017f, true) + supplyEntity, + SupplyEntityMother.random(user), + SupplyEntityMother.random(user) )); - String authHeader = loginAsDefaultAdmin(); - String supplyId = "1"; - mockMvc.perform(get("/api/v1/production") .header(HttpHeaders.AUTHORIZATION, authHeader) - .param("supplyId", supplyId)) + .param("supplyId", supplyId.toString())) .andExpect(status().isOk()) .andExpect(content().string(containsString("power"))); } @@ -70,16 +84,16 @@ void testGetInstantProductionBySupply() throws Exception { void testGetInstantProductionByUnknownSupply() throws Exception { String authHeader = loginAsDefaultAdmin(); - String supplyId = "1"; + UUID supplyId = UUID.randomUUID(); mockMvc.perform(get("/api/v1/production") .header(HttpHeaders.AUTHORIZATION, authHeader) - .param("supplyId", supplyId)) + .param("supplyId", supplyId.toString())) .andExpect(status().isBadRequest()) .andExpect(content().string(containsString("\"traceId\":"))) .andExpect(content().string(containsString("\"timestamp\":"))) .andExpect(content().string(containsString("\"status\":400"))) - .andExpect(content().string(containsString("\"message\":\"El punto de suministro con identificador '1' no ha sido encontrado. Revise que el identificador sea correcto.\""))); + .andExpect(content().string(containsString(String.format("\"message\":\"El punto de suministro con identificador '%s' no ha sido encontrado. Revise que el identificador sea correcto.\"", supplyId)))); } @Test diff --git a/src/test/resources/empty.csv b/src/test/resources/fixtures/empty.csv similarity index 100% rename from src/test/resources/empty.csv rename to src/test/resources/fixtures/empty.csv diff --git a/src/test/resources/users.csv b/src/test/resources/fixtures/users/users.csv similarity index 100% rename from src/test/resources/users.csv rename to src/test/resources/fixtures/users/users.csv diff --git a/src/test/resources/users_malformed.csv b/src/test/resources/fixtures/users/users_malformed.csv similarity index 100% rename from src/test/resources/users_malformed.csv rename to src/test/resources/fixtures/users/users_malformed.csv