17
17
import com .microsoft .azure .functions .worker .reflect .DefaultClassLoaderProvider ;
18
18
import org .junit .jupiter .api .Test ;
19
19
20
- import static org .junit .jupiter .api .Assertions .assertEquals ;
21
-
20
+ import static org .junit .jupiter .api .Assertions .*;
22
21
23
22
public class RpcHttpRequestDataSourceTest {
24
23
@@ -57,7 +56,7 @@ public static RpcHttp getTestRpcHttp(
57
56
}
58
57
59
58
@ Test
60
- public void rpcHttpDataSource_To_HttpRequestMessage_NullableQueryParamsEmpty_EnvSettingEnabled () throws Exception {
59
+ public void rpcHttpDataSourceToHttpRequestMessageEnvSettingEnabled () throws Exception {
61
60
DefaultClassLoaderProvider classLoader = new DefaultClassLoaderProvider ();
62
61
JavaFunctionBroker broker = new JavaFunctionBroker (classLoader );
63
62
FunctionEnvironmentReloadRequestHandler envHandler = new FunctionEnvironmentReloadRequestHandler (broker );
@@ -69,88 +68,29 @@ public void rpcHttpDataSource_To_HttpRequestMessage_NullableQueryParamsEmpty_Env
69
68
Method httpRequestMessageStringBodyMethod = getFunctionMethod ("HttpRequestStringBody" );
70
69
Map <String , String > queryMap = new HashMap <String , String >() {{
71
70
put ("name" , "" );
71
+ put ("count" , "1" );
72
72
}};
73
- Parameter [] parameters = httpRequestMessageStringBodyMethod .getParameters ();
74
- String sourceKey = "testRpcHttp" ;
75
- RpcHttp input = getTestRpcHttp (null , null , queryMap );
76
- RpcHttpRequestDataSource rpcHttp = new RpcHttpRequestDataSource (sourceKey , input );
77
- Optional <BindingData > actualBindingData = rpcHttp .computeByName (sourceKey ,
78
- parameters [0 ].getParameterizedType ());
79
- BindingData actualArg = actualBindingData .orElseThrow (WrongMethodTypeException ::new );
80
- HttpRequestMessage <?> requestMsg = (HttpRequestMessage <?>) actualArg .getValue ();
81
- assertEquals (requestMsg .getQueryParameters ().get ("name" ), "" );
82
- }
83
-
84
- @ Test
85
- public void rpcHttpDataSource_To_HttpRequestMessage_NullableQueryParamsEmpty_EnvSettingDisabled () throws Exception {
86
- DefaultClassLoaderProvider classLoader = new DefaultClassLoaderProvider ();
87
- JavaFunctionBroker broker = new JavaFunctionBroker (classLoader );
88
- FunctionEnvironmentReloadRequestHandler envHandler = new FunctionEnvironmentReloadRequestHandler (broker );
89
- Map <String , String > existingVariables = System .getenv ();
90
- Map <String , String > newEnvVariables = new HashMap <>();
91
- newEnvVariables .putAll (existingVariables );
92
- newEnvVariables .put ("FUNCTIONS_WORKER_NULLABLE_VALUES_ENABLED" , "false" );
93
- envHandler .setEnv (newEnvVariables );
94
- Method httpRequestMessageStringBodyMethod = getFunctionMethod ("HttpRequestStringBody" );
95
- Map <String , String > queryMap = new HashMap <String , String >() {{
96
- put ("name" , "" );
97
- }};
98
- Parameter [] parameters = httpRequestMessageStringBodyMethod .getParameters ();
99
- String sourceKey = "testRpcHttp" ;
100
- RpcHttp input = getTestRpcHttp (null , null , queryMap );
101
- RpcHttpRequestDataSource rpcHttp = new RpcHttpRequestDataSource (sourceKey , input );
102
- Optional <BindingData > actualBindingData = rpcHttp .computeByName (sourceKey ,
103
- parameters [0 ].getParameterizedType ());
104
- BindingData actualArg = actualBindingData .orElseThrow (WrongMethodTypeException ::new );
105
- HttpRequestMessage <?> requestMsg = (HttpRequestMessage <?>) actualArg .getValue ();
106
- assertEquals (requestMsg .getQueryParameters ().get ("name" ), null );
107
- }
108
-
109
- @ Test
110
- public void rpcHttpDataSource_To_HttpRequestMessage_NullableQueryParamsNonEmpty () throws Exception {
111
-
112
- Method httpRequestMessageStringBodyMethod = getFunctionMethod ("HttpRequestStringBody" );
113
- Map <String , String > queryMap = new HashMap <String , String >() {{
114
- put ("name" , "random" );
115
- }};
116
- Parameter [] parameters = httpRequestMessageStringBodyMethod .getParameters ();
117
- String sourceKey = "testRpcHttp" ;
118
- RpcHttp input = getTestRpcHttp (null , null , queryMap );
119
- RpcHttpRequestDataSource rpcHttp = new RpcHttpRequestDataSource (sourceKey , input );
120
- Optional <BindingData > actualBindingData = rpcHttp .computeByName (sourceKey ,
121
- parameters [0 ].getParameterizedType ());
122
- BindingData actualArg = actualBindingData .orElseThrow (WrongMethodTypeException ::new );
123
- HttpRequestMessage <?> requestMsg = (HttpRequestMessage <?>) actualArg .getValue ();
124
- assertEquals (requestMsg .getQueryParameters ().get ("name" ), "random" );
125
- }
126
-
127
- @ Test
128
- public void rpcHttpDataSource_To_HttpRequestMessage_NullableHeadersEmpty_EnvSettingEnabled () throws Exception {
129
- DefaultClassLoaderProvider classLoader = new DefaultClassLoaderProvider ();
130
- JavaFunctionBroker broker = new JavaFunctionBroker (classLoader );
131
- FunctionEnvironmentReloadRequestHandler envHandler = new FunctionEnvironmentReloadRequestHandler (broker );
132
- Map <String , String > existingVariables = System .getenv ();
133
- Map <String , String > newEnvVariables = new HashMap <>();
134
- newEnvVariables .putAll (existingVariables );
135
- newEnvVariables .put ("FUNCTIONS_WORKER_NULLABLE_VALUES_ENABLED" , "true" );
136
- envHandler .setEnv (newEnvVariables );
137
- Method httpRequestMessageStringBodyMethod = getFunctionMethod ("HttpRequestStringBody" );
138
73
Map <String , String > headersMap = new HashMap <String , String >() {{
139
74
put ("cookie" , "" );
75
+ put ("accept-encoding" , "gzip, deflate, br" );
140
76
}};
141
77
Parameter [] parameters = httpRequestMessageStringBodyMethod .getParameters ();
142
78
String sourceKey = "testRpcHttp" ;
143
- RpcHttp input = getTestRpcHttp (null , headersMap , null );
79
+ RpcHttp input = getTestRpcHttp (null , headersMap , queryMap );
144
80
RpcHttpRequestDataSource rpcHttp = new RpcHttpRequestDataSource (sourceKey , input );
145
81
Optional <BindingData > actualBindingData = rpcHttp .computeByName (sourceKey ,
146
82
parameters [0 ].getParameterizedType ());
147
83
BindingData actualArg = actualBindingData .orElseThrow (WrongMethodTypeException ::new );
148
84
HttpRequestMessage <?> requestMsg = (HttpRequestMessage <?>) actualArg .getValue ();
149
- assertEquals (requestMsg .getHeaders ().get ("cookie" ), "" );
85
+
86
+ assertTrue (requestMsg .getQueryParameters ().get ("name" ).isEmpty ());
87
+ assertEquals ("1" , requestMsg .getQueryParameters ().get ("count" ));
88
+ assertTrue (requestMsg .getHeaders ().get ("cookie" ).isEmpty ());
89
+ assertEquals ("gzip, deflate, br" , requestMsg .getHeaders ().get ("accept-encoding" ));
150
90
}
151
91
152
92
@ Test
153
- public void rpcHttpDataSource_To_HttpRequestMessage_NullableHeadersEmpty_EnvSettingDisabled () throws Exception {
93
+ public void rpcHttpDataSourceToHttpRequestMessageEnvSettingDisabled () throws Exception {
154
94
DefaultClassLoaderProvider classLoader = new DefaultClassLoaderProvider ();
155
95
JavaFunctionBroker broker = new JavaFunctionBroker (classLoader );
156
96
FunctionEnvironmentReloadRequestHandler envHandler = new FunctionEnvironmentReloadRequestHandler (broker );
@@ -160,40 +100,31 @@ public void rpcHttpDataSource_To_HttpRequestMessage_NullableHeadersEmpty_EnvSett
160
100
newEnvVariables .put ("FUNCTIONS_WORKER_NULLABLE_VALUES_ENABLED" , "false" );
161
101
envHandler .setEnv (newEnvVariables );
162
102
Method httpRequestMessageStringBodyMethod = getFunctionMethod ("HttpRequestStringBody" );
103
+ Map <String , String > queryMap = new HashMap <String , String >() {{
104
+ put ("name" , "" );
105
+ put ("count" , "1" );
106
+ }};
163
107
Map <String , String > headersMap = new HashMap <String , String >() {{
164
108
put ("cookie" , "" );
109
+ put ("accept-encoding" , "gzip, deflate, br" );
165
110
}};
166
111
Parameter [] parameters = httpRequestMessageStringBodyMethod .getParameters ();
167
112
String sourceKey = "testRpcHttp" ;
168
- RpcHttp input = getTestRpcHttp (null , headersMap , null );
113
+ RpcHttp input = getTestRpcHttp (null , headersMap , queryMap );
169
114
RpcHttpRequestDataSource rpcHttp = new RpcHttpRequestDataSource (sourceKey , input );
170
115
Optional <BindingData > actualBindingData = rpcHttp .computeByName (sourceKey ,
171
116
parameters [0 ].getParameterizedType ());
172
117
BindingData actualArg = actualBindingData .orElseThrow (WrongMethodTypeException ::new );
173
118
HttpRequestMessage <?> requestMsg = (HttpRequestMessage <?>) actualArg .getValue ();
174
- assertEquals (requestMsg .getHeaders ().get ("cookie" ), null );
175
- }
176
-
177
- @ Test
178
- public void rpcHttpDataSource_To_HttpRequestMessage_NullableHeadersNonEmpty () throws Exception {
179
119
180
- Method httpRequestMessageStringBodyMethod = getFunctionMethod ("HttpRequestStringBody" );
181
- Map <String , String > headersMap = new HashMap <String , String >() {{
182
- put ("cookie" , "foo=bar" );
183
- }};
184
- Parameter [] parameters = httpRequestMessageStringBodyMethod .getParameters ();
185
- String sourceKey = "testRpcHttp" ;
186
- RpcHttp input = getTestRpcHttp (null , headersMap , null );
187
- RpcHttpRequestDataSource rpcHttp = new RpcHttpRequestDataSource (sourceKey , input );
188
- Optional <BindingData > actualBindingData = rpcHttp .computeByName (sourceKey ,
189
- parameters [0 ].getParameterizedType ());
190
- BindingData actualArg = actualBindingData .orElseThrow (WrongMethodTypeException ::new );
191
- HttpRequestMessage <?> requestMsg = (HttpRequestMessage <?>) actualArg .getValue ();
192
- assertEquals (requestMsg .getHeaders ().get ("cookie" ), "foo=bar" );
120
+ assertNull (requestMsg .getQueryParameters ().get ("name" ));
121
+ assertEquals ("1" , requestMsg .getQueryParameters ().get ("count" ));
122
+ assertNull (requestMsg .getHeaders ().get ("cookie" ));
123
+ assertEquals ("gzip, deflate, br" , requestMsg .getHeaders ().get ("accept-encoding" ));
193
124
}
194
125
195
126
@ Test
196
- public void rpcHttpDataSource_To_HttpRequestMessage_StringBody () throws Exception {
127
+ public void rpcHttpDataSourceToHttpRequestMessageStringBody () throws Exception {
197
128
198
129
Method httpRequestMessageStringBodyMethod = getFunctionMethod ("HttpRequestStringBody" );
199
130
@@ -209,7 +140,7 @@ public void rpcHttpDataSource_To_HttpRequestMessage_StringBody() throws Exceptio
209
140
}
210
141
211
142
@ Test
212
- public void rpcHttpDataSource_To_HttpRequestMessage_IntegerBody () throws Exception {
143
+ public void rpcHttpDataSourceToHttpRequestMessageIntegerBody () throws Exception {
213
144
214
145
Method httpRequestMessageStringBodyMethod = getFunctionMethod ("HttpRequestIntBody" );
215
146
@@ -225,7 +156,7 @@ public void rpcHttpDataSource_To_HttpRequestMessage_IntegerBody() throws Excepti
225
156
}
226
157
227
158
@ Test
228
- public void rpcHttpDataSource_To_HttpRequestMessage_byteArrayBody () throws Exception {
159
+ public void rpcHttpDataSourceToHttpRequestMessageByteArrayBody () throws Exception {
229
160
230
161
Method httpRequestMessageStringBodyMethod = getFunctionMethod ("HttpRequestBinaryBody" );
231
162
0 commit comments