-
Notifications
You must be signed in to change notification settings - Fork 129
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: Xun Zhang <xunzh@amazon.com>
- Loading branch information
1 parent
83d905b
commit b22b45a
Showing
7 changed files
with
258 additions
and
1 deletion.
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
41 changes: 41 additions & 0 deletions
41
plugin/src/test/java/org/opensearch/ml/rest/RestMLDeleteModelActionIT.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,41 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.rest; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import org.apache.http.HttpEntity; | ||
import org.opensearch.client.Response; | ||
import org.opensearch.client.ResponseException; | ||
import org.opensearch.ml.utils.TestHelper; | ||
import org.opensearch.rest.RestStatus; | ||
|
||
public class RestMLDeleteModelActionIT extends MLCommonsRestTestCase { | ||
|
||
public void testDeleteModelAPI_EmptyResources() throws Exception { | ||
TestHelper | ||
.assertFailWith( | ||
ResponseException.class, | ||
"index_not_found_exception", | ||
() -> TestHelper.makeRequest(client(), "DELETE", "/_plugins/_ml/models/111222333", null, "", null) | ||
); | ||
} | ||
|
||
public void testDeleteModelAPI_Success() throws IOException { | ||
Response trainModelResponse = ingestModelData(); | ||
HttpEntity entity = trainModelResponse.getEntity(); | ||
assertNotNull(trainModelResponse); | ||
String entityString = TestHelper.httpEntityToString(entity); | ||
Map map = gson.fromJson(entityString, Map.class); | ||
String model_id = (String) map.get("model_id"); | ||
|
||
Response getModelResponse = TestHelper.makeRequest(client(), "DELETE", "/_plugins/_ml/models/" + model_id, null, "", null); | ||
HttpEntity responseEntity = getModelResponse.getEntity(); | ||
assertNotNull(getModelResponse); | ||
assertEquals(RestStatus.OK, TestHelper.restStatus(getModelResponse)); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
plugin/src/test/java/org/opensearch/ml/rest/RestMLGetModelActionIT.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,43 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.rest; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import org.apache.http.HttpEntity; | ||
import org.opensearch.client.Response; | ||
import org.opensearch.client.ResponseException; | ||
import org.opensearch.ml.utils.TestHelper; | ||
import org.opensearch.rest.RestStatus; | ||
|
||
public class RestMLGetModelActionIT extends MLCommonsRestTestCase { | ||
|
||
public void testGetModelAPI_EmptyResources() throws IOException { | ||
try { | ||
Response getModelResponse = TestHelper.makeRequest(client(), "GET", "/_plugins/_ml/models/111222333", null, "", null); | ||
HttpEntity entity = getModelResponse.getEntity(); | ||
assertNotNull(getModelResponse); | ||
assertEquals(RestStatus.INTERNAL_SERVER_ERROR, TestHelper.restStatus(getModelResponse)); | ||
} catch (Exception exception) { | ||
assertEquals(exception.getClass(), ResponseException.class); | ||
} | ||
} | ||
|
||
public void testGetModelAPI_Success() throws IOException { | ||
Response trainModelResponse = ingestModelData(); | ||
HttpEntity entity = trainModelResponse.getEntity(); | ||
assertNotNull(trainModelResponse); | ||
String entityString = TestHelper.httpEntityToString(entity); | ||
Map map = gson.fromJson(entityString, Map.class); | ||
String model_id = (String) map.get("model_id"); | ||
|
||
Response getModelResponse = TestHelper.makeRequest(client(), "GET", "/_plugins/_ml/models/" + model_id, null, "", null); | ||
HttpEntity responseEntity = getModelResponse.getEntity(); | ||
assertNotNull(getModelResponse); | ||
assertEquals(RestStatus.OK, TestHelper.restStatus(getModelResponse)); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
plugin/src/test/java/org/opensearch/ml/rest/RestMLGetModelActionTests.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,52 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.rest; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.opensearch.common.Strings; | ||
import org.opensearch.rest.RestHandler; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
public class RestMLGetModelActionTests extends OpenSearchTestCase { | ||
@Rule | ||
public ExpectedException thrown = ExpectedException.none(); | ||
|
||
private RestMLGetModelAction restMLGetModelAction; | ||
|
||
@Before | ||
public void setup() { | ||
restMLGetModelAction = new RestMLGetModelAction(); | ||
} | ||
|
||
@Test | ||
public void testConstructor() { | ||
RestMLGetModelAction mlGetModelAction = new RestMLGetModelAction(); | ||
assertNotNull(mlGetModelAction); | ||
} | ||
|
||
@Test | ||
public void testGetName() { | ||
String actionName = restMLGetModelAction.getName(); | ||
assertFalse(Strings.isNullOrEmpty(actionName)); | ||
assertEquals("ml_get_model_action", actionName); | ||
} | ||
|
||
@Test | ||
public void testRoutes() { | ||
List<RestHandler.Route> routes = restMLGetModelAction.routes(); | ||
assertNotNull(routes); | ||
assertFalse(routes.isEmpty()); | ||
RestHandler.Route route = routes.get(0); | ||
assertEquals(RestRequest.Method.GET, route.getMethod()); | ||
assertEquals("/_plugins/_ml/models/{model_id}", route.getPath()); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
plugin/src/test/java/org/opensearch/ml/rest/RestMLSearchModelActionIT.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,44 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.rest; | ||
|
||
import static org.opensearch.ml.utils.TestData.matchAllSearchQuery; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import org.apache.http.HttpEntity; | ||
import org.opensearch.client.Response; | ||
import org.opensearch.client.ResponseException; | ||
import org.opensearch.ml.utils.TestHelper; | ||
import org.opensearch.rest.RestStatus; | ||
|
||
public class RestMLSearchModelActionIT extends MLCommonsRestTestCase { | ||
|
||
public void testSearchModelAPI_EmptyResources() throws Exception { | ||
TestHelper | ||
.assertFailWith( | ||
ResponseException.class, | ||
"index_not_found_exception", | ||
() -> TestHelper.makeRequest(client(), "GET", "/_plugins/_ml/models/_search", null, matchAllSearchQuery(), null) | ||
); | ||
} | ||
|
||
public void testSearchModelAPI_Success() throws IOException { | ||
Response trainModelResponse = ingestModelData(); | ||
HttpEntity entity = trainModelResponse.getEntity(); | ||
assertNotNull(trainModelResponse); | ||
String entityString = TestHelper.httpEntityToString(entity); | ||
Map map = gson.fromJson(entityString, Map.class); | ||
String model_id = (String) map.get("model_id"); | ||
|
||
Response searchModelResponse = TestHelper | ||
.makeRequest(client(), "GET", "/_plugins/_ml/models/_search", null, matchAllSearchQuery(), null); | ||
HttpEntity responseEntity = searchModelResponse.getEntity(); | ||
assertNotNull(searchModelResponse); | ||
assertEquals(RestStatus.OK, TestHelper.restStatus(searchModelResponse)); | ||
} | ||
} |
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