diff --git a/core/src/main/kotlin/in/specmatic/core/utilities/ContractSource.kt b/core/src/main/kotlin/in/specmatic/core/utilities/ContractSource.kt index 2ad97043f..4f06937be 100644 --- a/core/src/main/kotlin/in/specmatic/core/utilities/ContractSource.kt +++ b/core/src/main/kotlin/in/specmatic/core/utilities/ContractSource.kt @@ -7,6 +7,7 @@ import `in`.specmatic.core.log.logger import java.io.File sealed class ContractSource { + abstract val type:String? abstract val testContracts: List abstract val stubContracts: List abstract fun pathDescriptor(path: String): String @@ -21,7 +22,8 @@ data class GitRepo( val gitRepositoryURL: String, val branchName: String?, override val testContracts: List, - override val stubContracts: List + override val stubContracts: List, + override val type: String? ) : ContractSource() { val repoName = gitRepositoryURL.split("/").last().removeSuffix(".git") override fun pathDescriptor(path: String): String { @@ -80,7 +82,7 @@ data class GitRepo( } return selector.select(this).map { - ContractPathData(repoDir.path, repoDir.resolve(it).path, "git", gitRepositoryURL, branchName, it) + ContractPathData(repoDir.path, repoDir.resolve(it).path, type, gitRepositoryURL, branchName, it) } } @@ -135,7 +137,8 @@ data class GitRepo( (sourceGit.workingDirectoryIsGitRepo() && sourceGit.getRemoteUrl() != this.gitRepositoryURL && sourceDir.listFiles()?.isEmpty() == true) } -data class GitMonoRepo(override val testContracts: List, override val stubContracts: List) : ContractSource() { +data class GitMonoRepo(override val testContracts: List, override val stubContracts: List, + override val type: String?) : ContractSource() { override fun pathDescriptor(path: String): String = path override fun install(workingDirectory: File) { println("Checking list of mono repo paths...") @@ -167,7 +170,7 @@ data class GitMonoRepo(override val testContracts: List, override val st val configFileLocation = File(configFilePath).absoluteFile.parentFile return selector.select(this).map { - ContractPathData(monoRepoBaseDir.canonicalPath, configFileLocation.resolve(it).canonicalPath) + ContractPathData(monoRepoBaseDir.canonicalPath, configFileLocation.resolve(it).canonicalPath, provider = type, specificationPath = it) } } } diff --git a/core/src/main/kotlin/in/specmatic/core/utilities/Utilities.kt b/core/src/main/kotlin/in/specmatic/core/utilities/Utilities.kt index 7b9aac718..6fc364610 100644 --- a/core/src/main/kotlin/in/specmatic/core/utilities/Utilities.kt +++ b/core/src/main/kotlin/in/specmatic/core/utilities/Utilities.kt @@ -174,8 +174,8 @@ fun loadSources(specmaticConfigJson: SpecmaticConfigJson): List val testPaths = source.test ?: emptyList() when (source.repository) { - null -> GitMonoRepo(testPaths, stubPaths) - else -> GitRepo(source.repository, source.branch, testPaths, stubPaths) + null -> GitMonoRepo(testPaths, stubPaths, source.provider.toString()) + else -> GitRepo(source.repository, source.branch, testPaths, stubPaths, source.provider.toString()) } } } @@ -199,10 +199,11 @@ fun loadSources(configJson: JSONObjectValue): List { val stubPaths = jsonArray(source, "stub") val testPaths = jsonArray(source, "test") + val type = nativeString(source.jsonObject, "provider") when (repositoryURL) { - null -> GitMonoRepo(testPaths, stubPaths) - else -> GitRepo(repositoryURL, branch, testPaths, stubPaths) + null -> GitMonoRepo(testPaths, stubPaths, type) + else -> GitRepo(repositoryURL, branch, testPaths, stubPaths, type) } } else -> throw ContractException("Provider ${nativeString(source.jsonObject, "provider")} not recognised in $globalConfigFileName") diff --git a/core/src/test/kotlin/utilities/UtilitiesTest.kt b/core/src/test/kotlin/utilities/UtilitiesTest.kt index 1fbe5973e..a6802e2d1 100644 --- a/core/src/test/kotlin/utilities/UtilitiesTest.kt +++ b/core/src/test/kotlin/utilities/UtilitiesTest.kt @@ -1,6 +1,7 @@ package utilities import `in`.specmatic.core.CONTRACT_EXTENSION +import `in`.specmatic.core.SourceProvider import `in`.specmatic.core.git.GitCommand import `in`.specmatic.core.git.SystemGit import `in`.specmatic.core.git.checkout @@ -30,7 +31,7 @@ internal class UtilitiesTest { @Test fun `contractFilePathsFrom sources when contracts repo dir does not exist`() { - val sources = listOf(GitRepo("https://repo1", null, listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION", "c/1.$CONTRACT_EXTENSION"))) + val sources = listOf(GitRepo("https://repo1", null, listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION", "c/1.$CONTRACT_EXTENSION"), SourceProvider.git.toString())) File(".spec").deleteRecursively() mockkStatic("in.specmatic.core.utilities.Utilities") @@ -54,7 +55,7 @@ internal class UtilitiesTest { fun `contractFilePathsFrom sources with branch when contracts repo dir does not exist`() { val branchName = "featureBranch" val sources = listOf(GitRepo("https://repo1", - branchName, listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION", "c/1.$CONTRACT_EXTENSION"))) + branchName, listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION", "c/1.$CONTRACT_EXTENSION"), SourceProvider.git.toString())) File(".spec").deleteRecursively() mockkStatic("in.specmatic.core.utilities.Utilities") @@ -77,7 +78,7 @@ internal class UtilitiesTest { @Test fun `contractFilePathsFrom sources when contracts repo dir exists and is clean`() { - val sources = listOf(GitRepo("https://repo1", null, listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION", "c/1.$CONTRACT_EXTENSION"))) + val sources = listOf(GitRepo("https://repo1", null, listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION", "c/1.$CONTRACT_EXTENSION"), SourceProvider.git.toString())) File(".spec").deleteRecursively() File(".spec/repos/repo1").mkdirs() @@ -101,7 +102,7 @@ internal class UtilitiesTest { @Test fun `contractFilePathsFrom sources when contracts repo dir exists and is not clean`() { - val sources = listOf(GitRepo("https://repo1", null, listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION", "c/1.$CONTRACT_EXTENSION"))) + val sources = listOf(GitRepo("https://repo1", null, listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION", "c/1.$CONTRACT_EXTENSION"), SourceProvider.git.toString())) File(".spec").deleteRecursively() File(".spec/repos/repo1").mkdirs() @@ -128,7 +129,7 @@ internal class UtilitiesTest { @Test fun `contractFilePathsFrom sources when contracts repo dir exists and is behind remote`() { - val sources = listOf(GitRepo("https://repo1", null, listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION", "c/1.$CONTRACT_EXTENSION"))) + val sources = listOf(GitRepo("https://repo1", null, listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION", "c/1.$CONTRACT_EXTENSION"), SourceProvider.git.toString())) File(".spec").deleteRecursively() File(".spec/repos/repo1").mkdirs() @@ -171,11 +172,11 @@ internal class UtilitiesTest { val testPaths = contractFilePathsFrom(configFilePath, ".$CONTRACT_EXTENSION") { source -> source.testContracts } val stubPaths = contractFilePathsFrom(configFilePath, ".$CONTRACT_EXTENSION") { source -> source.stubContracts } val expectedStubPaths = listOf( - ContractPathData("/path/to/monorepo", "$currentPath/monorepo/a/1.$CONTRACT_EXTENSION"), - ContractPathData("/path/to/monorepo", "$currentPath/monorepo/b/1.$CONTRACT_EXTENSION") + ContractPathData("/path/to/monorepo", "$currentPath/monorepo/a/1.$CONTRACT_EXTENSION", provider = SourceProvider.git.toString(), specificationPath = "../a/1.spec"), + ContractPathData("/path/to/monorepo", "$currentPath/monorepo/b/1.$CONTRACT_EXTENSION", provider = SourceProvider.git.toString(), specificationPath = "../b/1.spec") ) val expectedTestPaths = listOf( - ContractPathData("/path/to/monorepo", "$currentPath/monorepo/c/1.$CONTRACT_EXTENSION"), + ContractPathData("/path/to/monorepo", "$currentPath/monorepo/c/1.$CONTRACT_EXTENSION", provider=SourceProvider.git.toString(), specificationPath = "../c/1.spec"), ) assertThat(stubPaths == expectedStubPaths).isTrue @@ -189,7 +190,7 @@ internal class UtilitiesTest { val qontractJson = "{\"sources\": [{\"provider\": \"git\",\"repository\": \"https://repo1\",\"stub\": [\"a/1.$CONTRACT_EXTENSION\",\"b/1.$CONTRACT_EXTENSION\",\"c/1.$CONTRACT_EXTENSION\"]}]}" val configJson = parsedJSON(qontractJson) as JSONObjectValue val sources = loadSources(configJson) - val expectedSources = listOf(GitRepo("https://repo1", null, listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION", "c/1.$CONTRACT_EXTENSION"))) + val expectedSources = listOf(GitRepo("https://repo1", null, listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION", "c/1.$CONTRACT_EXTENSION"), SourceProvider.git.toString())) assertThat(sources == expectedSources).isTrue } @@ -200,8 +201,8 @@ internal class UtilitiesTest { val configJson = parsedJSON(qontractJson) as JSONObjectValue val sources = loadSources(configJson) val expectedSources = listOf( - GitRepo("https://repo1",null, listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION")), - GitRepo("https://repo2",null, listOf(), listOf("c/1.$CONTRACT_EXTENSION")) + GitRepo("https://repo1",null, listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION"), SourceProvider.git.toString()), + GitRepo("https://repo2",null, listOf(), listOf("c/1.$CONTRACT_EXTENSION"), SourceProvider.git.toString()) ) assertThat(sources == expectedSources).isTrue } @@ -211,7 +212,7 @@ internal class UtilitiesTest { val qontractJson = "{\"sources\": [{\"provider\": \"git\",\"stub\": [\"a/1.$CONTRACT_EXTENSION\",\"b/1.$CONTRACT_EXTENSION\",\"c/1.$CONTRACT_EXTENSION\"]}]}" val configJson = parsedJSON(qontractJson) as JSONObjectValue val sources = loadSources(configJson) - val expectedSources = listOf(GitMonoRepo(listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION", "c/1.$CONTRACT_EXTENSION"))) + val expectedSources = listOf(GitMonoRepo(listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION", "c/1.$CONTRACT_EXTENSION"), SourceProvider.git.toString())) assertThat(sources == expectedSources).isTrue } @@ -220,7 +221,7 @@ internal class UtilitiesTest { val qontractJson = "{\"sources\": [{\"provider\": \"git\",\"test\": [\"a/1.$CONTRACT_EXTENSION\",\"b/1.$CONTRACT_EXTENSION\",\"c/1.$CONTRACT_EXTENSION\"]}]}" val configJson = parsedJSON(qontractJson) as JSONObjectValue val sources = loadSources(configJson) - val expectedSources = listOf(GitMonoRepo(listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION", "c/1.$CONTRACT_EXTENSION"), listOf())) + val expectedSources = listOf(GitMonoRepo(listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION", "c/1.$CONTRACT_EXTENSION"), listOf(), SourceProvider.git.toString())) assertThat(sources == expectedSources).isTrue } @@ -229,7 +230,7 @@ internal class UtilitiesTest { val qontractJson = "{\"sources\": [{\"provider\": \"git\",\"test\": [\"a/1.$CONTRACT_EXTENSION\",\"b/1.$CONTRACT_EXTENSION\"],\"stub\": [\"c/1.$CONTRACT_EXTENSION\"]}]}" val configJson = parsedJSON(qontractJson) as JSONObjectValue val sources = loadSources(configJson) - val expectedSources = listOf(GitMonoRepo(listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION"), listOf("c/1.$CONTRACT_EXTENSION"))) + val expectedSources = listOf(GitMonoRepo(listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION"), listOf("c/1.$CONTRACT_EXTENSION"), SourceProvider.git.toString())) assertThat(sources == expectedSources).isTrue } @@ -240,8 +241,8 @@ internal class UtilitiesTest { val configJson = parsedJSON(qontractJson) as JSONObjectValue val sources = loadSources(configJson) val expectedSources = listOf( - GitMonoRepo(listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION")), - GitMonoRepo(listOf(), listOf("c/1.$CONTRACT_EXTENSION")) + GitMonoRepo(listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION"), SourceProvider.git.toString()), + GitMonoRepo(listOf(), listOf("c/1.$CONTRACT_EXTENSION"), SourceProvider.git.toString()) ) assertThat(sources == expectedSources).isTrue } @@ -253,8 +254,8 @@ internal class UtilitiesTest { val configJson = parsedJSON(qontractJson) as JSONObjectValue val sources = loadSources(configJson) val expectedSources = listOf( - GitRepo("https://repo1", null, listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION")), - GitMonoRepo(listOf(), listOf("c/1.$CONTRACT_EXTENSION")) + GitRepo("https://repo1", null, listOf(), listOf("a/1.$CONTRACT_EXTENSION", "b/1.$CONTRACT_EXTENSION"), SourceProvider.git.toString()), + GitMonoRepo(listOf(), listOf("c/1.$CONTRACT_EXTENSION"), SourceProvider.git.toString()) ) assertThat(sources == expectedSources).isTrue } diff --git a/junit5-support/src/main/kotlin/in/specmatic/test/reports/coverage/OpenApiCoverageReportInput.kt b/junit5-support/src/main/kotlin/in/specmatic/test/reports/coverage/OpenApiCoverageReportInput.kt index f6ea1014e..50b30c8e1 100644 --- a/junit5-support/src/main/kotlin/in/specmatic/test/reports/coverage/OpenApiCoverageReportInput.kt +++ b/junit5-support/src/main/kotlin/in/specmatic/test/reports/coverage/OpenApiCoverageReportInput.kt @@ -94,7 +94,7 @@ class OpenApiCoverageReportInput( method = operationGroup.second, responseCode = operationGroup.third, count = operationRows.count{it.includeForCoverage}, - coverageStatus = getRemarks(operationRows) + coverageStatus = getRemarks(operationRows).toString() ) } ) diff --git a/junit5-support/src/main/kotlin/in/specmatic/test/reports/coverage/json/OpenApiCoverageOperation.kt b/junit5-support/src/main/kotlin/in/specmatic/test/reports/coverage/json/OpenApiCoverageOperation.kt index 71f3b21c6..ac5090c49 100644 --- a/junit5-support/src/main/kotlin/in/specmatic/test/reports/coverage/json/OpenApiCoverageOperation.kt +++ b/junit5-support/src/main/kotlin/in/specmatic/test/reports/coverage/json/OpenApiCoverageOperation.kt @@ -1,13 +1,12 @@ package `in`.specmatic.test.reports.coverage.json -import `in`.specmatic.test.reports.coverage.console.Remarks import kotlinx.serialization.Serializable @Serializable data class OpenApiCoverageOperation( val path: String, val method: String, - val responseCode: Int, - val count: Int, - val coverageStatus: Remarks + val responseCode: Int = 0, + val count: Int = 0, + val coverageStatus: String ) \ No newline at end of file diff --git a/junit5-support/src/test/kotlin/in/specmatic/test/ApiCoverageReportInputTest.kt b/junit5-support/src/test/kotlin/in/specmatic/test/ApiCoverageReportInputTest.kt index d8c234ed3..932c494b5 100644 --- a/junit5-support/src/test/kotlin/in/specmatic/test/ApiCoverageReportInputTest.kt +++ b/junit5-support/src/test/kotlin/in/specmatic/test/ApiCoverageReportInputTest.kt @@ -253,8 +253,8 @@ class ApiCoverageReportInputTest { "in/specmatic/examples/store/route1.yaml", "HTTP", listOf( - OpenApiCoverageOperation("/route1", "GET",200, 1, Remarks.Covered), - OpenApiCoverageOperation( "/route1", "POST",200, 1, Remarks.Covered) + OpenApiCoverageOperation("/route1", "GET",200, 1, Remarks.Covered.toString()), + OpenApiCoverageOperation( "/route1", "POST",200, 1, Remarks.Covered.toString()) ) ), OpenApiCoverageJsonRow( @@ -264,15 +264,15 @@ class ApiCoverageReportInputTest { "in/specmatic/examples/store/route2.yaml", "HTTP", listOf( - OpenApiCoverageOperation( "/route2", "GET",200, 1, Remarks.Covered), - OpenApiCoverageOperation( "/route2", "POST",200, 0, Remarks.NotImplemented) + OpenApiCoverageOperation( "/route2", "GET",200, 1, Remarks.Covered.toString()), + OpenApiCoverageOperation( "/route2", "POST",200, 0, Remarks.NotImplemented.toString()) ) ), OpenApiCoverageJsonRow( serviceType = "HTTP", operations = listOf( - OpenApiCoverageOperation( "/route3/{route_id}", "GET",0, 0, Remarks.Missed), - OpenApiCoverageOperation( "/route3/{route_id}", "POST",0, 0, Remarks.Missed) + OpenApiCoverageOperation( "/route3/{route_id}", "GET",0, 0, Remarks.Missed.toString()), + OpenApiCoverageOperation( "/route3/{route_id}", "POST",0, 0, Remarks.Missed.toString() ) ) ) )