AdminApplicationTests.java
3.21 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
package cn.com.glsx.test;
import cn.com.glsx.Application;
import cn.com.glsx.admin.modules.model.ElectricFenceBO;
import cn.com.glsx.admin.modules.service.ElectricFenceService;
import cn.com.glsx.auth.model.SyntheticUser;
import cn.com.glsx.auth.utils.ShieldContextHolder;
import cn.hutool.core.lang.UUID;
import lombok.extern.slf4j.Slf4j;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Date;
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class AdminApplicationTests {
@Autowired
private ElectricFenceService electricFenceService;
// Should rename to @BeforeTestMethod
// e.g. Creating an similar object and share for all @Test
@Before
public void runBeforeTestMethod() {
System.out.println("@Before - runBeforeTestMethod");
SyntheticUser user = new SyntheticUser();
user.setUserId(2L);
user.setAdmin(false);
user.setAccount("payxz");
ShieldContextHolder.setUser(user);
}
// Should rename to @AfterTestMethod
@After
public void runAfterTestMethod() {
System.out.println("@After - runAfterTestMethod");
}
@Test
public void testAddFence() throws Exception {
ElectricFenceBO fenceBO = new ElectricFenceBO();
fenceBO.setFenceName("测试围栏");
fenceBO.setFenceNo(UUID.randomUUID().toString());
fenceBO.setBizFenceType(1);
fenceBO.setLocationType(0);
fenceBO.setShapeType(1);
fenceBO.setRadius(3000);
fenceBO.setLnglat("113.528632,22.443676");
fenceBO.setTriggerType(1);
fenceBO.setTimeType(0);
fenceBO.setStartTime(new Date());
fenceBO.setEndTime(new Date());
fenceBO.setEnableStatus(1);
fenceBO.setRemark("这是一个测试围栏");
fenceBO.setAreaCode("12213");
fenceBO.setAreaText("深圳");
fenceBO.setAnalysisAddress("深圳深南大道");
fenceBO.setTelNumbers("13800138000");
electricFenceService.addFence(fenceBO);
}
@Test
public void testUpdateFence() throws Exception {
ElectricFenceBO fenceBO = new ElectricFenceBO();
fenceBO.setId(1L);
fenceBO.setFenceName("测试围栏-1");
fenceBO.setFenceNo(UUID.randomUUID().toString());
fenceBO.setBizFenceType(1);
fenceBO.setLocationType(0);
fenceBO.setShapeType(1);
fenceBO.setRadius(1000);
fenceBO.setLnglat("113.528632,22.443676");
fenceBO.setTriggerType(1);
fenceBO.setTimeType(0);
fenceBO.setStartTime(new Date());
fenceBO.setEndTime(new Date());
fenceBO.setEnableStatus(1);
fenceBO.setRemark("这是一个测试围栏");
fenceBO.setAreaCode("12213");
fenceBO.setAreaText("深圳");
fenceBO.setAnalysisAddress("深圳深南大道333");
fenceBO.setTelNumbers("13800138000");
electricFenceService.updateFence(fenceBO);
}
}