From 5fc53a9bd4086b19a037f49ee6f562427fbcf49f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6rdes?= Date: Wed, 23 Aug 2023 16:02:47 +0200 Subject: [PATCH] implemented tests --- .../core/openapi/model/MessageTest.java | 26 +++++++++++++++---- .../validators/ContentTypeWildcardTests.java | 21 +++++++++------ .../openapi/specs/content-type-wildcards.yml | 6 ++--- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/model/MessageTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/model/MessageTest.java index 948c90468..ea462a6a4 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/model/MessageTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/model/MessageTest.java @@ -1,16 +1,32 @@ package com.predic8.membrane.core.openapi.model; -import org.junit.jupiter.api.*; -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import javax.validation.constraints.AssertTrue; +import java.net.URISyntaxException; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; class MessageTest { - @BeforeEach - void setUp() { + @Test + void starStarTest() throws URISyntaxException { + Request request = Request.post().json().path("/star-star").body("{}"); + assertTrue(request.isOfMediaType("*/*")); + } + + @Test + void typeStarTest() throws URISyntaxException { + Request request = Request.post().json().path("/star-star").body("{}"); + assertTrue(request.isOfMediaType("application/*")); } @Test - void isOfMediaType() { + void starTypeTest() throws URISyntaxException { + Request request = Request.post().json().path("/star-star").body("{}"); + assertFalse(request.isOfMediaType("*/json")); } } \ No newline at end of file diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/ContentTypeWildcardTests.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/ContentTypeWildcardTests.java index 639148a04..2e7c250a6 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/ContentTypeWildcardTests.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/ContentTypeWildcardTests.java @@ -17,12 +17,6 @@ String getOpenAPIFileName() { return "/openapi/specs/content-type-wildcards.yml"; } - @Test - void contentTypeMatchingSubtype() throws ParseException { - ContentType ct = new ContentType("application/*"); - assertTrue(ct.match(MimeType.APPLICATION_JSON)); - } - // See https://datatracker.ietf.org/doc/html/rfc7231#appendix-D // media-range = ( "*/*" / ( type "/*" ) / ( type "/" subtype ) ) *( OWS // ";" OWS parameter ) @@ -41,9 +35,20 @@ void contentTypeMatchingSwitch() throws ParseException { } @Test - void starStarAcceptAll() { + void starStarTest() { ValidationErrors errors = validator.validate(Request.post().json().path("/star-star").body("{}")); -// System.out.println(errors); + assertTrue(errors.isEmpty()); + } + + @Test + void starTypeTest() { + ValidationErrors errors = validator.validate(Request.post().json().path("/star-json").body("{}")); + assertFalse(errors.isEmpty()); + } + + @Test + void typeStarTest() { + ValidationErrors errors = validator.validate(Request.post().json().path("/application-star").body("{}")); assertTrue(errors.isEmpty()); } } diff --git a/core/src/test/resources/openapi/specs/content-type-wildcards.yml b/core/src/test/resources/openapi/specs/content-type-wildcards.yml index adc9e24a3..26646e262 100644 --- a/core/src/test/resources/openapi/specs/content-type-wildcards.yml +++ b/core/src/test/resources/openapi/specs/content-type-wildcards.yml @@ -21,13 +21,13 @@ paths: schema: type: string - /text-star: + /application-star: post: requestBody: content: - 'text/*': + 'application/*': schema: - type: string + type: object responses: '200': description: OK