forked from opensearch-project/flow-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding intial failure test case for the ProvisionWorkflowTransportAct…
…ion. Still need to add tests for success case Signed-off-by: Joshua Palis <[email protected]>
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...st/java/org/opensearch/flowframework/transport/ProvisionWorkflowTransportActionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.flowframework.transport; | ||
|
||
import org.opensearch.action.get.GetResponse; | ||
import org.opensearch.action.support.ActionFilters; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.util.concurrent.ThreadContext; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.flowframework.workflow.WorkflowProcessSorter; | ||
import org.opensearch.tasks.Task; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
import org.opensearch.threadpool.ThreadPool; | ||
import org.opensearch.transport.TransportService; | ||
|
||
import org.mockito.ArgumentCaptor; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.doAnswer; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class ProvisionWorkflowTransportActionTests extends OpenSearchTestCase { | ||
|
||
private ThreadPool threadPool; | ||
private Client client; | ||
private WorkflowProcessSorter workflowProcessSorter; | ||
private ProvisionWorkflowTransportAction provisionWorkflowTransportAction; | ||
|
||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
this.threadPool = mock(ThreadPool.class); | ||
this.client = mock(Client.class); | ||
this.workflowProcessSorter = mock(WorkflowProcessSorter.class); | ||
|
||
this.provisionWorkflowTransportAction = new ProvisionWorkflowTransportAction( | ||
mock(TransportService.class), | ||
mock(ActionFilters.class), | ||
threadPool, | ||
client, | ||
workflowProcessSorter | ||
); | ||
|
||
ThreadPool clientThreadPool = mock(ThreadPool.class); | ||
ThreadContext threadContext = new ThreadContext(Settings.EMPTY); | ||
|
||
when(client.threadPool()).thenReturn(clientThreadPool); | ||
when(clientThreadPool.getThreadContext()).thenReturn(threadContext); | ||
} | ||
|
||
public void testProvisionWorkflow() { | ||
// TODO : Add tests for success case | ||
} | ||
|
||
public void testFailedToRetrieveTemplateFromGlobalContext() { | ||
ActionListener<WorkflowResponse> listener = mock(ActionListener.class); | ||
WorkflowRequest request = new WorkflowRequest("1", null); | ||
doAnswer(invocation -> { | ||
ActionListener<GetResponse> responseListener = invocation.getArgument(1); | ||
responseListener.onFailure(new Exception("Failed to retrieve template from global context.")); | ||
return null; | ||
}).when(client).get(any(), any()); | ||
|
||
provisionWorkflowTransportAction.doExecute(mock(Task.class), request, listener); | ||
ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class); | ||
|
||
verify(listener, times(1)).onFailure(exceptionCaptor.capture()); | ||
assertEquals("Failed to retrieve template from global context.", exceptionCaptor.getValue().getMessage()); | ||
} | ||
|
||
} |