Skip to content
Snippets Groups Projects
Commit a878c03f authored by Martin Dorange's avatar Martin Dorange
Browse files

tp pas fini

parent c42d2483
No related branches found
No related tags found
No related merge requests found
Pipeline #8308 failed
......@@ -2,6 +2,7 @@ package fr.ulille.iut.todo.dao;
import java.util.List;
import org.jdbi.v3.sqlobject.config.RegisterBeanMapper;
import org.jdbi.v3.sqlobject.customizer.Bind;
import org.jdbi.v3.sqlobject.customizer.BindBean;
import org.jdbi.v3.sqlobject.statement.SqlQuery;
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
......@@ -24,5 +25,9 @@ public interface TacheDAO {
@SqlQuery("select * from taches")
@RegisterBeanMapper(Tache.class)
List<Tache> getAll();
@SqlQuery("select * from taches where id= :id")
@RegisterBeanMapper(Tache.class)
Tache getById(@Bind("id") String id);
}
......@@ -46,6 +46,22 @@ public class TodoRessource {
return todoService.getAll();
}
@GET
@Path("{id}")
public Tache getTache(@PathParam("id") UUID id) {
LOGGER.info("getTache()");
return todoService.getTache(id);
}
@GET
@Path("{id}/description")
public String getDescription(@PathParam("id") UUID id) {
LOGGER.info("getdescription()");
return todoService.getTache(id).getDescription();
}
@POST
public Response createTache(CreationTacheDTO tacheDto) {
LOGGER.info("createTache()");
......@@ -64,4 +80,17 @@ public class TodoRessource {
}
return builder.build();
}
@POST
@Consumes (MediaType.APPLICATION_FORM_URLENCODED)
public Response createTacheFromForm(MultivaluedMap<String, String> formParams) {
LOGGER.info("createTacheFromForm()");
Tache tache = new Tache();
// tache.setNom(formParams.);
return null;
}
}
......@@ -15,7 +15,7 @@ public class TodoService {
}
public Tache getTache(UUID id) {
return null;
return taches.getById(id.toString());
}
public List<Tache> getAll() {
......
......@@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -96,14 +97,47 @@ public class TodoRessourceTest extends JerseyTest {
@Test
public void get_with_wrong_id_should_return_404() {
try {
Tache tache = new Tache();
tache.setNom("test");
tache.setDescription("description");
dao.insert(tache);
Tache returned = target("taches").path(tache.getId().toString()).request().get(Tache.class);
assertEquals(tache, returned);
} catch (Exception e) {
assertEquals("HTTP 404 Not Found",e.getMessage());
}
}
@Test
public void get_for_description_should_work_with_existing_task() {
Tache tache=new Tache();
tache.setNom("test");
tache.setDescription("description");
dao.insert(tache);
Tache returned = target("taches").path(tache.getId().toString()).request().get(Tache.class);
assertEquals("description",returned.getDescription());
}
@Test
public void get_for_description_with_wrong_id_should_return_404() {
try {
Tache tache=new Tache();
tache.setNom("test");
tache.setDescription("description");
dao.insert(tache);
Tache returned = target("taches").path(tache.getId().toString()).request().get(Tache.class);
assertEquals("description",returned.getDescription());
}catch(Exception e) {
assertEquals("HTTP 404 Not Found",e.getMessage());
}
}
@Test
......@@ -124,5 +158,21 @@ public class TodoRessourceTest extends JerseyTest {
@Test
public void post_with_form_data_should_return_201_location_and_task() {
Form form=new Form();
form.param("nom","test");
form.param("description","description test");
Response response = target("taches").request(MediaType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
Tache tache = response.readEntity(Tache.class);
assertEquals(target("taches").getUri().toString() + "/" + tache.getId().toString(),
response.getHeaderString("Location"));
Map<String, List<String>> returned=form.asMap();
System.out.println(returned.toString());
// assertEquals(dto.getNom(), tache.getNom());
// assertEquals(dto.getDescription(), tache.getDescription());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment