-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: bowenlan-amzn <[email protected]>
- Loading branch information
1 parent
8805116
commit d6a547b
Showing
10 changed files
with
201 additions
and
139 deletions.
There are no files selected for viewing
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
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
85 changes: 85 additions & 0 deletions
85
...in/org/opensearch/indexmanagement/snapshotmanagement/SnapshotManagementClientMockTests.kt
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,85 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.indexmanagement.snapshotmanagement | ||
|
||
import com.nhaarman.mockitokotlin2.any | ||
import com.nhaarman.mockitokotlin2.doAnswer | ||
import com.nhaarman.mockitokotlin2.mock | ||
import com.nhaarman.mockitokotlin2.whenever | ||
import org.junit.Before | ||
import org.opensearch.action.ActionListener | ||
import org.opensearch.action.ActionResponse | ||
import org.opensearch.action.index.IndexResponse | ||
import org.opensearch.client.AdminClient | ||
import org.opensearch.client.Client | ||
import org.opensearch.client.ClusterAdminClient | ||
import org.opensearch.test.OpenSearchTestCase | ||
|
||
open class SnapshotManagementClientMockTests : OpenSearchTestCase() { | ||
|
||
val client: Client = mock() | ||
private val adminClient: AdminClient = mock() | ||
private val clusterAdminClient: ClusterAdminClient = mock() | ||
|
||
@Before | ||
fun setupClient() { | ||
doAnswer { | ||
val listener = it.getArgument<ActionListener<IndexResponse>>(1) | ||
listener.onResponse(mockIndexResponse()) | ||
}.whenever(client).index(any(), any()) | ||
} | ||
|
||
fun mockCreateSnapshotCall( | ||
response: ActionResponse? = null, | ||
exception: Exception? = null | ||
) { | ||
assertTrue( | ||
"Must provide either a response or an exception.", | ||
(response != null).xor(exception != null) | ||
) | ||
whenever(client.admin()).thenReturn(adminClient) | ||
whenever(adminClient.cluster()).thenReturn(clusterAdminClient) | ||
doAnswer { | ||
val listener = it.getArgument<ActionListener<ActionResponse>>(1) | ||
if (response != null) listener.onResponse(response) | ||
else listener.onFailure(exception) | ||
}.whenever(clusterAdminClient).createSnapshot(any(), any()) | ||
} | ||
|
||
fun mockDeleteSnapshotCall( | ||
response: ActionResponse? = null, | ||
exception: Exception? = null | ||
) { | ||
assertTrue( | ||
"Must provide either a response or an exception.", | ||
(response != null).xor(exception != null) | ||
) | ||
whenever(client.admin()).thenReturn(adminClient) | ||
whenever(adminClient.cluster()).thenReturn(clusterAdminClient) | ||
doAnswer { | ||
val listener = it.getArgument<ActionListener<ActionResponse>>(1) | ||
if (response != null) listener.onResponse(response) | ||
else listener.onFailure(exception) | ||
}.whenever(clusterAdminClient).deleteSnapshot(any(), any()) | ||
} | ||
|
||
fun mockGetSnapshotsCall( | ||
response: ActionResponse? = null, | ||
exception: Exception? = null | ||
) { | ||
assertTrue( | ||
"Must provide either a response or an exception.", | ||
(response != null).xor(exception != null) | ||
) | ||
whenever(client.admin()).thenReturn(adminClient) | ||
whenever(adminClient.cluster()).thenReturn(clusterAdminClient) | ||
doAnswer { | ||
val listener = it.getArgument<ActionListener<ActionResponse>>(1) | ||
if (response != null) listener.onResponse(response) | ||
else listener.onFailure(exception) | ||
}.whenever(clusterAdminClient).getSnapshots(any(), any()) | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.