PlanValidateTest.java
11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package com.bsth.service.schedule;
import com.bsth.BaseTest_junit4;
import com.bsth.TestApplication;
import com.bsth.service.schedule.plan.process._1_validate._1_timetable.PlanProcessValidateTimetableService;
import com.bsth.service.schedule.plan.process._1_validate._1_timetable.PlanProcessValidateTimetableServiceDroolsImpl;
import com.bsth.service.schedule.plan.process._1_validate._2_rule.PlanProcessValidateRuleService;
import com.bsth.service.schedule.plan.process._1_validate._2_rule.PlanProcessValidateRuleServiceDroolsImpl;
import org.joda.time.format.DateTimeFormat;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.api.KieBase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.*;
/**
* 排班计划,前置验证测试。
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {TestApplication.class})
public class PlanValidateTest extends BaseTest_junit4 {
@Override
public Map<String, String> getDbunitTestDbFileClassPathMap() {
Map<String, String> dbFileMap = new HashMap<>();
dbFileMap.put("_0_validate_timetable_test_case1", "testdata/_0_validate_timetable.xml");
dbFileMap.put("_1_validate_rule_test_case1", "testdata/_1_validate_rule.xml");
return dbFileMap;
}
@Autowired
@Qualifier("kBaseValidateTimetable_plus")
private KieBase kBaseValidateTimetable;
@Autowired
@Qualifier("kBaseValidateRule_plus")
private KieBase kBaseValidateRule;
@Autowired
private JdbcTemplate jdbcTemplate;
@Test
public void _0_validate_timetable_test_case1() {
LOG.info("---------------时刻表验证测试--------------");
// 使用builder创建服务
PlanProcessValidateTimetableService planProcessValidateTimetableService =
PlanProcessValidateTimetableServiceDroolsImpl.getBuilder()
.setkBaseValidateTimetable(kBaseValidateTimetable)
.setJdbcTemplate(jdbcTemplate)
.build();
/*
验证时刻表信息服务:
1、计算指定时间内匹配的所有时刻表的详细信息
2、计算时刻表冲突信息(同一天多张时刻表)
3、计算时刻表空信息(当天没有时刻表)
*/
PlanProcessValidateTimetableService.Result result = planProcessValidateTimetableService.validateTTInfovalidateTTInfo(
1,
DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime("2019-01-01").toDate(),
DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime("2019-01-14").toDate()
);
//--------------- 测试1 ----------------//
Assert.assertArrayEquals(
"时刻表数量不一致",
new Object[] {4},
new Object[] {result.getInfos().size()});
//--------------- 测试2 ----------------//
PlanProcessValidateTimetableService.ConflictStatInfo expectConflict1 = new PlanProcessValidateTimetableService.ConflictStatInfo();
expectConflict1.setDateDesc("2019年01月04日");
expectConflict1.getTtIdList().addAll(Arrays.asList(1L, 2L));
expectConflict1.getTtNameList().addAll(Arrays.asList("时刻表1", "时刻表2"));
PlanProcessValidateTimetableService.ConflictStatInfo expectConflict2 = new PlanProcessValidateTimetableService.ConflictStatInfo();
expectConflict2.setDateDesc("2019年01月05日");
expectConflict2.getTtIdList().addAll(Arrays.asList(3L, 4L));
expectConflict2.getTtNameList().addAll(Arrays.asList("时刻表3", "时刻表4"));
PlanProcessValidateTimetableService.ConflictStatInfo expectConflict3 = new PlanProcessValidateTimetableService.ConflictStatInfo();
expectConflict3.setDateDesc("2019年01月06日");
expectConflict3.getTtIdList().addAll(Arrays.asList(3L, 4L));
expectConflict3.getTtNameList().addAll(Arrays.asList("时刻表3", "时刻表4"));
PlanProcessValidateTimetableService.ConflictStatInfo expectConflict4 = new PlanProcessValidateTimetableService.ConflictStatInfo();
expectConflict4.setDateDesc("2019年01月07日");
expectConflict4.getTtIdList().addAll(Arrays.asList(3L, 4L));
expectConflict4.getTtNameList().addAll(Arrays.asList("时刻表3", "时刻表4"));
PlanProcessValidateTimetableService.ConflictStatInfo expectConflict5 = new PlanProcessValidateTimetableService.ConflictStatInfo();
expectConflict5.setDateDesc("2019年01月11日");
expectConflict5.getTtIdList().addAll(Arrays.asList(1L, 2L));
expectConflict5.getTtNameList().addAll(Arrays.asList("时刻表1", "时刻表2"));
// 注意:排序是为了测试需要
List<PlanProcessValidateTimetableService.ConflictStatInfo> expectConflictList = new ArrayList<>();
expectConflictList.add(expectConflict1);
expectConflictList.add(expectConflict2);
expectConflictList.add(expectConflict3);
expectConflictList.add(expectConflict4);
expectConflictList.add(expectConflict5);
for (PlanProcessValidateTimetableService.ConflictStatInfo cInfo : expectConflictList) {
Collections.sort(cInfo.getTtIdList());
Collections.sort(cInfo.getTtNameList());
}
Collections.sort(expectConflictList, new Comparator<PlanProcessValidateTimetableService.ConflictStatInfo>() {
@Override
public int compare(PlanProcessValidateTimetableService.ConflictStatInfo o1, PlanProcessValidateTimetableService.ConflictStatInfo o2) {
return o1.getDateDesc().compareTo(o2.getDateDesc());
}
});
List<PlanProcessValidateTimetableService.ConflictStatInfo> actualConflictList = result.getConflictStatInfos();
for (PlanProcessValidateTimetableService.ConflictStatInfo cInfo : actualConflictList) {
Collections.sort(cInfo.getTtIdList());
Collections.sort(cInfo.getTtNameList());
}
Collections.sort(actualConflictList, new Comparator<PlanProcessValidateTimetableService.ConflictStatInfo>() {
@Override
public int compare(PlanProcessValidateTimetableService.ConflictStatInfo o1, PlanProcessValidateTimetableService.ConflictStatInfo o2) {
return o1.getDateDesc().compareTo(o2.getDateDesc());
}
});
Assert.assertArrayEquals(
"时刻表冲突信息数量不一致",
new Object[] {expectConflictList.size()},
new Object[] {actualConflictList.size()});
for (int i = 0; i < expectConflictList.size(); i++) {
PlanProcessValidateTimetableService.ConflictStatInfo expectConflictInfo = expectConflictList.get(i);
PlanProcessValidateTimetableService.ConflictStatInfo actualConflictInfo = actualConflictList.get(i);
// 日期描述
Assert.assertEquals("日期描述不一致",
expectConflictInfo.getDateDesc(), actualConflictInfo.getDateDesc());
// 时刻表Id信息
Assert.assertEquals(expectConflictInfo.getDateDesc() + "时刻表Id列表信息不一致",
expectConflictInfo.getTtIdList(), actualConflictInfo.getTtIdList());
// 时刻表名字信息
Assert.assertEquals(expectConflictInfo.getDateDesc() + "时刻表名称列表信息不一致",
expectConflictInfo.getTtNameList(), actualConflictInfo.getTtNameList());
}
//-------------- 测试3 --------------//
PlanProcessValidateTimetableService.EmptyStatInfo expectEmptyInfo1 = new PlanProcessValidateTimetableService.EmptyStatInfo();
expectEmptyInfo1.setDateDesc("2019年01月01日");
PlanProcessValidateTimetableService.EmptyStatInfo expectEmptyInfo2 = new PlanProcessValidateTimetableService.EmptyStatInfo();
expectEmptyInfo2.setDateDesc("2019年01月08日");
// 注意,排序是为了测试需要
List<PlanProcessValidateTimetableService.EmptyStatInfo> expectEmptyInfoList = new ArrayList<>();
expectEmptyInfoList.add(expectEmptyInfo1);
expectEmptyInfoList.add(expectEmptyInfo2);
Collections.sort(expectEmptyInfoList, new Comparator<PlanProcessValidateTimetableService.EmptyStatInfo>() {
@Override
public int compare(PlanProcessValidateTimetableService.EmptyStatInfo o1, PlanProcessValidateTimetableService.EmptyStatInfo o2) {
return o1.getDateDesc().compareTo(o2.getDateDesc());
}
});
List<PlanProcessValidateTimetableService.EmptyStatInfo> actualEmptyInfoList = result.getEmptyStatInfos();
Collections.sort(actualEmptyInfoList, new Comparator<PlanProcessValidateTimetableService.EmptyStatInfo>() {
@Override
public int compare(PlanProcessValidateTimetableService.EmptyStatInfo o1, PlanProcessValidateTimetableService.EmptyStatInfo o2) {
return o1.getDateDesc().compareTo(o2.getDateDesc());
}
});
Assert.assertEquals("空信息数量不一致", expectEmptyInfoList.size(), actualEmptyInfoList.size());
for (int i = 0; i < expectEmptyInfoList.size(); i++) {
PlanProcessValidateTimetableService.EmptyStatInfo expectEmptyInfo = expectEmptyInfoList.get(i);
PlanProcessValidateTimetableService.EmptyStatInfo actualEmptyInfo = actualEmptyInfoList.get(i);
Assert.assertEquals("日期描述不一致",
expectEmptyInfo.getDateDesc(), actualEmptyInfo.getDateDesc());
}
}
@Test
public void _1_validate_rule_test_case1() {
LOG.info("---------------规则验证测试--------------");
// 使用builder创建服务
PlanProcessValidateRuleService planProcessValidateRuleService =
PlanProcessValidateRuleServiceDroolsImpl.getBuilder()
.setkBaseValidateRule(kBaseValidateRule)
.setJdbcTemplate(jdbcTemplate)
.build();
PlanProcessValidateRuleService.Result validateRuleResult = planProcessValidateRuleService.validateRule(
1,
DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime("2019-01-01").toDate(),
DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime("2019-01-14").toDate()
);
Assert.assertArrayEquals(
"验证结果不一致!",
new Object[] {
1,
3,
3,
0,
0
},
new Object[] {
validateRuleResult.getXlId(),
validateRuleResult.getCount(),
validateRuleResult.getQyCount(),
validateRuleResult.getQyErrorCount(),
validateRuleResult.getErrorInfos().size()
});
}
// TODO:有空再把排班的逻辑移植过来
}