From cc03aaf92f2899d3ad51cbfea8503307098bf5d5 Mon Sep 17 00:00:00 2001 From: Angel Borroy <48685308+aborroy@users.noreply.github.com> Date: Thu, 6 Feb 2020 13:10:30 +0100 Subject: [PATCH] RestWrapper for Solr Admin API (#34) --- .../org/alfresco/rest/core/RestWrapper.java | 6 ++ .../rest/requests/search/SolrAdminAPI.java | 58 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/SolrAdminAPI.java diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestWrapper.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestWrapper.java index be51f6594d..844017b431 100644 --- a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestWrapper.java +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestWrapper.java @@ -42,6 +42,7 @@ import org.alfresco.rest.requests.search.SearchSQLAPI; import org.alfresco.rest.requests.search.SearchSQLJDBC; import org.alfresco.rest.requests.search.ShardInfoAPI; import org.alfresco.rest.requests.search.SolrAPI; +import org.alfresco.rest.requests.search.SolrAdminAPI; import org.alfresco.rest.requests.workflowAPI.RestWorkflowAPI; import org.alfresco.utility.LogFactory; import org.alfresco.utility.Utility; @@ -955,6 +956,11 @@ public class RestWrapper extends DSLWrapper { return new SolrAPI(this); } + + public SolrAdminAPI withSolrAdminAPI() + { + return new SolrAdminAPI(this); + } /** * @return {@link RestDiscoveryAPI} using the rest Discovery API as prefix: {@link /alfresco/api/discovery} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/SolrAdminAPI.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/SolrAdminAPI.java new file mode 100644 index 0000000000..efe27443b7 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/SolrAdminAPI.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2020 Alfresco Software Limited. + * This file is part of Alfresco + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.rest.requests.search; + +import java.util.ArrayList; +import java.util.List; + +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestResponse; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.requests.ModelRequest; +import org.springframework.http.HttpMethod; + +import io.restassured.RestAssured; +import io.restassured.http.Header; +import io.restassured.http.Headers; + +/** + * Wrapper for SOLR Admin REST API + * + * @author aborroy + * + */ +public class SolrAdminAPI extends ModelRequest +{ + public SolrAdminAPI(RestWrapper restWrapper) + { + super(restWrapper); + RestAssured.basePath = "solr/admin"; + + restWrapper.configureSolrEndPoint(); + restWrapper.configureRequestSpec().setBasePath(RestAssured.basePath); + } + + public RestResponse getAction(String action) throws Exception + { + List
headers = new ArrayList
(); + headers.add(new Header("Content-Type", "application/json")); + Headers header = new Headers(headers); + restWrapper.setResponseHeaders(header); + restWrapper.configureRequestSpec().setUrlEncodingEnabled(false); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, + "cores?action=" + action + "&wt=json&{parameters}", restWrapper.getParameters()); + return restWrapper.process(request); + } +}