yeg
2026-09-29 b78295e8da96c3e5e76befeef9582ce5273dbb74
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
package com.battery.business.web;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.lang.reflect.Method;
import org.junit.jupiter.api.Test;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.security.access.prepost.PreAuthorize;
import com.battery.business.test.dto.TestConfigurationDto;
 
class TTestControllerContractTest
{
    @Test
    void configurationEndpointsKeepServerSidePermissions() throws Exception
    {
        assertPermission("options", "@ss.hasAnyPermi('system:test:add,system:test:edit')");
        assertPermission("getInfo", "@ss.hasPermi('system:test:query')", Long.class);
        assertPermission("add", "@ss.hasPermi('system:test:add')", TestConfigurationDto.class);
        assertPermission("edit", "@ss.hasPermi('system:test:edit')", TestConfigurationDto.class);
        assertPermission("startReception", "@ss.hasPermi('system:test:start')", Long.class);
        Method startReception = TTestController.class.getMethod("startReception", Long.class);
        assertEquals("/{testId}/reception/start", startReception.getAnnotation(PostMapping.class).value()[0]);
        assertPermission("pauseReception", "@ss.hasPermi('system:test:pause')", Long.class);
        assertEquals("/{testId}/reception/pause", TTestController.class.getMethod("pauseReception", Long.class)
                .getAnnotation(PostMapping.class).value()[0]);
        assertPermission("resumeReception", "@ss.hasPermi('system:test:resume')", Long.class);
        assertEquals("/{testId}/reception/resume", TTestController.class.getMethod("resumeReception", Long.class)
                .getAnnotation(PostMapping.class).value()[0]);
        assertPermission("stopTest", "@ss.hasPermi('system:test:stop')", Long.class);
        assertEquals("/{testId}/stop", TTestController.class.getMethod("stopTest", Long.class)
                .getAnnotation(PostMapping.class).value()[0]);
        assertPermission("endReception", "@ss.hasPermi('system:test:stop')", Long.class);
        assertEquals("/{testId}/reception/end", TTestController.class.getMethod("endReception", Long.class)
                .getAnnotation(PostMapping.class).value()[0]);
        assertPermission("persistedRecords", "@ss.hasPermi('system:test:query')", Long.class);
        assertEquals("/{testId}/data/records", TTestController.class.getMethod("persistedRecords", Long.class)
                .getAnnotation(org.springframework.web.bind.annotation.GetMapping.class).value()[0]);
        assertPermission("persistedSteps", "@ss.hasPermi('system:test:query')", Long.class);
        assertEquals("/{testId}/data/steps", TTestController.class.getMethod("persistedSteps", Long.class)
                .getAnnotation(org.springframework.web.bind.annotation.GetMapping.class).value()[0]);
        assertPermission("persistedCycles", "@ss.hasPermi('system:test:query')", Long.class);
        assertEquals("/{testId}/data/cycles", TTestController.class.getMethod("persistedCycles", Long.class)
                .getAnnotation(org.springframework.web.bind.annotation.GetMapping.class).value()[0]);
        assertPermission("saveConsoleDetail", "@ss.hasPermi('system:test:edit')", Long.class,
                com.battery.business.domain.TTestConsoleDetail.class);
        assertEquals("/{testId}/console-detail", TTestController.class.getMethod("saveConsoleDetail", Long.class,
                com.battery.business.domain.TTestConsoleDetail.class).getAnnotation(PutMapping.class).value()[0]);
    }
 
    private void assertPermission(String methodName, String permission, Class<?>... parameterTypes) throws Exception
    {
        Method method = TTestController.class.getMethod(methodName, parameterTypes);
        assertEquals(permission, method.getAnnotation(PreAuthorize.class).value());
    }
}