Skip to content

Commit

Permalink
tests(schemaFormat): new AsyncAPI Schema tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed Apr 12, 2024
1 parent fc65b73 commit 86f6ff8
Show file tree
Hide file tree
Showing 238 changed files with 6,876 additions and 555 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.asyncapi.v3.schema

import com.asyncapi.v3.schema.multiformat.AsyncAPIFormatSchema
import com.asyncapi.v3.schema.multiformat.JsonFormatSchema
import com.asyncapi.v3.schema.multiformat.OpenAPIFormatSchema
import com.asyncapi.v3.schema.openapi.OpenAPISchema

interface SchemaProvider {
Expand All @@ -15,44 +14,8 @@ interface SchemaProvider {

fun asyncAPISchema(): AsyncAPISchema = AsyncAPISchema()

fun asyncAPIFormatSchemaJsonV2_0_0(): AsyncAPIFormatSchema = AsyncAPIFormatSchema("application/vnd.aai.asyncapi+json;version=2.0.0", asyncAPISchema())

fun asyncAPIFormatSchemaYamlV2_0_0(): AsyncAPIFormatSchema = AsyncAPIFormatSchema("application/vnd.aai.asyncapi+yaml;version=2.0.0", asyncAPISchema())

fun asyncAPIFormatSchemaJsonV2_1_0(): AsyncAPIFormatSchema = AsyncAPIFormatSchema("application/vnd.aai.asyncapi+json;version=2.1.0", asyncAPISchema())

fun asyncAPIFormatSchemaYamlV2_1_0(): AsyncAPIFormatSchema = AsyncAPIFormatSchema("application/vnd.aai.asyncapi+yaml;version=2.1.0", asyncAPISchema())

fun asyncAPIFormatSchemaJsonV2_2_0(): AsyncAPIFormatSchema = AsyncAPIFormatSchema("application/vnd.aai.asyncapi+json;version=2.2.0", asyncAPISchema())

fun asyncAPIFormatSchemaYamlV2_2_0(): AsyncAPIFormatSchema = AsyncAPIFormatSchema("application/vnd.aai.asyncapi+yaml;version=2.2.0", asyncAPISchema())

fun asyncAPIFormatSchemaJsonV2_3_0(): AsyncAPIFormatSchema = AsyncAPIFormatSchema("application/vnd.aai.asyncapi+json;version=2.3.0", asyncAPISchema())

fun asyncAPIFormatSchemaYamlV2_3_0(): AsyncAPIFormatSchema = AsyncAPIFormatSchema("application/vnd.aai.asyncapi+yaml;version=2.3.0", asyncAPISchema())

fun asyncAPIFormatSchemaJsonV2_4_0(): AsyncAPIFormatSchema = AsyncAPIFormatSchema("application/vnd.aai.asyncapi+json;version=2.4.0", asyncAPISchema())

fun asyncAPIFormatSchemaYamlV2_4_0(): AsyncAPIFormatSchema = AsyncAPIFormatSchema("application/vnd.aai.asyncapi+yaml;version=2.4.0", asyncAPISchema())

fun asyncAPIFormatSchemaJsonV2_5_0(): AsyncAPIFormatSchema = AsyncAPIFormatSchema("application/vnd.aai.asyncapi+json;version=2.5.0", asyncAPISchema())

fun asyncAPIFormatSchemaYamlV2_5_0(): AsyncAPIFormatSchema = AsyncAPIFormatSchema("application/vnd.aai.asyncapi+yaml;version=2.5.0", asyncAPISchema())

fun asyncAPIFormatSchemaJsonV2_6_0(): AsyncAPIFormatSchema = AsyncAPIFormatSchema("application/vnd.aai.asyncapi+json;version=2.6.0", asyncAPISchema())

fun asyncAPIFormatSchemaYamlV2_6_0(): AsyncAPIFormatSchema = AsyncAPIFormatSchema("application/vnd.aai.asyncapi+yaml;version=2.6.0", asyncAPISchema())

fun asyncAPIFormatSchemaJsonV3_0_0(): AsyncAPIFormatSchema = AsyncAPIFormatSchema(asyncAPISchema())

fun asyncAPIFormatSchemaYamlV3_0_0(): AsyncAPIFormatSchema = AsyncAPIFormatSchema("application/vnd.aai.asyncapi+yaml;version=3.0.0", asyncAPISchema())

fun asyncAPIFormatSchemaEmptySchemaFormat(): AsyncAPIFormatSchema = AsyncAPIFormatSchema("application/vnd.aai.asyncapi+json;version=3.0.0", asyncAPISchema())

fun openAPISchema(): OpenAPISchema = OpenAPISchema()

fun openAPIFormatSchemaJson(): OpenAPIFormatSchema = OpenAPIFormatSchema(openAPISchema())

fun openAPIFormatSchemaYaml(): OpenAPIFormatSchema = OpenAPIFormatSchema("application/vnd.oai.openapi+yaml;version=3.0.0", openAPISchema())

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.asyncapi.v3.schema.multiformat.asyncapi

import com.asyncapi.v3.ClasspathUtils
import com.asyncapi.v3.schema.multiformat.AsyncAPIFormatSchema
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import org.junit.jupiter.api.Assertions

abstract class AsyncAPIFormatSchemaTest {

private val objectMapper: ObjectMapper = ObjectMapper(YAMLFactory())
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.findAndRegisterModules()

fun compareSchemas(
openAPIFormatSchemaToCompareWithFilePath: String,
schemaToCheck: AsyncAPIFormatSchema
) {
val schemaAsJson = ClasspathUtils.readAsString(openAPIFormatSchemaToCompareWithFilePath)
val schema = objectMapper.readValue(schemaAsJson, AsyncAPIFormatSchema::class.java)

Assertions.assertEquals(schema, schemaToCheck)
}

abstract fun parseJson(
asyncAPIFormatSchemaToCompareWithFilePath: String,
asyncAPIFormatSchema: AsyncAPIFormatSchema
)

abstract fun parseYaml(
asyncAPIFormatSchemaToCompareWithFilePath: String,
asyncAPIFormatSchema: AsyncAPIFormatSchema
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package com.asyncapi.v3.schema.multiformat.asyncapi

import com.asyncapi.v3.schema.json.*
import com.asyncapi.v3.schema.multiformat.AsyncAPIFormatSchema
import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.ArgumentsProvider
import org.junit.jupiter.params.provider.ArgumentsSource
import java.util.stream.Stream

abstract class AsyncAPIFormatSchemaV2_0_0Test: AsyncAPIFormatSchemaTest() {

@ArgumentsSource(JsonFormat::class)
@ParameterizedTest(name = "Read: {0}")
override fun parseJson(
asyncAPIFormatSchemaToCompareWithFilePath: String,
asyncAPIFormatSchema: AsyncAPIFormatSchema
) {
compareSchemas(asyncAPIFormatSchemaToCompareWithFilePath, asyncAPIFormatSchema)
}

@ArgumentsSource(YamlFormat::class)
@ParameterizedTest(name = "Read: {0}")
override fun parseYaml(
asyncAPIFormatSchemaToCompareWithFilePath: String,
asyncAPIFormatSchema: AsyncAPIFormatSchema
) {
compareSchemas(asyncAPIFormatSchemaToCompareWithFilePath, asyncAPIFormatSchema)
}

class JsonFormat: ArgumentsProvider {

override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return Stream.of(
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi+json/arrays.schema.json",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi+json;version=2.0.0", ArraysSchemaTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi+json/complex-object.schema.json",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi+json;version=2.0.0", ComplexObjectTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi+json/conditional-validation-if-else.schema.json",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi+json;version=2.0.0", ConditionalValidationIfElse().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi+json/draft-07-core-schema-meta-schema.json",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi+json;version=2.0.0", Draft07CoreSchemaMetaSchemaTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi+json/enumerated-values.schema.json",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi+json;version=2.0.0", EnumeratedValuesTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi+json/person.schema.json",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi+json;version=2.0.0", PersonTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi+json/regex-pattern.schema.json",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi+json;version=2.0.0", RegexPatternTest().asyncAPISchema())
),
//
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi/arrays.schema.json",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi;version=2.0.0", ArraysSchemaTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi/complex-object.schema.json",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi;version=2.0.0", ComplexObjectTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi/conditional-validation-if-else.schema.json",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi;version=2.0.0", ConditionalValidationIfElse().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi/draft-07-core-schema-meta-schema.json",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi;version=2.0.0", Draft07CoreSchemaMetaSchemaTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi/enumerated-values.schema.json",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi;version=2.0.0", EnumeratedValuesTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi/person.schema.json",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi;version=2.0.0", PersonTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi/regex-pattern.schema.json",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi;version=2.0.0", RegexPatternTest().asyncAPISchema())
)
)
}

}

class YamlFormat: ArgumentsProvider {

override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return Stream.of(
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi+yaml/arrays.schema.yaml",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi+yaml;version=2.0.0", ArraysSchemaTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi+yaml/complex-object.schema.yaml",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi+yaml;version=2.0.0", ComplexObjectTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi+yaml/conditional-validation-if-else.schema.yaml",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi+yaml;version=2.0.0", ConditionalValidationIfElse().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi+yaml/draft-07-core-schema-meta-schema.yaml",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi+yaml;version=2.0.0", Draft07CoreSchemaMetaSchemaTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi+yaml/enumerated-values.schema.yaml",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi+yaml;version=2.0.0", EnumeratedValuesTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi+yaml/person.schema.yaml",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi+yaml;version=2.0.0", PersonTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi+yaml/regex-pattern.schema.yaml",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi+yaml;version=2.0.0", RegexPatternTest().asyncAPISchema())
),
//
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi/arrays.schema.yaml",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi;version=2.0.0", ArraysSchemaTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi/complex-object.schema.yaml",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi;version=2.0.0", ComplexObjectTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi/conditional-validation-if-else.schema.yaml",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi;version=2.0.0", ConditionalValidationIfElse().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi/draft-07-core-schema-meta-schema.yaml",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi;version=2.0.0", Draft07CoreSchemaMetaSchemaTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi/enumerated-values.schema.yaml",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi;version=2.0.0", EnumeratedValuesTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi/person.schema.yaml",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi;version=2.0.0", PersonTest().asyncAPISchema())
),
Arguments.of(
"/json/v3/schema/multiformat/asyncapi/2.0.0/vnd.aai.asyncapi/regex-pattern.schema.yaml",
AsyncAPIFormatSchema("application/vnd.aai.asyncapi;version=2.0.0", RegexPatternTest().asyncAPISchema())
)
)
}

}

}
Loading

0 comments on commit 86f6ff8

Please sign in to comment.