Skip to content

Commit a6666d2

Browse files
feat(QTDI-1291): tests
1 parent e8bc2fb commit a6666d2

2 files changed

Lines changed: 70 additions & 43 deletions

File tree

component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/front/ActionResourceImplTest.java

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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.
@@ -30,6 +30,7 @@
3030
import java.util.Iterator;
3131
import java.util.List;
3232
import java.util.Map;
33+
import java.util.stream.Stream;
3334

3435
import javax.inject.Inject;
3536
import javax.json.JsonObject;
@@ -44,7 +45,11 @@
4445
import org.junit.jupiter.api.RepeatedTest;
4546
import org.junit.jupiter.api.Test;
4647
import org.junit.jupiter.params.ParameterizedTest;
48+
import org.junit.jupiter.params.provider.Arguments;
49+
import org.junit.jupiter.params.provider.MethodSource;
4750
import org.junit.jupiter.params.provider.ValueSource;
51+
import org.talend.sdk.component.api.exception.ComponentException.ErrorOrigin;
52+
import org.talend.sdk.component.api.exception.DiscoverSchemaException.HandleErrorWith;
4853
import org.talend.sdk.component.api.record.Schema;
4954
import org.talend.sdk.component.api.service.healthcheck.HealthCheckStatus;
5055
import org.talend.sdk.component.api.service.record.RecordBuilderFactory;
@@ -60,7 +65,8 @@ class ActionResourceImplTest {
6065
@Inject
6166
private WebTarget base;
6267

63-
@RepeatedTest(2) // this also checks the cache and queries usage
68+
@RepeatedTest(2)
69+
// this also checks the cache and queries usage
6470
void actionIndex() {
6571
{ // default
6672
final ActionList index = base.path("action/index").request(APPLICATION_JSON_TYPE).get(ActionList.class);
@@ -165,23 +171,32 @@ void testBackendException() {
165171
assertEquals("Action execution failed with: backend exception", errorPayload.getDescription());
166172
}
167173

168-
@Test
169-
void testDiscoverSchemaException() {
174+
@MethodSource("handleErrorWithSource")
175+
@ParameterizedTest
176+
void testDiscoverSchemaException(final HandleErrorWith origin) {
170177
final Response error = base
171178
.path("action/execute")
172179
.queryParam("type", "user")
173180
.queryParam("family", "custom")
174-
.queryParam("action", "discoverSchemaException")
181+
.queryParam("action", "discoverSchemaException" + origin)
175182
.request(APPLICATION_JSON_TYPE)
176183
.post(Entity.entity(new HashMap<String, String>(), APPLICATION_JSON_TYPE));
177184
assertEquals(400, error.getStatus());
178185
final ErrorPayload errorPayload = error.readEntity(ErrorPayload.class);
179186
assertEquals(ErrorDictionary.ACTION_ERROR, errorPayload.getCode());
180-
assertEquals("RETRY", errorPayload.getSubCode());
187+
assertEquals(origin.toString(), errorPayload.getSubCode());
181188
assertNotNull(errorPayload.getDescription());
182189
assertTrue(errorPayload.getDescription().startsWith("Action execution failed with:"));
183190
}
184191

192+
static Stream<Arguments> handleErrorWithSource() {
193+
return Stream.of(
194+
Arguments.of(HandleErrorWith.RETRY),
195+
Arguments.of(HandleErrorWith.EXECUTE_MOCK_JOB),
196+
Arguments.of(HandleErrorWith.EXECUTE_LIFECYCLE)
197+
);
198+
}
199+
185200
@Test
186201
void executeWithEnumParam() {
187202
final Response error = base
@@ -213,37 +228,37 @@ void checkSchemaSerialization() {
213228
.post(Entity.entity(emptyMap(), APPLICATION_JSON_TYPE), String.class);
214229
final String expected =
215230
"""
216-
{
217-
"entries":[
218-
{
219-
"elementSchema":{
220-
"entries":[
221-
],
222-
"metadata":[
223-
],
224-
"props":{
225-
226-
},
227-
"type":"STRING"
228-
},
229-
"errorCapable":false,
230-
"metadata":false,
231-
"name":"array",
232-
"nullable":false,
233-
"props":{
234-
235-
},
236-
"type":"ARRAY",
237-
"valid":true
238-
}
239-
],
240-
"metadata":[
241-
],
242-
"props":{
243-
"talend.fields.order":"array"
244-
},
245-
"type":"RECORD"
246-
}""";
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+
}""";
247262
assertEquals(expected, schema);
248263
}
249264

@@ -287,7 +302,7 @@ void checkDiscoverProcessorSchema() {
287302

288303
@Disabled
289304
@ParameterizedTest
290-
@ValueSource(strings = { "en", "fr" })
305+
@ValueSource(strings = {"en", "fr"})
291306
void i18nParameterized(final String lang) {
292307
final Response error = base
293308
.path("action/execute")
@@ -336,7 +351,7 @@ void checkLangIsAvailable() {
336351
}
337352

338353
private void assertAction(final String component, final String type, final String name, final int params,
339-
final ActionItem value) {
354+
final ActionItem value) {
340355
assertEquals(component, value.getComponent());
341356
assertEquals(type, value.getType());
342357
assertEquals(name, value.getName());

component-server-parent/component-server/src/test/java/org/talend/sdk/component/server/test/custom/CustomService.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,21 @@ public Map<String, String> generateBackendException(final LocalConfiguration con
7474
throw new ComponentException(ErrorOrigin.BACKEND, "backend exception");
7575
}
7676

77-
@Action("discoverSchemaException")
78-
public Map<String, String> generateDiscoverSchemaException(final LocalConfiguration configuration) {
77+
@Action("discoverSchemaExceptionRETRY")
78+
public Map<String, String> generateDiscoverSchemaExceptionRetry(final LocalConfiguration configuration) {
7979
throw new DiscoverSchemaException(
8080
new ComponentException(ErrorOrigin.USER, "schema not found"), HandleErrorWith.RETRY);
8181
}
82+
83+
@Action("discoverSchemaExceptionEXECUTE_MOCK_JOB")
84+
public Map<String, String> generateDiscoverSchemaExceptionMock(final LocalConfiguration configuration) {
85+
throw new DiscoverSchemaException(
86+
new ComponentException(ErrorOrigin.USER, "schema not found"), HandleErrorWith.EXECUTE_MOCK_JOB);
87+
}
88+
89+
@Action("discoverSchemaExceptionEXECUTE_LIFECYCLE")
90+
public Map<String, String> generateDiscoverSchemaExceptionLifecycle(final LocalConfiguration configuration) {
91+
throw new DiscoverSchemaException(
92+
new ComponentException(ErrorOrigin.USER, "schema not found"), HandleErrorWith.EXECUTE_LIFECYCLE);
93+
}
8294
}

0 commit comments

Comments
 (0)