Skip to content

Commit b291db9

Browse files
author
xiaowei1118
committed
add junit test
1 parent b045b6f commit b291db9

6 files changed

Lines changed: 40306 additions & 12 deletions

File tree

mybatis.log

Lines changed: 40189 additions & 0 deletions
Large diffs are not rendered by default.

src/main/java/com/changyu/foryou/controller/CampusController.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.changyu.foryou.controller;
22

3-
import java.util.Calendar;
4-
import java.util.Date;
53
import java.util.HashMap;
64
import java.util.List;
75
import java.util.Map;
@@ -13,7 +11,6 @@
1311
import org.springframework.web.bind.annotation.ResponseBody;
1412

1513
import com.alibaba.fastjson.JSON;
16-
import com.alibaba.fastjson.JSONArray;
1714
import com.changyu.foryou.model.Campus;
1815
import com.changyu.foryou.model.CampusAdmin;
1916
import com.changyu.foryou.model.CityWithCampus;

src/main/resources/config.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
hibernate.dialect=org.hibernate.dialect.MySQLDialect
99
driverClassName=com.mysql.jdbc.Driver
1010
validationQuery=SELECT 1
11-
jdbc_url=jdbc:mysql://localhost:3306/foryou?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
12-
jdbc_username=root
13-
jdbc_password=zc0829
11+
jdbc_url=jdbc:mysql://120.26.213.172:3306/foryou?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
12+
jdbc_username=changyu2015
13+
jdbc_password=changyu15
1414

1515
#hibernate.dialect=org.hibernate.dialect.SQLServerDialect
1616
#driverClassName=net.sourceforge.jtds.jdbc.Driver

src/main/resources/spring-mybatis.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ http://www.springframework.org/schema/task http://www.springframework.org/schema
1414

1515
<!-- <task:annotation-driven /> -->
1616
<!-- jndi方式 -->
17-
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
17+
<!-- <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
1818
<property name="jndiName">
1919
<value>java:comp/env/jdbc/foryouDB</value>
2020
</property>
@@ -23,10 +23,10 @@ http://www.springframework.org/schema/task http://www.springframework.org/schema
2323
<property name="dataSource">
2424
<ref bean="dataSource" />
2525
</property>
26-
</bean>
26+
</bean> -->
2727

2828
<!-- 配置数据源 -->
29-
<!-- <bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
29+
<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
3030
init-method="init" destroy-method="close">
3131
<property name="url" value="${jdbc_url}" />
3232
<property name="username" value="${jdbc_username}" />
@@ -48,10 +48,10 @@ http://www.springframework.org/schema/task http://www.springframework.org/schema
4848
<property name="removeAbandoned" value="true" />
4949
<property name="removeAbandonedTimeout" value="1800" />
5050
<property name="logAbandoned" value="true" />
51-
<property name="filters" value="stat" />
51+
<!-- <property name="filters" value="stat" /> -->
5252
<property name="filters" value="mergeStat" />
5353
</bean>
54-
-->
54+
5555

5656
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
5757
<property name="dataSource" ref="dataSource" />

src/main/resources/spring.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd
77
">
88

99
<!-- 引入属性文件 -->
10-
<!-- <context:property-placeholder location="classpath:config.properties" /> -->
10+
<context:property-placeholder location="classpath:config.properties" />
1111

1212
<!-- 自动扫描(自动注入) -->
1313
<context:component-scan base-package="com.changyu.foryou.service" />
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.changyu.test;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashMap;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
import org.apache.log4j.Logger;
9+
import org.junit.Test;
10+
import org.junit.runner.RunWith;
11+
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.test.context.ContextConfiguration;
13+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
14+
15+
import com.alibaba.fastjson.JSON;
16+
import com.changyu.foryou.model.SmallOrder;
17+
import com.changyu.foryou.model.TogetherOrder;
18+
import com.changyu.foryou.service.OrderService;
19+
import com.changyu.foryou.tools.Constants;
20+
21+
22+
@RunWith(SpringJUnit4ClassRunner.class)
23+
@ContextConfiguration(locations = { "classpath:spring.xml", "classpath:spring-mybatis.xml" })
24+
public class orderTest {
25+
private static final Logger LOGGER = Logger
26+
.getLogger(orderTest.class);
27+
private OrderService orderService;
28+
29+
public OrderService getOrderService() {
30+
return orderService;
31+
}
32+
33+
@Autowired
34+
public void setOrderService(OrderService orderService) {
35+
this.orderService = orderService;
36+
}
37+
38+
@Test
39+
public void getOrderInMine(){
40+
41+
Map<String, Object> map = new HashMap<String, Object>();
42+
43+
List<TogetherOrder> togetherOrdersList = new ArrayList<TogetherOrder>();
44+
45+
try {
46+
Map<String, Object> paramMap = new HashMap<String, Object>();
47+
//case 1
48+
paramMap.put("phoneId", "18896554880");
49+
paramMap.put("status", "a");
50+
51+
52+
//case 2
53+
54+
List<String> togetherIds = orderService.getTogetherId(paramMap);
55+
56+
System.out.println(JSON.toJSONString(togetherIds));
57+
58+
if (togetherIds.size() != 0) {
59+
for (String togetherId : togetherIds) {
60+
TogetherOrder togetherOrder = new TogetherOrder(); // 一单
61+
togetherOrder.setTogetherId(togetherId);
62+
63+
paramMap.put("togetherId", togetherId);
64+
List<SmallOrder> orderList = orderService
65+
.getOrderListInMine(paramMap); // 一单里面的小订单
66+
togetherOrder.setSmallOrders(orderList);
67+
togetherOrder.setPayWay(orderList.get(0).getPayWay());
68+
Short totalStatus=0;
69+
if(orderList.get(0).getStatus()!=4)
70+
{
71+
totalStatus=orderList.get(0).getStatus();
72+
}
73+
else
74+
{
75+
totalStatus=5;
76+
for (int i = 0; i < orderList.size(); i++) {
77+
if (orderList.get(i).getIsRemarked() == 0) {
78+
totalStatus = 4;
79+
}
80+
}
81+
}
82+
togetherOrder.setStatus(totalStatus);
83+
togetherOrder.setTogetherDate(orderList.get(0)
84+
.getTogetherDate());
85+
togetherOrdersList.add(togetherOrder);
86+
}
87+
88+
map.put(Constants.STATUS, Constants.SUCCESS);
89+
map.put(Constants.MESSAGE, "获取订单成功");
90+
map.put("orderList", JSON.parse(JSON
91+
.toJSONStringWithDateFormat(togetherOrdersList,
92+
"yyyy-MM-dd")));
93+
} else {
94+
map.put(Constants.STATUS, Constants.SUCCESS);
95+
map.put(Constants.MESSAGE, "暂无订单");
96+
}
97+
98+
} catch (Exception e) {
99+
e.printStackTrace();
100+
map.put(Constants.STATUS, Constants.FAILURE);
101+
map.put(Constants.MESSAGE, "获取订单失败");
102+
}
103+
104+
LOGGER.debug("订单为:==================="+JSON.toJSONString(map));
105+
return ;
106+
}
107+
108+
}

0 commit comments

Comments
 (0)