2020 */
2121package eu .openanalytics .containerproxy .test .unit ;
2222
23+ import com .fasterxml .jackson .databind .ObjectMapper ;
2324import eu .openanalytics .containerproxy .ContainerProxyApplication ;
2425import eu .openanalytics .containerproxy .auth .IAuthenticationBackend ;
2526import eu .openanalytics .containerproxy .model .runtime .AllowedParametersForUser ;
3435import eu .openanalytics .containerproxy .spec .expression .SpecExpressionResolver ;
3536import eu .openanalytics .containerproxy .test .proxy .PropertyOverrideContextInitializer ;
3637import eu .openanalytics .containerproxy .test .proxy .TestIntegrationOnKube ;
37- import org .apache .commons .lang3 .tuple .Pair ;
3838import org .junit .jupiter .api .Assertions ;
3939import org .junit .jupiter .api .Test ;
4040import org .springframework .boot .test .context .SpringBootTest ;
5050import java .util .Collection ;
5151import java .util .Collections ;
5252import java .util .HashMap ;
53+ import java .util .Map ;
5354
5455import static org .mockito .Mockito .mock ;
5556import static org .mockito .Mockito .when ;
@@ -65,6 +66,9 @@ public class TestParameterServiceAccessControl {
6566 @ Inject
6667 private IProxySpecProvider proxySpecProvider ;
6768
69+ @ Inject
70+ private ObjectMapper objectMapper ;
71+
6872 @ Inject
6973 private ProxyService proxyService ;
7074 private UserService userService ;
@@ -76,7 +80,7 @@ public void init() {
7680 SpecExpressionResolver specExpressionResolver = new SpecExpressionResolver (new GenericApplicationContext ());
7781 AccessControlEvaluationService accessControlEvaluationService = new AccessControlEvaluationService (authBackend , userService , specExpressionResolver );
7882
79- parametersService = new ParametersService (proxySpecProvider , accessControlEvaluationService );
83+ parametersService = new ParametersService (proxySpecProvider , accessControlEvaluationService , objectMapper );
8084 }
8185
8286 @ Test
@@ -117,31 +121,31 @@ public void testWithAccessControl() throws InvalidParametersException {
117121 Assertions .assertFalse (allowedParametersForUser .getAllowedCombinations ().contains (Arrays .asList (1 , 1 , 4 )));
118122
119123 // try to "start" the app with correct parameters
120- ProvidedParameters providedParameters = new ProvidedParameters ( new HashMap <String , String >() {{
124+ Map < String , String > providedParameters = new HashMap <String , String >() {{
121125 put ("environment" , "base_r" );
122126 put ("version" , "4.0.5" );
123127 put ("memory" , "8G" );
124- }}) ;
128+ }};
125129
126130 Assertions .assertTrue (parametersService .parseAndValidateRequest (auth , spec , providedParameters ).isPresent ());
127131
128132 // try to "start" the app with not-allowed parameters
129- ProvidedParameters providedParameters2 = new ProvidedParameters ( new HashMap <String , String >() {{
133+ Map < String , String > providedParameters2 = new HashMap <String , String >() {{
130134 put ("environment" , "breeding_r" );
131135 put ("version" , "4.0.3" );
132136 put ("memory" , "5G" );
133- }}) ;
137+ }};
134138
135139 Assertions .assertThrows (InvalidParametersException .class ,
136140 () -> parametersService .parseAndValidateRequest (auth , spec , providedParameters2 ),
137141 "Provided parameter values are not allowed" );
138142
139143 // try to "start" the app with not-allowed parameters
140- ProvidedParameters providedParameters3 = new ProvidedParameters ( new HashMap <String , String >() {{
144+ Map < String , String > providedParameters3 = new HashMap <String , String >() {{
141145 put ("environment" , "biogrid_r" );
142146 put ("version" , "4.0.3" );
143147 put ("memory" , "25G" );
144- }}) ;
148+ }};
145149
146150 Assertions .assertThrows (InvalidParametersException .class ,
147151 () -> parametersService .parseAndValidateRequest (auth , spec , providedParameters3 ),
@@ -189,20 +193,20 @@ public void testWithAccessControlWithGroupMembership() throws InvalidParametersE
189193 Assertions .assertFalse (allowedParametersForUser .getAllowedCombinations ().contains (Arrays .asList (4 , 1 , 1 )));
190194
191195 // try to "start" the app with correct parameters
192- ProvidedParameters providedParameters = new ProvidedParameters ( new HashMap <String , String >() {{
196+ Map < String , String > providedParameters = new HashMap <String , String >() {{
193197 put ("environment" , "breeding_r" );
194198 put ("version" , "4.0.3" );
195199 put ("memory" , "5G" );
196- }}) ;
200+ }};
197201
198202 Assertions .assertTrue (parametersService .parseAndValidateRequest (auth , spec , providedParameters ).isPresent ());
199203
200204 // try to "start" the app with not-allowed parameters
201- ProvidedParameters providedParameters3 = new ProvidedParameters ( new HashMap <String , String >() {{
205+ Map < String , String > providedParameters3 = new HashMap <String , String >() {{
202206 put ("environment" , "biogrid_r" );
203207 put ("version" , "4.0.3" );
204208 put ("memory" , "25G" );
205- }}) ;
209+ }};
206210
207211 Assertions .assertThrows (InvalidParametersException .class ,
208212 () -> parametersService .parseAndValidateRequest (auth , spec , providedParameters3 ),
@@ -249,31 +253,31 @@ public void testWithAccessControlWithAccessExpression() throws InvalidParameters
249253 Assertions .assertFalse (allowedParametersForUser .getAllowedCombinations ().contains (Arrays .asList (4 , 1 , 1 )));
250254
251255 // try to "start" the app with correct parameters
252- ProvidedParameters providedParameters = new ProvidedParameters ( new HashMap <String , String >() {{
256+ Map < String , String > providedParameters = new HashMap <String , String >() {{
253257 put ("environment" , "biogrid_r" );
254258 put ("version" , "4.1.13" );
255259 put ("memory" , "8G" );
256- }}) ;
260+ }};
257261
258262 Assertions .assertTrue (parametersService .parseAndValidateRequest (auth , spec , providedParameters ).isPresent ());
259263
260264 // try to "start" the app with not-allowed parameters
261- ProvidedParameters providedParameters2 = new ProvidedParameters ( new HashMap <String , String >() {{
265+ Map < String , String > providedParameters2 = new HashMap <String , String >() {{
262266 put ("environment" , "breeding_r" );
263267 put ("version" , "4.0.3" );
264268 put ("memory" , "5G" );
265- }}) ;
269+ }};
266270
267271 Assertions .assertThrows (InvalidParametersException .class ,
268272 () -> parametersService .parseAndValidateRequest (auth , spec , providedParameters2 ),
269273 "Provided parameter values are not allowed" );
270274
271275 // try to "start" the app with not-allowed parameters
272- ProvidedParameters providedParameters3 = new ProvidedParameters ( new HashMap <String , String >() {{
276+ Map < String , String > providedParameters3 = new HashMap <String , String >() {{
273277 put ("environment" , "biogrid_r" );
274278 put ("version" , "4.0.3" );
275279 put ("memory" , "25G" );
276- }}) ;
280+ }};
277281
278282 Assertions .assertThrows (InvalidParametersException .class ,
279283 () -> parametersService .parseAndValidateRequest (auth , spec , providedParameters3 ),
@@ -320,31 +324,31 @@ public void testWithAccessControlWithAccessUsers() throws InvalidParametersExcep
320324 Assertions .assertFalse (allowedParametersForUser .getAllowedCombinations ().contains (Arrays .asList (1 , 1 , 4 )));
321325
322326 // try to "start" the app with correct parameters
323- ProvidedParameters providedParameters = new ProvidedParameters ( new HashMap <String , String >() {{
327+ Map < String , String > providedParameters = new HashMap <String , String >() {{
324328 put ("environment" , "biogrid_r" );
325329 put ("version" , "4.0.3" );
326330 put ("memory" , "25G" );
327- }}) ;
331+ }};
328332
329333 Assertions .assertTrue (parametersService .parseAndValidateRequest (auth , spec , providedParameters ).isPresent ());
330334
331335 // try to "start" the app with not-allowed parameters
332- ProvidedParameters providedParameters2 = new ProvidedParameters ( new HashMap <String , String >() {{
336+ Map < String , String > providedParameters2 = new HashMap <String , String >() {{
333337 put ("environment" , "breeding_r" );
334338 put ("version" , "4.0.3" );
335339 put ("memory" , "5G" );
336- }}) ;
340+ }};
337341
338342 Assertions .assertThrows (InvalidParametersException .class ,
339343 () -> parametersService .parseAndValidateRequest (auth , spec , providedParameters2 ),
340344 "Provided parameter values are not allowed" );
341345
342346 // try to "start" the app with not-allowed parameters
343- ProvidedParameters providedParameters3 = new ProvidedParameters ( new HashMap <String , String >() {{
347+ Map < String , String > providedParameters3 = new HashMap <String , String >() {{
344348 put ("environment" , "biogrid_r" );
345349 put ("version" , "4.1.13" );
346350 put ("memory" , "8G" );
347- }}) ;
351+ }};
348352
349353 Assertions .assertThrows (InvalidParametersException .class ,
350354 () -> parametersService .parseAndValidateRequest (auth , spec , providedParameters3 ),
0 commit comments