刘光辉
4 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
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
package jnpf.controller;
 
import jnpf.dmsEntity.storage.form.DmsApprovedRegistrationForm;
import jnpf.dmsEntity.download.form.DmsWorkflowDownloadAuthorizeForm;
import jnpf.dmsEntity.print.form.DmsWorkflowPrintAuthorizeForm;
import jnpf.dmsEntity.storage.form.DmsWorkflowFileActivateForm;
import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
 
import java.lang.reflect.Method;
import java.util.List;
 
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
 
public class DmsFileUploadControllerTest {
 
    @Test
    public void exposesWorkflowFileRegisterAsJsonDmsRoute() throws Exception {
        assertArrayEquals(new String[]{"/Dms"},
                DmsFileUploadController.class.getAnnotation(RequestMapping.class).value());
        Method method = DmsFileUploadController.class.getDeclaredMethod("workflowFileRegister",
                String.class, String.class, DmsApprovedRegistrationForm.class);
        PostMapping mapping = method.getAnnotation(PostMapping.class);
 
        assertArrayEquals(new String[]{"/workflowFileRegister"}, mapping.value());
        assertArrayEquals(new String[]{MediaType.APPLICATION_JSON_VALUE}, mapping.consumes());
        assertEquals(RequestBody.class,
                method.getParameters()[2].getAnnotation(RequestBody.class).annotationType());
        assertTrue(method.getGenericReturnType().getTypeName().contains(
                "ActionResult<jnpf.dmsEntity.storage.approval.DmsApprovedBatch>"));
    }
 
    @Test
    public void exposesWorkflowFileActivateAsJsonDmsRoute() throws Exception {
        Method method = DmsFileUploadController.class.getDeclaredMethod("workflowFileActivate",
                DmsWorkflowFileActivateForm.class);
        PostMapping mapping = method.getAnnotation(PostMapping.class);
 
        assertArrayEquals(new String[]{"/workflowFileActivate"}, mapping.value());
        assertArrayEquals(new String[]{MediaType.APPLICATION_JSON_VALUE}, mapping.consumes());
        assertEquals(RequestBody.class,
                method.getParameters()[0].getAnnotation(RequestBody.class).annotationType());
    }
 
    @Test
    public void exposesWorkflowDownloadAuthorizeAsJsonDmsRoute() throws Exception {
        Method method = DmsFileUploadController.class.getDeclaredMethod(
                "workflowFileDownloadAuthorize", String.class,
                DmsWorkflowDownloadAuthorizeForm.class);
        PostMapping mapping = method.getAnnotation(PostMapping.class);
 
        assertArrayEquals(new String[]{"/workflowFileDownloadAuthorize"}, mapping.value());
        assertArrayEquals(new String[]{MediaType.APPLICATION_JSON_VALUE}, mapping.consumes());
        assertEquals(RequestBody.class,
                method.getParameters()[1].getAnnotation(RequestBody.class).annotationType());
    }
 
    @Test
    public void exposesWorkflowPrintAuthorizeAsJsonDmsRoute() throws Exception {
        Method method = DmsFileUploadController.class.getDeclaredMethod(
                "workflowFilePrintAuthorize", String.class,
                DmsWorkflowPrintAuthorizeForm.class);
        PostMapping mapping = method.getAnnotation(PostMapping.class);
 
        assertArrayEquals(new String[]{"/workflowFilePrintAuthorize"}, mapping.value());
        assertArrayEquals(new String[]{MediaType.APPLICATION_JSON_VALUE}, mapping.consumes());
        assertEquals(RequestBody.class,
                method.getParameters()[1].getAnnotation(RequestBody.class).annotationType());
    }
}