1 import org.junit.Assert;
2 import org.junit.Before;
3 import org.junit.Test;
4 import org.junit.runner.RunWith;
5 import org.mockito.InjectMocks;
6 import org.mockito.Mock;
7 import org.mockito.MockitoAnnotations;
8 import org.powermock.api.mockito.PowerMockito;
9 import org.powermock.core.classloader.annotations.PowerMockIgnore;
10 import org.powermock.core.classloader.annotations.PrepareForTest;
11 import org.powermock.modules.junit4.PowerMockRunner;
12 import org.springframework.beans.factory.annotation.Value;
13
14 import java.io.IOException;
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import static org.mockito.Matchers.any;
19 import static org.mockito.Matchers.anyString;
20
21 @RunWith(PowerMockRunner.class)
22 @PrepareForTest({RegistryUtilService.class, ApiContainer.class, HttpUtils.class})
23 @PowerMockIgnore({"javax.management.*", "javax.script.*", "javax.net.ssl.*"})
24 public class ReportQueryImplTest {
25
26 @Mock
27 ILogger logger;
28
29 @InjectMocks
30 ReportQueryImpl reportQueryImpl;
31
32 @Mock
33 MybatisQuery mybatisQuery;
34 @Mock
35 CountryProbeMapper countryProbeMapper;
36
37 @Mock
38 RegionMapper regionMapper;
39
40 @Value("${request.application.appId}")
41 private String appId;
42
43 @Value("${request.appSecret}")
44 private String appSecret;
45
46 @Before
47 public void setUp() {
48 MockitoAnnotations.initMocks(this);
49 }
50
51 @Test
52 public void testQueryKpi() throws Exception {
53 List<Filter> filters = new ArrayList<>();
54 filters.add(new Filter("organization", "全球"));
55 filters.add(new Filter("repoffce", "ALL"));
56 filters.add(new Filter("country", "ALL"));
57 Condition condition = new Condition("123", "20220102", "发未收比例", filters);
58
59 ArrayList<PreferItem> list = new ArrayList<>();
60 list.add(new PreferItem("1","发货",null));
61 list.add(new PreferItem("9","物流",null));
62 PowerMockito.when(mybatisQuery.queryKpi(any())).thenReturn(list);
63
64 ResultCollection resultCollection = reportQueryImpl.queryKpi(condition);
65 Assert.assertNotNull(resultCollection);
66 }
67
68 @Test
69 public void testQueryMap() throws IOException {
70 Region region = new Region("西欧地区部", "All", "ALL");
71 Condition condition = new Condition("123", "20220102", region);
72
73 String mapUrl = "http://apigw.huawei.com/api/data-subject/app_000000035085/D103187";
74 PowerMockito.mockStatic(ApiContainer.class);
75 ApiTemplate template = new ApiTemplate();
76 template.setUrl(mapUrl);
77 PowerMockito.when(ApiContainer.getApiById(ApiType.MAP.getId())).thenReturn(template);
78
79 PowerMockito.mockStatic(HttpUtils.class);
80 String result = "{\"list\":[{\"TOTAL\":\"14\",\"REGION_CN_NAME\":\"西欧地区部\",\"COUNTRY_CN_NAME\":null,\"MORE_THAN_7DAY\":\"14\",\"REPOFFICE_CN_NAME\":\"瑞士代表处\",\"PERIOD_ID\":\"20220102\",\"LESS_THAN_7DAY\":\"0\",\"PERCENTAGE_OF_REGION_CN_NAME_7\":\"1.00\",\"RANK\":\"1\",\"INDICATOR_NAME\":\"超期发未收\"},{\"TOTAL\":\"4\",\"REGION_CN_NAME\":\"西欧地区部\",\"COUNTRY_CN_NAME\":null,\"MORE_THAN_7DAY\":\"4\",\"REPOFFICE_CN_NAME\":\"英国代表处\",\"PERIOD_ID\":\"20220102\",\"LESS_THAN_7DAY\":\"0\",\"PERCENTAGE_OF_REGION_CN_NAME_7\":\"1.00\",\"RANK\":\"2\",\"INDICATOR_NAME\":\"超期发未收\"},{\"TOTAL\":\"66\",\"REGION_CN_NAME\":\"西欧地区部\",\"COUNTRY_CN_NAME\":null,\"MORE_THAN_7DAY\":\"64\",\"REPOFFICE_CN_NAME\":\"德国代表处\",\"PERIOD_ID\":\"20220102\",\"LESS_THAN_7DAY\":\"2\",\"PERCENTAGE_OF_REGION_CN_NAME_7\":\"0.96\",\"RANK\":\"3\",\"INDICATOR_NAME\":\"超期收未验\"},{\"TOTAL\":\"16\",\"REGION_CN_NAME\":\"西欧地区部\",\"COUNTRY_CN_NAME\":null,\"MORE_THAN_7DAY\":\"15\",\"REPOFFICE_CN_NAME\":\"瑞士代表处\",\"PERIOD_ID\":\"20220102\",\"LESS_THAN_7DAY\":\"1\",\"PERCENTAGE_OF_REGION_CN_NAME_7\":\"0.93\",\"RANK\":\"4\",\"INDICATOR_NAME\":\"超期收未验\"},{\"TOTAL\":\"24\",\"REGION_CN_NAME\":\"西欧地区部\",\"COUNTRY_CN_NAME\":null,\"MORE_THAN_7DAY\":\"22\",\"REPOFFICE_CN_NAME\":\"法国代表处\",\"PERIOD_ID\":\"20220102\",\"LESS_THAN_7DAY\":\"2\",\"PERCENTAGE_OF_REGION_CN_NAME_7\":\"0.91\",\"RANK\":\"5\",\"INDICATOR_NAME\":\"超期发未收\"},{\"TOTAL\":\"9\",\"REGION_CN_NAME\":\"西欧地区部\",\"COUNTRY_CN_NAME\":null,\"MORE_THAN_7DAY\":\"8\",\"REPOFFICE_CN_NAME\":\"西欧多国管理部\",\"PERIOD_ID\":\"20220102\",\"LESS_THAN_7DAY\":\"1\",\"PERCENTAGE_OF_REGION_CN_NAME_7\":\"0.88\",\"RANK\":\"6\",\"INDICATOR_NAME\":\"超期发未收\"},{\"TOTAL\":\"36\",\"REGION_CN_NAME\":\"西欧地区部\",\"COUNTRY_CN_NAME\":null,\"MORE_THAN_7DAY\":\"31\",\"REPOFFICE_CN_NAME\":\"法国代表处\",\"PERIOD_ID\":\"20220102\",\"LESS_THAN_7DAY\":\"5\",\"PERCENTAGE_OF_REGION_CN_NAME_7\":\"0.86\",\"RANK\":\"7\",\"INDICATOR_NAME\":\"超期收未验\"},{\"TOTAL\":\"98\",\"REGION_CN_NAME\":\"西欧地区部\",\"COUNTRY_CN_NAME\":null,\"MORE_THAN_7DAY\":\"84\",\"REPOFFICE_CN_NAME\":\"西班牙代表处\",\"PERIOD_ID\":\"20220102\",\"LESS_THAN_7DAY\":\"14\",\"PERCENTAGE_OF_REGION_CN_NAME_7\":\"0.85\",\"RANK\":\"8\",\"INDICATOR_NAME\":\"超期收未验\"},{\"TOTAL\":\"65\",\"REGION_CN_NAME\":\"西欧地区部\",\"COUNTRY_CN_NAME\":null,\"MORE_THAN_7DAY\":\"54\",\"REPOFFICE_CN_NAME\":\"德国代表处\",\"PERIOD_ID\":\"20220102\",\"LESS_THAN_7DAY\":\"11\",\"PERCENTAGE_OF_REGION_CN_NAME_7\":\"0.83\",\"RANK\":\"9\",\"INDICATOR_NAME\":\"超期发未收\"},{\"TOTAL\":\"20\",\"REGION_CN_NAME\":\"西欧地区部\",\"COUNTRY_CN_NAME\":null,\"MORE_THAN_7DAY\":\"15\",\"REPOFFICE_CN_NAME\":\"西欧多国管理部\",\"PERIOD_ID\":\"20220102\",\"LESS_THAN_7DAY\":\"5\",\"PERCENTAGE_OF_REGION_CN_NAME_7\":\"0.75\",\"RANK\":\"10\",\"INDICATOR_NAME\":\"超期收未验\"},{\"TOTAL\":\"33\",\"REGION_CN_NAME\":\"西欧地区部\",\"COUNTRY_CN_NAME\":null,\"MORE_THAN_7DAY\":\"23\",\"REPOFFICE_CN_NAME\":\"意大利代表处\",\"PERIOD_ID\":\"20220102\",\"LESS_THAN_7DAY\":\"10\",\"PERCENTAGE_OF_REGION_CN_NAME_7\":\"0.69\",\"RANK\":\"11\",\"INDICATOR_NAME\":\"超期收未验\"},{\"TOTAL\":\"101\",\"REGION_CN_NAME\":\"西欧地区部\",\"COUNTRY_CN_NAME\":null,\"MORE_THAN_7DAY\":\"68\",\"REPOFFICE_CN_NAME\":\"西班牙代表处\",\"PERIOD_ID\":\"20220102\",\"LESS_THAN_7DAY\":\"33\",\"PERCENTAGE_OF_REGION_CN_NAME_7\":\"0.67\",\"RANK\":\"12\",\"INDICATOR_NAME\":\"超期发未收\"},{\"TOTAL\":\"24\",\"REGION_CN_NAME\":\"西欧地区部\",\"COUNTRY_CN_NAME\":null,\"MORE_THAN_7DAY\":\"11\",\"REPOFFICE_CN_NAME\":\"意大利代表处\",\"PERIOD_ID\":\"20220102\",\"LESS_THAN_7DAY\":\"13\",\"PERCENTAGE_OF_REGION_CN_NAME_7\":\"0.45\",\"RANK\":\"13\",\"INDICATOR_NAME\":\"超期发未收\"}],\"total\":13}";
81 PowerMockito.when(HttpUtils.postRequest(anyString(), any(), any())).thenReturn(result);
82
83 LongitudeAndLatitude longitudeAndLatitude = new LongitudeAndLatitude(7.0,7.0);
84 PowerMockito.when( regionMapper.queryLongitudeAndLatitude(anyString(), anyString())).thenReturn(longitudeAndLatitude);
85
86 List<ProbeCriterion> probeCriterions = new ArrayList<>();
87 probeCriterions.add(new ProbeCriterion("long_term_inventory","thresholdVal","baseVal","targetVal"));
88 probeCriterions.add(new ProbeCriterion("long_term_inventory","thresholdVal","baseVal","targetVal"));
89 probeCriterions.add(new ProbeCriterion("long_term_inventory","thresholdVal","baseVal","targetVal"));
90 PowerMockito.when(countryProbeMapper.queryProbeByProbeIds(any(),any(),any())).thenReturn(probeCriterions);
91 reportQueryImpl.queryMap(condition);
92 }
93
94 @Test
95 public void testQueryProbe() {
96 Region region = new Region("西欧地区部", "ALL", "ALL");
97 Condition condition = new Condition("ywx1171065", "20220102", "发未收比例", region);
98
99 ArrayList<PreferProbeItem> preferProbeItems = new ArrayList<>();
100 preferProbeItems.add(new PreferProbeItem("1234","客户订单支付","需求管理","long_term_inventory","超长期存货",1));
101 preferProbeItems.add(new PreferProbeItem("1234","客户订单支付","订单履行","overdue_not_checked","超期收未验",1));
102 preferProbeItems.add(new PreferProbeItem("1234","客户订单支付","客户满意","overdue_not_received","超期发未收",1));
103 PowerMockito.when(mybatisQuery.queryProbe(any())).thenReturn(preferProbeItems);
104
105 ProbeCriterion probeCriterion = new ProbeCriterion("long_term_inventory","thresholdVal","baseVal","targetVal");
106 PowerMockito.when(mybatisQuery.queryProbeCriterion(any(),any(),any())).thenReturn(probeCriterion);
107
108 reportQueryImpl.queryProbe(condition);
109 }
110
111 @Test
112 public void testUpdatePerformanceDeploy() {
113 ArrayList<KpiDeploy> kpiDeploys = new ArrayList<>();
114 kpiDeploys.add(new KpiDeploy("1", "1", 1));
115 kpiDeploys.add(new KpiDeploy("111", "111", 111));
116 kpiDeploys.add(new KpiDeploy("222", "222", 222));
117 reportQueryImpl.updatePerformanceDeploy(kpiDeploys);
118 }
119
120 @Test
121 public void testUpdateStateDeploy() {
122 ArrayList<StateDeploy> stateDeploys = new ArrayList<>();
123 stateDeploys.add(new StateDeploy("1", "1", 1));
124 stateDeploys.add(new StateDeploy("111", "111", 111));
125 stateDeploys.add(new StateDeploy("222", "222", 222));
126 reportQueryImpl.updateStateDeploy(stateDeploys);
127 }
128
129 @Test
130 public void testQueryRelatedKpi() {
131 List<Filter> filters = new ArrayList<>();
132 filters.add(new Filter("organization", "全球"));
133 filters.add(new Filter("repoffce", "ALL"));
134 filters.add(new Filter("country", "ALL"));
135 Condition condition = new Condition("123", "20220102", "发未收比例", filters);
136
137 ArrayList<PreferItem> list = new ArrayList<>();
138 list.add(new PreferItem("1","发货",0));
139 list.add(new PreferItem("9","物流",2));
140 list.add(new PreferItem("7","收货",3));
141 PowerMockito.when(mybatisQuery.queryKpiList(any())).thenReturn(list);
142 reportQueryImpl.queryRelatedKpi(condition);
143 }
144
145 @Test
146 public void testQueryRelatedProbe() {
147 Condition condition = new Condition();
148 condition.setUserId("1234");
149 List<Filter> filters = new ArrayList<>();
150 filters.add(new Filter("topic", "客户订单支付"));
151 condition.setFilters(filters);
152
153 ArrayList<PreferProbeItem> preferProbeItems = new ArrayList<>();
154 preferProbeItems.add(new PreferProbeItem("1234","客户订单支付","需求管理","long_term_inventory","超长期存货",1));
155 preferProbeItems.add(new PreferProbeItem("1234","客户订单支付","订单履行","overdue_not_checked","超期收未验",1));
156 preferProbeItems.add(new PreferProbeItem("1234","客户订单支付","客户满意","overdue_not_received","超期发未收",1));
157 PowerMockito.when(mybatisQuery.queryUserProbes(any(),any())).thenReturn(preferProbeItems);
158
159 reportQueryImpl.queryRelatedProbe(condition);
160 }
161
162 @Test
163 public void testQueryRelatedProbe2() {
164 Condition condition = new Condition();
165 condition.setUserId("1234");
166 List<Filter> filters = new ArrayList<>();
167 filters.add(new Filter("topic", "客户订单支付"));
168 filters.add(new Filter("topic", "资源有效配置"));
169 condition.setFilters(filters);
170
171 ArrayList<PreferProbeItem> preferProbeItems = new ArrayList<>();
172 preferProbeItems.add(new PreferProbeItem("1234","客户订单支付","需求管理","long_term_inventory","超长期存货",1));
173 preferProbeItems.add(new PreferProbeItem("1234","客户订单支付","订单履行","overdue_not_checked","超期收未验",1));
174 preferProbeItems.add(new PreferProbeItem("1234","客户订单支付","客户满意","overdue_not_received","超期发未收",1));
175 PowerMockito.when(mybatisQuery.queryUserProbes(any(),any())).thenReturn(preferProbeItems);
176
177 PreferProbeInfo preferProbeInfo = reportQueryImpl.queryRelatedProbe(condition);
178 Assert.assertNull(preferProbeInfo);
179 }
180
181 }