Commit a0aa2e82 authored by Noel Alonso's avatar Noel Alonso
Browse files

Amplía tests para obtener esquema de queries

parent 4be22bb1
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -5,8 +5,7 @@ server.servlet.path=/vessels/view
vesseltracking.activity.id=999

documentation.VESSEL_HOST=redmic.es${server.servlet.context-path}${server.servlet.path}
documentation.VESSELTYPE_HOST=${documentation.VESSEL_HOST}${controller.mapping.vesseltype}
documentation.VESSELTRACKING_HOST=${documentation.VESSEL_HOST}${controller.mapping.vesseltracking}

spring.profiles.active=@spring.profiles.active@

info.vessels-view.name=@project.name@
+7 −5
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.util.Arrays;
import java.util.Map;

import javax.annotation.PostConstruct;

@@ -33,6 +34,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import es.redmic.models.es.common.query.dto.MetadataQueryDTO;
import es.redmic.models.es.common.query.dto.MgetDTO;
import es.redmic.testutils.documentation.DocumentationViewBaseTest;
import es.redmic.testutils.utils.JsonToBeanTestUtil;
import es.redmic.vesselsview.VesselsViewApplication;
import es.redmic.vesselsview.model.vessel.Vessel;
import es.redmic.vesselsview.model.vesseltype.VesselType;
@@ -226,21 +228,21 @@ public class VesselControllerTest extends DocumentationViewBaseTest {
		// @formatter:on
	}

	@SuppressWarnings("unchecked")
	@Test
	public void getFilterSchema_Return200_WhenSchemaIsAvailable() throws Exception {

		// @formatter:off
		
		Map<String, Object> schemaExpected = (Map<String, Object>) JsonToBeanTestUtil
				.getBean("/data/schemas/vesselqueryschema.json", Map.class);
		
		this.mockMvc.perform(get(filterSchemaPath)
				.accept(MediaType.APPLICATION_JSON))
			.andExpect(status().isOk())
			.andExpect(jsonPath("$.success", is(true)))
			.andExpect(jsonPath("$.body", notNullValue()))
			.andExpect(jsonPath("$.body.schema", notNullValue()))
			.andExpect(jsonPath("$.body.schema.properties", notNullValue()))
			.andExpect(jsonPath("$.body.schema.properties.postFilter", notNullValue()))
			.andExpect(jsonPath("$.body.schema.properties.aggs", notNullValue()));
			// TODO: aumentar el nivel de checkeo
			.andExpect(jsonPath("$.body", is(schemaExpected)));
		// @formatter:on
	}
}
+12 −9
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import javax.annotation.PostConstruct;
@@ -39,6 +40,7 @@ import com.vividsolutions.jts.geom.Point;
import es.redmic.models.es.common.query.dto.DataQueryDTO;
import es.redmic.models.es.common.query.dto.MgetDTO;
import es.redmic.testutils.documentation.DocumentationViewBaseTest;
import es.redmic.testutils.utils.JsonToBeanTestUtil;
import es.redmic.vesselsview.VesselsViewApplication;
import es.redmic.vesselsview.model.vessel.Vessel;
import es.redmic.vesselsview.model.vesseltracking.VesselTracking;
@@ -54,8 +56,8 @@ public class VesselTrackingControllerTest extends DocumentationViewBaseTest {

	public final static String PREFIX = "vesseltracking-mmsi-tstamp-", MMSI = "1234", USER = "1";

	@Value("${documentation.VESSELTRACKING_HOST}")
	private String VESSELTRACKING_HOST;
	@Value("${documentation.VESSEL_HOST}")
	private String HOST;

	@Value("${controller.mapping.vesseltracking}")
	private String VESSELTRACKING_PATH;
@@ -136,7 +138,7 @@ public class VesselTrackingControllerTest extends DocumentationViewBaseTest {
				.webAppContextSetup(webApplicationContext)
				.addFilters(springSecurityFilterChain)
				.apply(documentationConfiguration(this.restDocumentation)
						.uris().withScheme(SCHEME).withHost(VESSELTRACKING_HOST.replace("{activityId}", ACTIVITY_ID))
						.uris().withScheme(SCHEME).withHost(HOST.replace("{activityId}", ACTIVITY_ID))
							.withPort(PORT))
				.alwaysDo(this.document).build();

@@ -149,7 +151,7 @@ public class VesselTrackingControllerTest extends DocumentationViewBaseTest {
	}

	@Test
	public void getVessel_Return200_WhenItemExist() throws Exception {
	public void getVesselTracking_Return200_WhenItemExist() throws Exception {

		// @formatter:off
		
@@ -243,9 +245,13 @@ public class VesselTrackingControllerTest extends DocumentationViewBaseTest {
		// @formatter:on
	}

	@SuppressWarnings("unchecked")
	@Test
	public void getFilterSchema_Return200_WhenSchemaIsAvailable() throws Exception {

		Map<String, Object> schemaExpected = (Map<String, Object>) JsonToBeanTestUtil
				.getBean("/data/schemas/vesseltrackingqueryschema.json", Map.class);

		// @formatter:off
		
		this.mockMvc.perform(get(url + filterSchemaPath)
@@ -253,11 +259,8 @@ public class VesselTrackingControllerTest extends DocumentationViewBaseTest {
			.andExpect(status().isOk())
			.andExpect(jsonPath("$.success", is(true)))
			.andExpect(jsonPath("$.body", notNullValue()))
			.andExpect(jsonPath("$.body.schema", notNullValue()))
			.andExpect(jsonPath("$.body.schema.properties", notNullValue()))
			.andExpect(jsonPath("$.body.schema.properties.postFilter", notNullValue()))
			.andExpect(jsonPath("$.body.schema.properties.aggs", notNullValue()));
			// TODO: aumentar el nivel de checkeo
			.andExpect(jsonPath("$.body", notNullValue()))
			.andExpect(jsonPath("$.body", is(schemaExpected)));
		// @formatter:on
	}
}
+11 −8
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.util.Arrays;
import java.util.Map;

import javax.annotation.PostConstruct;

@@ -33,6 +34,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import es.redmic.models.es.common.query.dto.MgetDTO;
import es.redmic.models.es.common.query.dto.SimpleQueryDTO;
import es.redmic.testutils.documentation.DocumentationViewBaseTest;
import es.redmic.testutils.utils.JsonToBeanTestUtil;
import es.redmic.vesselsview.VesselsViewApplication;
import es.redmic.vesselsview.model.vesseltype.VesselType;
import es.redmic.vesselsview.repository.vesseltype.VesselTypeESRepository;
@@ -43,8 +45,8 @@ import es.redmic.vesselsview.repository.vesseltype.VesselTypeESRepository;
@DirtiesContext
public class VesselTypeControllerTest extends DocumentationViewBaseTest {

	@Value("${documentation.VESSELTYPE_HOST}")
	private String VESSELTYPE_HOST;
	@Value("${documentation.VESSEL_HOST}")
	private String HOST;

	@Value("${controller.mapping.vesseltype}")
	private String VESSELTYPE_PATH;
@@ -82,7 +84,7 @@ public class VesselTypeControllerTest extends DocumentationViewBaseTest {
				.webAppContextSetup(webApplicationContext)
				.addFilters(springSecurityFilterChain)
				.apply(documentationConfiguration(this.restDocumentation)
						.uris().withScheme(SCHEME).withHost(VESSELTYPE_HOST).withPort(PORT))
						.uris().withScheme(SCHEME).withHost(HOST).withPort(PORT))
				.alwaysDo(this.document).build();

		// @formatter:on
@@ -218,9 +220,13 @@ public class VesselTypeControllerTest extends DocumentationViewBaseTest {
		// @formatter:on
	}

	@SuppressWarnings("unchecked")
	@Test
	public void getFilterSchema_Return200_WhenSchemaIsAvailable() throws Exception {

		Map<String, Object> schemaExpected = (Map<String, Object>) JsonToBeanTestUtil
				.getBean("/data/schemas/vesseltypequeryschema.json", Map.class);

		// @formatter:off
		
		this.mockMvc.perform(get(VESSELTYPE_PATH + filterSchemaPath)
@@ -228,11 +234,8 @@ public class VesselTypeControllerTest extends DocumentationViewBaseTest {
			.andExpect(status().isOk())
			.andExpect(jsonPath("$.success", is(true)))
			.andExpect(jsonPath("$.body", notNullValue()))
			.andExpect(jsonPath("$.body.schema", notNullValue()))
			.andExpect(jsonPath("$.body.schema.properties", notNullValue()))
			.andExpect(jsonPath("$.body.schema.properties.postFilter").doesNotExist())
			.andExpect(jsonPath("$.body.schema.properties.aggs").doesNotExist());
			// TODO: aumentar el nivel de checkeo
			.andExpect(jsonPath("$.body", notNullValue()))
			.andExpect(jsonPath("$.body", is(schemaExpected)));
		// @formatter:on
	}
}
+1 −0
Original line number Diff line number Diff line
{"schema":{"$schema":"http://json-schema.org/draft-04/schema#","title":"Metadata Query DTO","type":"object","properties":{"from":{"type":["integer","null"],"default":"0"},"size":{"type":["integer","null"],"default":"100"},"terms":{"type":["object","null"],"additionalProperties":true},"sorts":{"type":["array","null"],"uniqueItems":true,"items":{"$ref":"#/definitions/SortDTO"}},"returnFields":{"type":["array","null"],"uniqueItems":true,"items":{"type":"string"}},"text":{"$ref":"#/definitions/TextQueryDTO"},"suggest":{"$ref":"#/definitions/SuggestQueryDTO"},"regexp":{"type":["array","null"],"uniqueItems":true,"items":{"$ref":"#/definitions/RegexpDTO"}},"postFilter":{"type":["object","null"],"additionalProperties":true},"aggs":{"type":["array","null"],"uniqueItems":true,"items":{"$ref":"#/definitions/AggsPropertiesDTO"}}},"definitions":{"SortDTO":{"type":["object","null"],"properties":{"field":{"type":"string"},"order":{"type":"string"}},"required":["field","order"]},"TextQueryDTO":{"type":["object","null"],"properties":{"text":{"type":"string","minLength":2},"searchFields":{"type":["array","null"],"uniqueItems":true,"items":{"type":"string"}},"highlightFields":{"type":["array","null"],"uniqueItems":true,"items":{"type":"string"}}},"required":["text"]},"SuggestQueryDTO":{"type":["object","null"],"properties":{"text":{"type":"string","minLength":2},"searchFields":{"type":["array","null"],"uniqueItems":true,"items":{"type":"string"}},"size":{"type":["integer","null"]}},"required":["text"]},"RegexpDTO":{"type":["object","null"],"properties":{"field":{"type":"string"},"exp":{"type":"string"}},"required":["field","exp"]},"AggsPropertiesDTO":{"type":["object","null"],"properties":{"field":{"type":"string"},"term":{"type":"string"},"nested":{"type":["string","null"]},"size":{"type":["integer","null"],"default":"20"},"minCount":{"type":["integer","null"]}},"required":["field","term"]}}}}
 No newline at end of file
Loading