From f7ef143ada8c9d3ac6cdbb99b78c143803f41e05 Mon Sep 17 00:00:00 2001 From: qiaowei Date: Mon, 15 Apr 2019 17:52:42 +0800 Subject: [PATCH] =?utf8?q?controller=E6=8E=A5=E5=8F=A3=E5=8D=95=E5=85=83?= =?utf8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../dlpay/framework/util/TradeDict.java | 1 + .../com/supwisdom/dlpay/DlpayApplication.kt | 1 - src/main/resources/application.properties | 17 ++++ .../supwisdom/dlpay/DlpayApplicationTests.kt | 7 +- .../com/supwisdom/dlpay/ShopControllerTest.kt | 89 +++++++++++++++++++ 5 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 src/test/kotlin/com/supwisdom/dlpay/ShopControllerTest.kt diff --git a/src/main/java/com/supwisdom/dlpay/framework/util/TradeDict.java b/src/main/java/com/supwisdom/dlpay/framework/util/TradeDict.java index 5596b244..65e525a6 100644 --- a/src/main/java/com/supwisdom/dlpay/framework/util/TradeDict.java +++ b/src/main/java/com/supwisdom/dlpay/framework/util/TradeDict.java @@ -10,6 +10,7 @@ public class TradeDict { public static final String STATUS_NORMAL = "normal"; public static final String STATUS_CLOSED = "closed"; public static final String STATUS_LOCKED = "locked"; + public static final String SUBJNO_SHOP = "locked"; /** * 流水状态 diff --git a/src/main/kotlin/com/supwisdom/dlpay/DlpayApplication.kt b/src/main/kotlin/com/supwisdom/dlpay/DlpayApplication.kt index a9cea45a..0a4f46a2 100644 --- a/src/main/kotlin/com/supwisdom/dlpay/DlpayApplication.kt +++ b/src/main/kotlin/com/supwisdom/dlpay/DlpayApplication.kt @@ -8,7 +8,6 @@ import org.springframework.context.annotation.PropertySource @ComponentScan("com.supwisdom.dlpay") @SpringBootApplication -@PropertySource("file:\${catalina.home}/conf/dlpay_config.properties") class DlpayApplication fun main(args: Array) { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e69de29b..c1512165 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -0,0 +1,17 @@ +#######################################springboot配置 start################################# +# 单库数据库配置 +spring.datasource.url=jdbc:oracle:thin:@172.28.201.101:47922:orcl +spring.datasource.username=dlpay +spring.datasource.password=kingstar +spring.datasource.driver.class=oracle.jdbc.driver.OracleDriver +spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect +spring.jpa.show-sql=true +spring.datasource.hikari.connection-timeout=60000 +spring.datasource.hikari.maximum-pool-size=5 +spring.jpa.hibernate.ddl-auto=update +# logging +logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n +logging.level.org.hibernate.SQL=debug +#################### JSP PAGE #################### +spring.mvc.view.prefix=/pages/ +spring.mvc.view.suffix=.jsp \ No newline at end of file diff --git a/src/test/kotlin/com/supwisdom/dlpay/DlpayApplicationTests.kt b/src/test/kotlin/com/supwisdom/dlpay/DlpayApplicationTests.kt index 625cdbdc..c8b875f3 100644 --- a/src/test/kotlin/com/supwisdom/dlpay/DlpayApplicationTests.kt +++ b/src/test/kotlin/com/supwisdom/dlpay/DlpayApplicationTests.kt @@ -1,16 +1,11 @@ package com.supwisdom.dlpay -import org.junit.Test import org.junit.runner.RunWith import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.context.junit4.SpringRunner @RunWith(SpringRunner::class) @SpringBootTest -class DlpayApplicationTests { - - @Test - fun contextLoads() { - } +abstract class DlpayApplicationTests{ } diff --git a/src/test/kotlin/com/supwisdom/dlpay/ShopControllerTest.kt b/src/test/kotlin/com/supwisdom/dlpay/ShopControllerTest.kt new file mode 100644 index 00000000..4ff17146 --- /dev/null +++ b/src/test/kotlin/com/supwisdom/dlpay/ShopControllerTest.kt @@ -0,0 +1,89 @@ +package com.supwisdom.dlpay + +import com.google.gson.Gson +import com.supwisdom.dlpay.framework.domain.TShop +import com.supwisdom.dlpay.shop.bean.ShopParam +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.http.MediaType +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import org.springframework.test.web.servlet.MockMvc + +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post +import org.springframework.test.web.servlet.result.MockMvcResultHandlers.print +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status + +/** + * Created by shuwei on 2019/4/15. + */ +@RunWith(SpringRunner::class) +@SpringBootTest +@AutoConfigureMockMvc +class ShopControllerTest { + @Autowired + private lateinit var mvc: MockMvc + + class RetBean { + var shopid: Int = 0 + var retcode: Int = 0 + lateinit var shop: TShop + } + + @Test + fun open() { + val shopParam = ShopParam() + shopParam.uniqueId = ""//random req + shopParam.shopname = "测试名称" + val gson = Gson() + val ret = mvc.perform(post("/shop/open").content(gson.toJson(shopParam)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk) + .andDo(print()) + .andReturn() + val res = ret.response.contentAsString + Assert.assertNotNull(res) + val retBean = gson.fromJson(res, RetBean::class.java) + Assert.assertNotNull(retBean) + Assert.assertEquals(0, retBean.retcode) + Assert.assertNotNull(retBean.shopid) + Assert.assertNotEquals(0, retBean.shopid) + } + + @Test + fun get() { + val shopParam = ShopParam() + shopParam.uniqueId = "testuniqueId"//测试用 + shopParam.shopname = "测试名称:testuniqueId" + val gson = Gson() + val ret = mvc.perform(post("/shop/open").content(gson.toJson(shopParam)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk) + .andDo(print()) + .andReturn() + val resOpen = ret.response.contentAsString + Assert.assertNotNull(resOpen) + val retBeanOpen = gson.fromJson(resOpen, RetBean::class.java) + Assert.assertNotNull(retBeanOpen) + Assert.assertNotNull(retBeanOpen.shopid) + shopParam.shopid = retBeanOpen.shopid + + val retGet = mvc.perform(get("/shop/get").content(gson.toJson(shopParam)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk) + .andDo(print()) + .andReturn() + val res = retGet.response.contentAsString + Assert.assertNotNull(res) + val retBean = gson.fromJson(res, RetBean::class.java) + Assert.assertNotNull(retBean) + Assert.assertEquals(0, retBean.retcode) + Assert.assertNotNull(retBean.shop) + Assert.assertEquals(retBeanOpen.shopid, retBean.shop.shopid) + } +} \ No newline at end of file -- 2.17.1