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

io.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.

There is a newer version: 2.0.37
Show newest version
package io.specmatic.core

import io.specmatic.core.pattern.Pattern
import io.specmatic.core.pattern.ReturnValue
import io.specmatic.core.pattern.Row
import io.specmatic.core.pattern.withoutOptionality
import io.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 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