Commit 1fd0f761 authored by Noel Alonso's avatar Noel Alonso
Browse files

Añade comprobación de esquema vía recurso

De este modo, se mantiene el esquema esperado como un json en los
recursos de tests y se comprueba que el esquema recibido sea igual
al esperado.
parent df51861f
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
@@ -48,6 +49,7 @@ import es.redmic.brokerlib.avro.common.Event;
import es.redmic.brokerlib.listener.SendListener;
import es.redmic.test.vesselscommands.integration.KafkaEmbeddedConfig;
import es.redmic.testutils.documentation.DocumentationCommandBaseTest;
import es.redmic.testutils.utils.JsonToBeanTestUtil;
import es.redmic.vesselscommands.VesselsCommandsApplication;
import es.redmic.vesselscommands.handler.VesselCommandHandler;
import es.redmic.vesselscommands.statestore.VesselStateStore;
@@ -229,22 +231,20 @@ public class CreateVesselFromRestTest extends DocumentationCommandBaseTest {
		assertEquals(event.getAggregateId(), expectedEvent.getAggregateId());
	}

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

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

		// @formatter:off
		
		this.mockMvc.perform(get(editSchemaPath)
				.header("Authorization", "Bearer " + getTokenOAGUser())
				.accept(MediaType.APPLICATION_JSON))
			.andExpect(status().isOk())
			.andExpect(jsonPath("$.title", is("Vessel DTO")))
			.andExpect(jsonPath("$.properties", notNullValue()))
			.andExpect(jsonPath("$.properties.id", notNullValue()))
			.andExpect(jsonPath("$.properties.type", notNullValue()))
			.andExpect(jsonPath("$.properties.type.type", notNullValue()))
			.andExpect(jsonPath("$.properties.type.url", notNullValue()));
			// TODO: aumentar el nivel de checkeo
			.andExpect(jsonPath("$", is(schemaExpected)));
		// @formatter:on
	}

+7 −8
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
@@ -50,6 +51,7 @@ import es.redmic.brokerlib.avro.common.Event;
import es.redmic.brokerlib.listener.SendListener;
import es.redmic.test.vesselscommands.integration.KafkaEmbeddedConfig;
import es.redmic.testutils.documentation.DocumentationCommandBaseTest;
import es.redmic.testutils.utils.JsonToBeanTestUtil;
import es.redmic.vesselscommands.VesselsCommandsApplication;
import es.redmic.vesselscommands.handler.VesselTrackingCommandHandler;
import es.redmic.vesselscommands.statestore.VesselTrackingStateStore;
@@ -295,23 +297,20 @@ public class CreateVesselTrackingFromRestTest extends DocumentationCommandBaseTe
		assertEquals(id, event.getAggregateId());
	}

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

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

		// @formatter:off
		
		this.mockMvc.perform(get(VESSELTRACKING_PATH + editSchemaPath)
				.header("Authorization", "Bearer " + getTokenOAGUser())
				.accept(MediaType.APPLICATION_JSON))
			.andExpect(status().isOk())
			.andExpect(jsonPath("$.title", is("Vessel Tracking DTO")))
			.andExpect(jsonPath("$.properties", notNullValue()))
			.andExpect(jsonPath("$.properties.id", notNullValue()))
			.andExpect(jsonPath("$.properties.uuid", notNullValue()))
			.andExpect(jsonPath("$.properties.properties", notNullValue()))
			.andExpect(jsonPath("$.properties.geometry", notNullValue()))
			.andExpect(jsonPath("$.required", notNullValue()));
			// TODO: aumentar el nivel de checkeo
			.andExpect(jsonPath("$", is(schemaExpected)));
		// @formatter:on
	}

+7 −4
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
@@ -47,6 +48,7 @@ import es.redmic.brokerlib.avro.common.Event;
import es.redmic.brokerlib.listener.SendListener;
import es.redmic.test.vesselscommands.integration.KafkaEmbeddedConfig;
import es.redmic.testutils.documentation.DocumentationCommandBaseTest;
import es.redmic.testutils.utils.JsonToBeanTestUtil;
import es.redmic.vesselscommands.VesselsCommandsApplication;
import es.redmic.vesselscommands.handler.VesselTypeCommandHandler;
import es.redmic.vesselscommands.statestore.VesselTypeStateStore;
@@ -225,19 +227,20 @@ public class CreateVesselTypeFromRestTest extends DocumentationCommandBaseTest {
		assertEquals(event.getAggregateId(), expectedEvent.getAggregateId());
	}

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

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

		// @formatter:off
		
		this.mockMvc.perform(get(VESSELTYPE_PATH + editSchemaPath)
				.header("Authorization", "Bearer " + getTokenOAGUser())
				.accept(MediaType.APPLICATION_JSON))
			.andExpect(status().isOk())
			.andExpect(jsonPath("$.title", is("Vessel Type DTO")))
			.andExpect(jsonPath("$.properties", notNullValue()))
			.andExpect(jsonPath("$.properties.id", notNullValue()));
			// TODO: aumentar el nivel de checkeo
			.andExpect(jsonPath("$", is(schemaExpected)));
		// @formatter:on
	}

+1 −0
Original line number Diff line number Diff line
{"$schema":"http://json-schema.org/draft-04/schema#","title":"Vessel DTO","type":"object","properties":{"id":{"type":["string","null"]},"mmsi":{"type":["integer","null"],"maximum":999999999},"imo":{"type":["integer","null"],"maximum":9999999},"type":{"type":"integer","url":"/api/vessels/commands/vesseltype"},"name":{"type":"string","minLength":1,"maxLength":500},"callSign":{"type":["string","null"]},"length":{"type":["number","null"]},"beam":{"type":["number","null"]},"inserted":{"type":["string","null"],"format":"date-time"},"updated":{"type":["string","null"],"format":"date-time"}},"required":["type","name"],"definitions":{}}
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
{"$schema":"http://json-schema.org/draft-04/schema#","title":"Vessel Tracking DTO","type":"object","properties":{"id":{"type":["string","null"]},"uuid":{"type":["string","null"]},"properties":{"$ref":"#/definitions/VesselTrackingPropertiesDTO"},"geometry":{"type":"object","additionalProperties":false,"properties":{"type":{"type":"string","enum":["Point"],"default":"Point"},"coordinates":{"type":"array","items":{"type":"number","maximum":9000000000000000,"minimum":-9000000000000000},"minItems":2,"maxItems":2}},"required":["type","coordinates"]}},"required":["properties","geometry"],"definitions":{"VesselTrackingPropertiesDTO":{"type":"object","properties":{"vessel":{"type":"integer","url":"none"},"date":{"type":"string","format":"date-time"},"cog":{"type":["number","null"]},"sog":{"type":["number","null"]},"heading":{"type":["integer","null"]},"navStat":{"type":["integer","null"]},"dest":{"type":["string","null"]},"eta":{"type":["string","null"]}},"required":["vessel","date"]}}}
 No newline at end of file
Loading