Interview Questions

Spring - Test Rest API using RestTemplate

package com.test;

import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.web.client.RestTemplate;

public class TestRestAPI {

            public static final String SERVER_URI = "http://localhost:8080/SpringTest-0.0.1-SNAPSHOT";
            public static void main(String args[]){
            private static void testGetAllEmployee() {
                RestTemplate restTemplate = new RestTemplate();
                //we can't get List<Employee> because JSON convertor doesn't know the type of
                //object in the list and hence convert it to default JSON object type LinkedHashMap
                List<LinkedHashMap> emps = restTemplate.getForObject(SERVER_URI+"/employee", List.class);
                for(LinkedHashMap map : emps){
           private static void testCreateEmployee() {
                RestTemplate restTemplate = new RestTemplate();
                Employee emp = new Employee();
                emp.setId(1);emp.setName("Pankaj Kumar");
                Employee response = restTemplate.postForObject(SERVER_URI, emp, Employee.class);