Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.wallmart.calculateroute.test.rest; import com.wallmart.calculateroute.Application; import com.wallmart.calculateroute.ws.domain.RouteInsert; import java.util.HashMap; import java.util.Map; import org.apache.log4j.Logger; import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; /** * * @author Thomas Daniel Kaneko Teixeira(TDKT) */ @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) @WebAppConfiguration @IntegrationTest public class InsertRouteTest { RestTemplate restTemplate; Map<String, String> vars; final String BASE_URL = "http://localhost:8080/insertRoute?"; final String BASE_URL_POST = "http://localhost:8080/insertRoute/"; final static Logger logger = Logger.getLogger(InsertRouteTest.class); @Before public void init() { restTemplate = new TestRestTemplate(); vars = new HashMap<>(); } @Test @Ignore public void shouldCreateNewMapCitiAndDistanceWithGet() { String result = ""; vars.put("map", "So Paulo"); vars.put("start", "Morumbi"); vars.put("end", "Jardins"); vars.put("distance", "13"); result = restTemplate.getForObject(BASE_URL + "map={map}&start={start}&end={end}&distance={distance}", String.class, vars); vars.clear(); Assert.assertTrue(result.contains("SUCESS")); vars.put("map", "mapCidade"); vars.put("start", "A"); vars.put("end", "B"); vars.put("distance", "10"); result = restTemplate.getForObject(BASE_URL + "map={map}&start={start}&end={end}&distance={distance}", String.class, vars); vars.clear(); Assert.assertTrue(result.contains("SUCESS")); } @Test // @Ignore public void shouldCreateNewMapCitiAndDistanceWithPost() { String result = ""; /*Post*/ restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); RouteInsert route = new RouteInsert(); route.setMap("mapCidade"); route.setStart("A"); route.setEnd("B"); route.setDistance("10"); result = restTemplate.postForObject(BASE_URL_POST, route, String.class); Assert.assertTrue(result.contains("SUCESS")); } }