June 2018
Intermediate to advanced
596 pages
12h 39m
English
We will now add a test method in the CourseManagementClient class, in the CourseManagementRESTClient project:
//Test addCourse method (JSON version) of CourseService
public static void testAddCourseJSON() {
//Create JAX-RS client
Client client = ClientBuilder.newClient();
//Get WebTarget for a URL
WebTarget webTarget = client.target("http://localhost:8600/CourseManagementREST/services/course/add");
//Create JSON representation of Course,
//with course_name and credits fields. Instead of creating
//JSON manually, you could also use JAXB to create JSON from
//Java object.
String courseJSON = "{"course_name":"Course-4", "credits":5}"; //Execute HTTP post method Response response = webTarget.request(). ...Read now
Unlock full access