11/**
22 * Copyright (C) 2006-2026 Talend Inc. - www.talend.com
3- *
3+ * <p>
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
66 * You may obtain a copy of the License at
7- *
7+ * <p>
88 * http://www.apache.org/licenses/LICENSE-2.0
9- *
9+ * <p>
1010 * Unless required by applicable law or agreed to in writing, software
1111 * distributed under the License is distributed on an "AS IS" BASIS,
1212 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1919import static javax .ws .rs .core .MediaType .APPLICATION_JSON_TYPE ;
2020import static org .junit .jupiter .api .Assertions .assertEquals ;
2121import static org .junit .jupiter .api .Assertions .assertNotNull ;
22+ import static org .junit .jupiter .api .Assertions .assertNull ;
2223import static org .junit .jupiter .api .Assertions .assertTrue ;
2324import static org .talend .sdk .component .api .record .Schema .Type .LONG ;
2425import static org .talend .sdk .component .api .record .Schema .Type .RECORD ;
3940import javax .ws .rs .client .WebTarget ;
4041import javax .ws .rs .core .GenericType ;
4142import javax .ws .rs .core .Response ;
43+ import javax .ws .rs .core .Response .Status ;
4244
4345import org .apache .meecrowave .junit5 .MonoMeecrowaveConfig ;
4446import org .junit .jupiter .api .Disabled ;
@@ -182,7 +184,7 @@ void testDiscoverSchemaException(final HandleErrorWith origin) {
182184 .queryParam ("action" , "discoverSchemaException" + origin )
183185 .request (APPLICATION_JSON_TYPE )
184186 .post (Entity .entity (new HashMap <String , String >(), APPLICATION_JSON_TYPE ));
185- assertEquals (400 , error .getStatus ());
187+ assertEquals (Status . BAD_REQUEST . getStatusCode () , error .getStatus ());
186188 final ErrorPayload errorPayload = error .readEntity (ErrorPayload .class );
187189 assertEquals (ErrorDictionary .ACTION_ERROR , errorPayload .getCode ());
188190 assertEquals (origin .toString (), errorPayload .getSubCode ());
@@ -197,6 +199,68 @@ static Stream<Arguments> handleErrorWithSource() {
197199 Arguments .of (HandleErrorWith .EXECUTE_LIFECYCLE ));
198200 }
199201
202+ @ Test
203+ void emptyAction () {
204+ final Response error = base
205+ .path ("action/execute" )
206+ .queryParam ("type" , "user" )
207+ .queryParam ("family" , "custom" )
208+ .request (APPLICATION_JSON_TYPE )
209+ .post (Entity .entity (new HashMap <String , String >(), APPLICATION_JSON_TYPE ));
210+ assertEquals (Status .BAD_REQUEST .getStatusCode (), error .getStatus ());
211+ final ErrorPayload errorPayload = error .readEntity (ErrorPayload .class );
212+ assertEquals (ErrorDictionary .ACTION_MISSING , errorPayload .getCode ());
213+ assertNull (errorPayload .getSubCode ());
214+ assertEquals ("Action can't be null" , errorPayload .getDescription ());
215+ }
216+
217+ @ Test
218+ void emptyType () {
219+ final Response error = base
220+ .path ("action/execute" )
221+ .queryParam ("family" , "custom" )
222+ .queryParam ("action" , "backendException" )
223+ .request (APPLICATION_JSON_TYPE )
224+ .post (Entity .entity (new HashMap <String , String >(), APPLICATION_JSON_TYPE ));
225+ assertEquals (Status .BAD_REQUEST .getStatusCode (), error .getStatus ());
226+ final ErrorPayload errorPayload = error .readEntity (ErrorPayload .class );
227+ assertEquals (ErrorDictionary .TYPE_MISSING , errorPayload .getCode ());
228+ assertNull (errorPayload .getSubCode ());
229+ assertEquals ("Type can't be null" , errorPayload .getDescription ());
230+ }
231+
232+ @ Test
233+ void emptyFamily () {
234+ final Response error = base
235+ .path ("action/execute" )
236+ .queryParam ("type" , "user" )
237+ .queryParam ("action" , "backendException" )
238+ .request (APPLICATION_JSON_TYPE )
239+ .post (Entity .entity (new HashMap <String , String >(), APPLICATION_JSON_TYPE ));
240+ assertEquals (Status .BAD_REQUEST .getStatusCode (), error .getStatus ());
241+ final ErrorPayload errorPayload = error .readEntity (ErrorPayload .class );
242+ assertEquals (ErrorDictionary .FAMILY_MISSING , errorPayload .getCode ());
243+ assertNull (errorPayload .getSubCode ());
244+ assertEquals ("Family can't be null" , errorPayload .getDescription ());
245+ }
246+
247+
248+ @ Test
249+ void emptyActionMeta () {
250+ final String actionName = "notExistedAction" ;
251+ final Response error = base
252+ .path ("action/execute" )
253+ .queryParam ("type" , "user" )
254+ .queryParam ("family" , "custom" )
255+ .queryParam ("action" , actionName )
256+ .request (APPLICATION_JSON_TYPE )
257+ .post (Entity .entity (new HashMap <String , String >(), APPLICATION_JSON_TYPE ));
258+ assertEquals (Status .NOT_FOUND .getStatusCode (), error .getStatus ());
259+ final ErrorPayload errorPayload = error .readEntity (ErrorPayload .class );
260+ assertEquals (ErrorDictionary .ACTION_MISSING , errorPayload .getCode ());
261+ assertEquals ("No action with id '" + actionName + "'" , errorPayload .getDescription ());
262+ }
263+
200264 @ Test
201265 void executeWithEnumParam () {
202266 final Response error = base
@@ -228,37 +292,37 @@ void checkSchemaSerialization() {
228292 .post (Entity .entity (emptyMap (), APPLICATION_JSON_TYPE ), String .class );
229293 final String expected =
230294 """
231- {
232- "entries":[
233- {
234- "elementSchema":{
235- "entries":[
236- ],
237- "metadata":[
238- ],
239- "props":{
240-
241- },
242- "type":"STRING"
243- },
244- "errorCapable":false,
245- "metadata":false,
246- "name":"array",
247- "nullable":false,
248- "props":{
249-
250- },
251- "type":"ARRAY",
252- "valid":true
253- }
254- ],
255- "metadata":[
256- ],
257- "props":{
258- "talend.fields.order":"array"
259- },
260- "type":"RECORD"
261- }""" ;
295+ {
296+ "entries":[
297+ {
298+ "elementSchema":{
299+ "entries":[
300+ ],
301+ "metadata":[
302+ ],
303+ "props":{
304+
305+ },
306+ "type":"STRING"
307+ },
308+ "errorCapable":false,
309+ "metadata":false,
310+ "name":"array",
311+ "nullable":false,
312+ "props":{
313+
314+ },
315+ "type":"ARRAY",
316+ "valid":true
317+ }
318+ ],
319+ "metadata":[
320+ ],
321+ "props":{
322+ "talend.fields.order":"array"
323+ },
324+ "type":"RECORD"
325+ }""" ;
262326 assertEquals (expected , schema );
263327 }
264328
@@ -302,7 +366,7 @@ void checkDiscoverProcessorSchema() {
302366
303367 @ Disabled
304368 @ ParameterizedTest
305- @ ValueSource (strings = { "en" , "fr" })
369+ @ ValueSource (strings = {"en" , "fr" })
306370 void i18nParameterized (final String lang ) {
307371 final Response error = base
308372 .path ("action/execute" )
@@ -351,7 +415,7 @@ void checkLangIsAvailable() {
351415 }
352416
353417 private void assertAction (final String component , final String type , final String name , final int params ,
354- final ActionItem value ) {
418+ final ActionItem value ) {
355419 assertEquals (component , value .getComponent ());
356420 assertEquals (type , value .getType ());
357421 assertEquals (name , value .getName ());
0 commit comments