diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/AirlinesAppTest.java b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/AirlinesAppTest.java index db57d16a..a01a280f 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/AirlinesAppTest.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/AirlinesAppTest.java @@ -16,6 +16,7 @@ package org.eclipse.microprofile.openapi.tck; +import static org.eclipse.microprofile.openapi.tck.utils.TCKMatchers.hasOptionalEntry; import static org.eclipse.microprofile.openapi.tck.utils.TCKMatchers.itemOrSingleton; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.anEmptyMap; @@ -408,8 +409,7 @@ private void testBookingIdMethods(ValidatableResponse vr) { } bookingParameters = "paths.'/bookings/{id}'.get.parameters"; - vr.body(bookingParameters + ".findAll { it.name == 'id' }.style", both(hasSize(1)).and(contains("simple"))); - + vr.body(bookingParameters + ".findAll { it.name == 'id' }", contains(hasOptionalEntry("style", "simple"))); } private void testAvailabilityGetParamater(ValidatableResponse vr) { @@ -690,7 +690,7 @@ public void testEncodingRequestBody(String type) { ValidatableResponse vr = callEndpoint(type); String s = "paths.'/user'.post.requestBody.content.'application/json'.encoding.email."; vr.body(s + "contentType", equalTo("text/plain")); - vr.body(s + "style", equalTo("form")); + vr.body(s, hasOptionalEntry("style", "form")); vr.body(s + "explode", equalTo(true)); vr.body(s + "allowReserved", equalTo(true)); vr.body(s + "x-encoding", equalTo("test-encoding")); @@ -702,13 +702,13 @@ public void testEncodingResponses(String type) { String s = "paths.'/user/username/{username}'.put.responses.'200'.content.'application/json'.encoding.password."; vr.body(s + "contentType", equalTo("text/plain")); - vr.body(s + "style", equalTo("form")); + vr.body(s, hasOptionalEntry("style", "form")); vr.body(s + "explode", equalTo(true)); vr.body(s + "allowReserved", equalTo(true)); String t = "paths.'/user/username/{username}'.put.responses.'200'.content.'application/xml'.encoding.password."; vr.body(t + "contentType", equalTo("text/plain")); - vr.body(t + "style", equalTo("form")); + vr.body(t, hasOptionalEntry("style", "form")); vr.body(t + "explode", equalTo(true)); vr.body(t + "allowReserved", equalTo(true)); @@ -930,7 +930,7 @@ public void testHeaderInAPIResponse(String type) { vr.body(responseHeader1 + ".required", equalTo(true)); vr.body(responseHeader1 + ".deprecated", equalTo(true)); vr.body(responseHeader1 + ".allowEmptyValue", equalTo(true)); - vr.body(responseHeader1 + ".style", equalTo("simple")); + vr.body(responseHeader1, hasOptionalEntry("style", "simple")); vr.body(responseHeader1 + ".schema.type", itemOrSingleton("integer")); String responseHeader2 = "paths.'/reviews/{id}'.get.responses.'200'.headers.responseHeader2"; @@ -939,7 +939,7 @@ public void testHeaderInAPIResponse(String type) { vr.body(responseHeader2 + ".required", equalTo(true)); vr.body(responseHeader2 + ".deprecated", equalTo(true)); vr.body(responseHeader2 + ".allowEmptyValue", equalTo(true)); - vr.body(responseHeader2 + ".style", equalTo("simple")); + vr.body(responseHeader2, hasOptionalEntry("style", "simple")); vr.body(responseHeader2 + ".schema.type", itemOrSingleton("string")); } @@ -955,7 +955,7 @@ public void testHeaderInEncoding(String type) { vr.body(testHeader + ".required", equalTo(true)); vr.body(testHeader + ".deprecated", equalTo(true)); vr.body(testHeader + ".allowEmptyValue", equalTo(true)); - vr.body(testHeader + ".style", equalTo("simple")); + vr.body(testHeader, hasOptionalEntry("style", "simple")); vr.body(testHeader + ".schema.type", itemOrSingleton("integer")); } @@ -988,7 +988,7 @@ public void testHeaderInComponents(String type) { vr.body(maxRate + ".required", equalTo(true)); vr.body(maxRate + ".deprecated", equalTo(true)); vr.body(maxRate + ".allowEmptyValue", equalTo(true)); - vr.body(maxRate + ".style", equalTo("simple")); + vr.body(maxRate, hasOptionalEntry("style", "simple")); vr.body(maxRate + ".schema.type", itemOrSingleton("integer")); vr.body(maxRate + ".x-header", equalTo("test-header")); } diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/FilterTest.java b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/FilterTest.java index 70d11bd7..2c3c2501 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/FilterTest.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/FilterTest.java @@ -16,6 +16,7 @@ package org.eclipse.microprofile.openapi.tck; +import static org.eclipse.microprofile.openapi.tck.utils.TCKMatchers.hasOptionalEntry; import static org.eclipse.microprofile.openapi.tck.utils.TCKMatchers.itemOrSingleton; import static org.hamcrest.Matchers.both; import static org.hamcrest.Matchers.contains; @@ -161,7 +162,7 @@ public void testFilterHeader(String type) { vr.body(maxRate + ".required", equalTo(true)); vr.body(maxRate + ".deprecated", equalTo(true)); vr.body(maxRate + ".allowEmptyValue", equalTo(true)); - vr.body(maxRate + ".style", equalTo("simple")); + vr.body(maxRate, hasOptionalEntry("style", "simple")); vr.body(maxRate + ".schema.type", itemOrSingleton("integer")); } diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/utils/TCKMatchers.java b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/utils/TCKMatchers.java index 61e12070..977aee30 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/utils/TCKMatchers.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/utils/TCKMatchers.java @@ -15,7 +15,13 @@ */ package org.eclipse.microprofile.openapi.tck.utils; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.either; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.isA; +import static org.hamcrest.Matchers.not; import static org.hamcrest.comparator.ComparatorMatcherBuilder.comparedBy; import java.math.BigDecimal; @@ -169,4 +175,21 @@ private static BigDecimal toBigDecimal(Number number) { } } + + /** + * Creates a matcher which matches a map entry with an allowed value or the absence of a map entry from the object. + * + * @param entryName + * name of the entry in the map + * @param value + * a single allowed value in the map entry, if present + * @return the matcher + */ + @SuppressWarnings("unchecked") + public static Matcher hasOptionalEntry(String entryName, Object value) { + Matcher hasEntry = (Matcher) hasEntry(entryName, value); + Matcher entryMissing = (Matcher) not(hasKey(entryName)); + + return allOf(isA(java.util.Map.class), either(hasEntry).or(entryMissing)); + } }