diff --git a/src/test/java/org/codelibs/fess/it/admin/BackupTests.java b/src/test/java/org/codelibs/fess/it/admin/BackupTests.java new file mode 100644 index 0000000000..a9440ecafb --- /dev/null +++ b/src/test/java/org/codelibs/fess/it/admin/BackupTests.java @@ -0,0 +1,93 @@ +/* + * Copyright 2012-2018 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 BackupTests extends CrudTestBase { + + private static final String NAME_PREFIX = "backupTest_"; + private static final String API_PATH = "/api/admin/backup"; + private static final String LIST_ENDPOINT_SUFFIX = "files"; + private static final String ITEM_ENDPOINT_SUFFIX = "file"; + + 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 createTestParam(int id) { + assertTrue(false); // Unreachable + return null; + } + + @Override + protected Map getUpdateMap() { + assertTrue(false); // Unreachable + return null; + } + + @Override + protected void testRead() { + final Map searchBody = new HashMap<>(); + final String response = checkMethodBase(searchBody).get(API_PATH + "/" + LIST_ENDPOINT_SUFFIX).asString(); + assertEquals(new Integer(0), JsonPath.from(response).get("response.status")); + } + + @Override + protected void tearDown() { + // do nothing + } + + @Test + void crudTest() { + testRead(); + } +} \ No newline at end of file diff --git a/src/test/java/org/codelibs/fess/it/admin/JobLogTests.java b/src/test/java/org/codelibs/fess/it/admin/JobLogTests.java new file mode 100644 index 0000000000..8d039deb9b --- /dev/null +++ b/src/test/java/org/codelibs/fess/it/admin/JobLogTests.java @@ -0,0 +1,93 @@ +/* + * Copyright 2012-2018 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 JobLogTests extends CrudTestBase { + + private static final String NAME_PREFIX = "joblogTest_"; + private static final String API_PATH = "/api/admin/joblog"; + private static final String LIST_ENDPOINT_SUFFIX = "logs"; + private static final String ITEM_ENDPOINT_SUFFIX = "log"; + + 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 createTestParam(int id) { + assertTrue(false); // Unreachable + return null; + } + + @Override + protected Map getUpdateMap() { + assertTrue(false); // Unreachable + return null; + } + + @Override + protected void testRead() { + final Map searchBody = new HashMap<>(); + final String response = checkMethodBase(searchBody).get(API_PATH + "/" + LIST_ENDPOINT_SUFFIX).asString(); + assertEquals(new Integer(0), JsonPath.from(response).get("response.status")); + } + + @Override + protected void tearDown() { + // do nothing + } + + @Test + void crudTest() { + testRead(); + } +} \ No newline at end of file diff --git a/src/test/java/org/codelibs/fess/it/admin/LogTests.java b/src/test/java/org/codelibs/fess/it/admin/LogTests.java new file mode 100644 index 0000000000..6efd072b4d --- /dev/null +++ b/src/test/java/org/codelibs/fess/it/admin/LogTests.java @@ -0,0 +1,93 @@ +/* + * Copyright 2012-2018 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 LogTests extends CrudTestBase { + + private static final String NAME_PREFIX = "logTest_"; + private static final String API_PATH = "/api/admin/log"; + private static final String LIST_ENDPOINT_SUFFIX = "files"; + private static final String ITEM_ENDPOINT_SUFFIX = "file"; + + 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 createTestParam(int id) { + assertTrue(false); // Unreachable + return null; + } + + @Override + protected Map getUpdateMap() { + assertTrue(false); // Unreachable + return null; + } + + @Override + protected void testRead() { + final Map searchBody = new HashMap<>(); + final String response = checkMethodBase(searchBody).get(API_PATH + "/" + LIST_ENDPOINT_SUFFIX).asString(); + assertEquals(new Integer(0), JsonPath.from(response).get("response.status")); + } + + @Override + protected void tearDown() { + // do nothing + } + + @Test + void crudTest() { + testRead(); + } +} \ No newline at end of file diff --git a/src/test/java/org/codelibs/fess/it/admin/SearchListTests.java b/src/test/java/org/codelibs/fess/it/admin/SearchListTests.java index b97e8b45d4..edad05fe8e 100644 --- a/src/test/java/org/codelibs/fess/it/admin/SearchListTests.java +++ b/src/test/java/org/codelibs/fess/it/admin/SearchListTests.java @@ -16,14 +16,19 @@ package org.codelibs.fess.it.admin; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.hamcrest.Matchers.equalTo; import java.util.HashMap; import java.util.Map; +import java.util.List; +import java.util.Set; 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 SearchListTests extends CrudTestBase { @@ -66,15 +71,13 @@ protected String getIdKey() { @Override protected Map createTestParam(int id) { - + final Map requestBody = new HashMap<>(); final Map doc = new HashMap<>(); final String keyProp = NAME_PREFIX + id; doc.put(KEY_PROPERTY, keyProp); doc.put("url", "http://example.com/" + id); doc.put("boost", id); doc.put("role", "Rguest"); - - final Map requestBody = new HashMap<>(); requestBody.put("doc", doc); return requestBody; } @@ -89,19 +92,58 @@ protected Map createSearchBody(final int size) { @Override protected Map getUpdateMap() { - // TODO - assertTrue(false); - final Map updateMap = new HashMap<>(); - updateMap.put("click_count", 100); +// updateMap.put("click_count", 100); return updateMap; } + @Override + protected void testUpdate() { + + // Test: update settings api + final Map updateMap = getUpdateMap(); + final Map searchBody = createSearchBody(SEARCH_ALL_NUM); + List> settings = getItemList(searchBody); + + for (Map setting : settings) { + final Map requestBody = new HashMap<>(updateMap); + final String idKey = getIdKey(); + + requestBody.put("version", 1); + requestBody.put("crud_mode", 2); + + if (setting.containsKey(idKey)) { + requestBody.put(idKey, setting.get(idKey)); + } + + final Map doc = new HashMap<>(); + doc.put("doc_id", setting.get("doc_id")); + doc.put("url", setting.get("url_link")); + doc.put("title", setting.get("title")); + doc.put("role", "Rguest"); + doc.put("boost", setting.get("boost")); + // doc.put("click_count", 100); // Validation Error + requestBody.put("doc", doc); + + checkPostMethod(requestBody, getItemEndpointSuffix()).then().body("response.status", equalTo(0)); + refresh(); + } + + checkUpdate(); + } + + @Override + protected List> getItemList(final Map body) { + final String response = checkMethodBase(body).get(getApiPath() + "/" + getListEndpointSuffix()).asString(); + final List> results = JsonPath.from(response).getList("response.docs"); + return results; + } + @Test void crudTest() { testCreate(); testRead(); - //testUpdate(); // TODO + testUpdate(); testDelete(); } }