chenw 6 жил өмнө
parent
commit
7076d264f0

+ 1 - 1
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/mapper/MessagelogMapper.java

@@ -20,5 +20,5 @@ public interface MessagelogMapper{
 
     int updateByPrimaryKey(Messagelog record);
 
-    List<Messagelog> selectMessageLog(@Param("con") String con, @Param("companyId") Long companyId);
+    List<Messagelog> selectMessageLog(@Param("con") String con, @Param("school_id") Long school_id);
 }

+ 15 - 47
applications/school/school-server/src/main/resources/mapper/MessagelogMapper.xml

@@ -34,12 +34,10 @@
   <insert id="insert" parameterType="com.usoftchina.smartschool.school.po.Messagelog" >
     insert into messagelog ( ml_code, ml_content,
       ml_result, ml_caller, ml_man, 
-      companyId, createTime, creatorId, 
-      updateTime, updaterId,ml_keyvalue,ml_name)
+      school_id, createTime,ml_keyvalue,ml_name)
     values (#{ml_code,jdbcType=VARCHAR}, #{ml_content,jdbcType=VARCHAR},
       #{ml_result,jdbcType=VARCHAR}, #{ml_caller,jdbcType=VARCHAR}, #{ml_man,jdbcType=VARCHAR}, 
-      #{companyId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{creatorId,jdbcType=INTEGER}, 
-      #{updateTime,jdbcType=TIMESTAMP}, #{updaterId,jdbcType=INTEGER},#{ml_keyvalue,jdbcType=INTEGER},#{ml_name,jdbcType=VARCHAR})
+      #{school_id,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{ml_keyvalue,jdbcType=INTEGER},#{ml_name,jdbcType=VARCHAR})
   </insert>
   <insert id="insertSelective" parameterType="com.usoftchina.smartschool.school.po.Messagelog" >
     insert into messagelog
@@ -62,20 +60,11 @@
       <if test="ml_man != null" >
         ml_man,
       </if>
-      <if test="companyId != null" >
-        companyId,
+      <if test="school_id != null" >
+        school_id,
       </if>
       <if test="createTime != null" >
-        createTime,
-      </if>
-      <if test="creatorId != null" >
-        creatorId,
-      </if>
-      <if test="updateTime != null" >
-        updateTime,
-      </if>
-      <if test="updaterId != null" >
-        updaterId,
+        createTime
       </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides="," >
@@ -97,20 +86,11 @@
       <if test="ml_man != null" >
         #{ml_man,jdbcType=VARCHAR},
       </if>
-      <if test="companyId != null" >
-        #{companyId,jdbcType=INTEGER},
+      <if test="school_id != null" >
+        #{school_id,jdbcType=INTEGER},
       </if>
       <if test="createTime != null" >
-        #{createTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="creatorId != null" >
-        #{creatorId,jdbcType=INTEGER},
-      </if>
-      <if test="updateTime != null" >
-        #{updateTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="updaterId != null" >
-        #{updaterId,jdbcType=INTEGER},
+        #{createTime,jdbcType=TIMESTAMP}
       </if>
     </trim>
   </insert>
@@ -133,20 +113,11 @@
       <if test="ml_man != null" >
         ml_man = #{ml_man,jdbcType=VARCHAR},
       </if>
-      <if test="companyId != null" >
-        companyId = #{companyId,jdbcType=INTEGER},
+      <if test="school_id != null" >
+        school_id = #{school_id,jdbcType=INTEGER},
       </if>
       <if test="createTime != null" >
-        createTime = #{createTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="creatorId != null" >
-        creatorId = #{creatorId,jdbcType=INTEGER},
-      </if>
-      <if test="updateTime != null" >
-        updateTime = #{updateTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="updaterId != null" >
-        updaterId = #{updaterId,jdbcType=INTEGER},
+        createTime = #{createTime,jdbcType=TIMESTAMP}
       </if>
     </set>
     where ml_id = #{id,jdbcType=INTEGER}
@@ -158,11 +129,8 @@
       ml_result = #{ml_result,jdbcType=VARCHAR},
       ml_caller = #{ml_caller,jdbcType=VARCHAR},
       ml_man = #{ml_man,jdbcType=VARCHAR},
-      companyId = #{companyId,jdbcType=INTEGER},
-      createTime = #{createTime,jdbcType=TIMESTAMP},
-      creatorId = #{creatorId,jdbcType=INTEGER},
-      updateTime = #{updateTime,jdbcType=TIMESTAMP},
-      updaterId = #{updaterId,jdbcType=INTEGER}
+      school_id = #{school_id,jdbcType=INTEGER},
+      createTime = #{createTime,jdbcType=TIMESTAMP}
     where ml_id = #{id,jdbcType=INTEGER}
   </update>
   <select id="selectMessageLog" resultMap="BaseResultMap">
@@ -171,8 +139,8 @@
       <if test="con != null">
         ${con}
       </if>
-      <if test="companyId != null">
-        and  companyId = #{companyId}
+      <if test="school_id != null">
+        and  school_id = #{school_id}
       </if>
     </where>
     order by ml_id DESC

+ 70 - 0
applications/school/school-server/src/test/java/com/usoftchina/smartschool/school/controller/MessageLogControllerTest.java

@@ -0,0 +1,70 @@
+package com.usoftchina.smartschool.school.controller;
+
+import com.github.pagehelper.PageInfo;
+import com.usoftchina.smartschool.base.Result;
+import com.usoftchina.smartschool.context.BaseContextHolder;
+import com.usoftchina.smartschool.school.dto.DocBaseDTO;
+import com.usoftchina.smartschool.test.BaseControllerTest;
+import com.usoftchina.smartschool.utils.JsonUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MvcResult;
+
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@EnableAutoConfiguration
+public class MessageLogControllerTest extends BaseControllerTest {
+
+    private static final String CODE = "Curriculum";
+    private static final String NAME = "课程表";
+
+    @Test
+    public void testA_getListData() throws Exception {
+        BaseContextHolder.setSchoolId(1L);
+        MvcResult mvcResult = mockMvc.perform(get("/messagelog/list"))
+                .andExpect(isSuccess())
+                .andReturn();
+        Result<PageInfo> result = result(mvcResult, PageInfo.class);
+        System.out.println(JsonUtils.toJsonString(result.getData()));
+    }
+
+    @Test
+    public void testB_save() throws Exception {
+        BaseContextHolder.setSchoolId(1L);
+        DocBaseDTO docBaseDTO = new DocBaseDTO(1L, CODE, NAME);
+        mockMvc.perform(requestBody("/messagelog/save", docBaseDTO));
+    }
+
+    @Test
+    public void testC_update() throws Exception {
+        BaseContextHolder.setSchoolId(1L);
+        DocBaseDTO docBaseDTO = new DocBaseDTO(1L, CODE, NAME);
+        mockMvc.perform(requestBody("/messagelog/update", docBaseDTO));
+    }
+
+    @Test
+    public void testD_delete() throws Exception {
+        DocBaseDTO docBaseDTO = new DocBaseDTO(1L, CODE, NAME);
+        BaseContextHolder.setSchoolId(1L);
+        mockMvc.perform(requestBody("/messagelog/delete", docBaseDTO));
+    }
+
+    @Test
+    public void testE_deleteDetail() throws Exception {
+        BaseContextHolder.setSchoolId(1L);
+        DocBaseDTO docBaseDTO = new DocBaseDTO(1L, CODE, NAME);
+        mockMvc.perform(requestBody("/messagelog/deleteDetail", docBaseDTO));
+    }
+
+    @Test
+    public void testF_customizeLog() throws Exception {
+        BaseContextHolder.setSchoolId(1L);
+        DocBaseDTO docBaseDTO = new DocBaseDTO(1L, CODE, NAME);
+        mockMvc.perform(requestBody("/messagelog/customizeLog", docBaseDTO));
+    }
+
+}

+ 156 - 0
framework/test-starter/src/main/java/com.usoftchina.smartschool.test/BaseControllerTest.java

@@ -0,0 +1,156 @@
+package com.usoftchina.smartschool.test;
+
+import com.fasterxml.jackson.databind.JavaType;
+import com.usoftchina.smartschool.base.Result;
+import com.usoftchina.smartschool.utils.JsonUtils;
+import org.junit.Before;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.MvcResult;
+import org.springframework.test.web.servlet.ResultMatcher;
+import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
+import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.web.context.WebApplicationContext;
+
+import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
+
+/**
+ * @author yingp
+ * @date 2018/10/23
+ */
+public abstract class BaseControllerTest {
+    @Autowired
+    protected WebApplicationContext context;
+
+    protected MockMvc mockMvc;
+
+    @Before
+    public void setup() {
+        this.mockMvc = MockMvcBuilders.webAppContextSetup(context)
+                .alwaysDo(print())
+                .alwaysExpect(isOk())
+                .alwaysExpect(isJson())
+                .build();
+    }
+
+    /**
+     * GET请求
+     *
+     * @param urlTemplate
+     * @return
+     */
+    public static MockHttpServletRequestBuilder get(String urlTemplate, Object... uriVars) {
+        return MockMvcRequestBuilders.get(urlTemplate, uriVars);
+    }
+
+    /**
+     * POST form方式请求
+     *
+     * @param urlTemplate
+     * @return
+     */
+    public static MockHttpServletRequestBuilder post(String urlTemplate, Object... uriVars) {
+        return MockMvcRequestBuilders.post(urlTemplate, uriVars);
+    }
+
+    /**
+     * 文件上传
+     *
+     * @param urlTemplate
+     * @param uriVars
+     * @return
+     */
+    public static MockMultipartHttpServletRequestBuilder multipart(String urlTemplate, Object... uriVars) {
+        return MockMvcRequestBuilders.multipart(urlTemplate, uriVars);
+    }
+
+    /**
+     * 请求
+     *
+     * @param urlTemplate
+     * @return
+     */
+    public static MockHttpServletRequestBuilder request(HttpMethod method, String urlTemplate, Object... uriVars) {
+        return MockMvcRequestBuilders.request(method, urlTemplate, uriVars);
+    }
+
+    /**
+     * POST Payload方式请求,使用@RequestBody注解情况下
+     *
+     * @param object
+     * @return
+     */
+    public static MockHttpServletRequestBuilder requestBody(String urlTemplate, Object object) {
+        return post(urlTemplate).contentType(MediaType.APPLICATION_JSON_UTF8)
+                .content(JsonUtils.toJsonString(object));
+    }
+
+    /**
+     * 是否返回 http status: 200
+     *
+     * @return
+     */
+    public static ResultMatcher isOk() {
+        return status().isOk();
+    }
+
+    /**
+     * 是否返回json格式
+     *
+     * @return
+     */
+    public static ResultMatcher isJson() {
+        return content().contentType(MediaType.APPLICATION_JSON_UTF8);
+    }
+
+    /**
+     * 是否执行成功 {"success": true}
+     *
+     * @return
+     */
+    public static ResultMatcher isSuccess() {
+        return jsonPath("success").value(true);
+    }
+
+    /**
+     * 是否执行失败 {"success": false}
+     *
+     * @return
+     */
+    public static ResultMatcher isFail() {
+        return jsonPath("success").value(false);
+    }
+
+    /**
+     * Result转换
+     *
+     * @param mvcResult
+     * @param <T>
+     * @return
+     * @throws Exception
+     */
+    public static <T> Result<T> result(MvcResult mvcResult, Class<T> targetClass) throws Exception {
+        String content = mvcResult.getResponse().getContentAsString();
+        return Result.fromJsonString(content, targetClass);
+    }
+
+    /**
+     * Result转换
+     *
+     * @param mvcResult
+     * @param targetType
+     * @param <T>
+     * @return
+     * @throws Exception
+     */
+    public static <T> Result<T> result(MvcResult mvcResult, JavaType targetType) throws Exception {
+        String content = mvcResult.getResponse().getContentAsString();
+        return Result.fromJsonString(content, targetType);
+    }
+
+}

+ 26 - 0
framework/test-starter/src/main/java/com.usoftchina.smartschool.test/TestConstant.java

@@ -0,0 +1,26 @@
+package com.usoftchina.smartschool.test;
+
+/**
+ * @author yingp
+ * @date 2018/10/22
+ */
+public class TestConstant {
+    /**
+     * 默认企业ID
+     */
+    public static final long DEFAULT_COMPANY_ID = 1;
+    /**
+     * 默认账户ID
+     */
+    public static final long DEFAULT_ACCOUNT_ID = 1;
+    /**
+     * 默认应用ID
+     * <p>
+     * trade-app - 贸易云
+     * manufacture-app - 制造云
+     * solution-app - 方案云
+     * ...
+     * </p>
+     */
+    public static final String DEFAULT_APP_ID = "trade-app";
+}

+ 19 - 0
framework/test-starter/src/main/java/com.usoftchina.smartschool.test/TestContextListener.java

@@ -0,0 +1,19 @@
+package com.usoftchina.smartschool.test;
+
+import com.usoftchina.smartschool.context.BaseContextHolder;
+import org.springframework.test.context.TestContext;
+import org.springframework.test.context.support.AbstractTestExecutionListener;
+
+/**
+ * @author yingp
+ * @date 2018/10/22
+ */
+public class TestContextListener extends AbstractTestExecutionListener {
+    @Override
+    public void beforeTestClass(TestContext testContext) throws Exception {
+        // 设置测试环境默认用户
+        BaseContextHolder.setCompanyId(TestConstant.DEFAULT_COMPANY_ID);
+        BaseContextHolder.setUserId(TestConstant.DEFAULT_ACCOUNT_ID);
+        BaseContextHolder.setAppId(TestConstant.DEFAULT_APP_ID);
+    }
+}

+ 3 - 0
framework/test-starter/src/main/resources/META-INF/spring.factories

@@ -0,0 +1,3 @@
+# Test Execution Listeners
+org.springframework.test.context.TestExecutionListener=\
+com.usoftchina.smartschool.test.TestContextListener