13
13
14
14
package com .amazon .ask .servlet ;
15
15
16
- import static com .amazon .ask .util .SdkConstants .FORMAT_VERSION ;
17
- import static org .mockito .Mockito .when ;
18
-
19
- import java .io .ByteArrayInputStream ;
20
- import java .io .ByteArrayOutputStream ;
21
- import java .io .IOException ;
22
- import java .io .InputStream ;
23
- import java .io .OutputStream ;
24
-
25
- import javax .servlet .ServletInputStream ;
26
- import javax .servlet .ServletOutputStream ;
27
- import javax .servlet .http .HttpServletRequest ;
28
- import javax .servlet .http .HttpServletResponse ;
29
-
30
- import com .amazon .ask .model .Application ;
31
- import com .amazon .ask .model .Request ;
32
- import com .amazon .ask .model .RequestEnvelope ;
33
- import com .amazon .ask .model .Session ;
34
- import com .amazon .ask .model .User ;
16
+ import com .amazon .ask .model .*;
17
+ import com .fasterxml .jackson .annotation .JsonInclude ;
18
+ import com .fasterxml .jackson .databind .ObjectMapper ;
35
19
import com .fasterxml .jackson .databind .SerializationFeature ;
36
20
import com .fasterxml .jackson .datatype .jsr310 .JavaTimeModule ;
21
+ import jakarta .servlet .ServletInputStream ;
22
+ import jakarta .servlet .ServletOutputStream ;
23
+ import jakarta .servlet .http .HttpServletRequest ;
24
+ import jakarta .servlet .http .HttpServletResponse ;
37
25
import org .mockito .Mockito ;
38
26
39
- import com .fasterxml .jackson .annotation .JsonInclude ;
40
- import com .fasterxml .jackson .databind .ObjectMapper ;
27
+ import java .io .*;
28
+
29
+ import static com .amazon .ask .util .SdkConstants .FORMAT_VERSION ;
30
+ import static org .mockito .Mockito .when ;
41
31
42
32
public class SkillServletTestBase {
43
33
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper ();
34
+
44
35
static {
45
36
OBJECT_MAPPER .registerModule (new JavaTimeModule ());
46
37
OBJECT_MAPPER .disable (SerializationFeature .WRITE_DATES_AS_TIMESTAMPS );
47
38
OBJECT_MAPPER .setSerializationInclusion (JsonInclude .Include .NON_NULL );
48
39
}
49
40
50
- /**
51
- * Tuple for useful parameters for a servlet invocation.
52
- */
53
- protected static final class ServletInvocationParameters {
54
- public final HttpServletRequest request ;
55
- public final HttpServletResponse response ;
56
- public final ByteArrayOutputStream output ;
57
-
58
- public ServletInvocationParameters (final HttpServletRequest request ,
59
- final HttpServletResponse response , final ByteArrayOutputStream output ) {
60
- this .request = request ;
61
- this .response = response ;
62
- this .output = output ;
63
- }
64
- }
65
-
66
- /**
67
- * Trivial implementation of the ServletInputStream that wraps an InputStream.
68
- */
69
- private static class MyServletInputStream extends ServletInputStream {
70
- private final InputStream in ;
71
-
72
- public MyServletInputStream (final InputStream in ) {
73
- this .in = in ;
74
- }
75
-
76
- @ Override
77
- public int read () throws IOException {
78
- return in .read ();
79
- }
80
- }
81
-
82
- /**
83
- * Trivial implementation of the ServletOutputStream that wraps an OutputStream.
84
- */
85
- private static class MyServletOutputStream extends ServletOutputStream {
86
- private final OutputStream out ;
87
-
88
- public MyServletOutputStream (final OutputStream out ) {
89
- this .out = out ;
90
- }
91
-
92
- @ Override
93
- public void write (int b ) throws IOException {
94
- out .write (b );
95
- }
96
- }
97
-
98
- // ------------------------------
99
- // Helper methods for subclasses
100
-
101
41
/**
102
42
* Common logic for all the tests.
103
43
*
104
- * @param version
105
- * the envelope version for the request envelope
106
- * @param request
107
- * a SkillRequest
108
- * @param session
109
- * a session for this invocation
44
+ * @param version the envelope version for the request envelope
45
+ * @param request a SkillRequest
46
+ * @param session a session for this invocation
110
47
* @return invocation parameters for a Skill
111
- *
112
48
* @throws IOException
113
49
*/
114
50
protected ServletInvocationParameters build (final String version , final Request request , final Session session ) throws IOException {
@@ -143,12 +79,9 @@ protected ServletInvocationParameters build(final String version, final Request
143
79
* <li>The current SDK version as a version</li>
144
80
* </ul>
145
81
*
146
- * @param request
147
- * a SkillRequest or OnSessionEndedRequest
148
- * @param session
149
- * a session for this invocation
82
+ * @param request a SkillRequest or OnSessionEndedRequest
83
+ * @param session a session for this invocation
150
84
* @return invocation parameters for a Skill
151
- *
152
85
* @throws IOException
153
86
*/
154
87
protected ServletInvocationParameters build (final Request request ,
@@ -159,17 +92,18 @@ protected ServletInvocationParameters build(final Request request,
159
92
/**
160
93
* Same as above using a simple Session and User.
161
94
*
162
- * @param request
163
- * a skill request
95
+ * @param request a skill request
164
96
* @return invocation parameters for a Skill
165
- *
166
97
* @throws IOException
167
98
*/
168
99
protected ServletInvocationParameters build (final Request request )
169
100
throws IOException {
170
101
return build (request , buildSession ());
171
102
}
172
103
104
+ // ------------------------------
105
+ // Helper methods for subclasses
106
+
173
107
/**
174
108
* @return a test session.
175
109
*/
@@ -186,4 +120,52 @@ protected Session buildSession(String applicationId) {
186
120
.build ();
187
121
}
188
122
123
+ /**
124
+ * Tuple for useful parameters for a servlet invocation.
125
+ */
126
+ protected static final class ServletInvocationParameters {
127
+ public final HttpServletRequest request ;
128
+ public final HttpServletResponse response ;
129
+ public final ByteArrayOutputStream output ;
130
+
131
+ public ServletInvocationParameters (final HttpServletRequest request ,
132
+ final HttpServletResponse response , final ByteArrayOutputStream output ) {
133
+ this .request = request ;
134
+ this .response = response ;
135
+ this .output = output ;
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Trivial implementation of the ServletInputStream that wraps an InputStream.
141
+ */
142
+ private static class MyServletInputStream extends ServletInputStream {
143
+ private final InputStream in ;
144
+
145
+ public MyServletInputStream (final InputStream in ) {
146
+ this .in = in ;
147
+ }
148
+
149
+ @ Override
150
+ public int read () throws IOException {
151
+ return in .read ();
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Trivial implementation of the ServletOutputStream that wraps an OutputStream.
157
+ */
158
+ private static class MyServletOutputStream extends ServletOutputStream {
159
+ private final OutputStream out ;
160
+
161
+ public MyServletOutputStream (final OutputStream out ) {
162
+ this .out = out ;
163
+ }
164
+
165
+ @ Override
166
+ public void write (int b ) throws IOException {
167
+ out .write (b );
168
+ }
169
+ }
170
+
189
171
}
0 commit comments