liujie
2026-01-14 f976a39b294f8c7dd60bcd2c661983c0dcc97fc6
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
package com.estate.expert.admin.service;
 
import com.estate.expert.admin.domain.standard.hierachy.HierarchyData;
import com.estate.expert.admin.domain.standard.hierachy.HierarchyIds;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Arrays;
 
/**
 * @ClassName HierarchySystemTest
 * @Description
 * @Author daisyli
 * @Date 2023/9/8
 **/
@Slf4j
@SpringBootTest
@ExtendWith(SpringExtension.class)
@Transactional
public class HierarchyServiceTest {
 
    @Autowired
    private HierarchyService service;
 
    @Test
    public void testRoot() {
        var root = service.root(HierarchyIds.SYSTEM);
        Assertions.assertNotNull(root);
 
        root = service.root(HierarchyIds.DEVICE);
        Assertions.assertNotNull(root);
    }
 
    @Test
    public void testGet() {
        var node = service.node(HierarchyIds.SYSTEM, "/", false);
        Assertions.assertEquals("综合体系-标准-层级", node.getName());
 
        node = service.node(HierarchyIds.SYSTEM, "/0", false);
        Assertions.assertEquals("安全检查", node.getName());
 
        node = service.node(HierarchyIds.SYSTEM, "/1", true);
        Assertions.assertEquals("管理行为", node.getName());
        Assertions.assertFalse(node.getChildren().isEmpty());
 
        node = service.node(HierarchyIds.DEVICE, "/1", false);
        Assertions.assertEquals("施工升降机", node.getName());
        Assertions.assertTrue(node.getChildren().isEmpty());
    }
 
    @Test
    public void testChildren() {
        var children = service.children(HierarchyIds.SYSTEM, "/0", null);
        Assertions.assertNotNull(children);
        Assertions.assertFalse(children.isEmpty());
 
        children = service.children(HierarchyIds.DEVICE, "/0", null);
        Assertions.assertNotNull(children);
        Assertions.assertTrue(children.get(0).getChildren().isEmpty());
    }
 
    @Test
    public void testAddAndDelete() {
 
        var child = service.addChild(HierarchyIds.SYSTEM, "/0", "测试3",
                new HierarchyData( 100f, 1.0f));
        Assertions.assertNotNull(child);
        var path = child.getPath();
 
        service.edit(HierarchyIds.SYSTEM, path, "测试2", new HierarchyData( 100f, 1.0f));
 
        child = service.node(HierarchyIds.SYSTEM, path, false);
        Assertions.assertEquals("测试2", child.getName());
 
        service.deleteNode(HierarchyIds.SYSTEM, path);
        var node = service.node(HierarchyIds.SYSTEM, path, false);
        Assertions.assertNull(node);
    }
 
    @Test
    public void testFindAllPaths(){
        var paths0 = service.findAllPaths(HierarchyIds.SYSTEM, Arrays.asList("/2/1/2/1/0"));
        Assertions.assertFalse(paths0.isEmpty());
        var paths1 = service.findAllPaths(HierarchyIds.SYSTEM, Arrays.asList("/2/1/2/1"));
        Assertions.assertTrue(paths1.size() > paths0.size());
        var paths2 = service.findAllPaths(HierarchyIds.SYSTEM, Arrays.asList("/2"));
        Assertions.assertTrue(paths2.size() > paths1.size());
    }
 
}