From 56e0db005229b77603f06adb8433bdc323276bf7 Mon Sep 17 00:00:00 2001 From: Zaid Date: Wed, 9 Oct 2024 17:57:28 +0530 Subject: [PATCH 1/8] Fix filter-name not running on example names --- .../specmatic/test/SpecmaticJUnitSupport.kt | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/junit5-support/src/main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt b/junit5-support/src/main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt index 2eb2edc61..1547b3ec5 100644 --- a/junit5-support/src/main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt +++ b/junit5-support/src/main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt @@ -232,8 +232,6 @@ open class SpecmaticJUnitSupport { suggestionsData, testConfig, specificationPath = it, - filterName = filterName, - filterNotName = filterNotName, specmaticConfig = specmaticConfig ) } @@ -264,8 +262,6 @@ open class SpecmaticJUnitSupport { it.branch, it.specificationPath, specmaticConfig?.security, - filterName, - filterNotName, specmaticConfig = specmaticConfig ) } @@ -426,8 +422,6 @@ open class SpecmaticJUnitSupport { sourceRepositoryBranch: String? = null, specificationPath: String? = null, securityConfiguration: SecurityConfiguration? = null, - filterName: String?, - filterNotName: String?, specmaticConfig: SpecmaticConfig? = null ): Pair, List> { if(hasOpenApiFileExtension(path) && !isOpenAPI(path)) @@ -468,15 +462,6 @@ open class SpecmaticJUnitSupport { } val tests: Sequence = feature - .copy(scenarios = selectTestsToRun(feature.scenarios.asSequence(), filterName, filterNotName) { it.testDescription() }.toList()) - .also { - if (it.scenarios.isEmpty()) - logger.log("All scenarios were filtered out.") - else if (it.scenarios.size < feature.scenarios.size) { - logger.debug("Selected scenarios:") - it.scenarios.forEach { scenario -> logger.debug(scenario.testDescription().prependIndent(" ")) } - } - } .generateContractTests(suggestions) return Pair(tests, allEndpoints) @@ -574,5 +559,12 @@ fun selectTestsToRun( } else filteredByName + if (filteredByNotName.count()==0) + logger.log("All scenarios were filtered out.") + else if (filteredByNotName.count() < testScenarios.count()) { + logger.debug("Selected scenarios:") + filteredByNotName.forEach { scenario -> logger.debug(getTestDescription(scenario).prependIndent(" ")) } + } + return filteredByNotName } From 047a3a9326508b83b8e603d13f75227b27cc6016 Mon Sep 17 00:00:00 2001 From: Zaid Date: Wed, 9 Oct 2024 18:36:33 +0530 Subject: [PATCH 2/8] fix test to not pass filtername --- .../kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt b/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt index 6e96be1f0..686ba9491 100644 --- a/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt +++ b/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt @@ -30,9 +30,7 @@ class SpecmaticJunitSupportTest { "./src/test/resources/spec_with_parameterized_paths.yaml", "", "", - TestConfig(emptyMap(), emptyMap()), - filterName = null, - filterNotName = null + TestConfig(emptyMap(), emptyMap()) ) val specEndpoints = result.second assertThat(specEndpoints.count()).isEqualTo(2) From fed9f9cd2f2ca14b4ae62c24d56599cc69ccb34c Mon Sep 17 00:00:00 2001 From: Zaid Date: Thu, 10 Oct 2024 11:34:21 +0530 Subject: [PATCH 3/8] Refactor code --- .../specmatic/test/SpecmaticJUnitSupport.kt | 19 ++++++++++++------- .../test/SpecmaticJunitSupportTest.kt | 1 - 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/junit5-support/src/main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt b/junit5-support/src/main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt index 1547b3ec5..e6f782df8 100644 --- a/junit5-support/src/main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt +++ b/junit5-support/src/main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt @@ -550,7 +550,7 @@ fun selectTestsToRun( } else testScenarios - val filteredByNotName: Sequence = if(!filterNotName.isNullOrBlank()) { + val filteredScenarios: Sequence = if(!filterNotName.isNullOrBlank()) { val filterNotNames = filterNotName.split(",").map { it.trim() } filteredByName.filterNot { test -> @@ -559,12 +559,17 @@ fun selectTestsToRun( } else filteredByName - if (filteredByNotName.count()==0) - logger.log("All scenarios were filtered out.") - else if (filteredByNotName.count() < testScenarios.count()) { - logger.debug("Selected scenarios:") - filteredByNotName.forEach { scenario -> logger.debug(getTestDescription(scenario).prependIndent(" ")) } + val filteredScenariosCount = filteredScenarios.count() + + when { + filteredScenariosCount == 0 -> logger.log("All scenarios were filtered out.") + filteredScenariosCount < testScenarios.count() -> { + logger.debug("Selected scenarios:") + filteredScenarios.forEach { scenario -> + logger.debug(getTestDescription(scenario).prependIndent(" ")) + } + } } - return filteredByNotName + return filteredScenarios } diff --git a/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt b/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt index 686ba9491..2cd6b8499 100644 --- a/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt +++ b/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt @@ -10,7 +10,6 @@ import io.specmatic.test.reports.coverage.Endpoint import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatCode import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import org.junit.jupiter.params.ParameterizedTest From 1a14598a8d3dbc29373a0281b1393003d1b04ae9 Mon Sep 17 00:00:00 2001 From: Zaid Date: Tue, 15 Oct 2024 18:20:35 +0530 Subject: [PATCH 4/8] Add tests for filterName bugfix --- .../test/SpecmaticJunitSupportTest.kt | 23 +++++++++++++++++++ .../src/test/resources/test_contract.yaml | 10 ++++++++ 2 files changed, 33 insertions(+) create mode 100644 junit5-support/src/test/resources/test_contract.yaml diff --git a/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt b/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt index 2cd6b8499..c205b61e3 100644 --- a/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt +++ b/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt @@ -1,6 +1,9 @@ package io.specmatic.test import io.specmatic.core.TestConfig +import io.specmatic.test.SpecmaticJUnitSupport.Companion.CONFIG_FILE_NAME +import io.specmatic.test.SpecmaticJUnitSupport.Companion.FILTER_NAME_PROPERTY +import io.specmatic.test.SpecmaticJUnitSupport.Companion.FILTER_NOT_NAME_PROPERTY import io.specmatic.test.SpecmaticJUnitSupport.Companion.HOST import io.specmatic.test.SpecmaticJUnitSupport.Companion.PORT import io.specmatic.test.SpecmaticJUnitSupport.Companion.PROTOCOL @@ -149,6 +152,26 @@ class SpecmaticJunitSupportTest { assertThat(registeredListeners).contains(ContractExecutionListener::class.java.name) } + @Test + fun`should return the two tests other than the test with example name given in filterNotName` () { + System.setProperty(CONFIG_FILE_NAME, "./src/test/resources/test_contract.yaml") + System.setProperty(TEST_BASE_URL, "https://test.com") + System.setProperty(FILTER_NOT_NAME_PROPERTY, "BLACKLISTED") + val filteredTests = SpecmaticJUnitSupport().contractTest().map { it }.toList() + assertThat(filteredTests).hasSize(2) + filteredTests.forEach{ assertThat(it.displayName).doesNotContain("BLACKLISTED") } + } + + @Test + fun`should return only the test with example name given in filterName` () { + System.setProperty(CONFIG_FILE_NAME, "./src/test/resources/test_contract.yaml") + System.setProperty(TEST_BASE_URL, "https://test.com") + System.setProperty(FILTER_NAME_PROPERTY, "BLACKLISTED") + val filteredTests = SpecmaticJUnitSupport().contractTest().map { it }.toList() + assertThat(filteredTests).hasSize(1) + assertThat(filteredTests.map { it.displayName.toString() }[0]).contains("BLACKLISTED") + } + @AfterEach fun tearDown() { System.getProperties().keys.minus(initialPropertyKeys).forEach { println("Clearing $it"); System.clearProperty(it.toString()) } diff --git a/junit5-support/src/test/resources/test_contract.yaml b/junit5-support/src/test/resources/test_contract.yaml new file mode 100644 index 000000000..6f253f06c --- /dev/null +++ b/junit5-support/src/test/resources/test_contract.yaml @@ -0,0 +1,10 @@ +sources: + - provider: filesystem + provides: + - ./src/test/resources/spec_with_parameterized_paths.yaml + consumes: + - ./src/test/resources/spec_with_parameterized_paths.yaml + +test: + resiliencyTests: + enable: none \ No newline at end of file From ef64c2a870f3303be037206c63391732bc2928f0 Mon Sep 17 00:00:00 2001 From: Zaid Date: Tue, 15 Oct 2024 19:02:54 +0530 Subject: [PATCH 5/8] refactor test --- .../test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt b/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt index c205b61e3..e4a293b34 100644 --- a/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt +++ b/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt @@ -159,7 +159,7 @@ class SpecmaticJunitSupportTest { System.setProperty(FILTER_NOT_NAME_PROPERTY, "BLACKLISTED") val filteredTests = SpecmaticJUnitSupport().contractTest().map { it }.toList() assertThat(filteredTests).hasSize(2) - filteredTests.forEach{ assertThat(it.displayName).doesNotContain("BLACKLISTED") } + assertThat(filteredTests.map { it.displayName }.toString()).doesNotContain("BLACKLISTED") } @Test From 2caa608138419ae95e1705545fcc7aaf30c1d078 Mon Sep 17 00:00:00 2001 From: Zaid Date: Wed, 30 Oct 2024 12:06:56 +0530 Subject: [PATCH 6/8] Add missing variable CONFIG_FILE_NAME --- .../main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/junit5-support/src/main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt b/junit5-support/src/main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt index 809dfea22..298046247 100644 --- a/junit5-support/src/main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt +++ b/junit5-support/src/main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt @@ -55,6 +55,7 @@ open class SpecmaticJUnitSupport { companion object { const val CONTRACT_PATHS = "contractPaths" const val WORKING_DIRECTORY = "workingDirectory" + const val CONFIG_FILE_NAME = "manifestFile" const val INLINE_SUGGESTIONS = "suggestions" const val SUGGESTIONS_PATH = "suggestionsPath" const val HOST = "host" @@ -249,8 +250,6 @@ open class SpecmaticJUnitSupport { suggestionsData, testConfig, specificationPath = it, - filterName = filterName, - filterNotName = filterNotName, specmaticConfig = specmaticConfig, overlayContent = overlayContent ) @@ -282,8 +281,6 @@ open class SpecmaticJUnitSupport { it.branch, it.specificationPath, specmaticConfig?.security, - filterName, - filterNotName, specmaticConfig = specmaticConfig, overlayContent = overlayContent ) @@ -454,8 +451,6 @@ open class SpecmaticJUnitSupport { sourceRepositoryBranch: String? = null, specificationPath: String? = null, securityConfiguration: SecurityConfiguration? = null, - filterName: String?, - filterNotName: String?, specmaticConfig: SpecmaticConfig? = null, overlayContent: String = "" ): Pair, List> { From 1a941acd4f61b43872f857d593f31c9c5b1f5db7 Mon Sep 17 00:00:00 2001 From: Zaid Date: Wed, 30 Oct 2024 12:53:42 +0530 Subject: [PATCH 7/8] Change Configuration file path key in test --- .../main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt | 1 - .../kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/junit5-support/src/main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt b/junit5-support/src/main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt index 298046247..c4b2e321a 100644 --- a/junit5-support/src/main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt +++ b/junit5-support/src/main/kotlin/io/specmatic/test/SpecmaticJUnitSupport.kt @@ -55,7 +55,6 @@ open class SpecmaticJUnitSupport { companion object { const val CONTRACT_PATHS = "contractPaths" const val WORKING_DIRECTORY = "workingDirectory" - const val CONFIG_FILE_NAME = "manifestFile" const val INLINE_SUGGESTIONS = "suggestions" const val SUGGESTIONS_PATH = "suggestionsPath" const val HOST = "host" diff --git a/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt b/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt index e4a293b34..7a3800df4 100644 --- a/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt +++ b/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt @@ -1,7 +1,7 @@ package io.specmatic.test import io.specmatic.core.TestConfig -import io.specmatic.test.SpecmaticJUnitSupport.Companion.CONFIG_FILE_NAME +import io.specmatic.core.utilities.Flags.Companion.CONFIG_FILE_PATH import io.specmatic.test.SpecmaticJUnitSupport.Companion.FILTER_NAME_PROPERTY import io.specmatic.test.SpecmaticJUnitSupport.Companion.FILTER_NOT_NAME_PROPERTY import io.specmatic.test.SpecmaticJUnitSupport.Companion.HOST @@ -154,7 +154,7 @@ class SpecmaticJunitSupportTest { @Test fun`should return the two tests other than the test with example name given in filterNotName` () { - System.setProperty(CONFIG_FILE_NAME, "./src/test/resources/test_contract.yaml") + System.setProperty(CONFIG_FILE_PATH, "./src/test/resources/test_contract.yaml") System.setProperty(TEST_BASE_URL, "https://test.com") System.setProperty(FILTER_NOT_NAME_PROPERTY, "BLACKLISTED") val filteredTests = SpecmaticJUnitSupport().contractTest().map { it }.toList() @@ -164,7 +164,7 @@ class SpecmaticJunitSupportTest { @Test fun`should return only the test with example name given in filterName` () { - System.setProperty(CONFIG_FILE_NAME, "./src/test/resources/test_contract.yaml") + System.setProperty(CONFIG_FILE_PATH, "./src/test/resources/test_contract.yaml") System.setProperty(TEST_BASE_URL, "https://test.com") System.setProperty(FILTER_NAME_PROPERTY, "BLACKLISTED") val filteredTests = SpecmaticJUnitSupport().contractTest().map { it }.toList() From f8c7e185c2198a5e27c8d29ec92ec8d33ed3f95e Mon Sep 17 00:00:00 2001 From: Zaid Date: Thu, 31 Oct 2024 13:40:12 +0530 Subject: [PATCH 8/8] use existing specification file --- .../io/specmatic/test/SpecmaticJunitSupportTest.kt | 6 +++--- junit5-support/src/test/resources/test_contract.yaml | 10 ---------- 2 files changed, 3 insertions(+), 13 deletions(-) delete mode 100644 junit5-support/src/test/resources/test_contract.yaml diff --git a/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt b/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt index 7a3800df4..f810273ce 100644 --- a/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt +++ b/junit5-support/src/test/kotlin/io/specmatic/test/SpecmaticJunitSupportTest.kt @@ -1,7 +1,7 @@ package io.specmatic.test import io.specmatic.core.TestConfig -import io.specmatic.core.utilities.Flags.Companion.CONFIG_FILE_PATH +import io.specmatic.test.SpecmaticJUnitSupport.Companion.CONTRACT_PATHS import io.specmatic.test.SpecmaticJUnitSupport.Companion.FILTER_NAME_PROPERTY import io.specmatic.test.SpecmaticJUnitSupport.Companion.FILTER_NOT_NAME_PROPERTY import io.specmatic.test.SpecmaticJUnitSupport.Companion.HOST @@ -154,7 +154,7 @@ class SpecmaticJunitSupportTest { @Test fun`should return the two tests other than the test with example name given in filterNotName` () { - System.setProperty(CONFIG_FILE_PATH, "./src/test/resources/test_contract.yaml") + System.setProperty(CONTRACT_PATHS, "./src/test/resources/spec_with_parameterized_paths.yaml") System.setProperty(TEST_BASE_URL, "https://test.com") System.setProperty(FILTER_NOT_NAME_PROPERTY, "BLACKLISTED") val filteredTests = SpecmaticJUnitSupport().contractTest().map { it }.toList() @@ -164,7 +164,7 @@ class SpecmaticJunitSupportTest { @Test fun`should return only the test with example name given in filterName` () { - System.setProperty(CONFIG_FILE_PATH, "./src/test/resources/test_contract.yaml") + System.setProperty(CONTRACT_PATHS, "./src/test/resources/spec_with_parameterized_paths.yaml") System.setProperty(TEST_BASE_URL, "https://test.com") System.setProperty(FILTER_NAME_PROPERTY, "BLACKLISTED") val filteredTests = SpecmaticJUnitSupport().contractTest().map { it }.toList() diff --git a/junit5-support/src/test/resources/test_contract.yaml b/junit5-support/src/test/resources/test_contract.yaml deleted file mode 100644 index 6f253f06c..000000000 --- a/junit5-support/src/test/resources/test_contract.yaml +++ /dev/null @@ -1,10 +0,0 @@ -sources: - - provider: filesystem - provides: - - ./src/test/resources/spec_with_parameterized_paths.yaml - consumes: - - ./src/test/resources/spec_with_parameterized_paths.yaml - -test: - resiliencyTests: - enable: none \ No newline at end of file