Skip to content

Commit

Permalink
implemented tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangoerdes committed Aug 23, 2023
1 parent 42a677c commit 5fc53a9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5fc53a9

Please sign in to comment.