|
| 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