Commit 4c132129 authored by Noel Alonso's avatar Noel Alonso
Browse files

Añade controladores de esquema de consulta

Añade test básico
parent e991dae8
Loading
Loading
Loading
Loading
+2 −6
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ public abstract class RBaseController<TModel extends BaseES<?>, TDTO extends Bas
	protected Class<TDTO> typeOfTDTO;
	protected Class<TQueryDTO> typeOfTQueryDTO;

	private Set<String> fieldsExcludedOnQuery = new HashSet<>();
	protected Set<String> fieldsExcludedOnQuery = new HashSet<>();

	protected RBaseController(RBaseESService<TModel, TDTO> service) {
		this.service = service;
@@ -82,11 +82,7 @@ public abstract class RBaseController<TModel extends BaseES<?>, TDTO extends Bas
			"${contoller.mapping.ANCESTORS_SCHEMA}", "${controller.mapping.TRACK_CLUSTER_SCHEMA}",
			"${controller.mapping.OBJECT_CLASSIFICATION_LIST_SCHEMA}",
			"${controller.mapping.OBJECT_CLASSIFICATION_SCHEMA}", "${controller.mapping.SERIES_TEMPORALDATA_SCHEMA}",
			"${controller.mapping.SERIES_WINDROSE_SCHEMA}", "${controller.mapping.GRID100_SCHEMA}",
			"${controller.mapping.GRID100_BY_ID_SCHEMA}", "${controller.mapping.GRID500_SCHEMA}",
			"${controller.mapping.GRID500_BY_ID_SCHEMA}", "${controller.mapping.GRID1000_SCHEMA}",
			"${controller.mapping.GRID1000_BY_ID_SCHEMA}", "${controller.mapping.GRID5000_SCHEMA}",
			"${controller.mapping.GRID5000_BY_ID_SCHEMA}" })
			"${controller.mapping.SERIES_WINDROSE_SCHEMA}" })
	@ResponseBody
	public ElasticSearchDTO getFilterSchema(HttpServletResponse response) {

+11 −1
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@@ -191,4 +190,15 @@ public class SpeciesDistributionController extends SelectionWorkController<Speci
		result.setTotal(speciesESService.getCountLeaves(dto.getIds()));
		return result;
	}

	@GetMapping(value = { "${controller.mapping.GRID100_SCHEMA}",
			"${controller.mapping.GRID100_BY_ID_SCHEMA}", "${controller.mapping.GRID500_SCHEMA}",
			"${controller.mapping.GRID500_BY_ID_SCHEMA}", "${controller.mapping.GRID1000_SCHEMA}",
			"${controller.mapping.GRID1000_BY_ID_SCHEMA}", "${controller.mapping.GRID5000_SCHEMA}",
			"${controller.mapping.GRID5000_BY_ID_SCHEMA}" })
	@ResponseBody
	public ElasticSearchDTO getFilterSchema(HttpServletResponse response) {

		return dist100MService.getFilterSchema(GeoDataQueryDTO.class, fieldsExcludedOnQuery);
	}
}
+100 −0
Original line number Diff line number Diff line
package es.redmic.test.integration.tools;

/*-
 * #%L
 * API
 * %%
 * Copyright (C) 2019 REDMIC Project / Server
 * %%
 * 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.
 * #L%
 */

import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.util.HashMap;

import com.fasterxml.jackson.databind.ObjectMapper;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.http.MediaType;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import es.redmic.ApiApplication;
import es.redmic.models.es.common.query.dto.GeoDataQueryDTO;
import es.redmic.test.integration.ApiApplicationTest;
import es.redmic.test.integration.common.IntegrationTestBase;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = { ApiApplication.class,
		ApiApplicationTest.class }, webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public class SpeciesDistributionControllerTest extends IntegrationTestBase {

	@Rule
	public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");

	@Autowired
	ObjectMapper mapper;

	private RestDocumentationResultHandler document;

	private final String DISTRIBUTION_URL_BASE = "/distributions/grid100";

	@Override
	@Before
	public void setUp() {

		// @formatter:off

		this.document = document("{class-name}/{method-name}", preprocessRequest(prettyPrint()),
				preprocessResponse(prettyPrint()));

		mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).addFilters(springSecurityFilterChain)
				.apply(documentationConfiguration(this.restDocumentation)).alwaysDo(this.document).build();

		// @formatter:on
	}

	@Test
	public void getSpeciesDistributionSchema_Return200_WhenSearchIsCorrect() throws Exception {

		// @formatter:off

		MvcResult result = this.mockMvc
				.perform(get(DISTRIBUTION_URL_BASE + "/_search/_schema").accept(MediaType.APPLICATION_JSON)).andReturn();
				//.andExpect(status().isOk());

		System.err.println(result.getResponse().getContentAsString());

		// @formatter:on
	}
}