Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
m4102_tp3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benjamin Tellier
m4102_tp3
Commits
f32548ef
Commit
f32548ef
authored
5 years ago
by
Yvan Peter
Browse files
Options
Downloads
Patches
Plain Diff
corrections pour aller jusqu'à la persistence
parent
65f5dbfd
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+59
-42
59 additions, 42 deletions
README.md
src/test/java/fr/ulille/iut/pizzaland/IngredientResourceTest.java
+1
-1
1 addition, 1 deletion
.../java/fr/ulille/iut/pizzaland/IngredientResourceTest.java
with
60 additions
and
43 deletions
README.md
+
59
−
42
View file @
f32548ef
...
...
@@ -262,16 +262,18 @@ Nous allons continuer en ajoutant la possibilité de récupérer un
ingrédient particulier à partir de son identifiant.
Pour cela voici un premier test qui permettra de vérifier cela :
import fr.ulille.iut.pizzaland.beans.Ingredient;
@Test
public void testGetExistingIngredient() {
Ingredient
Dto
ingredient = new Ingredient
Dto
();
Ingredient ingredient = new Ingredient();
ingredient.setId(1);
ingredient.setName("mozzarella");
Response response = target("/ingredients/1").request().get();
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
Ingredien
Dto
result = response.readEntity(IngredientDto.class);
Ingredien
t
result
=
Ingredient.fromDto(
response.readEntity(IngredientDto.class)
)
;
assertEquals(ingredient, result);
}
...
...
@@ -282,7 +284,7 @@ avec les getter/setter correspondant aux propriétés de l'object JSON.
public class IngredientDto {
private long id;
private String n
om
;
private String n
ame
;
public IngredientDto() {}
...
...
@@ -294,19 +296,19 @@ avec les getter/setter correspondant aux propriétés de l'object JSON.
this.id = id;
}
public void setN
om
(String n
om
) {
this.n
om
= n
om
;
public void setN
ame
(String n
ame
) {
this.n
ame
= n
ame
;
}
public String getN
om
() {
return n
om
;
public String getN
ame
() {
return n
ame
;
}
}
Du côté de la ressource, on peut fournir une première implémentation :
import javax.ws.rs.PathParam;
import fr.ulille.iut.pizzaland.beans.Ingredient;
@GET
@Path("{id}")
...
...
@@ -322,63 +324,78 @@ Pour cette méthode, nous avons introduit la classe `Ingredient`. Ce
JavaBean représente un ingrédient manipulé par la ressource.
Voici une implémentation pour cette classe :
package fr.ulille.iut.pizzaland.beans;
import fr.ulille.iut.pizzaland.dto.IngredientCreateDto;
import fr.ulille.iut.pizzaland.dto.IngredientDto;
public class Ingredient {
private long id;
private String name;
package fr.ulille.iut.pizzaland.beans;
import fr.ulille.iut.pizzaland.dto.IngredientDto;
public class Ingredient {
private long id;
private String name;
public Ingredient() {
}
public Ingredient() {
}
public Ingredient(long id, String name) {
public Ingredient(long id, String name) {
this.id = id;
this.name = name;
}
}
public void setId(long id) {
public void setId(long id) {
this.id = id;
}
}
public long getId() {
public long getId() {
return id;
}
}
public String getName() {
public String getName() {
return name;
}
}
public void setName(String name) {
public void setName(String name) {
this.name = name;
}
public static IngredientDto toDto(Ingredient i) {
IngredientDto dto = new IngredientDto();
dto.setId(i.getId());
dto.setName(i.getName());
}
return dto;
}
public static IngredientDto toDto(Ingredient i) {
public static IngredientDto toDto(Ingredient i) {
IngredientDto dto = new IngredientDto();
dto.setId(i.getId());
dto.setName(i.getName());
return dto;
}
return dto;
}
public static Ingredient fromDto(IngredientDto dto) {
public static Ingredient fromDto(IngredientDto dto) {
Ingredient ingredient = new Ingredient();
ingredient.setId(dto.getId());
ingredient.setName(dto.getName());
return ingredient;
}
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Ingredient other = (Ingredient) obj;
if (id != other.id)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override
public String toString() {
return "Ingredient [id=" + id + ", name=" + name + "]";
}
}
Le test devrait maintenant réussir :
...
...
This diff is collapsed.
Click to expand it.
src/test/java/fr/ulille/iut/pizzaland/IngredientResourceTest.java
+
1
−
1
View file @
f32548ef
...
...
@@ -59,7 +59,7 @@ public class IngredientResourceTest extends JerseyTest {
// On vérifie la valeur retournée (liste vide)
// L'entité (readEntity() correspond au corps de la réponse HTTP.
// La classe javax.ws.rs.core.GenericType<T> permet de définir le type
// de la réponse lue.
// de la réponse lue
quand on a un type complexe (typiquement une liste)
.
List
<
IngredientDto
>
ingredients
;
ingredients
=
response
.
readEntity
(
new
GenericType
<
List
<
IngredientDto
>>(){});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment