Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit f2bec8e

Browse files
committed
🍱 Ajout solution étape 8
1 parent 7907732 commit f2bec8e

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

courtage-application-springboot/src/main/java/devoxx/lab/archihexa/courtage/application/springboot/controller/CourtageResource.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77
import org.springframework.http.HttpStatus;
88
import org.springframework.http.MediaType;
99
import org.springframework.http.ResponseEntity;
10+
import org.springframework.validation.annotation.Validated;
1011
import org.springframework.web.bind.MethodArgumentNotValidException;
1112
import org.springframework.web.bind.annotation.*;
1213
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
1314

15+
import javax.validation.Valid;
1416
import java.net.URI;
1517
import java.util.stream.Collectors;
1618

1719
import static java.util.Optional.ofNullable;
1820

1921
@RestController
2022
@RequestMapping("/courtage")
23+
@Validated
2124
public class CourtageResource {
2225
private final ServiceCourtage serviceCourtage;
2326

@@ -48,7 +51,7 @@ public ResponseEntity<String> creationPortefeuille(@PathVariable(value = "nomPor
4851
@PostMapping("/portefeuilles/{nomPortefeuille}/actions")
4952
public ResponseEntity<String> ajoutActionsDansPortefeuille(
5053
@PathVariable(value = "nomPortefeuille") String nomPortefeuille,
51-
@RequestBody Achat achat
54+
@RequestBody @Valid Achat achat
5255
) throws PortefeuilleNonGereException {
5356
serviceCourtage.ajouteAction(nomPortefeuille, achat);
5457
return ResponseEntity.ok().build();

courtage-domain/src/test/java/devoxx/lab/archihexa/courtage/domain/port/primaire/CourtageStepDefinitions.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
import io.cucumber.datatable.DataTable;
1212
import io.cucumber.java8.DataTableEntryDefinitionBody;
1313
import io.cucumber.java8.Fr;
14+
import org.assertj.core.groups.Tuple;
1415

16+
import javax.validation.ConstraintViolation;
1517
import javax.validation.Validation;
1618
import javax.validation.Validator;
1719
import java.math.BigDecimal;
1820
import java.text.NumberFormat;
1921
import java.text.ParseException;
2022
import java.util.Locale;
2123
import java.util.Map;
24+
import java.util.Set;
25+
import java.util.stream.Collectors;
2226

2327
import static org.assertj.core.api.Assertions.assertThat;
2428

@@ -33,6 +37,7 @@ public class CourtageStepDefinitions implements Fr {
3337
private final PortefeuilleRepository portefeuilleRepository = new PortefeuilleRepositoryMock();
3438
private final ServiceBourse serviceBourse = new ServiceBourseMock();
3539
private final ServiceCourtage serviceCourtage = new Courtage(portefeuilleRepository, serviceBourse);
40+
private Achat achat;
3641
private Portefeuille portefeuilleCree;
3742
private Exception thrownException = null;
3843
private BigDecimal valeurPortefeuille = null;
@@ -102,11 +107,16 @@ public CourtageStepDefinitions() {
102107

103108
// étape 8
104109
DataTableType((Map<String, String> data) -> new Achat(data.get("action"), Integer.parseInt(data.get("nombre"))));
105-
Soit("l'achat", (Achat achat) -> {
106-
throw new io.cucumber.java8.PendingException();
107-
});
110+
Soit("l'achat", (Achat achat) ->
111+
this.achat = achat);
108112
Alors("l'achat est invalide avec l'erreur", (DataTable expected) -> {
109-
throw new io.cucumber.java8.PendingException();
113+
Set<ConstraintViolation<Achat>> violations = validator.validate(achat);
114+
assertThat(violations)
115+
.extracting("interpolatedMessage", "propertyPath.currentLeafNode.name")
116+
.containsExactlyInAnyOrderElementsOf(
117+
expected.asMaps().stream()
118+
.map(e -> new Tuple(e.get("message"), e.get("propriété")))
119+
.collect(Collectors.toList()));
110120
});
111121
}
112122

0 commit comments

Comments
 (0)