12
12
import com .microsoft .azure .functions .rpc .messages .RpcHttp ;
13
13
import com .microsoft .azure .functions .rpc .messages .TypedData ;
14
14
import com .microsoft .azure .functions .worker .binding .*;
15
+ import com .microsoft .azure .functions .worker .broker .JavaFunctionBroker ;
16
+ import com .microsoft .azure .functions .worker .handler .FunctionEnvironmentReloadRequestHandler ;
17
+ import com .microsoft .azure .functions .worker .reflect .DefaultClassLoaderProvider ;
15
18
import org .junit .jupiter .api .Test ;
16
19
17
20
import static org .junit .jupiter .api .Assertions .assertEquals ;
@@ -54,8 +57,15 @@ public static RpcHttp getTestRpcHttp(
54
57
}
55
58
56
59
@ Test
57
- public void rpcHttpDataSource_To_HttpRequestMessage_NullableQueryParamsEmpty () throws Exception {
58
-
60
+ public void rpcHttpDataSource_To_HttpRequestMessage_NullableQueryParamsEmpty_EnvSettingEnabled () throws Exception {
61
+ DefaultClassLoaderProvider classLoader = new DefaultClassLoaderProvider ();
62
+ JavaFunctionBroker broker = new JavaFunctionBroker (classLoader );
63
+ FunctionEnvironmentReloadRequestHandler envHandler = new FunctionEnvironmentReloadRequestHandler (broker );
64
+ Map <String , String > existingVariables = System .getenv ();
65
+ Map <String , String > newEnvVariables = new HashMap <>();
66
+ newEnvVariables .putAll (existingVariables );
67
+ newEnvVariables .put ("FUNCTIONS_WORKER_NULLABLE_VALUES_ENABLED" , "true" );
68
+ envHandler .setEnv (newEnvVariables );
59
69
Method httpRequestMessageStringBodyMethod = getFunctionMethod ("HttpRequestStringBody" );
60
70
Map <String , String > queryMap = new HashMap <String , String >() {{
61
71
put ("name" , "" );
@@ -71,6 +81,31 @@ public void rpcHttpDataSource_To_HttpRequestMessage_NullableQueryParamsEmpty() t
71
81
assertEquals (requestMsg .getQueryParameters ().get ("name" ), "" );
72
82
}
73
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
+
74
109
@ Test
75
110
public void rpcHttpDataSource_To_HttpRequestMessage_NullableQueryParamsNonEmpty () throws Exception {
76
111
@@ -90,8 +125,15 @@ public void rpcHttpDataSource_To_HttpRequestMessage_NullableQueryParamsNonEmpty(
90
125
}
91
126
92
127
@ Test
93
- public void rpcHttpDataSource_To_HttpRequestMessage_NullableHeadersEmpty () throws Exception {
94
-
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 );
95
137
Method httpRequestMessageStringBodyMethod = getFunctionMethod ("HttpRequestStringBody" );
96
138
Map <String , String > headersMap = new HashMap <String , String >() {{
97
139
put ("cookie" , "" );
@@ -107,6 +149,31 @@ public void rpcHttpDataSource_To_HttpRequestMessage_NullableHeadersEmpty() throw
107
149
assertEquals (requestMsg .getHeaders ().get ("cookie" ), "" );
108
150
}
109
151
152
+ @ Test
153
+ public void rpcHttpDataSource_To_HttpRequestMessage_NullableHeadersEmpty_EnvSettingDisabled () throws Exception {
154
+ DefaultClassLoaderProvider classLoader = new DefaultClassLoaderProvider ();
155
+ JavaFunctionBroker broker = new JavaFunctionBroker (classLoader );
156
+ FunctionEnvironmentReloadRequestHandler envHandler = new FunctionEnvironmentReloadRequestHandler (broker );
157
+ Map <String , String > existingVariables = System .getenv ();
158
+ Map <String , String > newEnvVariables = new HashMap <>();
159
+ newEnvVariables .putAll (existingVariables );
160
+ newEnvVariables .put ("FUNCTIONS_WORKER_NULLABLE_VALUES_ENABLED" , "false" );
161
+ envHandler .setEnv (newEnvVariables );
162
+ Method httpRequestMessageStringBodyMethod = getFunctionMethod ("HttpRequestStringBody" );
163
+ Map <String , String > headersMap = new HashMap <String , String >() {{
164
+ put ("cookie" , "" );
165
+ }};
166
+ Parameter [] parameters = httpRequestMessageStringBodyMethod .getParameters ();
167
+ String sourceKey = "testRpcHttp" ;
168
+ RpcHttp input = getTestRpcHttp (null , headersMap , null );
169
+ RpcHttpRequestDataSource rpcHttp = new RpcHttpRequestDataSource (sourceKey , input );
170
+ Optional <BindingData > actualBindingData = rpcHttp .computeByName (sourceKey ,
171
+ parameters [0 ].getParameterizedType ());
172
+ BindingData actualArg = actualBindingData .orElseThrow (WrongMethodTypeException ::new );
173
+ HttpRequestMessage <?> requestMsg = (HttpRequestMessage <?>) actualArg .getValue ();
174
+ assertEquals (requestMsg .getHeaders ().get ("cookie" ), null );
175
+ }
176
+
110
177
@ Test
111
178
public void rpcHttpDataSource_To_HttpRequestMessage_NullableHeadersNonEmpty () throws Exception {
112
179
0 commit comments