Merge pull request #1101 from kw-udon/add-integration-tests-Jun-10
Add Integration Tests (#1028, #1037, #1042, #1043)
This commit is contained in:
commit
b9d386959b
19 changed files with 806 additions and 1249 deletions
6
pom.xml
6
pom.xml
|
@ -1440,12 +1440,6 @@
|
|||
<artifactId>rest-assured</artifactId>
|
||||
<version>3.0.3</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpmime</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -36,8 +36,8 @@ public class ApiAdminRoleAction extends FessApiAdminAction {
|
|||
@Resource
|
||||
private RoleService roleService;
|
||||
|
||||
// GET /api/admin/role
|
||||
// POST /api/admin/role
|
||||
// GET /api/admin/role/settings
|
||||
// POST /api/admin/role/settings
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> settings(final SearchBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
|
|
|
@ -36,8 +36,8 @@ public class ApiAdminUserAction extends FessApiAdminAction {
|
|||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
// GET /api/admin/user
|
||||
// POST /api/admin/user
|
||||
// GET /api/admin/user/settings
|
||||
// POST /api/admin/user/settings
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> settings(final SearchBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
|
|
|
@ -16,9 +16,15 @@
|
|||
package org.codelibs.fess.it;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
@ -33,6 +39,8 @@ import io.restassured.specification.RequestSpecification;
|
|||
|
||||
public abstract class CrudTestBase extends ITBase {
|
||||
|
||||
protected static final int NUM = 20;
|
||||
|
||||
// ================
|
||||
// Abstract Methods
|
||||
// ================
|
||||
|
@ -46,15 +54,9 @@ public abstract class CrudTestBase extends ITBase {
|
|||
|
||||
abstract protected String getItemEndpointSuffix();
|
||||
|
||||
abstract protected void testCreate();
|
||||
abstract protected Map<String, Object> createTestParam(int id);
|
||||
|
||||
abstract protected void testRead();
|
||||
|
||||
abstract protected void testUpdate();
|
||||
|
||||
abstract protected void testDelete();
|
||||
|
||||
abstract protected void clearTestData();
|
||||
abstract protected Map<String, Object> getUpdateMap();
|
||||
|
||||
// ================
|
||||
|
||||
|
@ -70,7 +72,12 @@ public abstract class CrudTestBase extends ITBase {
|
|||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
clearTestData();
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 10);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
checkDeleteMethod(getItemEndpointSuffix() + "/" + id);
|
||||
});
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
|
@ -78,6 +85,104 @@ public abstract class CrudTestBase extends ITBase {
|
|||
deleteTestToken();
|
||||
}
|
||||
|
||||
// ================
|
||||
// Bodies
|
||||
// ================
|
||||
protected void testCreate() {
|
||||
// Test: create setting api.
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final Map<String, Object> requestBody = createTestParam(i);
|
||||
checkPutMethod(requestBody, getItemEndpointSuffix()).then().body("response.created", equalTo(true))
|
||||
.body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
// Test: number of settings.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
checkGetMethod(searchBody, getListEndpointSuffix()).then().body(getJsonPath() + ".size()", equalTo(NUM));
|
||||
}
|
||||
|
||||
protected void testRead() {
|
||||
// Test: get settings api.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> nameList = getPropList(searchBody, getKeyProperty());
|
||||
|
||||
assertEquals(NUM, nameList.size());
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final String name = getNamePrefix() + i;
|
||||
assertTrue(nameList.contains(name), name);
|
||||
}
|
||||
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
// Test: get setting api
|
||||
checkGetMethod(searchBody, getItemEndpointSuffix() + "/" + id).then()
|
||||
.body("response." + getItemEndpointSuffix() + ".id", equalTo(id))
|
||||
.body("response." + getItemEndpointSuffix() + "." + getKeyProperty(), startsWith(getNamePrefix()));
|
||||
});
|
||||
|
||||
// Test: paging
|
||||
searchBody.put("size", 1);
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
searchBody.put("page", i + 1);
|
||||
checkGetMethod(searchBody, getListEndpointSuffix()).then().body("response." + getListEndpointSuffix() + ".size()", equalTo(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void testUpdate() {
|
||||
// Test: update settings api
|
||||
final Set<String> keySet = createTestParam(0).keySet();
|
||||
final Map<String, Object> updateMap = getUpdateMap();
|
||||
Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<Map<String, Object>> settings = getItemList(searchBody);
|
||||
|
||||
for (Map<String, Object> setting : settings) {
|
||||
final Map<String, Object> requestBody = new HashMap<>(updateMap);
|
||||
requestBody.put("version_no", 1);
|
||||
if (setting.containsKey("id")) {
|
||||
requestBody.put("id", setting.get("id"));
|
||||
}
|
||||
for (String key : keySet) {
|
||||
if (!requestBody.containsKey(key)) {
|
||||
requestBody.put(key, setting.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
checkPostMethod(requestBody, getItemEndpointSuffix()).then().body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
checkUpdate();
|
||||
}
|
||||
|
||||
protected void checkUpdate() {
|
||||
final Map<String, Object> updateMap = getUpdateMap();
|
||||
Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
for (Map.Entry<String, Object> entry : updateMap.entrySet()) {
|
||||
List<String> updatedList = getPropList(searchBody, entry.getKey());
|
||||
for (String val : updatedList) {
|
||||
assertEquals(entry.getValue().toString(), val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void testDelete() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
|
||||
idList.forEach(id -> {
|
||||
//Test: delete setting api
|
||||
checkDeleteMethod(getItemEndpointSuffix() + "/" + id).then().body("response.status", equalTo(0));
|
||||
});
|
||||
|
||||
// Test: NUMber of settings.
|
||||
checkGetMethod(searchBody, getListEndpointSuffix()).then().body(getJsonPath() + ".size()", equalTo(0));
|
||||
}
|
||||
|
||||
// ================
|
||||
// Utilities
|
||||
// ================
|
||||
|
@ -111,7 +216,7 @@ public abstract class CrudTestBase extends ITBase {
|
|||
return "response." + getListEndpointSuffix() + ".findAll {it." + getKeyProperty() + ".startsWith(\"" + getNamePrefix() + "\")}";
|
||||
}
|
||||
|
||||
private RequestSpecification checkMethodBase(final Map<String, Object> body) {
|
||||
protected RequestSpecification checkMethodBase(final Map<String, Object> body) {
|
||||
return given().header("Authorization", getTestToken()).body(body, ObjectMapperType.JACKSON_2).when();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,10 +16,7 @@
|
|||
package org.codelibs.fess.it.admin;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -33,8 +30,6 @@ import io.restassured.path.json.JsonPath;
|
|||
|
||||
@Tag("it")
|
||||
public class AccessTokenTests extends CrudTestBase {
|
||||
private static final int NUM = 20;
|
||||
|
||||
private static final String NAME_PREFIX = "accessTokenTest_";
|
||||
private static final String API_PATH = "/api/admin/accesstoken";
|
||||
private static final String LIST_ENDPOINT_SUFFIX = "settings";
|
||||
|
@ -67,106 +62,30 @@ public class AccessTokenTests extends CrudTestBase {
|
|||
return ITEM_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@Test
|
||||
void crudTest() {
|
||||
testCreate();
|
||||
testRead();
|
||||
testUpdate();
|
||||
testDelete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void functionTest() {
|
||||
testPermission();
|
||||
@Override
|
||||
protected Map<String, Object> createTestParam(int id) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + id;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("permissions", "Radmin-api");
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testCreate() {
|
||||
// Test: create setting api.
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("permissions", "Radmin-api");
|
||||
|
||||
checkPutMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.created", equalTo(true))
|
||||
.body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
// Test: NUMber of settings.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(NUM));
|
||||
protected Map<String, Object> getUpdateMap() {
|
||||
final Map<String, Object> updateMap = new HashMap<>();
|
||||
updateMap.put("permissions", "Radmin-api2");
|
||||
return updateMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testRead() {
|
||||
// Test: get settings api.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> propList = getPropList(searchBody, KEY_PROPERTY);
|
||||
assertEquals(NUM, propList.size());
|
||||
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final String prop = NAME_PREFIX + i;
|
||||
assertTrue(propList.contains(prop), prop);
|
||||
}
|
||||
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
// Test: get setting api
|
||||
checkGetMethod(searchBody, ITEM_ENDPOINT_SUFFIX + "/" + id).then()
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + ".id", equalTo(id))
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + "." + KEY_PROPERTY, startsWith(NAME_PREFIX))
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + ".token.length()", greaterThan(0));
|
||||
});
|
||||
|
||||
// Test: paging
|
||||
searchBody.put("size", 1);
|
||||
for (int i = 0; i < NUM + 1; i++) {
|
||||
searchBody.put("page", i + 1);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body("response." + LIST_ENDPOINT_SUFFIX + ".size()", equalTo(1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testUpdate() {
|
||||
// Test: update settings api
|
||||
protected void checkUpdate() {
|
||||
Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<Map<String, Object>> settings = getItemList(searchBody);
|
||||
|
||||
String newPermission = "Radmin-api2";
|
||||
for (Map<String, Object> setting : settings) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("id", setting.get("id"));
|
||||
requestBody.put(KEY_PROPERTY, setting.get(KEY_PROPERTY));
|
||||
requestBody.put("permissions", newPermission);
|
||||
requestBody.put("version_no", 1);
|
||||
|
||||
checkPostMethod(requestBody, "setting").then().body("response.status", equalTo(0));
|
||||
List<String> updatedList = getPropList(searchBody, "permissions");
|
||||
for (String val : updatedList) {
|
||||
assertEquals(val, "{role}admin-api2");
|
||||
}
|
||||
|
||||
searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> permissionsList = getPropList(searchBody, "permissions");
|
||||
for (String permissions : permissionsList) {
|
||||
assertEquals(newPermission.replace("R", "{role}"), permissions);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testDelete() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
//Test: delete setting api
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id).then().body("response.status", equalTo(0));
|
||||
});
|
||||
|
||||
// Test: NUMber of settings.
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(0));
|
||||
}
|
||||
|
||||
private void testPermission() {
|
||||
|
@ -186,13 +105,16 @@ public class AccessTokenTests extends CrudTestBase {
|
|||
.body("response." + ITEM_ENDPOINT_SUFFIX + ".token", equalTo(token));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearTestData() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 10);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id);
|
||||
});
|
||||
@Test
|
||||
void crudTest() {
|
||||
testCreate();
|
||||
testRead();
|
||||
testUpdate();
|
||||
testDelete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void functionTest() {
|
||||
testPermission();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,13 +15,7 @@
|
|||
*/
|
||||
package org.codelibs.fess.it.admin;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.fess.it.CrudTestBase;
|
||||
|
@ -31,8 +25,6 @@ import org.junit.jupiter.api.Test;
|
|||
@Tag("it")
|
||||
public class BoostDocTests extends CrudTestBase {
|
||||
|
||||
private static final int NUM = 20;
|
||||
|
||||
private static final String NAME_PREFIX = "boostDocTest_";
|
||||
private static final String API_PATH = "/api/admin/boostdoc";
|
||||
private static final String LIST_ENDPOINT_SUFFIX = "settings";
|
||||
|
@ -65,6 +57,23 @@ public class BoostDocTests extends CrudTestBase {
|
|||
return ITEM_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> createTestParam(int id) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + id;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("boost_expr", new Integer(id).toString());
|
||||
requestBody.put("sort_order", id);
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getUpdateMap() {
|
||||
final Map<String, Object> updateMap = new HashMap<>();
|
||||
updateMap.put("boost_expr", "new_boost_expr");
|
||||
return updateMap;
|
||||
}
|
||||
|
||||
@Test
|
||||
void crudTest() {
|
||||
testCreate();
|
||||
|
@ -72,107 +81,4 @@ public class BoostDocTests extends CrudTestBase {
|
|||
testUpdate();
|
||||
testDelete();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testCreate() {
|
||||
// Test: create setting api.
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("boost_expr", new Integer(i).toString());
|
||||
requestBody.put("sort_order", i);
|
||||
|
||||
checkPutMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.created", equalTo(true))
|
||||
.body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
// Test: number of settings.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(NUM));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testRead() {
|
||||
// Test: get settings api.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> nameList = getPropList(searchBody, KEY_PROPERTY);
|
||||
|
||||
assertEquals(NUM, nameList.size());
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final String name = NAME_PREFIX + i;
|
||||
assertTrue(nameList.contains(name), name);
|
||||
}
|
||||
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
// Test: get setting api
|
||||
checkGetMethod(searchBody, ITEM_ENDPOINT_SUFFIX + "/" + id).then()
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + ".id", equalTo(id))
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + "." + KEY_PROPERTY, startsWith(NAME_PREFIX));
|
||||
});
|
||||
|
||||
// Test: paging
|
||||
searchBody.put("size", 1);
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
searchBody.put("page", i + 1);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body("response." + LIST_ENDPOINT_SUFFIX + ".size()", equalTo(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testUpdate() {
|
||||
// Test: update settings api
|
||||
Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<Map<String, Object>> settings = getItemList(searchBody);
|
||||
|
||||
final String newBoostExpr = "new_boost_expr";
|
||||
for (Map<String, Object> setting : settings) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("id", setting.get("id"));
|
||||
requestBody.put(KEY_PROPERTY, setting.get(KEY_PROPERTY));
|
||||
requestBody.put("boost_expr", newBoostExpr);
|
||||
requestBody.put("sort_order", setting.get("sort_order"));
|
||||
requestBody.put("version_no", 1);
|
||||
|
||||
checkPostMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> boostExprList = getPropList(searchBody, "boost_expr");
|
||||
for (String boostExpr : boostExprList) {
|
||||
assertEquals(boostExpr, newBoostExpr);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testDelete() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
|
||||
idList.forEach(id -> {
|
||||
//Test: delete setting api
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id).then().body("response.status", equalTo(0));
|
||||
});
|
||||
|
||||
// Test: NUMber of settings.
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearTestData() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 10);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,13 +15,7 @@
|
|||
*/
|
||||
package org.codelibs.fess.it.admin;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.fess.it.CrudTestBase;
|
||||
|
@ -31,8 +25,6 @@ import org.junit.jupiter.api.Test;
|
|||
@Tag("it")
|
||||
public class DataConfigTests extends CrudTestBase {
|
||||
|
||||
private static final int NUM = 20;
|
||||
|
||||
private static final String NAME_PREFIX = "dataConfigTest_";
|
||||
private static final String API_PATH = "/api/admin/dataconfig";
|
||||
private static final String LIST_ENDPOINT_SUFFIX = "settings";
|
||||
|
@ -65,6 +57,26 @@ public class DataConfigTests extends CrudTestBase {
|
|||
return ITEM_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> createTestParam(int id) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + id;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
final String handlerName = "DatabaseDataStore";
|
||||
requestBody.put("handler_name", handlerName);
|
||||
requestBody.put("boost", id);
|
||||
requestBody.put("available", true);
|
||||
requestBody.put("sort_order", id);
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getUpdateMap() {
|
||||
final Map<String, Object> updateMap = new HashMap<>();
|
||||
updateMap.put("handler_name", "CsvDataStore");
|
||||
return updateMap;
|
||||
}
|
||||
|
||||
@Test
|
||||
void crudTest() {
|
||||
testCreate();
|
||||
|
@ -72,112 +84,4 @@ public class DataConfigTests extends CrudTestBase {
|
|||
testUpdate();
|
||||
testDelete();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testCreate() {
|
||||
// Test: create setting api.
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
final String handlerName = "DatabaseDataStore";
|
||||
requestBody.put("handler_name", handlerName);
|
||||
requestBody.put("boost", i);
|
||||
requestBody.put("available", true);
|
||||
requestBody.put("sort_order", i);
|
||||
|
||||
checkPutMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.created", equalTo(true))
|
||||
.body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
// Test: number of settings.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(NUM));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testRead() {
|
||||
// Test: get settings api.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> nameList = getPropList(searchBody, KEY_PROPERTY);
|
||||
|
||||
assertEquals(NUM, nameList.size());
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final String name = NAME_PREFIX + i;
|
||||
assertTrue(nameList.contains(name), name);
|
||||
}
|
||||
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
// Test: get setting api
|
||||
checkGetMethod(searchBody, ITEM_ENDPOINT_SUFFIX + "/" + id).then()
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + ".id", equalTo(id))
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + "." + KEY_PROPERTY, startsWith(NAME_PREFIX));
|
||||
});
|
||||
|
||||
// Test: paging
|
||||
searchBody.put("size", 1);
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
searchBody.put("page", i + 1);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body("response." + LIST_ENDPOINT_SUFFIX + ".size()", equalTo(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testUpdate() {
|
||||
// Test: update settings api
|
||||
Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<Map<String, Object>> settings = getItemList(searchBody);
|
||||
|
||||
final String newHandlerName = "CsvDataStore";
|
||||
for (Map<String, Object> setting : settings) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("id", setting.get("id"));
|
||||
requestBody.put(KEY_PROPERTY, setting.get(KEY_PROPERTY));
|
||||
requestBody.put("handler_name", newHandlerName);
|
||||
requestBody.put("boost", setting.get("boost"));
|
||||
requestBody.put("available", true);
|
||||
requestBody.put("sort_order", setting.get("sort_order"));
|
||||
requestBody.put("version_no", 1);
|
||||
|
||||
checkPostMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> handlerList = getPropList(searchBody, "handler_name");
|
||||
for (String handler : handlerList) {
|
||||
assertEquals(handler, newHandlerName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testDelete() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
|
||||
idList.forEach(id -> {
|
||||
//Test: delete setting api
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id).then().body("response.status", equalTo(0));
|
||||
});
|
||||
|
||||
// Test: NUMber of settings.
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearTestData() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 10);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,13 +15,7 @@
|
|||
*/
|
||||
package org.codelibs.fess.it.admin;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.fess.it.CrudTestBase;
|
||||
|
@ -30,7 +24,6 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
@Tag("it")
|
||||
public class DuplicateHostTests extends CrudTestBase {
|
||||
private static final int NUM = 20;
|
||||
|
||||
private static final String NAME_PREFIX = "duplicateHostTest_";
|
||||
private static final String API_PATH = "/api/admin/duplicatehost";
|
||||
|
@ -64,6 +57,23 @@ public class DuplicateHostTests extends CrudTestBase {
|
|||
return ITEM_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> createTestParam(int id) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + id;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("duplicate_host_name", "duplicate_" + new Integer(id).toString());
|
||||
requestBody.put("sort_order", id);
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getUpdateMap() {
|
||||
final Map<String, Object> updateMap = new HashMap<>();
|
||||
updateMap.put("duplicate_host_name", "new_duplicate_host");
|
||||
return updateMap;
|
||||
}
|
||||
|
||||
@Test
|
||||
void crudTest() {
|
||||
testCreate();
|
||||
|
@ -72,106 +82,4 @@ public class DuplicateHostTests extends CrudTestBase {
|
|||
testDelete();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testCreate() {
|
||||
// Test: create setting api.
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("duplicate_host_name", "duplicate_" + i);
|
||||
requestBody.put("sort_order", i);
|
||||
|
||||
checkPutMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.created", equalTo(true))
|
||||
.body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
// Test: number of settings.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(NUM));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testRead() {
|
||||
// Test: get settings api.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> propList = getPropList(searchBody, KEY_PROPERTY);
|
||||
|
||||
assertEquals(NUM, propList.size());
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
assertTrue(propList.contains(keyProp), keyProp);
|
||||
}
|
||||
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
// Test: get setting api
|
||||
checkGetMethod(searchBody, ITEM_ENDPOINT_SUFFIX + "/" + id).then()
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + ".id", equalTo(id))
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + "." + KEY_PROPERTY, startsWith(NAME_PREFIX));
|
||||
});
|
||||
|
||||
// Test: paging
|
||||
searchBody.put("size", 1);
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
searchBody.put("page", i + 1);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body("response." + LIST_ENDPOINT_SUFFIX + ".size()", equalTo(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testUpdate() {
|
||||
// Test: update settings api
|
||||
Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<Map<String, Object>> settings = getItemList(searchBody);
|
||||
|
||||
final String newDHostName = "newDuplicateHost";
|
||||
for (Map<String, Object> setting : settings) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("id", setting.get("id"));
|
||||
requestBody.put(KEY_PROPERTY, setting.get(KEY_PROPERTY));
|
||||
requestBody.put("duplicate_host_name", newDHostName);
|
||||
requestBody.put("sort_order", setting.get("sort_order"));
|
||||
requestBody.put("version_no", 1);
|
||||
|
||||
checkPostMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> valueList = getPropList(searchBody, "duplicate_host_name");
|
||||
for (String value : valueList) {
|
||||
assertEquals(value, newDHostName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testDelete() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
|
||||
idList.forEach(id -> {
|
||||
//Test: delete setting api
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id).then().body("response.status", equalTo(0));
|
||||
});
|
||||
|
||||
// Test: NUMber of settings.
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearTestData() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 10);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
120
src/test/java/org/codelibs/fess/it/admin/FileAuthTests.java
Normal file
120
src/test/java/org/codelibs/fess/it/admin/FileAuthTests.java
Normal file
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* Copyright 2012-2017 CodeLibs Project and the Others.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific language
|
||||
* governing permissions and limitations under the License.
|
||||
*/
|
||||
package org.codelibs.fess.it.admin;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.fess.it.CrudTestBase;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.restassured.path.json.JsonPath;
|
||||
|
||||
@Tag("it")
|
||||
public class FileAuthTests extends CrudTestBase {
|
||||
|
||||
private static final String NAME_PREFIX = "fileAuthTest_";
|
||||
private static final String API_PATH = "/api/admin/fileauth";
|
||||
private static final String LIST_ENDPOINT_SUFFIX = "settings";
|
||||
private static final String ITEM_ENDPOINT_SUFFIX = "setting";
|
||||
|
||||
private static final String KEY_PROPERTY = "username";
|
||||
|
||||
@Override
|
||||
protected String getNamePrefix() {
|
||||
return NAME_PREFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getApiPath() {
|
||||
return API_PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getKeyProperty() {
|
||||
return KEY_PROPERTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getListEndpointSuffix() {
|
||||
return LIST_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getItemEndpointSuffix() {
|
||||
return ITEM_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void createFileConfig() {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("name", "test_fileconfig");
|
||||
requestBody.put("paths", "file:///example/path/");
|
||||
requestBody.put("num_of_thread", 5);
|
||||
requestBody.put("interval_time", 1000);
|
||||
requestBody.put("boost", 100.0);
|
||||
requestBody.put("available", true);
|
||||
requestBody.put("sort_order", 1);
|
||||
checkMethodBase(requestBody).put("/api/admin/fileconfig/setting").then().body("response.created", equalTo(true))
|
||||
.body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
String getFileConfigId() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("name", "test_fileconfig");
|
||||
String res = checkMethodBase(searchBody).get("/api/admin/fileconfig/settings").asString();
|
||||
List<String> fileConfigList = JsonPath.from(res).getList("response.settings.findAll {it.name.startsWith(\"test_fileconfig\")}.id");
|
||||
return fileConfigList.get(0);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void deleteFileConfig() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
final String fileConfigId = getFileConfigId();
|
||||
checkMethodBase(searchBody).delete("/api/admin/fileconfig/setting/" + fileConfigId).then().body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> createTestParam(int id) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + id;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("file_config_id", getFileConfigId());
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getUpdateMap() {
|
||||
final Map<String, Object> updateMap = new HashMap<>();
|
||||
updateMap.put("parameters", "new_parameters");
|
||||
return updateMap;
|
||||
}
|
||||
|
||||
@Test
|
||||
void crudTest() {
|
||||
testCreate();
|
||||
testRead();
|
||||
testUpdate();
|
||||
testDelete();
|
||||
}
|
||||
}
|
|
@ -15,13 +15,7 @@
|
|||
*/
|
||||
package org.codelibs.fess.it.admin;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.fess.it.CrudTestBase;
|
||||
|
@ -31,8 +25,6 @@ import org.junit.jupiter.api.Test;
|
|||
@Tag("it")
|
||||
public class FileConfigTests extends CrudTestBase {
|
||||
|
||||
private static final int NUM = 20;
|
||||
|
||||
private static final String NAME_PREFIX = "fileConfigTest_";
|
||||
private static final String API_PATH = "/api/admin/fileconfig";
|
||||
private static final String LIST_ENDPOINT_SUFFIX = "settings";
|
||||
|
@ -65,6 +57,28 @@ public class FileConfigTests extends CrudTestBase {
|
|||
return ITEM_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> createTestParam(int id) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + id;
|
||||
final String paths = "file:///" + NAME_PREFIX + id;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("paths", paths);
|
||||
requestBody.put("num_of_thread", 5);
|
||||
requestBody.put("interval_time", 1000);
|
||||
requestBody.put("boost", id);
|
||||
requestBody.put("available", true);
|
||||
requestBody.put("sort_order", id);
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getUpdateMap() {
|
||||
final Map<String, Object> updateMap = new HashMap<>();
|
||||
updateMap.put("paths", "file:///new/path");
|
||||
return updateMap;
|
||||
}
|
||||
|
||||
@Test
|
||||
void crudTest() {
|
||||
testCreate();
|
||||
|
@ -72,117 +86,4 @@ public class FileConfigTests extends CrudTestBase {
|
|||
testUpdate();
|
||||
testDelete();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testCreate() {
|
||||
// Test: create setting api.
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
final String paths = "file:///" + NAME_PREFIX + i;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("paths", paths);
|
||||
requestBody.put("num_of_thread", 5);
|
||||
requestBody.put("interval_time", 1000);
|
||||
requestBody.put("boost", i);
|
||||
requestBody.put("available", true);
|
||||
requestBody.put("sort_order", i);
|
||||
|
||||
checkPutMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.created", equalTo(true))
|
||||
.body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
// Test: number of settings.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(NUM));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testRead() {
|
||||
// Test: get settings api.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> propList = getPropList(searchBody, KEY_PROPERTY);
|
||||
|
||||
assertEquals(NUM, propList.size());
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final String prop = NAME_PREFIX + i;
|
||||
assertTrue(propList.contains(prop), prop);
|
||||
}
|
||||
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
// Test: get setting api
|
||||
checkGetMethod(searchBody, ITEM_ENDPOINT_SUFFIX + "/" + id).then()
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + ".id", equalTo(id))
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + "." + KEY_PROPERTY, startsWith(NAME_PREFIX));
|
||||
});
|
||||
|
||||
// Test: paging
|
||||
searchBody.put("size", 1);
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
searchBody.put("page", i + 1);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body("response." + LIST_ENDPOINT_SUFFIX + ".size()", equalTo(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testUpdate() {
|
||||
// Test: update settings api
|
||||
Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<Map<String, Object>> settings = getItemList(searchBody);
|
||||
|
||||
final String newPaths = "file:///new/" + NAME_PREFIX;
|
||||
for (Map<String, Object> setting : settings) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
|
||||
requestBody.put("id", setting.get("id"));
|
||||
requestBody.put(KEY_PROPERTY, setting.get(KEY_PROPERTY));
|
||||
requestBody.put("paths", newPaths);
|
||||
requestBody.put("num_of_thread", setting.get("num_of_thread"));
|
||||
requestBody.put("interval_time", setting.get("interval_time"));
|
||||
requestBody.put("boost", setting.get("boost"));
|
||||
requestBody.put("available", true);
|
||||
requestBody.put("sort_order", setting.get("sort_order"));
|
||||
requestBody.put("version_no", 1);
|
||||
|
||||
checkPostMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> valList = getPropList(searchBody, "paths");
|
||||
for (String val : valList) {
|
||||
assertEquals(val, newPaths);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testDelete() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
|
||||
idList.forEach(id -> {
|
||||
//Test: delete setting api
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id).then().body("response.status", equalTo(0));
|
||||
});
|
||||
|
||||
// Test: NUMber of settings.
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearTestData() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 10);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
*/
|
||||
package org.codelibs.fess.it.admin;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
@ -32,7 +30,6 @@ import io.restassured.path.json.JsonPath;
|
|||
|
||||
@Tag("it")
|
||||
public class GroupTests extends CrudTestBase {
|
||||
private static final int NUM = 20;
|
||||
|
||||
private static final String NAME_PREFIX = "groupTest_";
|
||||
private static final String API_PATH = "/api/admin/group";
|
||||
|
@ -66,6 +63,41 @@ public class GroupTests extends CrudTestBase {
|
|||
return ITEM_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> createTestParam(int id) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + id;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
final Map<String, String> attributes = new HashMap<>();
|
||||
attributes.put("gidNumber", new Integer(id).toString());
|
||||
requestBody.put("attributes", attributes);
|
||||
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getUpdateMap() {
|
||||
final Map<String, Object> updateMap = new HashMap<>();
|
||||
final Map<String, String> newAttributes = new HashMap<>();
|
||||
newAttributes.put("gidNumber", "100");
|
||||
updateMap.put("attributes", newAttributes);
|
||||
|
||||
return updateMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkUpdate() {
|
||||
Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
String response = checkGetMethod(searchBody, getListEndpointSuffix()).asString();
|
||||
List<Map<String, String>> attrList = JsonPath.from(response).getList(getJsonPath() + ".attributes");
|
||||
assertEquals(NUM, attrList.size());
|
||||
for (Map<String, String> attr : attrList) {
|
||||
assertTrue(attr.containsKey("gidNumber"));
|
||||
assertEquals(attr.get("gidNumber"), "100");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void crudTest() {
|
||||
testCreate();
|
||||
|
@ -73,111 +105,4 @@ public class GroupTests extends CrudTestBase {
|
|||
testUpdate();
|
||||
testDelete();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testCreate() {
|
||||
// Test: create setting api.
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
final Map<String, String> attributes = new HashMap<>();
|
||||
attributes.put("gidNumber", new Integer(i).toString());
|
||||
requestBody.put("attributes", attributes);
|
||||
|
||||
checkPutMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.created", equalTo(true))
|
||||
.body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
// Test: number of settings.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(NUM));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testRead() {
|
||||
// Test: get settings api.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> propList = getPropList(searchBody, KEY_PROPERTY);
|
||||
|
||||
assertEquals(NUM, propList.size());
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
assertTrue(propList.contains(keyProp), keyProp);
|
||||
}
|
||||
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
// Test: get setting api
|
||||
checkGetMethod(searchBody, ITEM_ENDPOINT_SUFFIX + "/" + id).then()
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + ".id", equalTo(id))
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + "." + KEY_PROPERTY, startsWith(NAME_PREFIX));
|
||||
});
|
||||
|
||||
// Test: paging
|
||||
searchBody.put("size", 1);
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
searchBody.put("page", i + 1);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body("response." + LIST_ENDPOINT_SUFFIX + ".size()", equalTo(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testUpdate() {
|
||||
// Test: update settings api
|
||||
Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<Map<String, Object>> settings = getItemList(searchBody);
|
||||
|
||||
final Map<String, String> newAttributes = new HashMap<>();
|
||||
newAttributes.put("gidNumber", "100");
|
||||
for (Map<String, Object> setting : settings) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("id", setting.get("id"));
|
||||
requestBody.put(KEY_PROPERTY, setting.get(KEY_PROPERTY));
|
||||
requestBody.put("attributes", newAttributes);
|
||||
requestBody.put("version_no", 1);
|
||||
|
||||
checkPostMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
String response = checkGetMethod(searchBody, getListEndpointSuffix()).asString();
|
||||
List<Map<String, String>> attrList = JsonPath.from(response).getList(getJsonPath() + ".attributes");
|
||||
assertEquals(settings.size(), attrList.size());
|
||||
for (Map<String, String> attr : attrList) {
|
||||
assertTrue(attr.containsKey("gidNumber"));
|
||||
assertEquals(attr.get("gidNumber"), "100");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testDelete() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
|
||||
idList.forEach(id -> {
|
||||
//Test: delete setting api
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id).then().body("response.status", equalTo(0));
|
||||
});
|
||||
|
||||
// Test: NUMber of settings.
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearTestData() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 10);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,13 +15,7 @@
|
|||
*/
|
||||
package org.codelibs.fess.it.admin;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.fess.it.CrudTestBase;
|
||||
|
@ -30,7 +24,6 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
@Tag("it")
|
||||
public class KeyMatchTests extends CrudTestBase {
|
||||
private static final int NUM = 20;
|
||||
|
||||
private static final String NAME_PREFIX = "keyMatchTest_";
|
||||
private static final String API_PATH = "/api/admin/keymatch";
|
||||
|
@ -64,6 +57,25 @@ public class KeyMatchTests extends CrudTestBase {
|
|||
return ITEM_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> createTestParam(int id) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + id;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("query", "query" + id);
|
||||
requestBody.put("max_size", new Integer(id).toString());
|
||||
requestBody.put("boost", 100);
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getUpdateMap() {
|
||||
final Map<String, Object> updateMap = new HashMap<>();
|
||||
updateMap.put("query", "new_query");
|
||||
return updateMap;
|
||||
}
|
||||
|
||||
@Test
|
||||
void crudTest() {
|
||||
testCreate();
|
||||
|
@ -71,109 +83,4 @@ public class KeyMatchTests extends CrudTestBase {
|
|||
testUpdate();
|
||||
testDelete();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testCreate() {
|
||||
// Test: create setting api.
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("query", "query" + i);
|
||||
requestBody.put("max_size", new Integer(i).toString());
|
||||
requestBody.put("boost", 100);
|
||||
|
||||
checkPutMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.created", equalTo(true))
|
||||
.body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
// Test: number of settings.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(NUM));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testRead() {
|
||||
// Test: get settings api.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> propList = getPropList(searchBody, KEY_PROPERTY);
|
||||
|
||||
assertEquals(NUM, propList.size());
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
assertTrue(propList.contains(keyProp), keyProp);
|
||||
}
|
||||
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
// Test: get setting api
|
||||
checkGetMethod(searchBody, ITEM_ENDPOINT_SUFFIX + "/" + id).then()
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + ".id", equalTo(id))
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + "." + KEY_PROPERTY, startsWith(NAME_PREFIX));
|
||||
});
|
||||
|
||||
// Test: paging
|
||||
searchBody.put("size", 1);
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
searchBody.put("page", i + 1);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body("response." + LIST_ENDPOINT_SUFFIX + ".size()", equalTo(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testUpdate() {
|
||||
// Test: update settings api
|
||||
Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<Map<String, Object>> settings = getItemList(searchBody);
|
||||
|
||||
final String newQuery = "new_query";
|
||||
for (Map<String, Object> setting : settings) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("id", setting.get("id"));
|
||||
requestBody.put(KEY_PROPERTY, setting.get(KEY_PROPERTY));
|
||||
requestBody.put("query", newQuery);
|
||||
requestBody.put("max_size", setting.get("max_size"));
|
||||
requestBody.put("boost", setting.get("boost"));
|
||||
requestBody.put("version_no", 1);
|
||||
|
||||
checkPostMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> valueList = getPropList(searchBody, "query");
|
||||
for (String value : valueList) {
|
||||
assertEquals(value, newQuery);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testDelete() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
|
||||
idList.forEach(id -> {
|
||||
//Test: delete setting api
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id).then().body("response.status", equalTo(0));
|
||||
});
|
||||
|
||||
// Test: NUMber of settings.
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearTestData() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 10);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,13 +15,7 @@
|
|||
*/
|
||||
package org.codelibs.fess.it.admin;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.fess.it.CrudTestBase;
|
||||
|
@ -30,7 +24,6 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
@Tag("it")
|
||||
public class LabelTypeTests extends CrudTestBase {
|
||||
private static final int NUM = 20;
|
||||
|
||||
private static final String NAME_PREFIX = "labelTypeTest_";
|
||||
private static final String API_PATH = "/api/admin/labeltype";
|
||||
|
@ -64,6 +57,22 @@ public class LabelTypeTests extends CrudTestBase {
|
|||
return ITEM_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> createTestParam(int id) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + id;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("value", new Integer(id).toString());
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getUpdateMap() {
|
||||
final Map<String, Object> updateMap = new HashMap<>();
|
||||
updateMap.put("value", "newValue");
|
||||
return updateMap;
|
||||
}
|
||||
|
||||
@Test
|
||||
void crudTest() {
|
||||
testCreate();
|
||||
|
@ -71,105 +80,4 @@ public class LabelTypeTests extends CrudTestBase {
|
|||
testUpdate();
|
||||
testDelete();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testCreate() {
|
||||
// Test: create setting api.
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("value", new Integer(i).toString());
|
||||
|
||||
checkPutMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.created", equalTo(true))
|
||||
.body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
// Test: number of settings.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(NUM));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testRead() {
|
||||
// Test: get settings api.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> propList = getPropList(searchBody, KEY_PROPERTY);
|
||||
|
||||
assertEquals(NUM, propList.size());
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
assertTrue(propList.contains(keyProp), keyProp);
|
||||
}
|
||||
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
// Test: get setting api
|
||||
checkGetMethod(searchBody, ITEM_ENDPOINT_SUFFIX + "/" + id).then()
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + ".id", equalTo(id))
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + "." + KEY_PROPERTY, startsWith(NAME_PREFIX));
|
||||
});
|
||||
|
||||
// Test: paging
|
||||
searchBody.put("size", 1);
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
searchBody.put("page", i + 1);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body("response." + LIST_ENDPOINT_SUFFIX + ".size()", equalTo(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testUpdate() {
|
||||
// Test: update settings api
|
||||
Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<Map<String, Object>> settings = getItemList(searchBody);
|
||||
|
||||
final String newValue = "newvalue";
|
||||
for (Map<String, Object> setting : settings) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("id", setting.get("id"));
|
||||
requestBody.put(KEY_PROPERTY, setting.get(KEY_PROPERTY));
|
||||
requestBody.put("value", newValue);
|
||||
requestBody.put("version_no", 1);
|
||||
|
||||
checkPostMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> valueList = getPropList(searchBody, "value");
|
||||
for (String value : valueList) {
|
||||
assertEquals(value, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testDelete() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
|
||||
idList.forEach(id -> {
|
||||
//Test: delete setting api
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id).then().body("response.status", equalTo(0));
|
||||
});
|
||||
|
||||
// Test: NUMber of settings.
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearTestData() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 10);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,13 +15,7 @@
|
|||
*/
|
||||
package org.codelibs.fess.it.admin;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.fess.it.CrudTestBase;
|
||||
|
@ -30,7 +24,6 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
@Tag("it")
|
||||
public class PathMapTests extends CrudTestBase {
|
||||
private static final int NUM = 20;
|
||||
|
||||
private static final String NAME_PREFIX = "pathMapTest_";
|
||||
private static final String API_PATH = "/api/admin/pathmap";
|
||||
|
@ -64,6 +57,24 @@ public class PathMapTests extends CrudTestBase {
|
|||
return ITEM_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> createTestParam(int id) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + id;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("replacement", "replacement" + id);
|
||||
requestBody.put("process_type", "C");
|
||||
requestBody.put("sort_order", id);
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getUpdateMap() {
|
||||
final Map<String, Object> updateMap = new HashMap<>();
|
||||
updateMap.put("process_type", "D");
|
||||
return updateMap;
|
||||
}
|
||||
|
||||
@Test
|
||||
void crudTest() {
|
||||
testCreate();
|
||||
|
@ -71,109 +82,4 @@ public class PathMapTests extends CrudTestBase {
|
|||
testUpdate();
|
||||
testDelete();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testCreate() {
|
||||
// Test: create setting api.
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("replacement", "replacement" + i);
|
||||
requestBody.put("process_type", "C");
|
||||
requestBody.put("sort_order", i);
|
||||
|
||||
checkPutMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.created", equalTo(true))
|
||||
.body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
// Test: number of settings.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(NUM));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testRead() {
|
||||
// Test: get settings api.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> propList = getPropList(searchBody, KEY_PROPERTY);
|
||||
|
||||
assertEquals(NUM, propList.size());
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
assertTrue(propList.contains(keyProp), keyProp);
|
||||
}
|
||||
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
// Test: get setting api
|
||||
checkGetMethod(searchBody, ITEM_ENDPOINT_SUFFIX + "/" + id).then()
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + ".id", equalTo(id))
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + "." + KEY_PROPERTY, startsWith(NAME_PREFIX));
|
||||
});
|
||||
|
||||
// Test: paging
|
||||
searchBody.put("size", 1);
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
searchBody.put("page", i + 1);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body("response." + LIST_ENDPOINT_SUFFIX + ".size()", equalTo(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testUpdate() {
|
||||
// Test: update settings api
|
||||
Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<Map<String, Object>> settings = getItemList(searchBody);
|
||||
|
||||
final String newProcessType = "D";
|
||||
for (Map<String, Object> setting : settings) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("id", setting.get("id"));
|
||||
requestBody.put(KEY_PROPERTY, setting.get(KEY_PROPERTY));
|
||||
requestBody.put("replacement", setting.get("replacement"));
|
||||
requestBody.put("process_type", newProcessType);
|
||||
requestBody.put("sort_order", setting.get("sort_order"));
|
||||
requestBody.put("version_no", 1);
|
||||
|
||||
checkPostMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> valueList = getPropList(searchBody, "process_type");
|
||||
for (String value : valueList) {
|
||||
assertEquals(value, newProcessType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testDelete() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
|
||||
idList.forEach(id -> {
|
||||
//Test: delete setting api
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id).then().body("response.status", equalTo(0));
|
||||
});
|
||||
|
||||
// Test: NUMber of settings.
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearTestData() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 10);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
122
src/test/java/org/codelibs/fess/it/admin/ReqHeaderTests.java
Normal file
122
src/test/java/org/codelibs/fess/it/admin/ReqHeaderTests.java
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Copyright 2012-2017 CodeLibs Project and the Others.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific language
|
||||
* governing permissions and limitations under the License.
|
||||
*/
|
||||
package org.codelibs.fess.it.admin;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.fess.it.CrudTestBase;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.restassured.path.json.JsonPath;
|
||||
|
||||
@Tag("it")
|
||||
public class ReqHeaderTests extends CrudTestBase {
|
||||
|
||||
private static final String NAME_PREFIX = "reqHeaderTest_";
|
||||
private static final String API_PATH = "/api/admin/reqheader";
|
||||
private static final String LIST_ENDPOINT_SUFFIX = "settings";
|
||||
private static final String ITEM_ENDPOINT_SUFFIX = "setting";
|
||||
|
||||
private static final String KEY_PROPERTY = "name";
|
||||
|
||||
@Override
|
||||
protected String getNamePrefix() {
|
||||
return NAME_PREFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getApiPath() {
|
||||
return API_PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getKeyProperty() {
|
||||
return KEY_PROPERTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getListEndpointSuffix() {
|
||||
return LIST_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getItemEndpointSuffix() {
|
||||
return ITEM_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void createWebConfig() {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("name", "test_webconfig");
|
||||
requestBody.put("urls", "http://www.example.com");
|
||||
requestBody.put("user_agent", "Mozilla/5.0");
|
||||
requestBody.put("num_of_thread", 5);
|
||||
requestBody.put("interval_time", 1000);
|
||||
requestBody.put("boost", 100.0);
|
||||
requestBody.put("available", true);
|
||||
requestBody.put("sort_order", 1);
|
||||
checkMethodBase(requestBody).put("/api/admin/webconfig/setting").then().body("response.created", equalTo(true))
|
||||
.body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
String getWebConfigId() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("name", "test_webconfig");
|
||||
String res = checkMethodBase(searchBody).get("/api/admin/webconfig/settings").asString();
|
||||
List<String> webConfigList = JsonPath.from(res).getList("response.settings.findAll {it.name.startsWith(\"test_webconfig\")}.id");
|
||||
return webConfigList.get(0);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void deleteWebConfig() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
final String webConfigId = getWebConfigId();
|
||||
checkMethodBase(searchBody).delete("/api/admin/webconfig/setting/" + webConfigId).then().body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> createTestParam(int id) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + id;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("value", "val" + id);
|
||||
requestBody.put("web_config_id", getWebConfigId());
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getUpdateMap() {
|
||||
final Map<String, Object> updateMap = new HashMap<>();
|
||||
updateMap.put("value", "new_value");
|
||||
return updateMap;
|
||||
}
|
||||
|
||||
@Test
|
||||
void crudTest() {
|
||||
testCreate();
|
||||
testRead();
|
||||
testUpdate();
|
||||
testDelete();
|
||||
}
|
||||
}
|
|
@ -15,9 +15,6 @@
|
|||
*/
|
||||
package org.codelibs.fess.it.admin;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -30,7 +27,6 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
@Tag("it")
|
||||
public class RoleTests extends CrudTestBase {
|
||||
private static final int NUM = 20;
|
||||
|
||||
private static final String NAME_PREFIX = "roleTest_";
|
||||
private static final String API_PATH = "/api/admin/role";
|
||||
|
@ -64,6 +60,33 @@ public class RoleTests extends CrudTestBase {
|
|||
return ITEM_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> createTestParam(int id) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + id;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
private static final String NEW_SUFFIX = "_new";
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getUpdateMap() {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put(KEY_PROPERTY, NAME_PREFIX + NEW_SUFFIX);
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkUpdate() {
|
||||
Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> valueList = getPropList(searchBody, KEY_PROPERTY);
|
||||
for (String value : valueList) {
|
||||
assertTrue(value.endsWith(NEW_SUFFIX));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void crudTest() {
|
||||
testCreate();
|
||||
|
@ -71,103 +94,4 @@ public class RoleTests extends CrudTestBase {
|
|||
testUpdate();
|
||||
testDelete();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testCreate() {
|
||||
// Test: create setting api.
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
|
||||
checkPutMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.created", equalTo(true))
|
||||
.body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
// Test: number of settings.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(NUM));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testRead() {
|
||||
// Test: get settings api.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> propList = getPropList(searchBody, KEY_PROPERTY);
|
||||
|
||||
assertEquals(NUM, propList.size());
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
assertTrue(propList.contains(keyProp), keyProp);
|
||||
}
|
||||
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
// Test: get setting api
|
||||
checkGetMethod(searchBody, ITEM_ENDPOINT_SUFFIX + "/" + id).then()
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + ".id", equalTo(id))
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + "." + KEY_PROPERTY, startsWith(NAME_PREFIX));
|
||||
});
|
||||
|
||||
// Test: paging
|
||||
searchBody.put("size", 1);
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
searchBody.put("page", i + 1);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body("response." + LIST_ENDPOINT_SUFFIX + ".size()", equalTo(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testUpdate() {
|
||||
// Test: update settings api
|
||||
Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<Map<String, Object>> settings = getItemList(searchBody);
|
||||
|
||||
final String newPrefix = "new_";
|
||||
for (Map<String, Object> setting : settings) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("id", setting.get("id"));
|
||||
requestBody.put(KEY_PROPERTY, newPrefix + setting.get(KEY_PROPERTY));
|
||||
requestBody.put("version_no", 1);
|
||||
|
||||
checkPostMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> valueList = getPropList(searchBody, KEY_PROPERTY);
|
||||
for (String value : valueList) {
|
||||
assertTrue(value.startsWith(newPrefix));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testDelete() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
|
||||
idList.forEach(id -> {
|
||||
//Test: delete setting api
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id).then().body("response.status", equalTo(0));
|
||||
});
|
||||
|
||||
// Test: NUMber of settings.
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearTestData() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 10);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
84
src/test/java/org/codelibs/fess/it/admin/UserTests.java
Normal file
84
src/test/java/org/codelibs/fess/it/admin/UserTests.java
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright 2012-2017 CodeLibs Project and the Others.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific language
|
||||
* governing permissions and limitations under the License.
|
||||
*/
|
||||
package org.codelibs.fess.it.admin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.fess.it.CrudTestBase;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@Tag("it")
|
||||
public class UserTests extends CrudTestBase {
|
||||
|
||||
private static final String NAME_PREFIX = "userTest_";
|
||||
private static final String API_PATH = "/api/admin/user";
|
||||
private static final String LIST_ENDPOINT_SUFFIX = "settings";
|
||||
private static final String ITEM_ENDPOINT_SUFFIX = "setting";
|
||||
|
||||
private static final String KEY_PROPERTY = "name";
|
||||
|
||||
@Override
|
||||
protected String getNamePrefix() {
|
||||
return NAME_PREFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getApiPath() {
|
||||
return API_PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getKeyProperty() {
|
||||
return KEY_PROPERTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getListEndpointSuffix() {
|
||||
return LIST_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getItemEndpointSuffix() {
|
||||
return ITEM_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> createTestParam(int id) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + id;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("password", "password" + id);
|
||||
requestBody.put("confirm_password", "password" + id);
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getUpdateMap() {
|
||||
final Map<String, Object> updateMap = new HashMap<>();
|
||||
updateMap.put("name", NAME_PREFIX + "new");
|
||||
return updateMap;
|
||||
}
|
||||
|
||||
@Test
|
||||
void crudTest() {
|
||||
testCreate();
|
||||
testRead();
|
||||
testUpdate();
|
||||
testDelete();
|
||||
}
|
||||
}
|
121
src/test/java/org/codelibs/fess/it/admin/WebAuthTests.java
Normal file
121
src/test/java/org/codelibs/fess/it/admin/WebAuthTests.java
Normal file
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* Copyright 2012-2017 CodeLibs Project and the Others.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific language
|
||||
* governing permissions and limitations under the License.
|
||||
*/
|
||||
package org.codelibs.fess.it.admin;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.fess.it.CrudTestBase;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.restassured.path.json.JsonPath;
|
||||
|
||||
@Tag("it")
|
||||
public class WebAuthTests extends CrudTestBase {
|
||||
|
||||
private static final String NAME_PREFIX = "webAuthTest_";
|
||||
private static final String API_PATH = "/api/admin/webauth";
|
||||
private static final String LIST_ENDPOINT_SUFFIX = "settings";
|
||||
private static final String ITEM_ENDPOINT_SUFFIX = "setting";
|
||||
|
||||
private static final String KEY_PROPERTY = "username";
|
||||
|
||||
@Override
|
||||
protected String getNamePrefix() {
|
||||
return NAME_PREFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getApiPath() {
|
||||
return API_PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getKeyProperty() {
|
||||
return KEY_PROPERTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getListEndpointSuffix() {
|
||||
return LIST_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getItemEndpointSuffix() {
|
||||
return ITEM_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void createWebConfig() {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("name", "test_webconfig");
|
||||
requestBody.put("urls", "http://www.example.com");
|
||||
requestBody.put("user_agent", "Mozilla/5.0");
|
||||
requestBody.put("num_of_thread", 5);
|
||||
requestBody.put("interval_time", 1000);
|
||||
requestBody.put("boost", 100.0);
|
||||
requestBody.put("available", true);
|
||||
requestBody.put("sort_order", 1);
|
||||
checkMethodBase(requestBody).put("/api/admin/webconfig/setting").then().body("response.created", equalTo(true))
|
||||
.body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
String getWebConfigId() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("name", "test_webconfig");
|
||||
String res = checkMethodBase(searchBody).get("/api/admin/webconfig/settings").asString();
|
||||
List<String> webConfigList = JsonPath.from(res).getList("response.settings.findAll {it.name.startsWith(\"test_webconfig\")}.id");
|
||||
return webConfigList.get(0);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void deleteWebConfig() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
final String webConfigId = getWebConfigId();
|
||||
checkMethodBase(searchBody).delete("/api/admin/webconfig/setting/" + webConfigId).then().body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> createTestParam(int id) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + id;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("web_config_id", getWebConfigId());
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getUpdateMap() {
|
||||
final Map<String, Object> updateMap = new HashMap<>();
|
||||
updateMap.put("parameters", "new_parameters");
|
||||
return updateMap;
|
||||
}
|
||||
|
||||
@Test
|
||||
void crudTest() {
|
||||
testCreate();
|
||||
testRead();
|
||||
testUpdate();
|
||||
testDelete();
|
||||
}
|
||||
}
|
|
@ -15,13 +15,7 @@
|
|||
*/
|
||||
package org.codelibs.fess.it.admin;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.fess.it.CrudTestBase;
|
||||
|
@ -31,8 +25,6 @@ import org.junit.jupiter.api.Test;
|
|||
@Tag("it")
|
||||
public class WebConfigTests extends CrudTestBase {
|
||||
|
||||
private static final int NUM = 20;
|
||||
|
||||
private static final String NAME_PREFIX = "webConfigTest_";
|
||||
private static final String API_PATH = "/api/admin/webconfig";
|
||||
private static final String LIST_ENDPOINT_SUFFIX = "settings";
|
||||
|
@ -65,6 +57,29 @@ public class WebConfigTests extends CrudTestBase {
|
|||
return ITEM_ENDPOINT_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> createTestParam(int id) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + id;
|
||||
final String urls = "http://" + NAME_PREFIX + id;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("urls", urls);
|
||||
requestBody.put("user_agent", "Mozilla/5.0");
|
||||
requestBody.put("num_of_thread", 5);
|
||||
requestBody.put("interval_time", 1000);
|
||||
requestBody.put("boost", id);
|
||||
requestBody.put("available", true);
|
||||
requestBody.put("sort_order", id);
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getUpdateMap() {
|
||||
final Map<String, Object> updateMap = new HashMap<>();
|
||||
updateMap.put("urls", "http://new." + NAME_PREFIX);
|
||||
return updateMap;
|
||||
}
|
||||
|
||||
@Test
|
||||
void crudTest() {
|
||||
testCreate();
|
||||
|
@ -72,119 +87,4 @@ public class WebConfigTests extends CrudTestBase {
|
|||
testUpdate();
|
||||
testDelete();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testCreate() {
|
||||
// Test: create setting api.
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
final String keyProp = NAME_PREFIX + i;
|
||||
final String urls = "http://" + NAME_PREFIX + i;
|
||||
requestBody.put(KEY_PROPERTY, keyProp);
|
||||
requestBody.put("urls", urls);
|
||||
requestBody.put("user_agent", "Mozilla/5.0");
|
||||
requestBody.put("num_of_thread", 5);
|
||||
requestBody.put("interval_time", 1000);
|
||||
requestBody.put("boost", i);
|
||||
requestBody.put("available", true);
|
||||
requestBody.put("sort_order", i);
|
||||
|
||||
checkPutMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.created", equalTo(true))
|
||||
.body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
// Test: number of settings.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(NUM));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testRead() {
|
||||
// Test: get settings api.
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> propList = getPropList(searchBody, KEY_PROPERTY);
|
||||
|
||||
assertEquals(NUM, propList.size());
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
final String prop = NAME_PREFIX + i;
|
||||
assertTrue(propList.contains(prop), prop);
|
||||
}
|
||||
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
// Test: get setting api
|
||||
checkGetMethod(searchBody, ITEM_ENDPOINT_SUFFIX + "/" + id).then()
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + ".id", equalTo(id))
|
||||
.body("response." + ITEM_ENDPOINT_SUFFIX + "." + KEY_PROPERTY, startsWith(NAME_PREFIX));
|
||||
});
|
||||
|
||||
// Test: paging
|
||||
searchBody.put("size", 1);
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
searchBody.put("page", i + 1);
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body("response." + LIST_ENDPOINT_SUFFIX + ".size()", equalTo(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testUpdate() {
|
||||
// Test: update settings api
|
||||
Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<Map<String, Object>> settings = getItemList(searchBody);
|
||||
|
||||
final String newUrls = "http://new." + NAME_PREFIX;
|
||||
for (Map<String, Object> setting : settings) {
|
||||
final Map<String, Object> requestBody = new HashMap<>();
|
||||
|
||||
requestBody.put("id", setting.get("id"));
|
||||
requestBody.put(KEY_PROPERTY, setting.get(KEY_PROPERTY));
|
||||
requestBody.put("urls", newUrls);
|
||||
requestBody.put("user_agent", setting.get("user_agent"));
|
||||
requestBody.put("num_of_thread", setting.get("num_of_thread"));
|
||||
requestBody.put("interval_time", setting.get("interval_time"));
|
||||
requestBody.put("boost", setting.get("boost"));
|
||||
requestBody.put("available", true);
|
||||
requestBody.put("sort_order", setting.get("sort_order"));
|
||||
requestBody.put("version_no", 1);
|
||||
|
||||
checkPostMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.status", equalTo(0));
|
||||
}
|
||||
|
||||
searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> valList = getPropList(searchBody, "urls");
|
||||
for (String val : valList) {
|
||||
assertEquals(val, newUrls);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testDelete() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 2);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
|
||||
idList.forEach(id -> {
|
||||
//Test: delete setting api
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id).then().body("response.status", equalTo(0));
|
||||
});
|
||||
|
||||
// Test: NUMber of settings.
|
||||
checkGetMethod(searchBody, LIST_ENDPOINT_SUFFIX).then().body(getJsonPath() + ".size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearTestData() {
|
||||
final Map<String, Object> searchBody = new HashMap<>();
|
||||
searchBody.put("size", NUM * 10);
|
||||
List<String> idList = getPropList(searchBody, "id");
|
||||
idList.forEach(id -> {
|
||||
checkDeleteMethod(ITEM_ENDPOINT_SUFFIX + "/" + id);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue