Skip to content
Snippets Groups Projects
Commit 92c3d51e authored by Jerry Xu's avatar Jerry Xu
Browse files

goodsdetails test

parent 2e45b680
No related branches found
No related tags found
1 merge request!26Resolve "Stocked Goods controller Integration test"
Pipeline #64240 canceled
package com.example.freshonline.model;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
public class Category {
/**
*
......
......@@ -149,7 +149,7 @@
values (#{id,jdbcType=INTEGER}, #{parentId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},
#{level,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.example.freshonline.model.Category">
<insert id="insertSelective" parameterType="com.example.freshonline.model.Category" useGeneratedKeys="true" keyProperty="id">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
......
......@@ -2,7 +2,9 @@ package com.example.freshonline.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.freshonline.dao.CategoryMapper;
import com.example.freshonline.dao.StockedGoodsMapper;
import com.example.freshonline.model.Category;
import com.example.freshonline.model.StockedGoods;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.jdbc.ScriptRunner;
......@@ -42,6 +44,9 @@ class StockedGoodsControllerIntegrationTest {
@Autowired
private StockedGoodsMapper stockedGoodsMapper;
@Autowired
private CategoryMapper categoryMapper;
@Nested
class TestNestPart1{
......@@ -126,11 +131,77 @@ class StockedGoodsControllerIntegrationTest {
}
}
@Test
void getGoodsDetails() {
@Nested
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestNestPart3{
private String url = "/goodsdetails/";
private StockedGoods stockedGoods;
Category cate1;
Category cate2;
Category cate3;
@BeforeAll
public void setup() {
this.cate1 = new Category((Integer) null, 0, "cate1", 1);
categoryMapper.insertSelective(cate1);
this.cate2 = new Category((Integer) null, cate1.getId(), "cate2", 1);
categoryMapper.insertSelective(cate2);
this.cate3 = new Category((Integer) null, cate2.getId(), "cate3", 1);
categoryMapper.insertSelective(cate3);
this.stockedGoods =
new StockedGoods((Integer) null, "testproduct", (byte)1, new BigDecimal(9.99), new BigDecimal(1000), new BigDecimal(100), (byte) 0, (BigDecimal) null, new BigDecimal(3.5),10, "brandname1", cate3.getId(), (byte)1, "String pic", true, "String descriptio");
stockedGoodsMapper.insertSelective(stockedGoods);
}
@Test
public void getGoodsDetailsSuccess() throws Exception{
// assert success
MvcResult mvcResult = mockMvc.perform(get(url+stockedGoods.getId().toString())).andReturn();
JSONObject resp = JSONObject.parseObject(mvcResult.getResponse().getContentAsString());
JSONObject data = (JSONObject) resp.get("data");
Assertions.assertEquals(0,resp.get("code"));
Assertions.assertEquals(stockedGoods.getId(), data.get("id"));
Assertions.assertEquals(cate3.getId(), ((JSONObject) data.get("cate3")).get("id"));
}
@Test
public void getGoodsDetailsMissingID() throws Exception{
// assert success
MvcResult mvcResult = mockMvc.perform(get(url+"0")).andReturn();
JSONObject resp = JSONObject.parseObject(mvcResult.getResponse().getContentAsString());
JSONObject data = (JSONObject) resp.get("data");
Assertions.assertEquals(0,resp.get("code"));
Assertions.assertNull(data);
}
@Test
public void getGoodsDetailsBadInputs() throws Exception{
// assert success
MvcResult mvcResult = mockMvc.perform(get(url+"badinputshshshsh")).andReturn();
JSONObject resp = JSONObject.parseObject(mvcResult.getResponse().getContentAsString());
Assertions.assertEquals(1,resp.get("code"));
Assertions.assertNotNull(resp.get("msg"));
}
@AfterAll
public void finish(){
stockedGoodsMapper.deleteByPrimaryKey(stockedGoods.getId());
categoryMapper.deleteByPrimaryKey(cate3.getId());
categoryMapper.deleteByPrimaryKey(cate2.getId());
categoryMapper.deleteByPrimaryKey(cate1.getId());
}
}
@Test
void uploadGoodsPictures() {
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment