Skip to content
Snippets Groups Projects
Commit c26ce4dc authored by Jeremy Delobel's avatar Jeremy Delobel
Browse files

Avancement du TP après le cours de PROG-REPARTIE

parent c42d2483
No related branches found
No related tags found
No related merge requests found
...@@ -24,5 +24,9 @@ public interface TacheDAO { ...@@ -24,5 +24,9 @@ public interface TacheDAO {
@SqlQuery("select * from taches") @SqlQuery("select * from taches")
@RegisterBeanMapper(Tache.class) @RegisterBeanMapper(Tache.class)
List<Tache> getAll(); List<Tache> getAll();
@SqlQuery("select * from taches where id = ?")
@RegisterBeanMapper(Tache.class)
Tache getById(String id);
} }
...@@ -24,6 +24,7 @@ import jakarta.ws.rs.core.MultivaluedMap; ...@@ -24,6 +24,7 @@ import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Request; import jakarta.ws.rs.core.Request;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.ResponseBuilder; import jakarta.ws.rs.core.Response.ResponseBuilder;
import jakarta.ws.rs.core.Response.Status;
import jakarta.ws.rs.core.UriInfo; import jakarta.ws.rs.core.UriInfo;
@Path("taches") @Path("taches")
...@@ -64,4 +65,28 @@ public class TodoRessource { ...@@ -64,4 +65,28 @@ public class TodoRessource {
} }
return builder.build(); return builder.build();
} }
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("{id}")
public Tache getById(@PathParam("id") String id) {
LOGGER.info("getById()");
Tache t1 = todoService.getTache(UUID.fromString(id));
if(t1 == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
return todoService.getTache(UUID.fromString(id));
}
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("{id}/description")
public String getByDescription(@PathParam("id") String id) {
LOGGER.info("getById()");
Tache t1 = todoService.getTache(UUID.fromString(id));
if(t1 == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
return todoService.getTache(UUID.fromString(id)).getDescription();
}
} }
...@@ -15,7 +15,7 @@ public class TodoService { ...@@ -15,7 +15,7 @@ public class TodoService {
} }
public Tache getTache(UUID id) { public Tache getTache(UUID id) {
return null; return taches.getById(id.toString());
} }
public List<Tache> getAll() { public List<Tache> getAll() {
...@@ -33,4 +33,5 @@ public class TodoService { ...@@ -33,4 +33,5 @@ public class TodoService {
public void updateTache(Tache tache) { public void updateTache(Tache tache) {
return; return;
} }
} }
...@@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue; ...@@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
...@@ -96,14 +97,24 @@ public class TodoRessourceTest extends JerseyTest { ...@@ -96,14 +97,24 @@ public class TodoRessourceTest extends JerseyTest {
@Test @Test
public void get_with_wrong_id_should_return_404() { public void get_with_wrong_id_should_return_404() {
Response response = target("taches").path(UUID.randomUUID().toString()).request().get();
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
} }
@Test @Test
public void get_for_description_should_work_with_existing_task() { public void get_for_description_should_work_with_existing_task() {
Tache tache = new Tache();
tache.setNom("test");
tache.setDescription("description");
dao.insert(tache);
String returned = target("taches").path(tache.getId().toString()).path("description").request().get(String.class);
assertEquals(tache.getDescription(), returned);
} }
@Test @Test
public void get_for_description_with_wrong_id_should_return_404() { public void get_for_description_with_wrong_id_should_return_404() {
Response response = target("taches").path(UUID.randomUUID().toString()).path("description").request().get();
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
} }
@Test @Test
...@@ -124,5 +135,7 @@ public class TodoRessourceTest extends JerseyTest { ...@@ -124,5 +135,7 @@ public class TodoRessourceTest extends JerseyTest {
@Test @Test
public void post_with_form_data_should_return_201_location_and_task() { public void post_with_form_data_should_return_201_location_and_task() {
Response response = target("taches").path(UUID.randomUUID().toString()).path("description").request().post(Form.class);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment