diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9ea6111 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,190 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +max_line_length = 200 +tab_width = 4 +trim_trailing_whitespace = true +ij_continuation_indent_size = 4 +ij_formatter_off_tag = @formatter:off +ij_formatter_on_tag = @formatter:on +ij_formatter_tags_enabled = true +ij_smart_tabs = false +ij_visual_guides = none +ij_wrap_on_typing = false + +[{*.kt,*.kts}] +ij_kotlin_align_in_columns_case_branch = false +ij_kotlin_align_multiline_binary_operation = false +ij_kotlin_align_multiline_extends_list = false +ij_kotlin_align_multiline_method_parentheses = false +ij_kotlin_align_multiline_parameters = true +ij_kotlin_align_multiline_parameters_in_calls = false +ij_kotlin_allow_trailing_comma = false +ij_kotlin_allow_trailing_comma_on_call_site = false +ij_kotlin_assignment_wrap = normal +ij_kotlin_blank_lines_after_class_header = 0 +ij_kotlin_blank_lines_around_block_when_branches = 0 +ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 1 +ij_kotlin_block_comment_add_space = false +ij_kotlin_block_comment_at_first_column = true +ij_kotlin_call_parameters_new_line_after_left_paren = true +ij_kotlin_call_parameters_right_paren_on_new_line = true +ij_kotlin_call_parameters_wrap = on_every_item +ij_kotlin_catch_on_new_line = false +ij_kotlin_class_annotation_wrap = split_into_lines +ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL +ij_kotlin_continuation_indent_for_chained_calls = false +ij_kotlin_continuation_indent_for_expression_bodies = false +ij_kotlin_continuation_indent_in_argument_lists = false +ij_kotlin_continuation_indent_in_elvis = false +ij_kotlin_continuation_indent_in_if_conditions = false +ij_kotlin_continuation_indent_in_parameter_lists = false +ij_kotlin_continuation_indent_in_supertype_lists = false +ij_kotlin_else_on_new_line = false +ij_kotlin_enum_constants_wrap = off +ij_kotlin_extends_list_wrap = normal +ij_kotlin_field_annotation_wrap = split_into_lines +ij_kotlin_finally_on_new_line = false +ij_kotlin_if_rparen_on_new_line = true +ij_kotlin_import_nested_classes = false +ij_kotlin_imports_layout = *, java.**, javax.**, kotlin.**, ^ +ij_kotlin_insert_whitespaces_in_simple_one_line_method = true +ij_kotlin_keep_blank_lines_before_right_brace = 2 +ij_kotlin_keep_blank_lines_in_code = 2 +ij_kotlin_keep_blank_lines_in_declarations = 2 +ij_kotlin_keep_first_column_comment = true +ij_kotlin_keep_indents_on_empty_lines = false +ij_kotlin_keep_line_breaks = true +ij_kotlin_lbrace_on_next_line = false +ij_kotlin_line_break_after_multiline_when_entry = true +ij_kotlin_line_comment_add_space = false +ij_kotlin_line_comment_add_space_on_reformat = false +ij_kotlin_line_comment_at_first_column = true +ij_kotlin_method_annotation_wrap = split_into_lines +ij_kotlin_method_call_chain_wrap = normal +ij_kotlin_method_parameters_new_line_after_left_paren = true +ij_kotlin_method_parameters_right_paren_on_new_line = true +ij_kotlin_method_parameters_wrap = on_every_item +ij_kotlin_name_count_to_use_star_import = 100 +ij_kotlin_name_count_to_use_star_import_for_members = 100 +ij_kotlin_packages_to_use_import_on_demand = java.util.*, kotlinx.android.synthetic.**, io.ktor.** +ij_kotlin_parameter_annotation_wrap = off +ij_kotlin_space_after_comma = true +ij_kotlin_space_after_extend_colon = true +ij_kotlin_space_after_type_colon = true +ij_kotlin_space_before_catch_parentheses = true +ij_kotlin_space_before_comma = false +ij_kotlin_space_before_extend_colon = true +ij_kotlin_space_before_for_parentheses = true +ij_kotlin_space_before_if_parentheses = true +ij_kotlin_space_before_lambda_arrow = true +ij_kotlin_space_before_type_colon = false +ij_kotlin_space_before_when_parentheses = true +ij_kotlin_space_before_while_parentheses = true +ij_kotlin_spaces_around_additive_operators = true +ij_kotlin_spaces_around_assignment_operators = true +ij_kotlin_spaces_around_equality_operators = true +ij_kotlin_spaces_around_function_type_arrow = true +ij_kotlin_spaces_around_logical_operators = true +ij_kotlin_spaces_around_multiplicative_operators = true +ij_kotlin_spaces_around_range = false +ij_kotlin_spaces_around_relational_operators = true +ij_kotlin_spaces_around_unary_operator = false +ij_kotlin_spaces_around_when_arrow = true +ij_kotlin_variable_annotation_wrap = off +ij_kotlin_while_on_new_line = false +ij_kotlin_wrap_elvis_expressions = 1 +ij_kotlin_wrap_expression_body_functions = 1 +ij_kotlin_wrap_first_method_in_call_chain = false + +[{*.gant,*.groovy,*.gson,*.gdsl,*.gy,*.gradle}] +ij_groovy_indent_size = 2 +ij_groovy_tab_width = 2 +ij_groovy_continuation_indent_size = 4 +ij_groovy_label_indent_size = 4 +ij_groovy_align_multiline_array_initializer_expression = true +ij_groovy_align_multiline_assignment = true +ij_groovy_align_multiline_binary_operation = true +ij_groovy_align_multiline_chained_methods = true +ij_groovy_align_multiline_parameters = false +ij_groovy_align_multiline_parameters_in_calls = true +ij_groovy_align_multiline_ternary_operation = true +ij_groovy_array_initializer_new_line_after_left_brace = true +ij_groovy_array_initializer_right_brace_on_new_line = true +ij_groovy_array_initializer_wrap = normal +ij_groovy_assert_statement_wrap = on_every_item +ij_groovy_assignment_wrap = normal +ij_groovy_binary_operation_wrap = normal +ij_groovy_blank_lines_around_method_in_interface = 0 +ij_groovy_block_brace_style = next_line_if_wrapped +ij_groovy_call_parameters_wrap = normal +ij_groovy_call_parameters_new_line_after_left_paren = false +ij_groovy_call_parameters_right_paren_on_new_line = false +ij_groovy_catch_on_new_line = true +ij_groovy_class_brace_style = next_line_if_wrapped +ij_groovy_do_while_brace_force = always +ij_groovy_else_on_new_line = true +ij_groovy_enum_constants_wrap = on_every_item +ij_groovy_extends_keyword_wrap = normal +ij_groovy_finally_on_new_line = true +ij_groovy_for_brace_force = always +ij_groovy_for_statement_wrap = on_every_item +ij_groovy_if_brace_force = always +ij_groovy_imports_layout = *, |, jakarta.**, javax.**, java.**, |, $* +ij_groovy_keep_first_column_comment = true +ij_groovy_keep_multiple_expressions_in_one_line = true +ij_groovy_keep_simple_blocks_in_one_line = true +ij_groovy_lambda_brace_style = next_line_if_wrapped +ij_groovy_method_brace_style = next_line_if_wrapped +ij_groovy_method_call_chain_wrap = on_every_item +ij_groovy_method_parameters_new_line_after_left_paren = true +ij_groovy_method_parameters_wrap = normal +ij_groovy_parentheses_expression_new_line_after_left_paren = true +ij_groovy_parentheses_expression_right_paren_on_new_line = true +ij_groovy_prefer_parameters_wrap = true +ij_groovy_resource_list_new_line_after_left_paren = true +ij_groovy_resource_list_wrap = on_every_item +ij_groovy_space_before_array_initializer_left_brace = true +ij_groovy_spaces_within_gstring_injection_braces = false +ij_groovy_ternary_operation_wrap = on_every_item +ij_groovy_throws_keyword_wrap = normal +ij_groovy_throws_list_wrap = normal +ij_groovy_while_brace_force = always +ij_groovy_while_on_new_line = true + +[{*.markdown,*.md}] +ij_markdown_force_one_space_after_blockquote_symbol = true +ij_markdown_force_one_space_after_header_symbol = true +ij_markdown_force_one_space_after_list_bullet = true +ij_markdown_force_one_space_between_words = true +ij_markdown_keep_indents_on_empty_lines = false +ij_markdown_max_lines_around_block_elements = 1 +ij_markdown_max_lines_around_header = 1 +ij_markdown_max_lines_between_paragraphs = 1 +ij_markdown_min_lines_around_block_elements = 1 +ij_markdown_min_lines_around_header = 1 +ij_markdown_min_lines_between_paragraphs = 1 + +[*.properties] +ij_properties_align_group_field_declarations = false +ij_properties_keep_blank_lines = true +ij_properties_key_value_delimiter = equals +ij_properties_spaces_around_key_value_delimiter = false + +[{*.yaml,*.yml}] +ij_yaml_indent_size = 2 +ij_yaml_align_values_properties = do_not_align +ij_yaml_autoinsert_sequence_marker = true +ij_yaml_block_mapping_on_new_line = false +ij_yaml_indent_sequence_value = true +ij_yaml_keep_indents_on_empty_lines = false +ij_yaml_keep_line_breaks = true +ij_yaml_sequence_on_new_line = false +ij_yaml_space_before_colon = false +ij_yaml_spaces_within_braces = false +ij_yaml_spaces_within_brackets = false diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec56034..af9c3f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,8 +10,8 @@ jobs: build-and-deploy-documentation: strategy: matrix: - java: [ "17" ] - os: [ ubuntu-latest ] + java: ["11"] + os: [ubuntu-latest] runs-on: ${{ matrix.os }} name: ${{ matrix.os }} - JDK ${{ matrix.java }} @@ -93,4 +93,4 @@ jobs: if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }} uses: gradle/gradle-build-action@v2 with: - arguments: :plugin:publishPlugins -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} \ No newline at end of file + arguments: :plugin:publishPlugins -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} diff --git a/README.md b/README.md index 425bafa..2663dc2 100644 --- a/README.md +++ b/README.md @@ -42,17 +42,17 @@ under the `schemaRegistry` group: ## License Copyright (c) 2023 CROZ Ltd. - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2d2fd7c..070cb70 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists \ No newline at end of file +zipStorePath=wrapper/dists diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 7a0fdc1..f1b31d9 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -16,7 +16,6 @@ plugins { alias(libs.plugins.kotlinx.binaryCompatibilityValidator) } -// Dependencies dependencies { implementation(libs.apicurio.client) @@ -24,17 +23,15 @@ dependencies { testFixturesImplementation(libs.spock.testContainers) } -// Compile java { - sourceCompatibility = JavaVersion.VERSION_18 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 } tasks.withType { - kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString() + kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString() } -// Test testing { suites { val test by getting(JvmTestSuite::class) { @@ -93,7 +90,6 @@ kover { } } -// Documentation tasks.withType() { dokkaSourceSets { configureEach { @@ -102,7 +98,6 @@ tasks.withType() { } } -// Plugin gradlePlugin { plugins { create("apicurio-registry-gradle-plugin") { @@ -116,8 +111,6 @@ gradlePlugin { testSourceSets(sourceSets.getByName("functionalTest")) } -// For publishing to the Gradle Plugin Portal -// https://plugins.gradle.org/docs/publish-plugin pluginBundle { website = "https://github.com/croz-ltd/apicurio-registry-gradle-plugin" vcsUrl = "https://github.com/croz-ltd/apicurio-registry-gradle-plugin.git" @@ -129,7 +122,6 @@ val isSnapshot = project.version.toString().endsWith("SNAPSHOT") val isRelease = !isSnapshot val check = tasks.named("check") -val functionalTest = tasks.named("functionalTest") tasks.named("publishPlugins") { onlyIf { isRelease } @@ -137,4 +129,4 @@ tasks.named("publishPlugins") { if (isRelease) { dependsOn(check) } -} \ No newline at end of file +} diff --git a/plugin/dokka/moduledoc.md b/plugin/dokka/moduledoc.md index 8d886fd..cd4fbe0 100644 --- a/plugin/dokka/moduledoc.md +++ b/plugin/dokka/moduledoc.md @@ -6,6 +6,10 @@ This module shows the Apicurio Registry Gradle Plugin syntax usage. The root package containing the plugin implementation. +# Package net.croz.apicurio.exception + +Contains the exceptions used by this plugin. + # Package net.croz.apicurio.extension Contains the extensions that consist of all the settings and properties for this plugin. diff --git a/plugin/gradle.properties b/plugin/gradle.properties index 9ba57cd..3ea9e11 100644 --- a/plugin/gradle.properties +++ b/plugin/gradle.properties @@ -1,3 +1,3 @@ -VERSION=1.0.0 +VERSION=1.1.0 -kotlin.code.style=official \ No newline at end of file +kotlin.code.style=official diff --git a/plugin/src/functionalTest/groovy/net/croz/apicurio/SchemaRegistryPluginSpecification.groovy b/plugin/src/functionalTest/groovy/net/croz/apicurio/SchemaRegistryPluginSpecification.groovy index fa0347a..2f57ae7 100644 --- a/plugin/src/functionalTest/groovy/net/croz/apicurio/SchemaRegistryPluginSpecification.groovy +++ b/plugin/src/functionalTest/groovy/net/croz/apicurio/SchemaRegistryPluginSpecification.groovy @@ -3,17 +3,17 @@ package net.croz.apicurio import net.croz.apicurio.core.specification.AbstractFunctionalSpecification class SchemaRegistryPluginSpecification extends AbstractFunctionalSpecification { - def setup() { - appendPluginDefinition() - } + def setup() { + appendPluginDefinition() + } - def "adds tasks"() { - when: + def "adds tasks"() { + when: def buildResult = build("tasks") - then: + then: buildResult.output.contains( - """ + """ SchemaRegistry tasks -------------------- schemaRegistryCompatibility - Checks for compatibility issues between local artifacts and remote artifacts on the Apicurio schema registry @@ -21,5 +21,5 @@ class SchemaRegistryPluginSpecification extends AbstractFunctionalSpecification schemaRegistryRegister - Registers artifacts on the Apicurio schema registry """.stripIndent() ) - } + } } diff --git a/plugin/src/functionalTest/groovy/net/croz/apicurio/core/specification/AbstractFunctionalSpecification.groovy b/plugin/src/functionalTest/groovy/net/croz/apicurio/core/specification/AbstractFunctionalSpecification.groovy index 9a398c2..e9f8dc8 100644 --- a/plugin/src/functionalTest/groovy/net/croz/apicurio/core/specification/AbstractFunctionalSpecification.groovy +++ b/plugin/src/functionalTest/groovy/net/croz/apicurio/core/specification/AbstractFunctionalSpecification.groovy @@ -16,67 +16,64 @@ import java.nio.file.Path @Testcontainers abstract class AbstractFunctionalSpecification extends Specification { - @TempDir - Path projectDir - Path buildFile + @TempDir + Path projectDir + Path buildFile - static final GenericContainer schemaRegistryContainer + static final GenericContainer schemaRegistryContainer = ApicurioSchemaRegistryContainerFactory.makeAndStartContainer() - static { - schemaRegistryContainer = ApicurioSchemaRegistryContainerFactory.makeAndStartContainer() - } + def setup() { + buildFile = Files.createFile(projectDir.resolve("build.gradle.kts")) + } - def setup() { - buildFile = Files.createFile(projectDir.resolve("build.gradle.kts")) - } + protected void assertArtifactExistsAndIsReadable(String path, String fileName) { + def outputParentPath = projectDir.resolve(path) + assert Files.exists(outputParentPath): "output file parent path must exist" - protected void assertArtifactExistsAndIsReadable(String path, String fileName) { - def outputParentPath = projectDir.resolve(path) - assert Files.exists(outputParentPath): "output file parent path must exist" + def outputPath = outputParentPath.resolve(fileName) + assert Files.exists(outputPath): "output file path must exist" + assert Files.isReadable(outputPath): "output file must be readable" + } - def outputPath = outputParentPath.resolve(fileName) - assert Files.exists(outputPath): "output file path must exist" - assert Files.isReadable(outputPath): "output file must be readable" + protected void assertArtifactRegisteredProperly(String groupId = null, String artifactId, ClientArtifactType clientArtifactType) { + def metadata = SchemaRegistryUtil.retrieveArtifactMetadata(schemaRegistryUrl, new RetrieveArtifactMetadata(groupId, artifactId)) + assert metadata: "metadata must be present" + if (!groupId) { + assert !metadata.groupId: "group ID should be default (null)" } - - protected void assertArtifactRegisteredProperly(String groupId = null, String artifactId, ClientArtifactType clientArtifactType) { - def metadata = SchemaRegistryUtil.retrieveArtifactMetadata(schemaRegistryUrl, new RetrieveArtifactMetadata(groupId, artifactId)) - assert metadata: "metadata must be present" - if (!groupId) { - assert !metadata.groupId: "group ID should be default (null)" - } else { - assert metadata.groupId == groupId: "group ID must match" - } - assert metadata.id == artifactId: "artifact ID must match" - assert metadata.type == clientArtifactType: "artifact type must match" + else { + assert metadata.groupId == groupId: "group ID must match" } + assert metadata.id == artifactId: "artifact ID must match" + assert metadata.type == clientArtifactType: "artifact type must match" + } - protected String getSchemaRegistryUrl() { - "http://$schemaRegistryContainer.host:${schemaRegistryContainer.firstMappedPort}" - } + protected String getSchemaRegistryUrl() { + "http://$schemaRegistryContainer.host:${schemaRegistryContainer.firstMappedPort}" + } - protected appendPluginDefinition() { - buildFile << """ + protected appendPluginDefinition() { + buildFile << """ plugins { id("net.croz.apicurio-registry-gradle-plugin") } """ - } + } - protected BuildResult build(String... arguments) { - createAndConfigureGradleRunner(arguments).build() - } + protected BuildResult build(String... arguments) { + createAndConfigureGradleRunner(arguments).build() + } - protected BuildResult buildAndFail(String... arguments) { - createAndConfigureGradleRunner(arguments).buildAndFail() - } + protected BuildResult buildAndFail(String... arguments) { + createAndConfigureGradleRunner(arguments).buildAndFail() + } - private GradleRunner createAndConfigureGradleRunner(String... arguments) { - GradleRunner.create() + private GradleRunner createAndConfigureGradleRunner(String... arguments) { + GradleRunner.create() .withPluginClasspath() .withProjectDir(projectDir.toFile()) .withArguments(arguments + '-s' as List) .withDebug(true) .forwardOutput() - } + } } diff --git a/plugin/src/functionalTest/groovy/net/croz/apicurio/task/compatibility/SchemaRegistryCompatibilityTaskSpecification.groovy b/plugin/src/functionalTest/groovy/net/croz/apicurio/task/compatibility/SchemaRegistryCompatibilityTaskSpecification.groovy index 0fda6fc..431c376 100644 --- a/plugin/src/functionalTest/groovy/net/croz/apicurio/task/compatibility/SchemaRegistryCompatibilityTaskSpecification.groovy +++ b/plugin/src/functionalTest/groovy/net/croz/apicurio/task/compatibility/SchemaRegistryCompatibilityTaskSpecification.groovy @@ -12,12 +12,12 @@ import org.gradle.testkit.runner.TaskOutcome import java.nio.file.Files class SchemaRegistryCompatibilityTaskSpecification extends AbstractFunctionalSpecification { - def setup() { - appendPluginDefinition() - } + def setup() { + appendPluginDefinition() + } - def "should fail checking for compatibility issues of a non-existent artifact"() { - setup: + def "should fail checking for compatibility issues of a non-existent artifact"() { + setup: def metadata = ArtifactMetadataGeneratingUtil.generate() def artifactFile = projectDir.resolve(inputFileName) Files.createFile(artifactFile) << IOUtil.getResource(inputFileName) @@ -27,7 +27,7 @@ class SchemaRegistryCompatibilityTaskSpecification extends AbstractFunctionalSpe url("$schemaRegistryUrl") } compatibility { - artifact { + artifact { id = "$metadata.artifactId" path = "${artifactFile.toAbsolutePath().toString()}" } @@ -35,22 +35,23 @@ class SchemaRegistryCompatibilityTaskSpecification extends AbstractFunctionalSpe } """ - when: + when: def result = buildAndFail(SchemaRegistryCompatibilityTask.TASK_NAME) - then: + then: result.task(":$SchemaRegistryCompatibilityTask.TASK_NAME").outcome == TaskOutcome.FAILED result.output.contains("1 artifacts not compatible, see logs for details") - where: + where: inputFileName | _ "TestAvro.avsc" | _ - } + } - def "should check artifact compatibility"() { - setup: + def "should check artifact compatibility"() { + setup: def metadata = ArtifactMetadataGeneratingUtil.generate() - SchemaRegistryUtil.registerArtifact(schemaRegistryUrl, new RegisterArtifact(path: inputFileName, artifactId: metadata.artifactId, name: metadata.name, type: ArtifactTypeKt.toClientArtifactType(ArtifactType.@Companion.fromName(artifactTypeName)))) + SchemaRegistryUtil.registerArtifact(schemaRegistryUrl, new RegisterArtifact(path: inputFileName, artifactId: metadata.artifactId, name: metadata.name, + type: ArtifactTypeKt.toClientArtifactType(ArtifactType.@Companion.fromName(artifactTypeName)))) def artifactFile = projectDir.resolve(inputFileName) Files.createFile(artifactFile) << IOUtil.getResource(inputFileName) buildFile << """ @@ -67,14 +68,14 @@ class SchemaRegistryCompatibilityTaskSpecification extends AbstractFunctionalSpe } """ - when: + when: def result = build(SchemaRegistryCompatibilityTask.TASK_NAME) - then: + then: result.task(":$SchemaRegistryCompatibilityTask.TASK_NAME").outcome == TaskOutcome.SUCCESS - where: + where: inputFileName | artifactTypeName "TestAvro.avsc" | "AVRO" - } + } } diff --git a/plugin/src/functionalTest/groovy/net/croz/apicurio/task/download/SchemaRegistryDownloadTaskSpecification.groovy b/plugin/src/functionalTest/groovy/net/croz/apicurio/task/download/SchemaRegistryDownloadTaskSpecification.groovy index 100b2ee..7edf4b7 100644 --- a/plugin/src/functionalTest/groovy/net/croz/apicurio/task/download/SchemaRegistryDownloadTaskSpecification.groovy +++ b/plugin/src/functionalTest/groovy/net/croz/apicurio/task/download/SchemaRegistryDownloadTaskSpecification.groovy @@ -9,12 +9,12 @@ import net.croz.apicurio.util.SchemaRegistryUtil import org.gradle.testkit.runner.TaskOutcome class SchemaRegistryDownloadTaskSpecification extends AbstractFunctionalSpecification { - def setup() { - appendPluginDefinition() - } + def setup() { + appendPluginDefinition() + } - def "should fail downloading non-existent unversioned artifact"() { - setup: + def "should fail downloading non-existent unversioned artifact"() { + setup: def metadata = ArtifactMetadataGeneratingUtil.generate() buildFile << """ schemaRegistry { @@ -30,16 +30,16 @@ class SchemaRegistryDownloadTaskSpecification extends AbstractFunctionalSpecific } """ - when: + when: def result = buildAndFail(SchemaRegistryDownloadTask.TASK_NAME) - then: + then: result.task(":$SchemaRegistryDownloadTask.TASK_NAME").outcome == TaskOutcome.FAILED result.output.contains("1 artifacts not downloaded, see logs for details") - } + } - def "should fail downloading non-existent versioned artifact"() { - setup: + def "should fail downloading non-existent versioned artifact"() { + setup: def metadata = ArtifactMetadataGeneratingUtil.generate() buildFile << """ schemaRegistry { @@ -56,18 +56,19 @@ class SchemaRegistryDownloadTaskSpecification extends AbstractFunctionalSpecific } """ - when: + when: def result = buildAndFail(SchemaRegistryDownloadTask.TASK_NAME) - then: + then: result.task(":$SchemaRegistryDownloadTask.TASK_NAME").outcome == TaskOutcome.FAILED result.output.contains("1 artifacts not downloaded, see logs for details") - } + } - def "should download an existing unversioned artifact"() { - setup: + def "should download an existing unversioned artifact"() { + setup: def metadata = ArtifactMetadataGeneratingUtil.generate(artifactType) - SchemaRegistryUtil.registerArtifact(schemaRegistryUrl, new RegisterArtifact(path: inputFileName, artifactId: metadata.artifactId, name: metadata.name, type: ArtifactTypeKt.toClientArtifactType(artifactType))) + SchemaRegistryUtil.registerArtifact(schemaRegistryUrl, + new RegisterArtifact(path: inputFileName, artifactId: metadata.artifactId, name: metadata.name, type: ArtifactTypeKt.toClientArtifactType(artifactType))) buildFile << """ schemaRegistry { config { @@ -82,22 +83,23 @@ class SchemaRegistryDownloadTaskSpecification extends AbstractFunctionalSpecific } """ - when: + when: def result = build(SchemaRegistryDownloadTask.TASK_NAME) - then: + then: result.task(":$SchemaRegistryDownloadTask.TASK_NAME").outcome == TaskOutcome.SUCCESS assertArtifactExistsAndIsReadable(metadata.outputPath, "${metadata.name}.${artifactType.extension}") - where: + where: inputFileName | artifactType "TestAvro.avsc" | ArtifactType.AVRO - } + } - def "should download an existing versioned artifact"() { - setup: + def "should download an existing versioned artifact"() { + setup: def metadata = ArtifactMetadataGeneratingUtil.generate(artifactType) - SchemaRegistryUtil.registerArtifact(schemaRegistryUrl, new RegisterArtifact(path: inputFileName, artifactId: metadata.artifactId, name: metadata.name, version: metadata.version, type: ArtifactTypeKt.toClientArtifactType(artifactType))) + SchemaRegistryUtil.registerArtifact(schemaRegistryUrl, new RegisterArtifact(path: inputFileName, artifactId: metadata.artifactId, name: metadata.name, version: metadata.version, + type: ArtifactTypeKt.toClientArtifactType(artifactType))) buildFile << """ schemaRegistry { config { @@ -113,22 +115,23 @@ class SchemaRegistryDownloadTaskSpecification extends AbstractFunctionalSpecific } """ - when: + when: def result = build(SchemaRegistryDownloadTask.TASK_NAME) - then: + then: result.task(":$SchemaRegistryDownloadTask.TASK_NAME").outcome == TaskOutcome.SUCCESS assertArtifactExistsAndIsReadable(metadata.outputPath, "${metadata.name}.${artifactType.extension}") - where: + where: inputFileName | artifactType "TestAvro.avsc" | ArtifactType.AVRO - } + } - def "should download artifact with custom output file name"() { - setup: + def "should download artifact with custom output file name"() { + setup: def metadata = ArtifactMetadataGeneratingUtil.generate(artifactType) - SchemaRegistryUtil.registerArtifact(schemaRegistryUrl, new RegisterArtifact(path: inputFileName, artifactId: metadata.artifactId, name: metadata.name, type: ArtifactTypeKt.toClientArtifactType(artifactType))) + SchemaRegistryUtil.registerArtifact(schemaRegistryUrl, + new RegisterArtifact(path: inputFileName, artifactId: metadata.artifactId, name: metadata.name, type: ArtifactTypeKt.toClientArtifactType(artifactType))) buildFile << """ schemaRegistry { config { @@ -144,15 +147,15 @@ class SchemaRegistryDownloadTaskSpecification extends AbstractFunctionalSpecific } """ - when: + when: def result = build(SchemaRegistryDownloadTask.TASK_NAME) - then: + then: result.task(":$SchemaRegistryDownloadTask.TASK_NAME").outcome == TaskOutcome.SUCCESS assertArtifactExistsAndIsReadable(metadata.outputPath, "${outputFileName}.${artifactType.extension}") - where: + where: inputFileName | outputFileName | artifactType "TestAvro.avsc" | "CustomTestAvro" | ArtifactType.AVRO - } + } } diff --git a/plugin/src/functionalTest/groovy/net/croz/apicurio/task/register/SchemaRegistryRegisterTaskSpecification.groovy b/plugin/src/functionalTest/groovy/net/croz/apicurio/task/register/SchemaRegistryRegisterTaskSpecification.groovy index 96a837c..4717dc3 100644 --- a/plugin/src/functionalTest/groovy/net/croz/apicurio/task/register/SchemaRegistryRegisterTaskSpecification.groovy +++ b/plugin/src/functionalTest/groovy/net/croz/apicurio/task/register/SchemaRegistryRegisterTaskSpecification.groovy @@ -9,13 +9,13 @@ import org.gradle.testkit.runner.TaskOutcome import java.nio.file.Files class SchemaRegistryRegisterTaskSpecification extends AbstractFunctionalSpecification { - def setup() { - appendPluginDefinition() - Files.createDirectories(projectDir.resolve("src").resolve("main").resolve("artifact")) - } + def setup() { + appendPluginDefinition() + Files.createDirectories(projectDir.resolve("src").resolve("main").resolve("artifact")) + } - def "should fail registering non-existent local artifact"() { - setup: + def "should fail registering non-existent local artifact"() { + setup: def metadata = ArtifactMetadataGeneratingUtil.generate() def artifactTypeName = "AVRO" buildFile << """ @@ -34,16 +34,16 @@ class SchemaRegistryRegisterTaskSpecification extends AbstractFunctionalSpecific } """ - when: + when: def result = buildAndFail(SchemaRegistryRegisterTask.TASK_NAME) - then: + then: result.task(":$SchemaRegistryRegisterTask.TASK_NAME").outcome == TaskOutcome.FAILED result.output.contains("1 artifacts not registered, see logs for details") - } + } - def "should fail registering an artifact with an unknown artifact type"() { - setup: + def "should fail registering an artifact with an unknown artifact type"() { + setup: def metadata = ArtifactMetadataGeneratingUtil.generate() def artifactTypeName = "TEST" buildFile << """ @@ -62,15 +62,15 @@ class SchemaRegistryRegisterTaskSpecification extends AbstractFunctionalSpecific } """ - when: + when: def result = buildAndFail(SchemaRegistryRegisterTask.TASK_NAME) - then: + then: result.output.contains("Cannot derive artifact type from name [$artifactTypeName]. Possible values include: [AVRO, PROTOBUF, JSON, OPENAPI, ASYNCAPI, GRAPHQL, KCONNECT, WSDL, XSD, XML].") - } + } - def "should register local artifact in default group"() { - setup: + def "should register local artifact in default group"() { + setup: def metadata = ArtifactMetadataGeneratingUtil.generate() def artifactFile = projectDir.resolve(inputFileName) Files.createFile(artifactFile) << IOUtil.getResource(inputFileName) @@ -90,20 +90,20 @@ class SchemaRegistryRegisterTaskSpecification extends AbstractFunctionalSpecific } """ - when: + when: def result = build(SchemaRegistryRegisterTask.TASK_NAME) - then: + then: result.task(":$SchemaRegistryRegisterTask.TASK_NAME").outcome == TaskOutcome.SUCCESS assertArtifactRegisteredProperly metadata.artifactId, clientArtifactType - where: + where: inputFileName | artifactTypeName || clientArtifactType "TestAvro.avsc" | "AVRO" || ClientArtifactType.AVRO - } + } - def "should register local artifact in specific group"() { - setup: + def "should register local artifact in specific group"() { + setup: def metadata = ArtifactMetadataGeneratingUtil.generate() def artifactFile = projectDir.resolve(inputFileName) Files.createFile(artifactFile) << IOUtil.getResource(inputFileName) @@ -125,15 +125,15 @@ class SchemaRegistryRegisterTaskSpecification extends AbstractFunctionalSpecific } """ - when: + when: def result = build(SchemaRegistryRegisterTask.TASK_NAME) - then: + then: result.task(":$SchemaRegistryRegisterTask.TASK_NAME").outcome == TaskOutcome.SUCCESS assertArtifactRegisteredProperly metadata.groupId, metadata.artifactId, clientArtifactType - where: + where: inputFileName | artifactTypeName | conflictHandleTypeName || clientArtifactType "TestAvro.avsc" | "AVRO" | "RETURN_OR_UPDATE" || ClientArtifactType.AVRO - } + } } diff --git a/plugin/src/main/kotlin/net/croz/apicurio/exception/UnknownArtifactTypeException.kt b/plugin/src/main/kotlin/net/croz/apicurio/exception/UnknownArtifactTypeException.kt new file mode 100644 index 0000000..5a95011 --- /dev/null +++ b/plugin/src/main/kotlin/net/croz/apicurio/exception/UnknownArtifactTypeException.kt @@ -0,0 +1,16 @@ +package net.croz.apicurio.exception + +import net.croz.apicurio.model.ArtifactType + +/** + * An exception representing a state where an artifact type name cannot be associated with from the given string value. + * Used by [ArtifactType] internally. + * + * @see ArtifactType + */ +internal class UnknownArtifactTypeException(type: String) : + Exception( + "Cannot derive artifact type from name [${type}]. Possible values include: [${ + ArtifactType.values().joinToString() + }]." + ) diff --git a/plugin/src/main/kotlin/net/croz/apicurio/exception/UnknownConflictHandleTypeException.kt b/plugin/src/main/kotlin/net/croz/apicurio/exception/UnknownConflictHandleTypeException.kt new file mode 100644 index 0000000..2a93de5 --- /dev/null +++ b/plugin/src/main/kotlin/net/croz/apicurio/exception/UnknownConflictHandleTypeException.kt @@ -0,0 +1,16 @@ +package net.croz.apicurio.exception + +import net.croz.apicurio.model.ConflictHandleType + +/** + * An exception representing a state where a conflict handle type name cannot be associated with from the given string value. + * Used by [ConflictHandleType] internally. + * + * @see ConflictHandleType + */ +internal class UnknownConflictHandleTypeException(type: String) : + Exception( + "Cannot derive conflict handle type from name [${type}]. Possible values include: [${ + ConflictHandleType.values().joinToString() + }]." + ) diff --git a/plugin/src/main/kotlin/net/croz/apicurio/extension/ConfigurationHandler.kt b/plugin/src/main/kotlin/net/croz/apicurio/extension/ConfigurationHandler.kt index fc9f2b0..cd5aba8 100644 --- a/plugin/src/main/kotlin/net/croz/apicurio/extension/ConfigurationHandler.kt +++ b/plugin/src/main/kotlin/net/croz/apicurio/extension/ConfigurationHandler.kt @@ -5,7 +5,6 @@ import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.Property import javax.inject.Inject - /** * A nested DSL structure which configures the connection information (URL, authentication) need to connect to the Apicurio Schema Registry. */ @@ -51,4 +50,4 @@ open class ConfigurationHandler @Inject constructor(factory: ObjectFactory) { ) authentication.disallowChanges() } -} \ No newline at end of file +} diff --git a/plugin/src/main/kotlin/net/croz/apicurio/model/Artifact.kt b/plugin/src/main/kotlin/net/croz/apicurio/model/Artifact.kt index e98b949..69bbad8 100644 --- a/plugin/src/main/kotlin/net/croz/apicurio/model/Artifact.kt +++ b/plugin/src/main/kotlin/net/croz/apicurio/model/Artifact.kt @@ -7,11 +7,9 @@ import org.gradle.api.tasks.Optional /** * A DSL structure representing the basic artifact details. * -/** * @property id The corresponding artifact ID from the schema registry. * @property groupId The specific group ID from the schema registry. Default group ID is applied if omitted. * @property version The specific version from the schema registry. The latest version is considered implicitly if omitted. -*/ */ open class Artifact { @get:Input @@ -32,4 +30,4 @@ open class Artifact { } else { "$groupId:$id" } -} \ No newline at end of file +} diff --git a/plugin/src/main/kotlin/net/croz/apicurio/model/ArtifactType.kt b/plugin/src/main/kotlin/net/croz/apicurio/model/ArtifactType.kt index 18fe34d..9267b8e 100644 --- a/plugin/src/main/kotlin/net/croz/apicurio/model/ArtifactType.kt +++ b/plugin/src/main/kotlin/net/croz/apicurio/model/ArtifactType.kt @@ -1,6 +1,6 @@ package net.croz.apicurio.model -import net.croz.apicurio.core.UnknownArtifactTypeException +import net.croz.apicurio.exception.UnknownArtifactTypeException import net.croz.apicurio.service.client.ClientArtifactType /** @@ -29,7 +29,7 @@ internal enum class ArtifactType(val extension: String) { * @throws UnknownArtifactTypeException if the associated artifact type is not found */ fun fromName(name: String) = - values().firstOrNull() { it.name == name } ?: throw UnknownArtifactTypeException(name) + values().firstOrNull { it.name == name } ?: throw UnknownArtifactTypeException(name) } } diff --git a/plugin/src/main/kotlin/net/croz/apicurio/model/ConflictHandleType.kt b/plugin/src/main/kotlin/net/croz/apicurio/model/ConflictHandleType.kt index 79d168d..5eb7056 100644 --- a/plugin/src/main/kotlin/net/croz/apicurio/model/ConflictHandleType.kt +++ b/plugin/src/main/kotlin/net/croz/apicurio/model/ConflictHandleType.kt @@ -1,13 +1,13 @@ package net.croz.apicurio.model -import net.croz.apicurio.core.UnknownConflictHandleTypeException +import net.croz.apicurio.exception.UnknownConflictHandleTypeException import net.croz.apicurio.service.client.ClientConflictHandleType /** * Contains the conflict handle types available for usage with this plugin which determines the behavior * during registering a local artifact which is the identical to its remote counterpart. */ -internal enum class ConflictHandleType() { +internal enum class ConflictHandleType { FAIL, UPDATE, RETURN, @@ -21,7 +21,7 @@ internal enum class ConflictHandleType() { * @throws UnknownConflictHandleTypeException if the associated conflict handle type is not found */ fun fromName(name: String) = - ConflictHandleType.values().firstOrNull() { it.name == name } ?: throw UnknownConflictHandleTypeException( + ConflictHandleType.values().firstOrNull { it.name == name } ?: throw UnknownConflictHandleTypeException( name ) } diff --git a/plugin/src/main/kotlin/net/croz/apicurio/model/Exceptions.kt b/plugin/src/main/kotlin/net/croz/apicurio/model/Exceptions.kt deleted file mode 100644 index 09cd506..0000000 --- a/plugin/src/main/kotlin/net/croz/apicurio/model/Exceptions.kt +++ /dev/null @@ -1,30 +0,0 @@ -package net.croz.apicurio.core - -import net.croz.apicurio.model.ArtifactType -import net.croz.apicurio.model.ConflictHandleType - -/** - * An exception representing a state where an artifact type name cannot be associated with from the given string value. - * Used by [ArtifactType] internally. - * - * @see ArtifactType - */ -internal class UnknownArtifactTypeException(type: String) : - Exception( - "Cannot derive artifact type from name [${type}]. Possible values include: [${ - ArtifactType.values().joinToString(", ") - }]." - ) - -/** - * An exception representing a state where a conflict handle type name cannot be associated with from the given string value. - * Used by [ConflictHandleType] internally. - * - * @see ConflictHandleType - */ -internal class UnknownConflictHandleTypeException(type: String) : - Exception( - "Cannot derive conflict handle type from name [${type}]. Possible values include: [${ - ConflictHandleType.values().joinToString(", ") - }]." - ) \ No newline at end of file diff --git a/plugin/src/main/kotlin/net/croz/apicurio/service/SchemaRegistryClientService.kt b/plugin/src/main/kotlin/net/croz/apicurio/service/SchemaRegistryClientService.kt index 42879f8..ef3cebe 100644 --- a/plugin/src/main/kotlin/net/croz/apicurio/service/SchemaRegistryClientService.kt +++ b/plugin/src/main/kotlin/net/croz/apicurio/service/SchemaRegistryClientService.kt @@ -33,10 +33,10 @@ internal abstract class SchemaRegistryClientService : BuildService { + client = RegistryClientFactory.create(url) + } + + is Authentication.Basic -> { + val auth = BasicAuth(authentication.username, authentication.password) + client = RegistryClientFactory.create(url, emptyMap(), auth) + } + + is Authentication.OAuth -> { + httpClient = + ApicurioHttpClientFactory.create(authentication.authServerUrl, AuthErrorHandler()) + val auth = OidcAuth( + httpClient, + authentication.clientId, + authentication.clientSecret + ) + client = RegistryClientFactory.create(url, emptyMap(), auth) + } + } + } + /** * Retrieves the metadata correlated to a specific artifact with the information from the [command] object. * @@ -31,7 +66,25 @@ internal interface SchemaRegistryClient { * * @return the artifact metadata */ - fun fetchMetadata(command: ClientCommand.Download): ClientMetadata + fun fetchMetadata(command: ClientCommand.Download): ClientMetadata { + val artifact = command.artifact + + return if (artifact.version == null) { + val metadata = + client.getArtifactMetaData(artifact.groupId, artifact.id) + + ClientMetadata(metadata.name, metadata.type.toArtifactType()) + } else { + val metadata = + client.getArtifactVersionMetaData( + artifact.groupId, + artifact.id, + artifact.version + ) + + ClientMetadata(metadata.name, metadata.type.toArtifactType()) + } + } /** * Retrieves an input stream correlated to a specific artifact with the information from the [command] object. @@ -41,7 +94,19 @@ internal interface SchemaRegistryClient { * * @return an input stream to be consumed for manipulation */ - fun fetchContent(command: ClientCommand.Download): InputStream + fun fetchContent(command: ClientCommand.Download): InputStream { + val artifact = command.artifact + + return if (artifact.version == null) { + client.getLatestArtifact(artifact.groupId, artifact.id) + } else { + client.getArtifactVersion( + artifact.groupId, + artifact.id, + artifact.version + ) + } + } /** * Registers a new artifact with the information from the [command] object. @@ -50,7 +115,30 @@ internal interface SchemaRegistryClient { * * @return the created artifact's metadata */ - fun register(command: ClientCommand.Register): ClientMetadata + fun register(command: ClientCommand.Register): ClientMetadata { + val artifact = command.artifact + + val artifactType = ArtifactType.fromName(artifact.type) + val conflictHandleTypeValue = artifact.conflictHandleType + val conflictHandleType = if (conflictHandleTypeValue != null) { + ConflictHandleType.fromName(conflictHandleTypeValue) + } else { + ConflictHandleType.FAIL + } + val createArtifactMetadata = client.createArtifact( + artifact.groupId, + artifact.id, + artifact.version, + artifactType.toClientArtifactType(), + conflictHandleType.toClientConflictHandleType(), + artifact.canonicalize, + artifact.name, + artifact.description, + command.data + ) + + return ClientMetadata(createArtifactMetadata.name, createArtifactMetadata.type.toArtifactType()) + } /** * Validates that the local artifact file is compatible with its remote counterpart located on the Apicurio Schema Registry. @@ -59,130 +147,19 @@ internal interface SchemaRegistryClient { * * @return the created artifact's metadata */ - fun isCompatible(command: ClientCommand.Compatibility) - - companion object : SchemaRegistryClient { - private lateinit var httpClient: ApicurioHttpClient - private lateinit var client: RegistryClient - - @Volatile - private var INSTANCE: SchemaRegistryClient? = null - - fun getInstance( - url: String, - authentication: Authentication - ): SchemaRegistryClient = - INSTANCE ?: synchronized(this) { - INSTANCE ?: buildClient(url, authentication).also { INSTANCE = it } - } - - /** - * Attemps to clean-up opened resources. - */ - fun close() { - if (Companion::httpClient.isInitialized) { - httpClient.close() - } - if (Companion::client.isInitialized) { - client.close() - } - } - - /** - * Builds a new singleton instance of this wrapper utilizing the provided schema registry URL and the authentication details. - */ - private fun buildClient( - url: String, - authentication: Authentication - ): SchemaRegistryClient { - when (authentication) { - is Authentication.None -> { - client = RegistryClientFactory.create(url) - } - - is Authentication.Basic -> { - val auth = BasicAuth(authentication.username, authentication.password) - client = RegistryClientFactory.create(url, emptyMap(), auth) - } - - is Authentication.OAuth -> { - httpClient = - ApicurioHttpClientFactory.create(authentication.authServerUrl, AuthErrorHandler()) - val auth = OidcAuth( - httpClient, - authentication.clientId, - authentication.clientSecret - ) - client = RegistryClientFactory.create(url, emptyMap(), auth) - } - } - - return this@Companion - } - - override fun fetchMetadata(command: ClientCommand.Download): ClientMetadata { - val artifact = command.artifact - - return if (artifact.version == null) { - val metadata = - client.getArtifactMetaData(artifact.groupId, artifact.id) - - ClientMetadata(metadata.name, metadata.type.toArtifactType()) - } else { - val metadata = - client.getArtifactVersionMetaData( - artifact.groupId, - artifact.id, - artifact.version - ) - - ClientMetadata(metadata.name, metadata.type.toArtifactType()) - } - } - - override fun fetchContent(command: ClientCommand.Download): InputStream { - val artifact = command.artifact - - return if (artifact.version == null) { - client.getLatestArtifact(artifact.groupId, artifact.id) - } else { - client.getArtifactVersion( - artifact.groupId, - artifact.id, - artifact.version - ) - } - } - - override fun register(command: ClientCommand.Register): ClientMetadata { - val artifact = command.artifact - - val artifactType = ArtifactType.fromName(artifact.type) - val conflictHandleTypeValue = artifact.conflictHandleType - val conflictHandleType = if (conflictHandleTypeValue != null) { - ConflictHandleType.fromName(conflictHandleTypeValue) - } else { - ConflictHandleType.FAIL - } - val createArtifactMetadata = client.createArtifact( - artifact.groupId, - artifact.id, - artifact.version, - artifactType.toClientArtifactType(), - conflictHandleType.toClientConflictHandleType(), - artifact.canonicalize, - artifact.name, - artifact.description, - command.data - ) - - return ClientMetadata(createArtifactMetadata.name, createArtifactMetadata.type.toArtifactType()) - } + fun isCompatible(command: ClientCommand.Compatibility) { + val artifact = command.artifact - override fun isCompatible(command: ClientCommand.Compatibility) { - val artifact = command.artifact + client.testUpdateArtifact(artifact.groupId, artifact.id, command.data) + } - client.testUpdateArtifact(artifact.groupId, artifact.id, command.data) + /** + * Attempts to clean-up opened resources. + */ + fun close() { + if (this::httpClient.isInitialized) { + httpClient.close() } + client.close() } -} \ No newline at end of file +} diff --git a/plugin/src/test/groovy/net/croz/apicurio/ArtifactTypeSpecification.groovy b/plugin/src/test/groovy/net/croz/apicurio/ArtifactTypeSpecification.groovy deleted file mode 100644 index e2503fc..0000000 --- a/plugin/src/test/groovy/net/croz/apicurio/ArtifactTypeSpecification.groovy +++ /dev/null @@ -1,26 +0,0 @@ -package net.croz.apicurio - -import net.croz.apicurio.core.UnknownArtifactTypeException -import net.croz.apicurio.model.ArtifactType -import spock.lang.Specification - -class ArtifactTypeSpecification extends Specification { - def "should return correct artifact type from #artifactTypeName name"(String artifactTypeName) { - expect: - ArtifactType.@Companion.fromName(artifactTypeName).name() == artifactTypeName - - where: - artifactTypeName << ArtifactType.values() - } - - def "should throw exception for non-existent artifact type name"() { - given: - def name = "UNKNOWN" - - when: - ArtifactType.@Companion.fromName(name) - - then: - thrown(UnknownArtifactTypeException.class) - } -} diff --git a/plugin/src/test/groovy/net/croz/apicurio/ConflictHandleTypeSpecification.groovy b/plugin/src/test/groovy/net/croz/apicurio/ConflictHandleTypeSpecification.groovy deleted file mode 100644 index 4efbfe2..0000000 --- a/plugin/src/test/groovy/net/croz/apicurio/ConflictHandleTypeSpecification.groovy +++ /dev/null @@ -1,26 +0,0 @@ -package net.croz.apicurio - -import net.croz.apicurio.core.UnknownConflictHandleTypeException -import net.croz.apicurio.model.ConflictHandleType -import spock.lang.Specification - -class ConflictHandleTypeSpecification extends Specification { - def "should return correct conflict handle type from #conflictHandleTypeName name"(String conflictHandleTypeName) { - expect: - ConflictHandleType.@Companion.fromName(conflictHandleTypeName).name() == conflictHandleTypeName - - where: - conflictHandleTypeName << ConflictHandleType.values() - } - - def "should throw exception for non-existent conflcit handle type name"() { - given: - def name = "UNKNOWN" - - when: - ConflictHandleType.@Companion.fromName(name) - - then: - thrown(UnknownConflictHandleTypeException.class) - } -} diff --git a/plugin/src/test/groovy/net/croz/apicurio/SchemaRegistryExtensionSpecification.groovy b/plugin/src/test/groovy/net/croz/apicurio/SchemaRegistryExtensionSpecification.groovy index 05a68d2..c413dba 100644 --- a/plugin/src/test/groovy/net/croz/apicurio/SchemaRegistryExtensionSpecification.groovy +++ b/plugin/src/test/groovy/net/croz/apicurio/SchemaRegistryExtensionSpecification.groovy @@ -7,74 +7,65 @@ import net.croz.apicurio.extension.RegisterHandler import net.croz.apicurio.model.* import net.croz.apicurio.util.ArtifactMetadataGeneratingUtil import org.gradle.api.Action -import org.gradle.api.Project import org.gradle.testfixtures.ProjectBuilder -import spock.lang.Shared import spock.lang.Specification class SchemaRegistryExtensionSpecification extends Specification { - @Shared - private Project project = ProjectBuilder.builder().build() + private SchemaRegistryExtension extension = new SchemaRegistryExtension(ProjectBuilder.builder().build().objects) - private SchemaRegistryExtension extension - - def setup() { - extension = new SchemaRegistryExtension(project.objects) - } - - def "should set schema registry URL through configuration handler"() { - given: + def "should set schema registry URL through configuration handler"() { + given: def url = "localhost:8080" - when: + when: extension.config(new Action() { - @Override - void execute(ConfigurationHandler handler) { - handler.url(url) - } + @Override + void execute(ConfigurationHandler handler) { + handler.url(url) + } }) - then: + then: extension.config$plugin.url$plugin.get() == url - } + } - def "should set basic authentication details through configuration handler"() { - given: + def "should set basic authentication details through configuration handler"() { + given: def username = "test" def password = "password" - when: + when: extension.config(new Action() { - @Override - void execute(ConfigurationHandler handler) { - handler.auth(username, password) - } + @Override + void execute(ConfigurationHandler handler) { + handler.auth(username, password) + } }) - then: + then: Authentication authenticationContext = extension.config$plugin.authentication$plugin.get() authenticationContext authenticationContext instanceof Authentication.Basic def castedAuthenticationContext = authenticationContext as Authentication.Basic castedAuthenticationContext.username == username castedAuthenticationContext.password == password - } + } - def "should set OAuth authentication details through configuration handler"() { - given: + def "should set OAuth authentication details through configuration handler"() { + given: def authServerUrl = "http://localhost:8080" def clientId = UUID.randomUUID().toString() def clientSecret = UUID.randomUUID().toString() - when: + when: extension.config(new Action() { - @Override - void execute(ConfigurationHandler handler) { - handler.auth(authServerUrl, clientId, clientSecret) - } + @Override + void execute(ConfigurationHandler handler) { + handler.auth(authServerUrl, clientId, clientSecret) + } }) - then: + then: Authentication authenticationContext = extension.config$plugin.authentication$plugin.get() authenticationContext authenticationContext instanceof Authentication.OAuth @@ -82,196 +73,196 @@ class SchemaRegistryExtensionSpecification extends Specification { castedAuthenticationContext.authServerUrl == authServerUrl castedAuthenticationContext.clientId == clientId castedAuthenticationContext.clientSecret == clientSecret - } + } - def "should set artifact details to be downloaded through download handler"() { - given: + def "should set artifact details to be downloaded through download handler"() { + given: def metadata = ArtifactMetadataGeneratingUtil.generate() - when: + when: extension.download(new Action() { - @Override - void execute(DownloadHandler handler) { - handler.artifact(new Action() { - @Override - void execute(DownloadArtifact artifact) { - artifact.groupId = metadata.groupId - artifact.id = metadata.artifactId - artifact.version = metadata.version - artifact.outputPath = metadata.outputPath - } - }) - } + @Override + void execute(DownloadHandler handler) { + handler.artifact(new Action() { + @Override + void execute(DownloadArtifact artifact) { + artifact.groupId = metadata.groupId + artifact.id = metadata.artifactId + artifact.version = metadata.version + artifact.outputPath = metadata.outputPath + } + }) + } }) - then: + then: def artifactCommandList = extension.download$plugin.artifacts$plugin.get() artifactCommandList != null artifactCommandList.size() == 1 artifactCommandList.every { - it.id == metadata.artifactId - it.groupId == metadata.groupId - it.version == metadata.version - it.outputPath == metadata.outputPath - !it.outputFileName + it.id == metadata.artifactId + it.groupId == metadata.groupId + it.version == metadata.version + it.outputPath == metadata.outputPath + !it.outputFileName } - } + } - def "should set artifacts details for specific group to be registered through register handler"(String conflictHandleType) { - given: + def "should set artifacts details for specific group to be registered through register handler"(String conflictHandleType) { + given: def metadata = ArtifactMetadataGeneratingUtil.generate() def description = "description" def artifactTypeName = "AVRO" def canonicalize = false - when: + when: extension.register(new Action() { - @Override - void execute(RegisterHandler handler) { - handler.artifact(new Action() { - @Override - void execute(RegisterArtifact artifact) { - artifact.groupId = metadata.groupId - artifact.id = metadata.artifactId - artifact.name = metadata.name - artifact.type = artifactTypeName - artifact.path = metadata.outputPath - artifact.description = description - artifact.version = metadata.version - artifact.canonicalize = canonicalize - artifact.conflictHandleType = conflictHandleType - } - }) - } + @Override + void execute(RegisterHandler handler) { + handler.artifact(new Action() { + @Override + void execute(RegisterArtifact artifact) { + artifact.groupId = metadata.groupId + artifact.id = metadata.artifactId + artifact.name = metadata.name + artifact.type = artifactTypeName + artifact.path = metadata.outputPath + artifact.description = description + artifact.version = metadata.version + artifact.canonicalize = canonicalize + artifact.conflictHandleType = conflictHandleType + } + }) + } }) - then: + then: def artifactCommandList = extension.register$plugin.artifacts$plugin.get() artifactCommandList != null artifactCommandList.size() == 1 artifactCommandList.every { - it.id == metadata.artifactId - it.groupId === metadata.groupId - it.name == metadata.name - it.type == artifactTypeName - it.path == metadata.outputPath - it.description == description - it.version == metadata.version - it.canonicalize == canonicalize - it.conflictHandleType == conflictHandleType ?: ConflictHandleType.FAIL + it.id == metadata.artifactId + it.groupId === metadata.groupId + it.name == metadata.name + it.type == artifactTypeName + it.path == metadata.outputPath + it.description == description + it.version == metadata.version + it.canonicalize == canonicalize + it.conflictHandleType == conflictHandleType ?: ConflictHandleType.FAIL } - where: + where: conflictHandleType | _ ConflictHandleType.RETURN_OR_UPDATE.name() | _ null | _ - } + } - def "should set artifacts details for default group to be registered through register handler"(String conflictHandleType) { - given: + def "should set artifacts details for default group to be registered through register handler"(String conflictHandleType) { + given: def metadata = ArtifactMetadataGeneratingUtil.generate() def description = "description" def artifactTypeName = "AVRO" def canonicalize = false - when: + when: extension.register(new Action() { - @Override - void execute(RegisterHandler handler) { - handler.artifact(new Action() { - @Override - void execute(RegisterArtifact artifact) { - artifact.id = metadata.artifactId - artifact.name = metadata.name - artifact.type = artifactTypeName - artifact.path = metadata.outputPath - artifact.description = description - artifact.version = metadata.version - artifact.canonicalize = canonicalize - artifact.conflictHandleType = conflictHandleType - } - }) - } + @Override + void execute(RegisterHandler handler) { + handler.artifact(new Action() { + @Override + void execute(RegisterArtifact artifact) { + artifact.id = metadata.artifactId + artifact.name = metadata.name + artifact.type = artifactTypeName + artifact.path = metadata.outputPath + artifact.description = description + artifact.version = metadata.version + artifact.canonicalize = canonicalize + artifact.conflictHandleType = conflictHandleType + } + }) + } }) - then: + then: def artifactCommandList = extension.register$plugin.artifacts$plugin.get() artifactCommandList != null artifactCommandList.size() == 1 artifactCommandList.every { - !it.groupId - it.id == metadata.artifactId - it.name == metadata.name - it.type == artifactTypeName - it.description == description - it.version == metadata.version - it.canonicalize == canonicalize - it.conflictHandleType == conflictHandleType ?: ConflictHandleType.FAIL - it.path == metadata.outputPath + !it.groupId + it.id == metadata.artifactId + it.name == metadata.name + it.type == artifactTypeName + it.description == description + it.version == metadata.version + it.canonicalize == canonicalize + it.conflictHandleType == conflictHandleType ?: ConflictHandleType.FAIL + it.path == metadata.outputPath } - where: + where: conflictHandleType | _ ConflictHandleType.RETURN_OR_UPDATE.name() | _ null | _ - } + } - def "should set artifact details for specific group to check for compatibility issues through compatibility handler"() { - given: + def "should set artifact details for specific group to check for compatibility issues through compatibility handler"() { + given: def metadata = ArtifactMetadataGeneratingUtil.generate() - when: + when: extension.compatibility(new Action() { - @Override - void execute(CompatibilityHandler handler) { - handler.artifact(new Action() { - @Override - void execute(CompatibilityArtifact artifact) { - artifact.groupId = metadata.groupId - artifact.id = metadata.artifactId - artifact.path = metadata.outputPath - } - }) - } + @Override + void execute(CompatibilityHandler handler) { + handler.artifact(new Action() { + @Override + void execute(CompatibilityArtifact artifact) { + artifact.groupId = metadata.groupId + artifact.id = metadata.artifactId + artifact.path = metadata.outputPath + } + }) + } }) - then: + then: def artifactCommandList = extension.compatibility$plugin.artifacts$plugin.get() artifactCommandList != null artifactCommandList.size() == 1 artifactCommandList.every { - it.id == metadata.artifactId - it.groupId == metadata.groupId - it.path == metadata.outputPath + it.id == metadata.artifactId + it.groupId == metadata.groupId + it.path == metadata.outputPath } - } + } - def "should set artifact details for default group to check for compatibility issues through compatibility handler"() { - given: + def "should set artifact details for default group to check for compatibility issues through compatibility handler"() { + given: def metadata = ArtifactMetadataGeneratingUtil.generate() - when: + when: extension.compatibility(new Action() { - @Override - void execute(CompatibilityHandler handler) { - handler.artifact(new Action() { - @Override - void execute(CompatibilityArtifact artifact) { - artifact.id = metadata.artifactId - artifact.path = metadata.outputPath - } - }) - } + @Override + void execute(CompatibilityHandler handler) { + handler.artifact(new Action() { + @Override + void execute(CompatibilityArtifact artifact) { + artifact.id = metadata.artifactId + artifact.path = metadata.outputPath + } + }) + } }) - then: + then: def artifactCommandList = extension.compatibility$plugin.artifacts$plugin.get() artifactCommandList != null artifactCommandList.size() == 1 artifactCommandList.every { - !it.groupId - it.id == metadata.artifactId - it.path == metadata.outputPath + !it.groupId + it.id == metadata.artifactId + it.path == metadata.outputPath } - } -} \ No newline at end of file + } +} diff --git a/plugin/src/test/groovy/net/croz/apicurio/SchemaRegistryPluginSpecification.groovy b/plugin/src/test/groovy/net/croz/apicurio/SchemaRegistryPluginSpecification.groovy index 9779831..a24856c 100644 --- a/plugin/src/test/groovy/net/croz/apicurio/SchemaRegistryPluginSpecification.groovy +++ b/plugin/src/test/groovy/net/croz/apicurio/SchemaRegistryPluginSpecification.groovy @@ -10,47 +10,50 @@ import spock.lang.Shared import spock.lang.Specification class SchemaRegistryPluginSpecification extends Specification { - @Shared - private Project project = ProjectBuilder.builder().build() + @Shared + private Project project = ProjectBuilder.builder().build() - def setupSpec() { - project.apply(plugin: SchemaRegistryPlugin) - } + def setupSpec() { + project.apply(plugin: SchemaRegistryPlugin) + } - def "plugin should be applied and tasks should be registered and extension should be created"() { - expect: + def "shoud apply plugin and register tasks with the extension"() { + expect: project.plugins.hasPlugin(SchemaRegistryPlugin) project.tasks.withType(SchemaRegistryTask) - .names - .containsAll( - SchemaRegistryDownloadTask.TASK_NAME, - SchemaRegistryRegisterTask.TASK_NAME, - SchemaRegistryCompatibilityTask.TASK_NAME - ) + .names + .containsAll( + SchemaRegistryDownloadTask.TASK_NAME, + SchemaRegistryRegisterTask.TASK_NAME, + SchemaRegistryCompatibilityTask.TASK_NAME + ) project.extensions.getByName(SchemaRegistryExtension.EXTENSION_NAME) instanceof SchemaRegistryExtension - } + } - def "creates and configures download task"() { - expect: - SchemaRegistryExtension extension = project.extensions.getByName(SchemaRegistryExtension.EXTENSION_NAME) + def "should create and configure download task"() { + when: SchemaRegistryDownloadTask task = project.tasks.getByName(SchemaRegistryDownloadTask.TASK_NAME) + + then: task instanceof SchemaRegistryDownloadTask task.description == "Downloads artifacts from the Apicurio schema registry" - } + } - def "creates and configures register task"() { - expect: - SchemaRegistryExtension extension = project.extensions.getByName(SchemaRegistryExtension.EXTENSION_NAME) + def "should create and configure register task"() { + when: SchemaRegistryRegisterTask task = project.tasks.getByName(SchemaRegistryRegisterTask.TASK_NAME) + + then: task instanceof SchemaRegistryRegisterTask task.description == "Registers artifacts on the Apicurio schema registry" - } + } - def "creates and configures compatibility task"() { - expect: - SchemaRegistryExtension extension = project.extensions.getByName(SchemaRegistryExtension.EXTENSION_NAME) + def "should create and configure compatibility task"() { + when: SchemaRegistryCompatibilityTask task = project.tasks.getByName(SchemaRegistryCompatibilityTask.TASK_NAME) + + then: task instanceof SchemaRegistryCompatibilityTask task.description == "Checks for compatibility issues between local artifacts and remote artifacts on the Apicurio schema registry" - } -} \ No newline at end of file + } +} diff --git a/plugin/src/test/groovy/net/croz/apicurio/ArtifactTypeKtSpecification.groovy b/plugin/src/test/groovy/net/croz/apicurio/model/ArtifactTypeKtSpecification.groovy similarity index 50% rename from plugin/src/test/groovy/net/croz/apicurio/ArtifactTypeKtSpecification.groovy rename to plugin/src/test/groovy/net/croz/apicurio/model/ArtifactTypeKtSpecification.groovy index 4e10c64..4514891 100644 --- a/plugin/src/test/groovy/net/croz/apicurio/ArtifactTypeKtSpecification.groovy +++ b/plugin/src/test/groovy/net/croz/apicurio/model/ArtifactTypeKtSpecification.groovy @@ -1,26 +1,24 @@ -package net.croz.apicurio +package net.croz.apicurio.model import io.apicurio.registry.types.ArtifactType as ClientArtifactType -import net.croz.apicurio.model.ArtifactType -import net.croz.apicurio.model.ArtifactTypeKt import spock.lang.Specification class ArtifactTypeKtSpecification extends Specification { - def "should return artifact type #artifactType from client artifact type #clientArtifactType"(ArtifactType artifactType, ClientArtifactType clientArtifactType) { - expect: + def "should return artifact type #artifactType from client artifact type #clientArtifactType"(ArtifactType artifactType, ClientArtifactType clientArtifactType) { + expect: ArtifactTypeKt.toArtifactType(clientArtifactType) == artifactType - where: + where: clientArtifactType << ClientArtifactType.values() artifactType << ArtifactType.values() - } + } - def "should return client artifact type #clientArtifactType from artifact type #artifactType"(ClientArtifactType clientArtifactType, ArtifactType artifactType) { - expect: + def "should return client artifact type #clientArtifactType from artifact type #artifactType"(ClientArtifactType clientArtifactType, ArtifactType artifactType) { + expect: ArtifactTypeKt.toClientArtifactType(artifactType) == clientArtifactType - where: + where: artifactType << ArtifactType.values() clientArtifactType << ClientArtifactType.values() - } + } } diff --git a/plugin/src/test/groovy/net/croz/apicurio/model/ArtifactTypeSpecification.groovy b/plugin/src/test/groovy/net/croz/apicurio/model/ArtifactTypeSpecification.groovy new file mode 100644 index 0000000..12a8f49 --- /dev/null +++ b/plugin/src/test/groovy/net/croz/apicurio/model/ArtifactTypeSpecification.groovy @@ -0,0 +1,25 @@ +package net.croz.apicurio.model + +import net.croz.apicurio.exception.UnknownArtifactTypeException +import spock.lang.Specification + +class ArtifactTypeSpecification extends Specification { + def "should return correct artifact type from #artifactTypeName name"(String artifactTypeName) { + expect: + ArtifactType.@Companion.fromName(artifactTypeName).name() == artifactTypeName + + where: + artifactTypeName << ArtifactType.values() + } + + def "should throw exception for non-existent artifact type name"() { + given: + def name = "UNKNOWN" + + when: + ArtifactType.@Companion.fromName(name) + + then: + thrown(UnknownArtifactTypeException) + } +} diff --git a/plugin/src/test/groovy/net/croz/apicurio/ConflictHandleTypeKtSpecification.groovy b/plugin/src/test/groovy/net/croz/apicurio/model/ConflictHandleTypeKtSpecification.groovy similarity index 51% rename from plugin/src/test/groovy/net/croz/apicurio/ConflictHandleTypeKtSpecification.groovy rename to plugin/src/test/groovy/net/croz/apicurio/model/ConflictHandleTypeKtSpecification.groovy index 4ccd336..8327d3a 100644 --- a/plugin/src/test/groovy/net/croz/apicurio/ConflictHandleTypeKtSpecification.groovy +++ b/plugin/src/test/groovy/net/croz/apicurio/model/ConflictHandleTypeKtSpecification.groovy @@ -1,17 +1,17 @@ -package net.croz.apicurio +package net.croz.apicurio.model import io.apicurio.registry.rest.v2.beans.IfExists as ClientConflictHandleType -import net.croz.apicurio.model.ConflictHandleType -import net.croz.apicurio.model.ConflictHandleTypeKt import spock.lang.Specification class ConflictHandleTypeKtSpecification extends Specification { - def "should return client conflict handle type #clientConflictHandleType from conflict handle type #conflictHandleType"(ClientConflictHandleType clientConflictHandleType, ConflictHandleType conflictHandleType) { - expect: + def "should return client conflict handle type #clientConflictHandleType from conflict handle type #conflictHandleType"( + ClientConflictHandleType clientConflictHandleType, ConflictHandleType conflictHandleType) + { + expect: ConflictHandleTypeKt.toClientConflictHandleType(conflictHandleType) == clientConflictHandleType - where: + where: conflictHandleType << ConflictHandleType.values() clientConflictHandleType << ClientConflictHandleType.values() - } + } } diff --git a/plugin/src/test/groovy/net/croz/apicurio/model/ConflictHandleTypeSpecification.groovy b/plugin/src/test/groovy/net/croz/apicurio/model/ConflictHandleTypeSpecification.groovy new file mode 100644 index 0000000..576a8f1 --- /dev/null +++ b/plugin/src/test/groovy/net/croz/apicurio/model/ConflictHandleTypeSpecification.groovy @@ -0,0 +1,25 @@ +package net.croz.apicurio.model + +import net.croz.apicurio.exception.UnknownConflictHandleTypeException +import spock.lang.Specification + +class ConflictHandleTypeSpecification extends Specification { + def "should return correct conflict handle type from #conflictHandleTypeName name"(String conflictHandleTypeName) { + expect: + ConflictHandleType.@Companion.fromName(conflictHandleTypeName).name() == conflictHandleTypeName + + where: + conflictHandleTypeName << ConflictHandleType.values() + } + + def "should throw exception for non-existent conflcit handle type name"() { + given: + def name = "UNKNOWN" + + when: + ConflictHandleType.@Companion.fromName(name) + + then: + thrown(UnknownConflictHandleTypeException) + } +} diff --git a/plugin/src/testFixtures/groovy/net/croz/apicurio/core/model/GeneratedArtifactMetadata.groovy b/plugin/src/testFixtures/groovy/net/croz/apicurio/core/model/GeneratedArtifactMetadata.groovy index e442afe..d63753c 100644 --- a/plugin/src/testFixtures/groovy/net/croz/apicurio/core/model/GeneratedArtifactMetadata.groovy +++ b/plugin/src/testFixtures/groovy/net/croz/apicurio/core/model/GeneratedArtifactMetadata.groovy @@ -4,6 +4,6 @@ import groovy.transform.Immutable @Immutable class GeneratedArtifactMetadata { - String groupId, artifactId, name, version, outputPath + String groupId, artifactId, name, version, outputPath } diff --git a/plugin/src/testFixtures/groovy/net/croz/apicurio/core/model/RegisterArtifact.groovy b/plugin/src/testFixtures/groovy/net/croz/apicurio/core/model/RegisterArtifact.groovy index 84d02d3..1effbbd 100644 --- a/plugin/src/testFixtures/groovy/net/croz/apicurio/core/model/RegisterArtifact.groovy +++ b/plugin/src/testFixtures/groovy/net/croz/apicurio/core/model/RegisterArtifact.groovy @@ -5,6 +5,6 @@ import io.apicurio.registry.types.ArtifactType @Immutable class RegisterArtifact { - String path, groupId, artifactId, name, version - ArtifactType type -} \ No newline at end of file + String path, groupId, artifactId, name, version + ArtifactType type +} diff --git a/plugin/src/testFixtures/groovy/net/croz/apicurio/core/model/RetrieveArtifactMetadata.groovy b/plugin/src/testFixtures/groovy/net/croz/apicurio/core/model/RetrieveArtifactMetadata.groovy index 9d5fc62..ef824f4 100644 --- a/plugin/src/testFixtures/groovy/net/croz/apicurio/core/model/RetrieveArtifactMetadata.groovy +++ b/plugin/src/testFixtures/groovy/net/croz/apicurio/core/model/RetrieveArtifactMetadata.groovy @@ -4,6 +4,6 @@ import groovy.transform.Immutable @Immutable class RetrieveArtifactMetadata { - String groupId = "default", artifactId + String groupId = "default", artifactId } diff --git a/plugin/src/testFixtures/groovy/net/croz/apicurio/core/testcontainers/ApicurioSchemaRegistryContainerFactory.groovy b/plugin/src/testFixtures/groovy/net/croz/apicurio/core/testcontainers/ApicurioSchemaRegistryContainerFactory.groovy index 2f9341c..be20ea9 100644 --- a/plugin/src/testFixtures/groovy/net/croz/apicurio/core/testcontainers/ApicurioSchemaRegistryContainerFactory.groovy +++ b/plugin/src/testFixtures/groovy/net/croz/apicurio/core/testcontainers/ApicurioSchemaRegistryContainerFactory.groovy @@ -5,17 +5,17 @@ import org.testcontainers.containers.wait.strategy.Wait import org.testcontainers.utility.DockerImageName class ApicurioSchemaRegistryContainerFactory { - static GenericContainer makeAndStartContainer(String containerName = "apicurio-schema-registry", Integer httpPort = 8080) { - String containerNameSuffix = UUID.randomUUID() - GenericContainer apicurioSchemaRegistry = new GenericContainer(DockerImageName.parse("apicurio/apicurio-registry-mem").withTag("2.3.1.Final")) + static GenericContainer makeAndStartContainer(String containerName = "apicurio-schema-registry", Integer httpPort = 8080) { + def containerNameSuffix = UUID.randomUUID() + GenericContainer apicurioSchemaRegistry = new GenericContainer(DockerImageName.parse("apicurio/apicurio-registry-mem").withTag("2.3.1.Final")) - apicurioSchemaRegistry.with { - withExposedPorts(httpPort) - withCreateContainerCmdModifier { it.withName("${containerName}-${containerNameSuffix}") } - waitingFor(Wait.forListeningPort()) - start() - } - - return apicurioSchemaRegistry + apicurioSchemaRegistry.with { + withExposedPorts(httpPort) + withCreateContainerCmdModifier { it.withName("${containerName}-${containerNameSuffix}") } + waitingFor(Wait.forListeningPort()) + start() } + + return apicurioSchemaRegistry + } } diff --git a/plugin/src/testFixtures/groovy/net/croz/apicurio/util/ArtifactMetadataGeneratingUtil.groovy b/plugin/src/testFixtures/groovy/net/croz/apicurio/util/ArtifactMetadataGeneratingUtil.groovy index eed6c52..6ec0ecf 100644 --- a/plugin/src/testFixtures/groovy/net/croz/apicurio/util/ArtifactMetadataGeneratingUtil.groovy +++ b/plugin/src/testFixtures/groovy/net/croz/apicurio/util/ArtifactMetadataGeneratingUtil.groovy @@ -4,27 +4,31 @@ import net.croz.apicurio.core.model.GeneratedArtifactMetadata import net.croz.apicurio.model.ArtifactType final class ArtifactMetadataGeneratingUtil { - final static GeneratedArtifactMetadata generate() { - def (groupId, artifactId, artifactName, artifactVersion, outputPath) = generateBaseMetadata() + private ArtifactMetadataGeneratingUtil() { + throw new UnsupportedOperationException("Utility class") + } - new GeneratedArtifactMetadata(groupId, artifactId, artifactName, artifactVersion, outputPath) - } + final static GeneratedArtifactMetadata generate() { + def (groupId, artifactId, artifactName, artifactVersion, outputPath) = generateBaseMetadata() - final static GeneratedArtifactMetadata generate(ArtifactType artifactType) { - def (groupId, artifactId, artifactName, artifactVersion) = generateBaseMetadata() - def outputPath = "src/main/${artifactType.name().toLowerCase()}" + new GeneratedArtifactMetadata(groupId, artifactId, artifactName, artifactVersion, outputPath) + } - new GeneratedArtifactMetadata(groupId, artifactId, artifactName, artifactVersion, outputPath) - } + final static GeneratedArtifactMetadata generate(ArtifactType artifactType) { + def (groupId, artifactId, artifactName, artifactVersion) = generateBaseMetadata() + def outputPath = "src/main/${artifactType.name().toLowerCase()}" - private static List generateBaseMetadata() { - def suffix = UUID.randomUUID().toString() - def groupId = "artifact-group-${suffix}" - def artifactId = "artifact-id-${suffix}" - def artifactName = "artifact-name-${suffix}" - def artifactVersion = "artifact-version-${suffix}" - def outputPath = "src/main/artifact" + new GeneratedArtifactMetadata(groupId, artifactId, artifactName, artifactVersion, outputPath) + } - [groupId, artifactId, artifactName, artifactVersion, outputPath] - } + private static List generateBaseMetadata() { + def suffix = UUID.randomUUID().toString() + def groupId = "artifact-group-${suffix}" + def artifactId = "artifact-id-${suffix}" + def artifactName = "artifact-name-${suffix}" + def artifactVersion = "artifact-version-${suffix}" + def outputPath = "src/main/artifact" + + [groupId, artifactId, artifactName, artifactVersion, outputPath] + } } diff --git a/plugin/src/testFixtures/groovy/net/croz/apicurio/util/IOUtil.groovy b/plugin/src/testFixtures/groovy/net/croz/apicurio/util/IOUtil.groovy index 4093e45..b8a7b46 100644 --- a/plugin/src/testFixtures/groovy/net/croz/apicurio/util/IOUtil.groovy +++ b/plugin/src/testFixtures/groovy/net/croz/apicurio/util/IOUtil.groovy @@ -1,24 +1,16 @@ package net.croz.apicurio.util -import org.slf4j.Logger -import org.slf4j.LoggerFactory - final class IOUtil { - private static final Logger LOGGER = LoggerFactory.getLogger(IOUtil.class); + private IOUtil() { + throw new UnsupportedOperationException("Utility class") + } - private IOUtil() { - throw new UnsupportedOperationException("Utility class") + final static URL getResource(String path) { + URL resource = Thread.currentThread().getContextClassLoader().getResource(path) + if (!resource) { + resource = IOUtil.getClassLoader().getResource(path) } - final static URL getResource(String path) { - URL resource = Thread.currentThread().getContextClassLoader().getResource(path); - if (!resource) { - resource = IOUtil.class.getClassLoader().getResource(path); - if (!resource) { - LOGGER.warn("Could not load classpath resource: {}", path); - } - } - - resource - } + resource + } } diff --git a/plugin/src/testFixtures/groovy/net/croz/apicurio/util/SchemaRegistryUtil.groovy b/plugin/src/testFixtures/groovy/net/croz/apicurio/util/SchemaRegistryUtil.groovy index bf36304..f7c715a 100644 --- a/plugin/src/testFixtures/groovy/net/croz/apicurio/util/SchemaRegistryUtil.groovy +++ b/plugin/src/testFixtures/groovy/net/croz/apicurio/util/SchemaRegistryUtil.groovy @@ -5,29 +5,25 @@ import io.apicurio.registry.rest.v2.beans.ArtifactMetaData import io.apicurio.registry.rest.v2.beans.IfExists import net.croz.apicurio.core.model.RegisterArtifact import net.croz.apicurio.core.model.RetrieveArtifactMetadata -import org.slf4j.Logger -import org.slf4j.LoggerFactory final class SchemaRegistryUtil { - private static final Logger LOGGER = LoggerFactory.getLogger(SchemaRegistryUtil.class); + private SchemaRegistryUtil() { + throw new UnsupportedOperationException("Utility class") + } - private SchemaRegistryUtil() { - throw new UnsupportedOperationException("Utility class") - } + static void registerArtifact(String containerBaseUrl, RegisterArtifact artifact) { + def resource = IOUtil.getResource(artifact.path) - static void registerArtifact(String containerBaseUrl, RegisterArtifact artifact) { - def resource = IOUtil.getResource(artifact.path) + def client = RegistryClientFactory.create(containerBaseUrl) + client.createArtifact(artifact.groupId, artifact.artifactId, artifact.version, artifact.type, IfExists.FAIL, null, artifact.name, null, resource.newInputStream()) + client.close() + } - def client = RegistryClientFactory.create(containerBaseUrl) - client.createArtifact(artifact.groupId, artifact.artifactId, artifact.version, artifact.type, IfExists.FAIL, null, artifact.name, null, resource.newInputStream()) - client.close() - } + static ArtifactMetaData retrieveArtifactMetadata(String containerBaseUrl, RetrieveArtifactMetadata artifact) { + def client = RegistryClientFactory.create(containerBaseUrl) + def data = client.getArtifactMetaData(artifact.groupId, artifact.artifactId) + client.close() - static ArtifactMetaData retrieveArtifactMetadata(String containerBaseUrl, RetrieveArtifactMetadata artifact) { - def client = RegistryClientFactory.create(containerBaseUrl) - def data = client.getArtifactMetaData(artifact.groupId, artifact.artifactId) - client.close() - - data - } + data + } } diff --git a/plugin/src/testFixtures/resources/TestAsyncApi.json b/plugin/src/testFixtures/resources/TestAsyncApi.json index f4e156c..6728435 100644 --- a/plugin/src/testFixtures/resources/TestAsyncApi.json +++ b/plugin/src/testFixtures/resources/TestAsyncApi.json @@ -1,8 +1,8 @@ { - "asyncapi": "2.0.0", - "info": { - "title": "AsyncAPI 2.0 App", - "description": "This is a very simple AsyncAPI file.", - "version": "1.0.1" - } -} \ No newline at end of file + "asyncapi": "2.0.0", + "info": { + "title": "AsyncAPI 2.0 App", + "description": "This is a very simple AsyncAPI file.", + "version": "1.0.1" + } +} diff --git a/plugin/src/testFixtures/resources/TestJsonSchema.json b/plugin/src/testFixtures/resources/TestJsonSchema.json index 736f9d6..4da259c 100644 --- a/plugin/src/testFixtures/resources/TestJsonSchema.json +++ b/plugin/src/testFixtures/resources/TestJsonSchema.json @@ -1,16 +1,16 @@ { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://test.com/test.schema.json", - "title": "Test", - "type": "object", - "properties": { - "id": { - "description": "The unique identifier", - "type": "integer" - }, - "name": { - "description": "The name", - "type": "string" + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.com/test.schema.json", + "title": "Test", + "type": "object", + "properties": { + "id": { + "description": "The unique identifier", + "type": "integer" + }, + "name": { + "description": "The name", + "type": "string" + } } - } -} \ No newline at end of file +} diff --git a/plugin/src/testFixtures/resources/TestKConnect.json b/plugin/src/testFixtures/resources/TestKConnect.json index 117fc5e..c592bbd 100644 --- a/plugin/src/testFixtures/resources/TestKConnect.json +++ b/plugin/src/testFixtures/resources/TestKConnect.json @@ -1,16 +1,16 @@ { - "type": "struct", - "fields": [ - { - "type": "integer", - "optional": false, - "field": "id" - }, - { - "type": "string", - "optional": false, - "field": "name" - } - ], - "optional": false -} \ No newline at end of file + "type": "struct", + "fields": [ + { + "type": "integer", + "optional": false, + "field": "id" + }, + { + "type": "string", + "optional": false, + "field": "name" + } + ], + "optional": false +} diff --git a/plugin/src/testFixtures/resources/TestOpenApi.json b/plugin/src/testFixtures/resources/TestOpenApi.json index 65e3d84..97a6387 100644 --- a/plugin/src/testFixtures/resources/TestOpenApi.json +++ b/plugin/src/testFixtures/resources/TestOpenApi.json @@ -1,8 +1,8 @@ { - "openapi": "3.0.2", - "info": { - "title": "Empty API", - "version": "1.0.0", - "description": "An example API design using OpenAPI." - } -} \ No newline at end of file + "openapi": "3.0.2", + "info": { + "title": "Empty API", + "version": "1.0.0", + "description": "An example API design using OpenAPI." + } +} diff --git a/plugin/src/testFixtures/resources/TestProto.proto b/plugin/src/testFixtures/resources/TestProto.proto index b07721a..61bd468 100644 --- a/plugin/src/testFixtures/resources/TestProto.proto +++ b/plugin/src/testFixtures/resources/TestProto.proto @@ -2,6 +2,6 @@ syntax = "proto3"; package test; message Test { - int32 id = 1; - string name = 2; + int32 id = 1; + string name = 2; } diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 0349fd1..2eef1f5 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("net.croz.apicurio-registry-gradle-plugin") version "0.1-SNAPSHOT" + id("net.croz.apicurio-registry-gradle-plugin") version "1.1.0" } schemaRegistry { @@ -15,4 +15,4 @@ schemaRegistry { path = "support/schema/Person.avsc" } } -} \ No newline at end of file +} diff --git a/sample/support/docker/docker-compose.yml b/sample/support/docker/docker-compose.yml index fe211e4..90aa69f 100644 --- a/sample/support/docker/docker-compose.yml +++ b/sample/support/docker/docker-compose.yml @@ -1,34 +1,6 @@ services: - kafka: - image: quay.io/strimzi/kafka:latest-kafka-3.3.1 - container_name: kafka - command: - [ - "sh", - "-c", - "export CLUSTER_ID=$$(bin/kafka-storage.sh random-uuid) && bin/kafka-storage.sh format -t $$CLUSTER_ID --ignore-formatted -c config/kraft/server.properties && bin/kafka-server-start.sh config/kraft/server.properties --override advertised.listeners=$${KAFKA_ADVERTISED_LISTENERS} --override listener.security.protocol.map=$${KAFKA_LISTENER_SECURITY_PROTOCOL_MAP} --override listeners=$${KAFKA_LISTENERS}" - ] - ports: - - "9092:9092" - environment: - LOG_DIR: "/tmp/logs" - KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT - KAFKA_LISTENERS: PLAINTEXT://:29092,PLAINTEXT_HOST://:9092,CONTROLLER://:9093 - KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092 - healthcheck: - test: nc -z localhost 9092 || exit -1 - start_period: 15s - interval: 5s - timeout: 10s - retries: 10 - schema-registry: - image: quay.io/apicurio/apicurio-registry-kafkasql:2.3.1.Final + image: quay.io/apicurio/apicurio-registry-mem:2.3.1.Final container_name: schema-registry ports: - 8080:8080 - environment: - - KAFKA_BOOTSTRAP_SERVERS=kafka:29092 - depends_on: - kafka: - condition: service_healthy \ No newline at end of file