forked from opensearch-project/job-scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestReleaseLockActionTests.java
75 lines (63 loc) · 2.71 KB
/
RestReleaseLockActionTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* 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.jobscheduler.rest.action;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.junit.Before;
import org.mockito.Mockito;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.jobscheduler.JobSchedulerPlugin;
import org.opensearch.jobscheduler.spi.LockModel;
import org.opensearch.jobscheduler.spi.utils.LockService;
import org.opensearch.rest.RestHandler;
import org.opensearch.rest.RestRequest;
import org.opensearch.test.OpenSearchTestCase;
import org.opensearch.test.rest.FakeRestChannel;
import org.opensearch.test.rest.FakeRestRequest;
import org.opensearch.transport.client.Client;
@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
public class RestReleaseLockActionTests extends OpenSearchTestCase {
private RestReleaseLockAction restReleaseLockAction;
private LockService lockService;
private String releaseLockPath;
private ClusterService clusterService;
private Client client;
@Before
public void setUp() throws Exception {
super.setUp();
this.clusterService = Mockito.mock(ClusterService.class, Mockito.RETURNS_DEEP_STUBS);
this.client = Mockito.mock(Client.class);
this.lockService = new LockService(client, clusterService);
restReleaseLockAction = new RestReleaseLockAction(this.lockService);
this.releaseLockPath = String.format(Locale.ROOT, "%s/%s/{%s}", JobSchedulerPlugin.JS_BASE_URI, "_release_lock", LockModel.LOCK_ID);
}
public void testGetNames() {
String name = restReleaseLockAction.getName();
assertEquals(restReleaseLockAction.RELEASE_LOCK_ACTION, name);
}
public void testGetRoutes() {
List<RestHandler.Route> routes = restReleaseLockAction.routes();
assertEquals(releaseLockPath, routes.get(0).getPath());
}
public void testPrepareReleaseLockRequest() throws IOException {
Map<String, String> params = new HashMap<>();
params.put(LockModel.LOCK_ID, "lock_id");
FakeRestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withMethod(RestRequest.Method.PUT)
.withPath(releaseLockPath)
.withParams(params)
.build();
final FakeRestChannel channel = new FakeRestChannel(request, true, 0);
assertEquals(channel.responses().get(), 0);
assertEquals(channel.errors().get(), 0);
}
}