All Downloads are FREE. Search and download functionalities are using the official Maven repository.

in.specmatic.core.GenerationStrategies.kt Maven / Gradle / Ivy

Go to download

Turn your contracts into executable specifications. Contract Driven Development - Collaboratively Design & Independently Deploy MicroServices & MicroFrontends. Deprecation Notice for group ID "in.specmatic" ****************************************************************************************************** Updates for "specmatic-core" will no longer be available under the deprecated group ID "in.specmatic". Please update your dependencies to use the new group ID "io.specmatic". ******************************************************************************************************

There is a newer version: 1.3.39
Show newest version
package `in`.specmatic.core

import `in`.specmatic.core.pattern.Pattern
import `in`.specmatic.core.pattern.ReturnValue
import `in`.specmatic.core.pattern.Row
import `in`.specmatic.core.pattern.withoutOptionality
import `in`.specmatic.core.value.Value

interface GenerationStrategies {
    fun generatedPatternsForGenerativeTests(resolver: Resolver, pattern: Pattern, key: String): Sequence>
    fun generateHttpRequestBodies(resolver: Resolver, body: Pattern, row: Row, requestBodyAsIs: Pattern, value: Value): Sequence>
    fun generateHttpRequestBodies(resolver: Resolver, body: Pattern, row: Row): Sequence>
    fun resolveRow(row: Row): Row
    fun generateKeySubLists(key: String, subList: List): Sequence>
    fun positiveTestScenarios(feature: Feature, suggestions: List): Sequence>>
    fun negativeTestScenarios(feature: Feature): Sequence>>
    fun fillInTheMissingMapPatterns(
        newQueryParamsList: Sequence>,
        queryPatterns: Map,
        additionalProperties: Pattern?,
        row: Row,
        resolver: Resolver
    ): Sequence>
}

internal fun noOverlapBetween(
    map: Map,
    otherMaps: Sequence>,
    resolver: Resolver
): Map? {
    val otherMapsWithSameKeys = otherMaps.filter {
        it.keys.map(::withoutOptionality) == map.keys.map(::withoutOptionality)
    }.map {
        it.mapKeys { withoutOptionality(it.key) }
    }

    val mapWithoutOptionality = map.mapKeys { withoutOptionality(it.key) }

    val results: Sequence = otherMapsWithSameKeys.map { otherMap ->
        val valueMatchResults = otherMap.map { (key, otherPattern) ->
            val itemPattern = mapWithoutOptionality.getValue(key)

            itemPattern.encompasses(otherPattern, resolver, resolver)
        }

        Result.fromResults(valueMatchResults)
    }

    if(results.any { it is Result.Success })
        return null

    return map
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy