Merge pull request #1110 from kw-udon/add-integration-tests-Jun-17

Add Integration Tests
This commit is contained in:
Shinsuke Sugaya 2017-06-17 22:21:33 +09:00 committed by GitHub
commit 1fd3918663
14 changed files with 760 additions and 51 deletions

View file

@ -118,6 +118,7 @@ public class ApiResult {
public ApiConfigsResponse<T> settings(final List<T> settings) {
this.settings = settings;
this.total = settings.size();
return this;
}

View file

@ -36,6 +36,8 @@ import org.codelibs.fess.app.service.BadWordService;
import org.codelibs.fess.app.web.CrudMode;
import org.codelibs.fess.app.web.admin.badword.UploadForm;
import org.codelibs.fess.app.web.api.ApiResult;
import org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse;
import org.codelibs.fess.app.web.api.ApiResult.Status;
import org.codelibs.fess.app.web.api.admin.FessApiAdminAction;
import org.codelibs.fess.es.config.exentity.BadWord;
import org.codelibs.fess.exception.FessSystemException;
@ -52,8 +54,8 @@ public class ApiAdminBadwordAction extends FessApiAdminAction {
@Resource
protected SuggestHelper suggestHelper;
// GET /api/admin/badword
// POST /api/admin/badword
// GET /api/admin/badword/settings
// POST /api/admin/badword/settings
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
validateApi(body, messages -> {});
@ -64,6 +66,19 @@ public class ApiAdminBadwordAction extends FessApiAdminAction {
.total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
}
// GET /api/admin/badword/{id}
@Execute
public JsonResponse<ApiResult> get$setting(final String id) {
final BadWord entity = badWordService.getBadWord(id).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
return null;
});
final EditBody body = createEditBody(entity);
return asJson(new ApiResult.ApiConfigResponse().setting(body).status(ApiResult.Status.OK).result());
}
// PUT /api/admin/badword/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
@ -89,19 +104,20 @@ public class ApiAdminBadwordAction extends FessApiAdminAction {
public JsonResponse<ApiResult> post$setting(final EditBody body) {
validateApi(body, messages -> {});
body.crudMode = CrudMode.EDIT;
final BadWord entity = getBadWord(body).orElseGet(() -> {
throwValidationErrorApi(messages -> {
messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id);
});
final BadWord badWord = getBadWord(body).map(entity -> {
try {
badWordService.store(entity);
suggestHelper.storeAllBadWords();
} catch (final Exception e) {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
}
return entity;
}).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id));
return null;
});
try {
badWordService.store(entity);
suggestHelper.storeAllBadWords();
} catch (final Exception e) {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
}
return asJson(new ApiResult.ApiUpdateResponse().id(entity.getId()).created(false).status(ApiResult.Status.OK).result());
return asJson(new ApiUpdateResponse().id(badWord.getId()).created(false).status(Status.OK).result());
}
// DELETE /api/admin/badword/setting/{id}
@ -163,13 +179,9 @@ public class ApiAdminBadwordAction extends FessApiAdminAction {
protected EditBody createEditBody(final BadWord entity) {
final EditBody body = new EditBody();
body.id = entity.getId();
body.versionNo = entity.getVersionNo();
body.createdBy = entity.getCreatedBy();
body.createdTime = entity.getCreatedTime();
body.suggestWord = entity.getSuggestWord();
body.updatedBy = entity.getUpdatedBy();
body.updatedTime = entity.getUpdatedTime();
copyBeanToBean(entity, body, copyOp -> {
copyOp.excludeNull();
});
return body;
}

View file

@ -33,10 +33,8 @@ public class ApiAdminDictAction extends FessApiAdminAction {
protected DictionaryManager dictionaryManager;
// GET /api/admin/dict
// POST /api/admin/dict
@Execute
public JsonResponse<ApiResult> settings(final ListBody body) {
validateApi(body, messages -> {});
public JsonResponse<ApiResult> get$index() {
final DictionaryFile<? extends DictionaryItem>[] dictFiles = dictionaryManager.getDictionaryFiles();
return asJson(new ApiResult.ApiConfigsResponse<ListBody>()
.settings(Stream.of(dictFiles).map(dictionaryFile -> createListBody(dictionaryFile)).collect(Collectors.toList()))

View file

@ -38,6 +38,8 @@ import org.codelibs.fess.app.service.ElevateWordService;
import org.codelibs.fess.app.web.CrudMode;
import org.codelibs.fess.app.web.admin.elevateword.UploadForm;
import org.codelibs.fess.app.web.api.ApiResult;
import org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse;
import org.codelibs.fess.app.web.api.ApiResult.Status;
import org.codelibs.fess.app.web.api.admin.FessApiAdminAction;
import org.codelibs.fess.es.config.exentity.ElevateWord;
import org.codelibs.fess.exception.FessSystemException;
@ -112,20 +114,21 @@ public class ApiAdminElevatewordAction extends FessApiAdminAction {
public JsonResponse<ApiResult> post$setting(final EditBody body) {
validateApi(body, messages -> {});
body.crudMode = CrudMode.EDIT;
final ElevateWord entity = getElevateWord(body).orElseGet(() -> {
throwValidationErrorApi(messages -> {
messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id);
});
final ElevateWord elevateWord = getElevateWord(body).map(entity -> {
try {
elevateWordService.store(entity);
suggestHelper.deleteAllElevateWord();
suggestHelper.storeAllElevateWords();
} catch (final Exception e) {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
}
return entity;
}).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id));
return null;
});
try {
elevateWordService.store(entity);
suggestHelper.deleteAllElevateWord();
suggestHelper.storeAllElevateWords();
} catch (final Exception e) {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
}
return asJson(new ApiResult.ApiUpdateResponse().id(entity.getId()).created(false).status(ApiResult.Status.OK).result());
return asJson(new ApiUpdateResponse().id(elevateWord.getId()).created(false).status(Status.OK).result());
}
// DELETE /api/admin/elevateword/setting/{id}
@ -187,21 +190,14 @@ public class ApiAdminElevatewordAction extends FessApiAdminAction {
protected EditBody createEditBody(final ElevateWord entity) {
final EditBody body = new EditBody();
body.id = entity.getId();
body.versionNo = entity.getVersionNo();
body.createdBy = entity.getCreatedBy();
body.createdTime = entity.getCreatedTime();
body.suggestWord = entity.getSuggestWord();
body.updatedBy = entity.getUpdatedBy();
body.updatedTime = entity.getUpdatedTime();
body.labelTypeIds = entity.getLabelTypeIds();
copyBeanToBean(entity, body, copyOp -> {
copyOp.excludeNull();
});
final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
body.permissions =
stream(entity.getPermissions()).get(
stream -> stream.map(s -> permissionHelper.decode(s)).filter(StringUtil::isNotBlank).distinct()
.collect(Collectors.joining("\n")));
body.targetLabel = entity.getTargetLabel();
body.reading = entity.getReading();
return body;
}

View file

@ -37,9 +37,9 @@ public class ApiAdminSysteminfoAction extends FessApiAdminAction {
// Search Execute
// ==============
// GET /api/admin/systeminfo/info
// GET /api/admin/systeminfo
@Execute
public JsonResponse<ApiResult> info() {
public JsonResponse<ApiResult> get$index() {
final List<Map<String, String>> bugReportItems = getBugReportItems();
final List<Map<String, String>> envItems = getEnvItems();
final List<Map<String, String>> fessPropItems = getFessPropItems();

View file

@ -61,17 +61,17 @@ public abstract class CrudTestBase extends ITBase {
// ================
@BeforeAll
static void initAll() {
protected static void initAll() {
RestAssured.baseURI = getFessUrl();
settingTestToken();
}
@BeforeEach
void init() {
protected void init() {
}
@AfterEach
void tearDown() {
protected void tearDown() {
final Map<String, Object> searchBody = new HashMap<>();
searchBody.put("size", NUM * 10);
List<String> idList = getPropList(searchBody, "id");
@ -81,7 +81,7 @@ public abstract class CrudTestBase extends ITBase {
}
@AfterAll
static void tearDownAll() {
protected static void tearDownAll() {
deleteTestToken();
}

View file

@ -0,0 +1,82 @@
/*
* 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 BadWordTests extends CrudTestBase {
private static final String NAME_PREFIX = "badWordTest_";
private static final String API_PATH = "/api/admin/badword";
private static final String LIST_ENDPOINT_SUFFIX = "settings";
private static final String ITEM_ENDPOINT_SUFFIX = "setting";
private static final String KEY_PROPERTY = "suggest_word";
@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);
return requestBody;
}
@Override
protected Map<String, Object> getUpdateMap() {
final Map<String, Object> updateMap = new HashMap<>();
updateMap.put(KEY_PROPERTY, NAME_PREFIX + "new");
return updateMap;
}
@Test
void crudTest() {
testCreate();
testRead();
testUpdate();
testDelete();
}
}

View file

@ -0,0 +1,83 @@
/*
* 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 ElevateWordTests extends CrudTestBase {
private static final String NAME_PREFIX = "elevateWordTest_";
private static final String API_PATH = "/api/admin/elevateword";
private static final String LIST_ENDPOINT_SUFFIX = "settings";
private static final String ITEM_ENDPOINT_SUFFIX = "setting";
private static final String KEY_PROPERTY = "suggest_word";
@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("boost", id);
return requestBody;
}
@Override
protected Map<String, Object> getUpdateMap() {
final Map<String, Object> updateMap = new HashMap<>();
updateMap.put(KEY_PROPERTY, NAME_PREFIX + "new");
return updateMap;
}
@Test
void crudTest() {
testCreate();
testRead();
testUpdate();
testDelete();
}
}

View file

@ -0,0 +1,95 @@
/*
* 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.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
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;
import io.restassured.path.json.JsonPath;
@Tag("it")
public class GeneralTests extends CrudTestBase {
private static final String NAME_PREFIX = "generalTest_";
private static final String API_PATH = "/api/admin/general";
private static final String LIST_ENDPOINT_SUFFIX = "";
private static final String ITEM_ENDPOINT_SUFFIX = "";
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) {
assertTrue(false); // Unreachable
return null;
}
@Override
protected Map<String, Object> getUpdateMap() {
assertTrue(false); // Unreachable
return null;
}
@Override
protected void testRead() {
final Map<String, Object> searchBody = new HashMap<>();
String response = checkGetMethod(searchBody, "").asString();
final Map<String, Object> res = JsonPath.from(response).getMap("response.setting");
assertTrue(!res.isEmpty());
assertEquals(new Integer(0), JsonPath.from(response).get("response.status"));
}
@Override
protected void tearDown() {
// do nothing
}
@Test
void crudTest() {
testRead();
}
}

View file

@ -0,0 +1,85 @@
/*
* 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 SchedulerTests extends CrudTestBase {
private static final String NAME_PREFIX = "schedulerTest_";
private static final String API_PATH = "/api/admin/scheduler";
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("target", "target" + id);
requestBody.put("script_type", "script" + id);
requestBody.put("sort_order", id);
return requestBody;
}
@Override
protected Map<String, Object> getUpdateMap() {
final Map<String, Object> updateMap = new HashMap<>();
updateMap.put("target", "new_target");
return updateMap;
}
@Test
void crudTest() {
testCreate();
testRead();
testUpdate();
testDelete();
}
}

View file

@ -0,0 +1,97 @@
/*
* 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.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
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;
import io.restassured.path.json.JsonPath;
@Tag("it")
public class SuggestTests extends CrudTestBase {
private static final String NAME_PREFIX = "";
private static final String API_PATH = "/api/admin/suggest";
private static final String LIST_ENDPOINT_SUFFIX = "";
private static final String ITEM_ENDPOINT_SUFFIX = "";
private static final String KEY_PROPERTY = "";
@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) {
assertTrue(false); // Unreachable
return null;
}
@Override
protected Map<String, Object> getUpdateMap() {
assertTrue(false); // Unreachable
return null;
}
@Override
protected void testRead() {
final Map<String, Object> searchBody = new HashMap<>();
String response = checkGetMethod(searchBody, "").asString();
final Map<String, Object> res = JsonPath.from(response).getMap("response.setting");
assertTrue(res.containsKey("total_words_num"));
assertTrue(res.containsKey("document_words_num"));
assertTrue(res.containsKey("query_words_num"));
assertEquals(new Integer(0), JsonPath.from(response).get("response.status"));
}
@Override
protected void tearDown() {
// do nothing
}
@Test
void crudTest() {
testRead();
}
}

View file

@ -0,0 +1,98 @@
/*
* 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.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
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;
import io.restassured.path.json.JsonPath;
@Tag("it")
public class SystemInfoTests extends CrudTestBase {
private static final String NAME_PREFIX = "systemInfoTest_";
private static final String API_PATH = "/api/admin/systeminfo";
private static final String LIST_ENDPOINT_SUFFIX = "";
private static final String ITEM_ENDPOINT_SUFFIX = "";
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) {
assertTrue(false); // Unreachable
return null;
}
@Override
protected Map<String, Object> getUpdateMap() {
assertTrue(false); // Unreachable
return null;
}
@Override
protected void testRead() {
final Map<String, Object> searchBody = new HashMap<>();
String response = checkGetMethod(searchBody, "").asString();
final Map<String, Object> res = JsonPath.from(response).getMap("response");
assertTrue(res.containsKey("env_props"));
assertTrue(res.containsKey("system_props"));
assertTrue(res.containsKey("fess_props"));
assertTrue(res.containsKey("bug_report_props"));
assertEquals(new Integer(0), JsonPath.from(response).get("response.status"));
}
@Override
protected void tearDown() {
// do nothing
}
@Test
void crudTest() {
testRead();
}
}

View file

@ -0,0 +1,64 @@
/*
* 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.dict;
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;
import org.junit.jupiter.api.BeforeEach;
import io.restassured.path.json.JsonPath;
public abstract class DictCrudTestBase extends CrudTestBase {
protected String dictId;
abstract protected String getDictType();
private static final String LIST_ENDPOINT_SUFFIX = "settings";
private static final String ITEM_ENDPOINT_SUFFIX = "setting";
@Override
protected String getListEndpointSuffix() {
return LIST_ENDPOINT_SUFFIX + "/" + dictId;
}
@Override
protected String getItemEndpointSuffix() {
return ITEM_ENDPOINT_SUFFIX + "/" + dictId;
}
@BeforeEach
protected void initializeDictId() {
final Map<String, Object> searchBody = new HashMap<>();
final String response = checkMethodBase(searchBody).get("/api/admin/dict").asString();
final List<Map<String, String>> dicts = JsonPath.from(response).getList("response.settings");
for (Map<String, String> item : dicts) {
assertTrue(item.containsKey("id"));
assertTrue(item.containsKey("type"));
if (getDictType().equals(item.get("type"))) {
dictId = item.get("id");
return;
}
}
assertTrue(false);
}
}

View file

@ -0,0 +1,98 @@
/*
* 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.dict;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
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;
import io.restassured.path.json.JsonPath;
@Tag("it")
public class DictTests extends CrudTestBase {
private static final String NAME_PREFIX = "dictTest_";
private static final String API_PATH = "/api/admin/dict";
private static final String LIST_ENDPOINT_SUFFIX = "";
private static final String ITEM_ENDPOINT_SUFFIX = "";
private static final String KEY_PROPERTY = "";
@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) {
assertTrue(false); // Unreachable
return null;
}
@Override
protected Map<String, Object> getUpdateMap() {
assertTrue(false); // Unreachable
return null;
}
@Override
protected void testRead() {
final Map<String, Object> searchBody = new HashMap<>();
String response = checkGetMethod(searchBody, "").asString();
final int total = JsonPath.from(response).getInt("response.total");
final List<Map<String, String>> dicts = JsonPath.from(response).getList("response.settings");
final int status = JsonPath.from(response).getInt("response.status");
assertEquals(total, dicts.size());
assertEquals(0, status);
}
@Override
protected void tearDown() {
// do nothing
}
@Test
void crudTest() {
testRead();
}
}