Skip to content

Commit 4a9ef42

Browse files
Fixes unit tests
Signed-off-by: Darshit Chanpura <[email protected]>
1 parent 735955d commit 4a9ef42

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/test/java/org/opensearch/flowframework/transport/CreateWorkflowTransportActionTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public void testCreateNewWorkflow() {
376376

377377
// Bypass putInitialStateToWorkflowState and force on response
378378
doAnswer(invocation -> {
379-
ActionListener<IndexResponse> responseListener = invocation.getArgument(3);
379+
ActionListener<IndexResponse> responseListener = invocation.getArgument(4);
380380
responseListener.onResponse(new IndexResponse(new ShardId(WORKFLOW_STATE_INDEX, "", 1), "1", 1L, 1L, 1L, true));
381381
return null;
382382
}).when(flowFrameworkIndicesHandler).putInitialStateToWorkflowState(any(), any(), any(), any(), any());
@@ -450,7 +450,7 @@ public void testCreateWithUserAndFilterOn() {
450450

451451
// Bypass putInitialStateToWorkflowState and force on response
452452
doAnswer(invocation -> {
453-
ActionListener<IndexResponse> responseListener = invocation.getArgument(3);
453+
ActionListener<IndexResponse> responseListener = invocation.getArgument(4);
454454
responseListener.onResponse(new IndexResponse(new ShardId(WORKFLOW_STATE_INDEX, "", 1), "1", 1L, 1L, 1L, true));
455455
return null;
456456
}).when(flowFrameworkIndicesHandler).putInitialStateToWorkflowState(any(), any(), any(), any(), any());
@@ -925,7 +925,7 @@ public void testCreateWorkflow_withValidation_withProvision_Success() throws Exc
925925

926926
// Bypass putInitialStateToWorkflowState and force on response
927927
doAnswer(invocation -> {
928-
ActionListener<IndexResponse> responseListener = invocation.getArgument(3);
928+
ActionListener<IndexResponse> responseListener = invocation.getArgument(4);
929929
responseListener.onResponse(new IndexResponse(new ShardId(WORKFLOW_STATE_INDEX, "", 1), "1", 1L, 1L, 1L, true));
930930
return null;
931931
}).when(flowFrameworkIndicesHandler).putInitialStateToWorkflowState(any(), any(), any(), any(), any());
@@ -986,7 +986,7 @@ public void testCreateWorkflow_withValidation_withWaitForCompletion_withProvisio
986986

987987
// Bypass putInitialStateToWorkflowState and force on response
988988
doAnswer(invocation -> {
989-
ActionListener<IndexResponse> responseListener = invocation.getArgument(3);
989+
ActionListener<IndexResponse> responseListener = invocation.getArgument(4);
990990
responseListener.onResponse(new IndexResponse(new ShardId(WORKFLOW_STATE_INDEX, "", 1), "1", 1L, 1L, 1L, true));
991991
return null;
992992
}).when(flowFrameworkIndicesHandler).putInitialStateToWorkflowState(any(), any(), any(), any(), any());
@@ -1063,7 +1063,7 @@ public void testCreateWorkflow_withValidation_withWaitForCompletionTimeSetZero_w
10631063

10641064
// Bypass putInitialStateToWorkflowState and force on response
10651065
doAnswer(invocation -> {
1066-
ActionListener<IndexResponse> responseListener = invocation.getArgument(3);
1066+
ActionListener<IndexResponse> responseListener = invocation.getArgument(4);
10671067
responseListener.onResponse(new IndexResponse(new ShardId(WORKFLOW_STATE_INDEX, "", 1), "1", 1L, 1L, 1L, true));
10681068
return null;
10691069
}).when(flowFrameworkIndicesHandler).putInitialStateToWorkflowState(any(), any(), any(), any(), any());
@@ -1140,7 +1140,7 @@ public void testCreateWorkflow_withValidation_withProvision_FailedProvisioning()
11401140

11411141
// Bypass putInitialStateToWorkflowState and force on response
11421142
doAnswer(invocation -> {
1143-
ActionListener<IndexResponse> responseListener = invocation.getArgument(3);
1143+
ActionListener<IndexResponse> responseListener = invocation.getArgument(4);
11441144
responseListener.onResponse(new IndexResponse(new ShardId(WORKFLOW_STATE_INDEX, "", 1), "1", 1L, 1L, 1L, true));
11451145
return null;
11461146
}).when(flowFrameworkIndicesHandler).putInitialStateToWorkflowState(any(), any(), any(), any(), any());

src/test/java/org/opensearch/flowframework/transport/DeprovisionWorkflowTransportActionTests.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ public void testDeprovisionWorkflow() throws Exception {
170170
return null;
171171
}).when(flowFrameworkIndicesHandler).doesTemplateExist(anyString(), any(), any(), any());
172172

173+
// putInitialStateToWorkflowState must invoke its ActionListener.onResponse
174+
doAnswer(inv -> {
175+
ActionListener<?> l = inv.getArgument(4);
176+
l.onResponse(null);
177+
return null;
178+
}).when(flowFrameworkIndicesHandler).putInitialStateToWorkflowState(anyString(), any(), any(), any(), any());
179+
173180
PlainActionFuture<WorkflowData> future = PlainActionFuture.newFuture();
174181
future.onResponse(WorkflowData.EMPTY);
175182
when(this.deleteConnectorStep.execute(anyString(), any(WorkflowData.class), anyMap(), anyMap(), anyMap(), nullable(String.class)))
@@ -291,6 +298,21 @@ public void testAllowDeleteRequired() throws Exception {
291298
"These resources require the allow_delete parameter to deprovision: [index_name test-index].",
292299
exceptionCaptor.getValue().getMessage()
293300
);
301+
302+
// doesTemplateExist -> false for this test
303+
doAnswer(inv -> {
304+
java.util.function.Consumer<Boolean> cb = inv.getArgument(2);
305+
cb.accept(Boolean.FALSE);
306+
return null;
307+
}).when(flowFrameworkIndicesHandler).doesTemplateExist(anyString(), any(), any(), any());
308+
309+
// deleteFlowFrameworkSystemIndexDoc must call onResponse
310+
doAnswer(inv -> {
311+
ActionListener<?> l = inv.getArgument(2);
312+
l.onResponse(null);
313+
return null;
314+
}).when(flowFrameworkIndicesHandler).deleteFlowFrameworkSystemIndexDoc(anyString(), any(), any());
315+
294316
verify(flowFrameworkIndicesHandler, times(0)).deleteResourceFromStateIndex(
295317
anyString(),
296318
nullable(String.class),

0 commit comments

Comments
 (0)