1
2
3
4
5
6
7
8
9
10
11 package psiprobe;
12
13 import jakarta.servlet.ServletException;
14 import jakarta.servlet.http.HttpServletRequest;
15 import jakarta.servlet.http.HttpSession;
16
17 import java.io.IOException;
18
19 import org.apache.catalina.Valve;
20 import org.apache.catalina.connector.Request;
21 import org.apache.catalina.connector.Response;
22 import org.junit.jupiter.api.Test;
23 import org.junit.jupiter.api.extension.ExtendWith;
24 import org.mockito.Mock;
25 import org.mockito.Mockito;
26 import org.mockito.junit.jupiter.MockitoExtension;
27
28
29
30
31 @ExtendWith(MockitoExtension.class)
32 class Tomcat10AgentValveTest {
33
34
35 Tomcat10AgentValve valve;
36
37
38 @Mock
39 Request request;
40
41
42 @Mock
43 Response response;
44
45
46 @Mock
47 HttpSession session;
48
49
50 @Mock
51 HttpServletRequest servletRequest;
52
53
54 @Mock
55 Valve valveMock;
56
57
58
59
60
61
62
63 @Test
64 void invoke() throws IOException, ServletException {
65 Mockito.when(request.getSession(Mockito.anyBoolean())).thenReturn(session);
66 Mockito.when(request.getRequest()).thenReturn(servletRequest);
67
68 valve = new Tomcat10AgentValve();
69 valve.setNext(valveMock);
70 valve.invoke(request, response);
71 Mockito.verify(session, Mockito.times(2)).setAttribute(Mockito.anyString(), Mockito.any());
72 }
73
74 }