Skip to content

Commit

Permalink
Made fields sourceProvider, sourceRepository, sourceRepositoryBranch,…
Browse files Browse the repository at this point in the history
… specification, serviceType nullable everywhere with default value as null.

Fixed ContractSource tests.
  • Loading branch information
jaydeepk authored and harikrishnan83 committed Sep 13, 2023
1 parent 52c7ec4 commit d729162
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import java.io.File

private const val BEARER_SECURITY_SCHEME = "bearer"

class OpenApiSpecification(private val openApiFile: String, val openApi: OpenAPI, val sourceProvider:String = "", val sourceRepository:String = "", val sourceRepositoryBranch:String = "", val specificationPath:String = "") : IncludedSpecification,
class OpenApiSpecification(private val openApiFile: String, val openApi: OpenAPI, private val sourceProvider:String? = null, private val sourceRepository:String? = null, private val sourceRepositoryBranch:String? = null, private val specificationPath:String? = null) : IncludedSpecification,
ApiSpecification {
companion object {
fun fromFile(openApiFilePath: String, relativeTo: String = ""): OpenApiSpecification {
Expand All @@ -51,7 +51,7 @@ class OpenApiSpecification(private val openApiFile: String, val openApi: OpenAPI
return OpenApiSpecification(openApiFile, openApi)
}

fun fromYAML(yamlContent: String, filePath: String, sourceProvider:String = "", sourceRepository:String = "", sourceRepositoryBranch:String = "", specificationPath:String = "", loggerForErrors: LogStrategy = logger): OpenApiSpecification {
fun fromYAML(yamlContent: String, filePath: String, loggerForErrors: LogStrategy = logger, sourceProvider:String? = null, sourceRepository:String? = null, sourceRepositoryBranch:String? = null, specificationPath:String? = null,): OpenApiSpecification {
val parseResult: SwaggerParseResult =
OpenAPIV3Parser().readContents(yamlContent, null, resolveExternalReferences(), filePath)
val openApi: OpenAPI? = parseResult.openAPI
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/kotlin/in/specmatic/core/Feature.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class BadRequestOrDefault(private val badRequestResponses: Map<Int, HttpResponse
httpResponse.status in badRequestResponses || defaultResponse != null
}

fun parseContractFileToFeature(contractPath: String, hook: Hook = PassThroughHook(), sourceProvider:String = "", sourceRepository:String = "", sourceRepositoryBranch:String = "", specificationPath:String = "" ): Feature {
fun parseContractFileToFeature(contractPath: String, hook: Hook = PassThroughHook(), sourceProvider:String? = null, sourceRepository:String? = null, sourceRepositoryBranch:String? = null, specificationPath:String? = null): Feature {
return parseContractFileToFeature(File(contractPath), hook, sourceProvider, sourceRepository, sourceRepositoryBranch, specificationPath)
}

Expand All @@ -50,11 +50,11 @@ fun checkExists(file: File) = file.also {
throw ContractException("File ${file.path} does not exist (absolute path ${file.canonicalPath})")
}

fun parseContractFileToFeature(file: File, hook: Hook = PassThroughHook(), sourceProvider:String = "", sourceRepository:String = "", sourceRepositoryBranch:String = "", specificationPath:String = "" ): Feature {
fun parseContractFileToFeature(file: File, hook: Hook = PassThroughHook(), sourceProvider:String? = null, sourceRepository:String? = null, sourceRepositoryBranch:String? = null, specificationPath:String? = null): Feature {
logger.debug("Parsing contract file ${file.path}, absolute path ${file.absolutePath}")

return when (file.extension) {
"yaml" -> OpenApiSpecification.fromYAML(hook.readContract(file.path), file.path, sourceProvider, sourceRepository, sourceRepositoryBranch, specificationPath).toFeature()
"yaml" -> OpenApiSpecification.fromYAML(hook.readContract(file.path), file.path, sourceProvider =sourceProvider, sourceRepository = sourceRepository, sourceRepositoryBranch = sourceRepositoryBranch, specificationPath = specificationPath).toFeature()
"wsdl" -> wsdlContentToFeature(checkExists(file).readText(), file.canonicalPath)
in CONTRACT_EXTENSIONS -> parseGherkinStringToFeature(checkExists(file).readText().trim(), file.canonicalPath)
else -> throw ContractException("File extension of ${file.path} not recognized")
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/kotlin/in/specmatic/core/Scenario.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ data class Scenario(
val exampleName: String? = null,
val generativeTestingEnabled: Boolean = false,
val generatedFromExamples: Boolean = examples.isNotEmpty(),
val sourceProvider:String = "",
val sourceRepository:String = "",
val sourceRepositoryBranch:String = "",
val specification:String = "",
val serviceType:String = ""
val sourceProvider:String? = null,
val sourceRepository:String? = null,
val sourceRepositoryBranch:String? = null,
val specification:String? = null,
val serviceType:String? = null
): ScenarioDetailsForResult {
constructor(scenarioInfo: ScenarioInfo) : this(
scenarioInfo.scenarioName,
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/kotlin/in/specmatic/core/ScenarioInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ data class ScenarioInfo(
val references: Map<String, References> = emptyMap(),
val bindings: Map<String, String> = emptyMap(),
val isGherkinScenario: Boolean = false,
val sourceProvider:String = "",
val sourceRepository:String = "",
val sourceRepositoryBranch:String = "",
val specification:String = "",
val serviceType:String = ""
val sourceProvider:String? = null,
val sourceRepository:String? = null,
val sourceRepositoryBranch:String? = null,
val specification:String? = null,
val serviceType:String? = null
) {
fun matchesSignature(other: ScenarioInfo) = httpRequestPattern.matchesSignature(other.httpRequestPattern) &&
httpResponsePattern.status == other.httpResponsePattern.status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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, "git", gitRepositoryURL, branchName, it)
}
}

Expand Down Expand Up @@ -167,7 +167,7 @@ data class GitMonoRepo(override val testContracts: List<String>, override val st
val configFileLocation = File(configFilePath).absoluteFile.parentFile

return selector.select(this).map {
ContractPathData(monoRepoBaseDir.canonicalPath, configFileLocation.resolve(it).canonicalPath, specificationPath = it)
ContractPathData(monoRepoBaseDir.canonicalPath, configFileLocation.resolve(it).canonicalPath)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/kotlin/in/specmatic/core/utilities/Utilities.kt
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ fun gitRootDir(): String {
data class ContractPathData(
val baseDir: String,
val path: String,
val provider: String = "",
val repository: String = "",
val branch: String = "",
val specificationPath: String = ""
val provider: String? = null,
val repository: String? = null,
val branch: String? = null,
val specificationPath: String? = null
) {
val relativePath: String
get() {
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/kotlin/in/specmatic/test/ContractTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ data class TestResultRecord(
val method: String,
val responseStatus: Int,
val result: TestResult,
val sourceProvider: String = "",
val sourceRepository: String = "",
val sourceRepositoryBranch: String = "",
val specification: String = "",
val serviceType: String = ""
val sourceProvider: String? = null,
val sourceRepository: String? = null,
val sourceRepositoryBranch: String? = null,
val specification: String? = null,
val serviceType: String? = null
) {
val includeForCoverage = result !in listOf(TestResult.Skipped, TestResult.NotImplemented)
}
Expand Down
12 changes: 7 additions & 5 deletions core/src/main/kotlin/in/specmatic/test/ScenarioTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import `in`.specmatic.core.TestResult
import `in`.specmatic.core.executeTest

class ScenarioTest(
val scenario: Scenario, private val generativeTestingEnabled: Boolean = false, val sourceProvider: String = "",
val sourceRepository: String = "",
val sourceRepositoryBranch: String = "",
val specification: String = "",
val serviceType: String = ""
val scenario: Scenario,
private val generativeTestingEnabled: Boolean = false,
private val sourceProvider: String? = null,
private val sourceRepository: String? = null,
private val sourceRepositoryBranch: String? = null,
private val specification: String? = null,
private val serviceType: String? = null
) : ContractTest {
override fun testResultRecord(result: Result): TestResultRecord {
val resultStatus = if (scenario.generatedFromExamples) result.testResult() else TestResult.Skipped
Expand Down
30 changes: 15 additions & 15 deletions core/src/test/kotlin/utilities/UtilitiesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ internal class UtilitiesTest {

val contractPaths = contractFilePathsFrom("/configFilePath", ".$CONTRACT_EXTENSION") { source -> source.stubContracts }
val expectedContractPaths = listOf(
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/a/1.$CONTRACT_EXTENSION"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/b/1.$CONTRACT_EXTENSION"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/c/1.$CONTRACT_EXTENSION"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/a/1.$CONTRACT_EXTENSION", "git", "https://repo1", specificationPath = "a/1.spec"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/b/1.$CONTRACT_EXTENSION", "git", "https://repo1", specificationPath = "b/1.spec"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/c/1.$CONTRACT_EXTENSION", "git", "https://repo1", specificationPath = "c/1.spec"),
)
verify(exactly = 0) { checkout(any(), any()) }
assertThat(contractPaths == expectedContractPaths).isTrue
Expand All @@ -67,9 +67,9 @@ internal class UtilitiesTest {

val contractPaths = contractFilePathsFrom("/configFilePath", ".$CONTRACT_EXTENSION") { source -> source.stubContracts }
val expectedContractPaths = listOf(
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/a/1.$CONTRACT_EXTENSION"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/b/1.$CONTRACT_EXTENSION"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/c/1.$CONTRACT_EXTENSION"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/a/1.$CONTRACT_EXTENSION", "git", "https://repo1", "featureBranch", "a/1.spec"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/b/1.$CONTRACT_EXTENSION", "git", "https://repo1", "featureBranch", "b/1.spec"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/c/1.$CONTRACT_EXTENSION", "git", "https://repo1", "featureBranch", "c/1.spec"),
)
verify(exactly = 1) { checkout(repositoryDirectory, branchName) }
assertThat(contractPaths == expectedContractPaths).isTrue
Expand All @@ -92,9 +92,9 @@ internal class UtilitiesTest {

val contractPaths = contractFilePathsFrom("/configFilePath", ".$CONTRACT_EXTENSION") { source -> source.stubContracts }
val expectedContractPaths = listOf(
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/a/1.$CONTRACT_EXTENSION"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/b/1.$CONTRACT_EXTENSION"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/c/1.$CONTRACT_EXTENSION"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/a/1.$CONTRACT_EXTENSION", "git", "https://repo1", specificationPath = "a/1.spec"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/b/1.$CONTRACT_EXTENSION", "git", "https://repo1", specificationPath = "b/1.spec"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/c/1.$CONTRACT_EXTENSION", "git", "https://repo1", specificationPath = "c/1.spec"),
)
assertThat(contractPaths == expectedContractPaths).isTrue
}
Expand All @@ -119,9 +119,9 @@ internal class UtilitiesTest {

val contractPaths = contractFilePathsFrom("/configFilePath", ".$CONTRACT_EXTENSION") { source -> source.stubContracts }
val expectedContractPaths = listOf(
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/a/1.$CONTRACT_EXTENSION"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/b/1.$CONTRACT_EXTENSION"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/c/1.$CONTRACT_EXTENSION"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/a/1.$CONTRACT_EXTENSION", "git", "https://repo1", specificationPath = "a/1.spec"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/b/1.$CONTRACT_EXTENSION", "git", "https://repo1", specificationPath = "b/1.spec"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/c/1.$CONTRACT_EXTENSION", "git", "https://repo1", specificationPath = "c/1.spec"),
)
assertThat(contractPaths == expectedContractPaths).isTrue
}
Expand All @@ -145,9 +145,9 @@ internal class UtilitiesTest {

val contractPaths = contractFilePathsFrom("/configFilePath", ".$CONTRACT_EXTENSION") { source -> source.stubContracts }
val expectedContractPaths = listOf(
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/a/1.$CONTRACT_EXTENSION"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/b/1.$CONTRACT_EXTENSION"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/c/1.$CONTRACT_EXTENSION"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/a/1.$CONTRACT_EXTENSION", "git", "https://repo1", specificationPath = "a/1.spec"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/b/1.$CONTRACT_EXTENSION", "git", "https://repo1", specificationPath = "b/1.spec"),
ContractPathData(".spec/repos/repo1", ".spec/repos/repo1/c/1.$CONTRACT_EXTENSION", "git", "https://repo1", specificationPath = "c/1.spec"),
)
assertThat(contractPaths == expectedContractPaths).isTrue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ open class SpecmaticJUnitSupport {

fun getConfigFile() = System.getProperty(CONFIG_FILE_NAME) ?: globalConfigFileName

fun getConfigFileWithAbsolutePath() = File(getConfigFile()).absolutePath
fun getConfigFileWithAbsolutePath() = File(getConfigFile()).canonicalPath
}

private fun getEnvConfig(envName: String?): JSONObjectValue {
Expand Down Expand Up @@ -250,10 +250,10 @@ open class SpecmaticJUnitSupport {
suggestionsPath: String,
suggestionsData: String,
config: TestConfig,
sourceProvider:String = "",
sourceRepository:String = "",
sourceRepositoryBranch:String = "",
specificationPath:String = ""
sourceProvider:String? = null,
sourceRepository:String? = null,
sourceRepositoryBranch:String? = null,
specificationPath:String? = null
): List<ContractTest> {
if(isYAML(path) && !isOpenAPI(path))
return emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OpenApiCoverageReportProcessor(private val openApiCoverageReportInput: Ope
}

private fun saveAsJson(openApiCoverageJsonReport: OpenApiCoverageJsonReport) {
println("Saving Open API Coverage Report json to $JSON_REPORT_PATH...")
println("Saving Open API Coverage Report json to $JSON_REPORT_PATH ...")
val json = Json {
encodeDefaults = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ class OpenApiCoverageReportInput(
}

data class CoverageGroupKey(
val sourceProvider: String,
val sourceRepository: String,
val sourceRepositoryBranch: String,
val specification: String,
val serviceType: String
val sourceProvider: String?,
val sourceRepository: String?,
val sourceRepositoryBranch: String?,
val specification: String?,
val serviceType: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import kotlinx.serialization.Serializable

@Serializable
data class OpenApiCoverageJsonRow(
val type: String?,
val repository: String?,
val branch: String?,
val specification: String?,
val serviceType: String?,
val type: String? = null,
val repository: String? = null,
val branch: String? = null,
val specification: String? = null,
val serviceType: String? = null,
val operations: List<OpenApiCoverageOperation>
)
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,8 @@ class ApiCoverageReportInputTest {
)
),
OpenApiCoverageJsonRow(
"",
"",
"",
"",
"HTTP",
listOf(
serviceType = "HTTP",
operations = listOf(
OpenApiCoverageOperation( "/route3/{route_id}", "GET",0, 0, Remarks.Missed),
OpenApiCoverageOperation( "/route3/{route_id}", "POST",0, 0, Remarks.Missed)
)
Expand Down

0 comments on commit d729162

Please sign in to comment.