Review corrections
This commit is contained in:
parent
987c55e934
commit
15f3c94023
|
@ -1,5 +1,8 @@
|
||||||
package com.baeldung.openliberty.person.resource;
|
package com.baeldung.openliberty.person.resource;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
@ -16,7 +19,7 @@ import com.baeldung.openliberty.person.dao.PersonDao;
|
||||||
import com.baeldung.openliberty.person.model.Person;
|
import com.baeldung.openliberty.person.model.Person;
|
||||||
|
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
@Path("person")
|
@Path("persons")
|
||||||
public class PersonResource {
|
public class PersonResource {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -24,9 +27,11 @@ public class PersonResource {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public Person getPerson() {
|
public List<Person> getAllPerson() {
|
||||||
Person person = new Person(1, "normanlewis", "normanlewis@email.com");
|
Person person = new Person(1, "normanlewis", "normanlewis@email.com");
|
||||||
return person;
|
List<Person> persons = new ArrayList<>();
|
||||||
|
persons.add(person);
|
||||||
|
return persons;
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
|
@ -35,7 +40,7 @@ public class PersonResource {
|
||||||
public Response addPerson(Person person) {
|
public Response addPerson(Person person) {
|
||||||
personDao.createPerson(person);
|
personDao.createPerson(person);
|
||||||
String respMessage = "Person #" + person.getId() + " created successfully.";
|
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
|
@GET
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class RestClientTest {
|
||||||
|
|
||||||
private static String BASE_URL;
|
private static String BASE_URL;
|
||||||
|
|
||||||
private final String API_PERSON = "api/person";
|
private final String API_PERSON = "api/persons";
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void oneTimeSetup() {
|
public static void oneTimeSetup() {
|
||||||
|
@ -24,11 +24,11 @@ public class RestClientTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSuite() {
|
public void testSuite() {
|
||||||
//run the test only when liberty server is started
|
//run the test only when liberty server is started
|
||||||
//this.whenConsumeWithJsonb_thenGetPerson();
|
this.whenConsumeWithJsonb_thenGetPerson();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void whenConsumeWithJsonb_thenGetPerson() {
|
public void whenConsumeWithJsonb_thenGetPerson() {
|
||||||
String url = BASE_URL + API_PERSON;
|
String url = BASE_URL + API_PERSON + "/1";
|
||||||
String result = RestConsumer.consumeWithJsonb(url);
|
String result = RestConsumer.consumeWithJsonb(url);
|
||||||
|
|
||||||
Person person = JsonbBuilder.create().fromJson(result, Person.class);
|
Person person = JsonbBuilder.create().fromJson(result, Person.class);
|
||||||
|
|
Loading…
Reference in New Issue