Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mpOpenAPI-4.0: implement validation #29687

Open
wants to merge 7 commits into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.ibm.ws.microprofile.openapi.validation.fat;

import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;

import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -35,7 +40,7 @@ public class OpenAPIValidationTestFive {
public static LibertyServer server;

@ClassRule
public static RepeatTests r = FATSuite.repeatPre40(SERVER_NAME);
public static RepeatTests r = FATSuite.defaultRepeat(SERVER_NAME);

private static final String OPENAPI_VALIDATION_YAML = "Validation";

Expand Down Expand Up @@ -64,43 +69,48 @@ public static void tearDown() throws Exception {

@Test
public void testTags() throws Exception {
assertNotNull("The Tag Validator should have been triggered by the missing 'name' field",
server.waitForStringInLog(
assertNotEmpty("The Tag Validator should have been triggered by the missing 'name' field",
server.findStringsInLogs(
" - Message: Required \"name\" field is missing or is set to an invalid value, Location: #/tags"));
}

@Test
public void testDiscriminator() throws Exception {
assertNotNull("The Discriminator validator should have been triggered by the missing 'propertyName' field",
server.waitForStringInLog(
assertNotEmpty("The Discriminator validator should have been triggered by the missing 'propertyName' field",
server.findStringsInLogs(
"- Message: Required \"propertyName\" field is missing or is set to an invalid value,*"));
}

@Test
public void testSchema() throws Exception {
assertNotNull("The Schema validator should have been triggered by the missing 'items' field",
server.waitForStringInLog(
assertNotEmpty("The Schema validator should have been triggered by the missing 'items' field",
server.findStringsInLogs(
" - Message: The Schema Object of \"array\" type must have \"items\" property defined, Location: #/paths/~1availability/get/parameters/schema"));
assertNotNull("The Schema validator should have been triggered by the invalid 'multipleOf' field",
server.waitForStringInLog(
assertNotEmpty("The Schema validator should have been triggered by the invalid 'multipleOf' field",
server.findStringsInLogs(
" - Message: The Schema Object must have the \"multipleOf\" property set to a number strictly greater than zero, Location: #/paths/~1availability/get/parameters/schema"));
assertNotNull("The Schema validator should have been triggered by the invalid 'minItems' field",
server.waitForStringInLog(
assertNotEmpty("The Schema validator should have been triggered by the invalid 'minItems' field",
server.findStringsInLogs(
"- Message: The \"minItems\" property of the Schema Object must be greater than or equal to zero, Location: #/paths/~1availability/get/parameters/schema"));
assertNotNull("The Schema validator should have been triggered by the invalid 'maxItems' field",
server.waitForStringInLog(
assertNotEmpty("The Schema validator should have been triggered by the invalid 'maxItems' field",
server.findStringsInLogs(
" - Message: The \"maxItems\" property of the Schema Object must be greater than or equal to zero, Location: #/paths/~1availability/get/parameters/schema"));
assertNotNull("The Schema validator should have been triggered by the invalid 'minProperties' field",
server.waitForStringInLog(
assertNotEmpty("The Schema validator should have been triggered by the invalid 'minProperties' field",
server.findStringsInLogs(
" - Message: The \"minProperties\" property of the Schema Object must be greater than or equal to zero, Location: #/paths/~1availability/get/parameters/schema"));
assertNotNull("The Schema validator should have been triggered by the invalid 'maxProperties' field",
server.waitForStringInLog(
assertNotEmpty("The Schema validator should have been triggered by the invalid 'maxProperties' field",
server.findStringsInLogs(
" - Message: The \"maxProperties\" property of the Schema Object must be greater than or equal to zero, Location: #/paths/~1availability/get/parameters/schema"));
assertNotNull("The Schema validator should have been triggered by the invalid 'minItems' field",
server.waitForStringInLog(
assertNotEmpty("The Schema validator should have been triggered by the invalid 'minItems' field",
server.findStringsInLogs(
" - Message: The \"minItems\" property is not appropriate for the Schema Object of \"object\" type, Location: #/paths/~1availability/get/parameters/schema"));
assertNotNull("The Schema validator should have been triggered by the invalid 'maxItems' field",
server.waitForStringInLog(
assertNotEmpty("The Schema validator should have been triggered by the invalid 'maxItems' field",
server.findStringsInLogs(
" - Message: The \"maxItems\" property is not appropriate for the Schema Object of \"object\" type, Location: #/paths/~1availability/get/parameters/schema"));
}

private void assertNotEmpty(String message,
List<String> stringsInLogs) {
assertThat(message, stringsInLogs, not(empty()));
}
}
Loading