package org.xmx0632.deliciousfruit.api.v1; import static org.junit.Assert.assertEquals; import java.math.BigDecimal; import org.junit.BeforeClass; import org.junit.Test; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.web.client.RestTemplate; import org.xmx0632.deliciousfruit.api.v1.bo.GetProductByIDRequest; import org.xmx0632.deliciousfruit.api.v1.bo.GetProductByIDResponse; import org.xmx0632.deliciousfruit.api.v1.bo.GetProductByIDResponse.FruitProductBoForByID; import org.xmx0632.deliciousfruit.api.v1.bo.Result; import org.xmx0632.deliciousfruit.api.v1.bo.TerminalType; import org.xmx0632.deliciousfruit.functional.BaseControllerTestCase; public class FruitProductApiGetByIDTest extends BaseControllerTestCase { private final RestTemplate restTemplate = new RestTemplate(); private static String url; @BeforeClass public static void initUrl() { url = baseUrl + "/fruitproduct/getProductByID"; } @Test public void testGetByIDSuccess() throws Exception { HttpHeaders requestHeaders = createHttpHeader("user2", "password"); GetProductByIDRequest getProductByIDRequest = new GetProductByIDRequest(); getProductByIDRequest.setFruitProductId("120101"); getProductByIDRequest.setTerminalType(TerminalType.IOS_RETINA.name()); HttpEntity<GetProductByIDRequest> entity = new HttpEntity<GetProductByIDRequest>( getProductByIDRequest, requestHeaders); GetProductByIDResponse response = restTemplate.postForObject(url, entity, GetProductByIDResponse.class); assertEquals(Result.SUCCESS, response.getResult().getValue()); assertEquals(genSucessResFruitProduct().toString(), response .getFruitProduct().toString()); formatHttpInfoPrint(HttpMethod.POST, url, requestHeaders, "通过ID获得水果产, 成功", jsonMapper.toJson(getProductByIDRequest), jsonMapper.toJson(response)); } private FruitProductBoForByID genSucessResFruitProduct() { FruitProductBoForByID fruitProductBo1 = new FruitProductBoForByID(); fruitProductBo1.setDescription("不错"); fruitProductBo1.setDescriptionPicUrl(pictureServerRootUrl + "/ios_retina/fruit_product/product_desc_4.jpg"); fruitProductBo1.setE6Price(new BigDecimal("20.00")); fruitProductBo1.setExpirationDate("2014-07-30 00:00:00+0800"); fruitProductBo1.setFruitCategoryId("S001201"); fruitProductBo1.setIntroduction("很甜"); fruitProductBo1.setKeyword("甜"); fruitProductBo1.setMarketPrice(new BigDecimal("30.00")); fruitProductBo1.setMax(5); fruitProductBo1.setMin(1); fruitProductBo1.setPlace("新疆"); fruitProductBo1.setProductId("120101"); fruitProductBo1.setProductName("新疆葡萄"); fruitProductBo1.setSpec("好葡萄"); fruitProductBo1.setUnit("串"); fruitProductBo1.setPicUrl(pictureServerRootUrl + "/ios_retina/fruit_product/product_4.jpg"); fruitProductBo1.setSeconddiscount(new BigDecimal("0.00")); fruitProductBo1 .setFruitcategoryiconurl("http://localhost/ios_retina/category/2.jpg"); return fruitProductBo1; } }