Skip to content

Commit aebe1f5

Browse files
http-tasks: refactor tests, support for parallel tests (#1123)
Co-authored-by: Ivan Bodrov <[email protected]>
1 parent 9afe7cb commit aebe1f5

File tree

8 files changed

+708
-453
lines changed

8 files changed

+708
-453
lines changed

plugins/tasks/http/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@
7171
<artifactId>mockito-core</artifactId>
7272
<scope>test</scope>
7373
</dependency>
74+
<dependency>
75+
<groupId>org.mockito</groupId>
76+
<artifactId>mockito-junit-jupiter</artifactId>
77+
<scope>test</scope>
78+
</dependency>
7479
<dependency>
7580
<groupId>ch.qos.logback</groupId>
7681
<artifactId>logback-classic</artifactId>

plugins/tasks/http/src/main/java/com/walmartlabs/concord/plugins/http/HttpTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public String asString(String url) throws Exception {
7070
* @return Map
7171
* @throws Exception exception
7272
*/
73-
private Map<String, Object> executeRequest(Configuration config) throws Exception {
73+
Map<String, Object> executeRequest(Configuration config) throws Exception {
7474
log.info("Request method: {}", config.getMethodType());
7575

7676
Map<String, Object> response = SimpleHttpClient.create(config, false).execute().getResponse();

plugins/tasks/http/src/test/java/com/walmartlabs/concord/plugins/http/HttpTaskTest.java

Lines changed: 23 additions & 363 deletions
Large diffs are not rendered by default.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.walmartlabs.concord.plugins.http;
2+
3+
/*-
4+
* *****
5+
* Concord
6+
* -----
7+
* Copyright (C) 2017 - 2025 Walmart Inc.
8+
* -----
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* =====
21+
*/
22+
23+
import com.walmartlabs.concord.runtime.v2.sdk.Context;
24+
import com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables;
25+
import com.walmartlabs.concord.runtime.v2.sdk.TaskResult;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
28+
import org.junit.jupiter.api.extension.ExtendWith;
29+
import org.junit.jupiter.api.io.TempDir;
30+
import org.mockito.Answers;
31+
import org.mockito.Mock;
32+
import org.mockito.junit.jupiter.MockitoExtension;
33+
34+
import java.nio.file.Path;
35+
import java.util.HashMap;
36+
import java.util.Map;
37+
38+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
39+
import static org.junit.jupiter.api.Assertions.assertEquals;
40+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
41+
import static org.junit.jupiter.api.Assertions.assertTrue;
42+
import static org.mockito.Mockito.when;
43+
44+
@ExtendWith(MockitoExtension.class)
45+
class HttpTaskV2Test {
46+
47+
@TempDir
48+
Path tempDir;
49+
50+
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
51+
Context ctx;
52+
53+
HttpTaskV2 task;
54+
55+
@BeforeEach
56+
void setUp() {
57+
when(ctx.processConfiguration().dryRun()).thenReturn(true);
58+
when(ctx.workingDirectory()).thenReturn(tempDir);
59+
task = new HttpTaskV2(ctx);
60+
}
61+
62+
@Test
63+
void testExecute() {
64+
var input = defaultInput();
65+
66+
var result = execute(input);
67+
68+
assertTrue(result.ok());
69+
assertEquals(200, result.values().get("statusCode"));
70+
}
71+
72+
private static Map<String, Object> defaultInput() {
73+
Map<String, Object> defaultInput = new HashMap<>();
74+
defaultInput.put("url", "https://mock.local");
75+
defaultInput.put("method", "POST");
76+
defaultInput.put("request", "json");
77+
defaultInput.put("body", "{}");
78+
79+
return defaultInput;
80+
}
81+
82+
private TaskResult.SimpleResult execute(Map<String, Object> input) {
83+
var result = assertDoesNotThrow(() -> task.execute(new MapBackedVariables(input)));
84+
return assertInstanceOf(TaskResult.SimpleResult.class, result);
85+
}
86+
}

0 commit comments

Comments
 (0)