Skip to content

Commit b2bfccf

Browse files
committed
3182 - update tests
1 parent 0913ee6 commit b2bfccf

File tree

2 files changed

+433
-0
lines changed

2 files changed

+433
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.component.jira.action;
18+
19+
import com.bytechef.component.definition.ActionContext;
20+
import com.bytechef.component.definition.Context;
21+
import com.bytechef.component.definition.Context.ContextFunction;
22+
import com.bytechef.component.definition.Context.Http;
23+
import com.bytechef.component.definition.Context.Http.Configuration.ConfigurationBuilder;
24+
import com.bytechef.component.definition.Parameters;
25+
import com.bytechef.component.definition.TypeReference;
26+
import com.bytechef.component.test.definition.MockParametersFactory;
27+
import org.junit.jupiter.api.Test;
28+
import org.mockito.ArgumentCaptor;
29+
30+
import java.util.Map;
31+
32+
import static com.bytechef.component.jira.constant.JiraConstants.ISSUE_ID;
33+
import static com.bytechef.component.jira.constant.JiraConstants.MAX_RESULTS;
34+
import static com.bytechef.component.jira.constant.JiraConstants.ORDER_BY;
35+
import static org.junit.jupiter.api.Assertions.assertEquals;
36+
import static org.junit.jupiter.api.Assertions.assertNotNull;
37+
import static org.mockito.ArgumentCaptor.forClass;
38+
import static org.mockito.ArgumentMatchers.any;
39+
import static org.mockito.Mockito.mock;
40+
import static org.mockito.Mockito.when;
41+
42+
/**
43+
* @author Ivona Pavela
44+
*/
45+
class JiraListIssueCommentsActionTest {
46+
47+
private final ArgumentCaptor<ConfigurationBuilder> configurationBuilderArgumentCaptor =
48+
forClass(ConfigurationBuilder.class);
49+
@SuppressWarnings("unchecked")
50+
private final ArgumentCaptor<ContextFunction<Http, Http.Executor>> httpFunctionArgumentCaptor =
51+
forClass(ContextFunction.class);
52+
private final ActionContext mockedActionContext = mock(ActionContext.class);
53+
private final Http.Executor mockedExecutor = mock(Http.Executor.class);
54+
private final Http mockedHttp = mock(Http.class);
55+
private final Parameters mockedParameters = MockParametersFactory.create(
56+
Map.of(
57+
ISSUE_ID, "xy",
58+
ORDER_BY, "+created",
59+
MAX_RESULTS, 50));
60+
private final Http.Response mockedResponse = mock(Http.Response.class);
61+
private final Map<String, Object> responseMap = Map.of("comments", "example");
62+
private final ArgumentCaptor<String> stringArgumentCaptor = forClass(String.class);
63+
64+
@Test
65+
void testPerform() {
66+
when(mockedActionContext.http(httpFunctionArgumentCaptor.capture()))
67+
.thenAnswer(_ -> httpFunctionArgumentCaptor.getValue()
68+
.apply(mockedHttp));
69+
when(mockedHttp.get(stringArgumentCaptor.capture()))
70+
.thenReturn(mockedExecutor);
71+
when(mockedExecutor.configuration(configurationBuilderArgumentCaptor.capture()))
72+
.thenReturn(mockedExecutor);
73+
when(mockedExecutor.queryParameters(ORDER_BY, "+created", MAX_RESULTS, 50))
74+
.thenReturn(mockedExecutor);
75+
when(mockedExecutor.execute())
76+
.thenReturn(mockedResponse);
77+
when(mockedResponse.getBody(any(TypeReference.class)))
78+
.thenReturn(responseMap);
79+
80+
Object result = JiraListIssueCommentsAction.perform(mockedParameters, null, mockedActionContext);
81+
assertEquals(responseMap, result);
82+
83+
ContextFunction<Context.Http, Http.Executor> capturedFunction = httpFunctionArgumentCaptor.getValue();
84+
85+
assertNotNull(capturedFunction);
86+
87+
ConfigurationBuilder configurationBuilder = configurationBuilderArgumentCaptor.getValue();
88+
89+
Http.Configuration configuration = configurationBuilder.build();
90+
91+
Http.ResponseType responseType = configuration.getResponseType();
92+
93+
assertEquals(Http.ResponseType.Type.JSON, responseType.getType());
94+
95+
assertEquals("/issue/xy/comment", stringArgumentCaptor.getValue());
96+
97+
}
98+
99+
}

0 commit comments

Comments
 (0)