Merge pull request #1061 from kw-udon/integration-test-May-20

Add Integration Tests (#1033, #1034)
This commit is contained in:
Shinsuke Sugaya 2017-05-21 15:48:15 +09:00 committed by GitHub
commit 34081f6fb3
12 changed files with 392 additions and 35 deletions

View file

@ -52,7 +52,6 @@ public class CreateForm {
@ValidateTypeFailure
public Float boost;
@Required
@Size(max = 255)
public String createdBy;

View file

@ -57,6 +57,8 @@ public class ApiAdminKeymatchAction extends FessApiAdminAction {
public JsonResponse<ApiResult> settings(final SearchBody body) {
validateApi(body, messages -> {});
final KeyMatchPager pager = new KeyMatchPager();
pager.setPageSize(body.size);
pager.setCurrentPageNumber(body.page);
copyBeanToBean(body, pager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
final List<KeyMatch> list = keyMatchService.getKeyMatchList(pager);
return asJson(new ApiResult.ApiConfigsResponse<EditBody>()

View file

@ -15,8 +15,8 @@
*/
package org.codelibs.fess.app.web.api.admin.keymatch;
import org.codelibs.fess.app.web.admin.keymatch.SearchForm;
import org.codelibs.fess.app.web.api.admin.BaseSearchBody;
public class SearchBody extends SearchForm {
public class SearchBody extends BaseSearchBody {
}

View file

@ -57,6 +57,8 @@ public class ApiAdminLabeltypeAction extends FessApiAdminAction {
public JsonResponse<ApiResult> settings(final SearchBody body) {
validateApi(body, messages -> {});
final LabelTypePager pager = new LabelTypePager();
pager.setPageSize(body.size);
pager.setCurrentPageNumber(body.page);
copyBeanToBean(body, pager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
final List<LabelType> list = labelTypeService.getLabelTypeList(pager);
return asJson(new ApiResult.ApiConfigsResponse<EditBody>()

View file

@ -15,8 +15,8 @@
*/
package org.codelibs.fess.app.web.api.admin.labeltype;
import org.codelibs.fess.app.web.admin.labeltype.SearchForm;
import org.codelibs.fess.app.web.api.admin.BaseSearchBody;
public class SearchBody extends SearchForm {
public class SearchBody extends BaseSearchBody {
}

View file

@ -84,9 +84,9 @@ public class AccessTokenTests extends CrudTestBase {
protected void testCreate() {
// Test: create setting api.
for (int i = 0; i < NUM; i++) {
final String name = NAME_PREFIX + i;
final String keyProp = NAME_PREFIX + i;
final Map<String, Object> requestBody = new HashMap<>();
requestBody.put("name", name);
requestBody.put(KEY_PROPERTY, keyProp);
requestBody.put("permissions", "Radmin-api");
checkPutMethod(requestBody, ITEM_ENDPOINT_SUFFIX).then().body("response.created", equalTo(true))
@ -104,12 +104,12 @@ public class AccessTokenTests extends CrudTestBase {
// Test: get settings api.
final Map<String, Object> searchBody = new HashMap<>();
searchBody.put("size", NUM * 2);
List<String> nameList = getPropList(searchBody, "name");
assertEquals(NUM, nameList.size());
List<String> propList = getPropList(searchBody, KEY_PROPERTY);
assertEquals(NUM, propList.size());
for (int i = 0; i < NUM; i++) {
final String name = NAME_PREFIX + i;
assertTrue(nameList.contains(name), name);
final String prop = NAME_PREFIX + i;
assertTrue(propList.contains(prop), prop);
}
List<String> idList = getPropList(searchBody, "id");
@ -117,7 +117,7 @@ public class AccessTokenTests extends CrudTestBase {
// Test: get setting api
checkGetMethod(searchBody, ITEM_ENDPOINT_SUFFIX + "/" + id).then()
.body("response." + ITEM_ENDPOINT_SUFFIX + ".id", equalTo(id))
.body("response." + ITEM_ENDPOINT_SUFFIX + ".name", startsWith(NAME_PREFIX))
.body("response." + ITEM_ENDPOINT_SUFFIX + "." + KEY_PROPERTY, startsWith(NAME_PREFIX))
.body("response." + ITEM_ENDPOINT_SUFFIX + ".token.length()", greaterThan(0));
});
@ -140,7 +140,7 @@ public class AccessTokenTests extends CrudTestBase {
for (Map<String, Object> setting : settings) {
final Map<String, Object> requestBody = new HashMap<>();
requestBody.put("id", setting.get("id"));
requestBody.put("name", setting.get("name"));
requestBody.put(KEY_PROPERTY, setting.get(KEY_PROPERTY));
requestBody.put("permissions", newPermission);
requestBody.put("version_no", 1);

View file

@ -78,8 +78,8 @@ public class BoostDocTests extends CrudTestBase {
// Test: create setting api.
for (int i = 0; i < NUM; i++) {
final Map<String, Object> requestBody = new HashMap<>();
final String url_expr = NAME_PREFIX + i;
requestBody.put("url_expr", url_expr);
final String keyProp = NAME_PREFIX + i;
requestBody.put(KEY_PROPERTY, keyProp);
requestBody.put("boost_expr", new Integer(i).toString());
requestBody.put("sort_order", i);
@ -98,7 +98,7 @@ public class BoostDocTests extends CrudTestBase {
// Test: get settings api.
final Map<String, Object> searchBody = new HashMap<>();
searchBody.put("size", NUM * 2);
List<String> nameList = getPropList(searchBody, "url_expr");
List<String> nameList = getPropList(searchBody, KEY_PROPERTY);
assertEquals(NUM, nameList.size());
for (int i = 0; i < NUM; i++) {
@ -111,7 +111,7 @@ public class BoostDocTests extends CrudTestBase {
// Test: get setting api
checkGetMethod(searchBody, ITEM_ENDPOINT_SUFFIX + "/" + id).then()
.body("response." + ITEM_ENDPOINT_SUFFIX + ".id", equalTo(id))
.body("response." + ITEM_ENDPOINT_SUFFIX + ".url_expr", startsWith(NAME_PREFIX));
.body("response." + ITEM_ENDPOINT_SUFFIX + "." + KEY_PROPERTY, startsWith(NAME_PREFIX));
});
// Test: paging
@ -134,7 +134,7 @@ public class BoostDocTests extends CrudTestBase {
for (Map<String, Object> setting : settings) {
final Map<String, Object> requestBody = new HashMap<>();
requestBody.put("id", setting.get("id"));
requestBody.put("url_expr", setting.get("url_expr"));
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);

View file

@ -78,9 +78,9 @@ public class DataConfigTests extends CrudTestBase {
// Test: create setting api.
for (int i = 0; i < NUM; i++) {
final Map<String, Object> requestBody = new HashMap<>();
final String name = NAME_PREFIX + i;
final String keyProp = NAME_PREFIX + i;
requestBody.put(KEY_PROPERTY, keyProp);
final String handlerName = "DatabaseDataStore";
requestBody.put("name", name);
requestBody.put("handler_name", handlerName);
requestBody.put("boost", i);
requestBody.put("available", true);
@ -137,7 +137,7 @@ public class DataConfigTests extends CrudTestBase {
for (Map<String, Object> setting : settings) {
final Map<String, Object> requestBody = new HashMap<>();
requestBody.put("id", setting.get("id"));
requestBody.put("name", setting.get("name"));
requestBody.put(KEY_PROPERTY, setting.get(KEY_PROPERTY));
requestBody.put("handler_name", newHandlerName);
requestBody.put("boost", setting.get("boost"));
requestBody.put("available", true);

View file

@ -78,9 +78,9 @@ public class FileConfigTests extends CrudTestBase {
// Test: create setting api.
for (int i = 0; i < NUM; i++) {
final Map<String, Object> requestBody = new HashMap<>();
final String name = NAME_PREFIX + i;
final String keyProp = NAME_PREFIX + i;
final String paths = "file:///" + NAME_PREFIX + i;
requestBody.put("name", name);
requestBody.put(KEY_PROPERTY, keyProp);
requestBody.put("paths", paths);
requestBody.put("num_of_thread", 5);
requestBody.put("interval_time", 1000);
@ -103,12 +103,12 @@ public class FileConfigTests extends CrudTestBase {
// Test: get settings api.
final Map<String, Object> searchBody = new HashMap<>();
searchBody.put("size", NUM * 2);
List<String> nameList = getPropList(searchBody, KEY_PROPERTY);
List<String> propList = getPropList(searchBody, KEY_PROPERTY);
assertEquals(NUM, nameList.size());
assertEquals(NUM, propList.size());
for (int i = 0; i < NUM; i++) {
final String name = NAME_PREFIX + i;
assertTrue(nameList.contains(name), name);
final String prop = NAME_PREFIX + i;
assertTrue(propList.contains(prop), prop);
}
List<String> idList = getPropList(searchBody, "id");
@ -140,7 +140,7 @@ public class FileConfigTests extends CrudTestBase {
final Map<String, Object> requestBody = new HashMap<>();
requestBody.put("id", setting.get("id"));
requestBody.put("name", setting.get("name"));
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"));

View file

@ -0,0 +1,179 @@
/*
* 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 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;
import org.junit.jupiter.api.Tag;
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";
private static final String LIST_ENDPOINT_SUFFIX = "settings";
private static final String ITEM_ENDPOINT_SUFFIX = "setting";
private static final String KEY_PROPERTY = "term";
@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;
}
@Test
void crudTest() {
testCreate();
testRead();
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);
});
}
}

View file

@ -0,0 +1,175 @@
/*
* 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 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;
import org.junit.jupiter.api.Tag;
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";
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;
}
@Test
void crudTest() {
testCreate();
testRead();
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);
});
}
}

View file

@ -78,9 +78,9 @@ public class WebConfigTests extends CrudTestBase {
// Test: create setting api.
for (int i = 0; i < NUM; i++) {
final Map<String, Object> requestBody = new HashMap<>();
final String name = NAME_PREFIX + i;
final String keyProp = NAME_PREFIX + i;
final String urls = "http://" + NAME_PREFIX + i;
requestBody.put("name", name);
requestBody.put(KEY_PROPERTY, keyProp);
requestBody.put("urls", urls);
requestBody.put("user_agent", "Mozilla/5.0");
requestBody.put("num_of_thread", 5);
@ -104,12 +104,12 @@ public class WebConfigTests extends CrudTestBase {
// Test: get settings api.
final Map<String, Object> searchBody = new HashMap<>();
searchBody.put("size", NUM * 2);
List<String> nameList = getPropList(searchBody, KEY_PROPERTY);
List<String> propList = getPropList(searchBody, KEY_PROPERTY);
assertEquals(NUM, nameList.size());
assertEquals(NUM, propList.size());
for (int i = 0; i < NUM; i++) {
final String name = NAME_PREFIX + i;
assertTrue(nameList.contains(name), name);
final String prop = NAME_PREFIX + i;
assertTrue(propList.contains(prop), prop);
}
List<String> idList = getPropList(searchBody, "id");
@ -141,7 +141,7 @@ public class WebConfigTests extends CrudTestBase {
final Map<String, Object> requestBody = new HashMap<>();
requestBody.put("id", setting.get("id"));
requestBody.put("name", setting.get("name"));
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"));