From 15f3c94023c59ca118ddce3d2ae05b224bf21b55 Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Mon, 20 Jan 2020 18:03:39 +0200 Subject: [PATCH] Review corrections --- .../person/resource/PersonResource.java | 15 ++++++++++----- .../com/baeldung/openliberty/RestClientTest.java | 6 +++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/open-liberty/src/main/java/com/baeldung/openliberty/person/resource/PersonResource.java b/open-liberty/src/main/java/com/baeldung/openliberty/person/resource/PersonResource.java index 049f4761b5..89f39adccc 100644 --- a/open-liberty/src/main/java/com/baeldung/openliberty/person/resource/PersonResource.java +++ b/open-liberty/src/main/java/com/baeldung/openliberty/person/resource/PersonResource.java @@ -1,5 +1,8 @@ package com.baeldung.openliberty.person.resource; +import java.util.ArrayList; +import java.util.List; + import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.transaction.Transactional; @@ -16,7 +19,7 @@ import com.baeldung.openliberty.person.dao.PersonDao; import com.baeldung.openliberty.person.model.Person; @RequestScoped -@Path("person") +@Path("persons") public class PersonResource { @Inject @@ -24,9 +27,11 @@ public class PersonResource { @GET @Produces(MediaType.APPLICATION_JSON) - public Person getPerson() { - Person person = new Person(1, "normanlewis", "normanlewis@email.com"); - return person; + public List getAllPerson() { + Person person = new Person(1, "normanlewis", "normanlewis@email.com"); + List persons = new ArrayList<>(); + persons.add(person); + return persons; } @POST @@ -35,7 +40,7 @@ public class PersonResource { public Response addPerson(Person person) { personDao.createPerson(person); String respMessage = "Person #" + person.getId() + " created successfully."; - return Response.status(Response.Status.OK).entity(respMessage).build(); + return Response.status(Response.Status.CREATED).entity(respMessage).build(); } @GET diff --git a/open-liberty/src/test/java/com/baeldung/openliberty/RestClientTest.java b/open-liberty/src/test/java/com/baeldung/openliberty/RestClientTest.java index ab024d788a..93231635ed 100644 --- a/open-liberty/src/test/java/com/baeldung/openliberty/RestClientTest.java +++ b/open-liberty/src/test/java/com/baeldung/openliberty/RestClientTest.java @@ -14,7 +14,7 @@ public class RestClientTest { private static String BASE_URL; - private final String API_PERSON = "api/person"; + private final String API_PERSON = "api/persons"; @BeforeClass public static void oneTimeSetup() { @@ -24,11 +24,11 @@ public class RestClientTest { @Test public void testSuite() { //run the test only when liberty server is started - //this.whenConsumeWithJsonb_thenGetPerson(); + this.whenConsumeWithJsonb_thenGetPerson(); } public void whenConsumeWithJsonb_thenGetPerson() { - String url = BASE_URL + API_PERSON; + String url = BASE_URL + API_PERSON + "/1"; String result = RestConsumer.consumeWithJsonb(url); Person person = JsonbBuilder.create().fromJson(result, Person.class);