Best Hikaku code snippet using de.codecentric.hikaku.SupportedFeatures
WadlConverter.kt
Source:WadlConverter.kt
1package de.codecentric.hikaku.converters.wadl2import de.codecentric.hikaku.SupportedFeatures3import de.codecentric.hikaku.SupportedFeatures.Feature4import de.codecentric.hikaku.converters.AbstractEndpointConverter5import de.codecentric.hikaku.converters.EndpointConverterException6import de.codecentric.hikaku.converters.wadl.extensions.getAttribute7import de.codecentric.hikaku.endpoints.*8import de.codecentric.hikaku.extensions.checkFileValidity9import org.w3c.dom.Node10import org.w3c.dom.NodeList11import org.xml.sax.InputSource12import java.io.File13import java.io.StringReader14import java.nio.charset.Charset15import java.nio.charset.StandardCharsets.UTF_816import java.nio.file.Files17import java.nio.file.Path18import javax.xml.parsers.DocumentBuilderFactory19import javax.xml.xpath.XPathConstants.NODESET20import javax.xml.xpath.XPathFactory21/**22 * Extracts and converts [Endpoint]s from a *.wadl* file.23 */24class WadlConverter private constructor(private val wadl: String) : AbstractEndpointConverter() {25 @JvmOverloads26 constructor(wadlFile: File, charset: Charset = UTF_8): this(wadlFile.toPath(), charset)27 @JvmOverloads28 constructor(wadlFile: Path, charset: Charset = UTF_8): this(readFileContent(wadlFile, charset))29 override val supportedFeatures = SupportedFeatures(30 Feature.QueryParameters,31 Feature.HeaderParameters,32 Feature.PathParameters,33 Feature.MatrixParameters,34 Feature.Produces,35 Feature.Consumes36 )37 private val xPath = XPathFactory38 .newInstance()39 .newXPath()40 override fun convert(): Set<Endpoint> {41 try {42 return parseWadl()43 } catch (throwable: Throwable) {...
SpringConverter.kt
Source:SpringConverter.kt
1package de.codecentric.hikaku.converters.spring2import de.codecentric.hikaku.SupportedFeatures3import de.codecentric.hikaku.SupportedFeatures.Feature4import de.codecentric.hikaku.converters.AbstractEndpointConverter5import de.codecentric.hikaku.converters.spring.extensions.*6import de.codecentric.hikaku.endpoints.Endpoint7import de.codecentric.hikaku.endpoints.HttpMethod8import de.codecentric.hikaku.endpoints.HttpMethod.*9import org.springframework.context.ApplicationContext10import org.springframework.web.method.HandlerMethod11import org.springframework.web.servlet.mvc.method.RequestMappingInfo12import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping13/**14 * Extracts and converts [Endpoint]s from a spring [ApplicationContext].15 * @param applicationContext Spring application context16 */17class SpringConverter(private val applicationContext: ApplicationContext) : AbstractEndpointConverter() {18 override val supportedFeatures = SupportedFeatures(19 Feature.QueryParameters,20 Feature.PathParameters,21 Feature.HeaderParameters,22 Feature.MatrixParameters,23 Feature.Produces,24 Feature.Consumes,25 Feature.Deprecation26 )27 override fun convert(): Set<Endpoint> {28 return applicationContext.getBean(RequestMappingHandlerMapping::class.java)29 .handlerMethods30 .flatMap { mappingEntry ->31 mappingEntry.key.paths().flatMap { path ->32 createEndpoints(path, mappingEntry)...
OpenApiConverter.kt
Source:OpenApiConverter.kt
1package de.codecentric.hikaku.converters.openapi2import de.codecentric.hikaku.SupportedFeatures3import de.codecentric.hikaku.SupportedFeatures.Feature4import de.codecentric.hikaku.converters.AbstractEndpointConverter5import de.codecentric.hikaku.converters.EndpointConverterException6import de.codecentric.hikaku.converters.openapi.extensions.httpMethods7import de.codecentric.hikaku.converters.openapi.extractors.*8import de.codecentric.hikaku.endpoints.Endpoint9import de.codecentric.hikaku.endpoints.HttpMethod10import de.codecentric.hikaku.extensions.checkFileValidity11import io.swagger.v3.oas.models.Operation12import io.swagger.v3.parser.OpenAPIV3Parser13import java.io.File14import java.nio.charset.Charset15import java.nio.charset.StandardCharsets.UTF_816import java.nio.file.Files.readAllLines17import java.nio.file.Path18/**19 * Extracts and converts [Endpoint]s from OpenAPI 3.0.X document. Either a *.yaml*, *.yml* or a *.json* file.20 */21class OpenApiConverter private constructor(private val specificationContent: String) : AbstractEndpointConverter() {22 @JvmOverloads23 constructor(openApiSpecification: File, charset: Charset = UTF_8): this(openApiSpecification.toPath(), charset)24 @JvmOverloads25 constructor(openApiSpecification: Path, charset: Charset = UTF_8): this(readFileContent(openApiSpecification, charset))26 override val supportedFeatures = SupportedFeatures(27 Feature.QueryParameters,28 Feature.PathParameters,29 Feature.HeaderParameters,30 Feature.Produces,31 Feature.Consumes,32 Feature.Deprecation33 )34 override fun convert(): Set<Endpoint> {35 try {36 return parseOpenApi()37 } catch (throwable: Throwable) {38 throw EndpointConverterException(throwable)39 }40 }...
Hikaku.kt
Source:Hikaku.kt
1package de.codecentric.hikaku2import de.codecentric.hikaku.SupportedFeatures.Feature3import de.codecentric.hikaku.converters.EndpointConverter4import de.codecentric.hikaku.endpoints.Endpoint5import de.codecentric.hikaku.reporters.MatchResult6import de.codecentric.hikaku.reporters.Reporter7import kotlin.test.fail8/**9 * Entry point for writing a hikaku test. Provide the [EndpointConverter]s and call [match] to test if the specification and the implementation of your REST-API match.10 * @param specification An [EndpointConverter] which converts your specification for the equality check.11 * @param implementation An [EndpointConverter] which converts your implementation for the equality check.12 * @param config The configuration is optional. It lets you control the matching.13 */14class Hikaku(15 private val specification: EndpointConverter,16 private val implementation: EndpointConverter,17 var config: HikakuConfig = HikakuConfig()18) {19 private val supportedFeatures = SupportedFeatures(specification.supportedFeatures.intersect(implementation.supportedFeatures))20 private fun Set<Endpoint>.applyConfig(config: HikakuConfig): List<Endpoint> {21 val result = this.toMutableList()22 config.filters.forEach {23 result.removeAll(this.filter(it))24 }25 return result26 }27 private fun reportResult(matchResult: MatchResult) {28 config.reporters.forEach { it.report(matchResult) }29 }30 /**31 * Calling this method creates a [MatchResult]. It will be passed to the [Reporter] defined in the configuration and call [assert] with the end result.32 */33 fun match() {...
CommandLineReporter.kt
Source:CommandLineReporter.kt
1package de.codecentric.hikaku.reporters2import de.codecentric.hikaku.SupportedFeatures3import de.codecentric.hikaku.SupportedFeatures.*4import de.codecentric.hikaku.endpoints.*5/**6 * Simply prints the result to [System.out].7 */8class CommandLineReporter : Reporter {9 override fun report(endpointMatchResult: MatchResult) {10 val heading = "hikaku test result:"11 println("\n")12 println(heading)13 println("#".repeat(heading.length))14 val features = endpointMatchResult.supportedFeatures.joinToString(separator = ", ")15 println("The following features were used for matching: HttpMethod, Path, $features")16 if (endpointMatchResult.notFound.isEmpty() && endpointMatchResult.notExpected.isEmpty()) {17 println ("")18 println ("â
Test successful. Specification and implementation match.")19 }20 if (endpointMatchResult.notFound.isNotEmpty()) {21 println("\nð Expected, but unable to find:")22 endpointMatchResult.notFound.forEach {23 printEndpoint(endpointMatchResult.supportedFeatures, it)24 }25 }26 if (endpointMatchResult.notExpected.isNotEmpty()) {27 println("\nð» Unexpected, but found:")28 endpointMatchResult.notExpected.forEach {29 printEndpoint(endpointMatchResult.supportedFeatures, it)30 }31 }32 }33 private fun printEndpoint(supportedFeatures: SupportedFeatures, endpoint: Endpoint) {34 var path = "< ${endpoint.httpMethod} ${endpoint.path}"35 supportedFeatures.forEach {36 path += when(it) {37 Feature.QueryParameters -> listQueryParameters(endpoint.queryParameters)38 Feature.PathParameters -> listPathParameters(endpoint.pathParameters)39 Feature.HeaderParameters -> listHeaderParameter(endpoint.headerParameters)40 Feature.MatrixParameters -> listMatrixParameter(endpoint.matrixParameters)41 Feature.Consumes -> listRequestMediaTypes(endpoint.consumes)42 Feature.Produces -> listResponseMediaTypes(endpoint.produces)43 Feature.Deprecation -> if (endpoint.deprecated) " Deprecated" else ""44 }45 }46 println("$path >")47 }...
RamlConverter.kt
Source:RamlConverter.kt
1package de.codecentric.hikaku.converters.raml2import de.codecentric.hikaku.SupportedFeatures3import de.codecentric.hikaku.SupportedFeatures.Feature4import de.codecentric.hikaku.converters.AbstractEndpointConverter5import de.codecentric.hikaku.converters.EndpointConverterException6import de.codecentric.hikaku.converters.raml.extensions.*7import de.codecentric.hikaku.endpoints.Endpoint8import de.codecentric.hikaku.extensions.checkFileValidity9import org.raml.v2.api.RamlModelBuilder10import org.raml.v2.api.RamlModelResult11import org.raml.v2.api.model.v10.resources.Resource12import java.io.File13import java.nio.file.Path14class RamlConverter(private val ramlSpecification: File) : AbstractEndpointConverter() {15 constructor(ramlSpecification: Path) : this(ramlSpecification.toFile())16 override val supportedFeatures = SupportedFeatures(17 Feature.QueryParameters,18 Feature.PathParameters,19 Feature.HeaderParameters,20 Feature.Produces,21 Feature.Consumes,22 Feature.Deprecation23 )24 override fun convert(): Set<Endpoint> {25 val ramlParserResult: RamlModelResult?26 try {27 ramlSpecification.checkFileValidity(".raml")28 ramlParserResult = RamlModelBuilder().buildApi(ramlSpecification)29 } catch(throwable: Throwable) {30 throw EndpointConverterException(throwable)...
MatchResult.kt
Source:MatchResult.kt
1package de.codecentric.hikaku.reporters2import de.codecentric.hikaku.SupportedFeatures3import de.codecentric.hikaku.endpoints.Endpoint4/**5 * Contains the complete result.6 * @param supportedFeatures Contains all features which have been used for the match.7 * @param specificationEndpoints All [Endpoint]s extracted from the specification.8 * @param implementationEndpoints All [Endpoint]s extracted from the implementation.9 * @param notFound A [Set] of [Endpoint]s which were expected due to their existence in the specification, but which couldn't be found.10 * @param notExpected A [Set] of [Endpoint]s which have been found in the implementation, but which were unexpected, because they don't exist in the specification.11 */12data class MatchResult(13 val supportedFeatures: SupportedFeatures,14 val specificationEndpoints: Set<Endpoint>,15 val implementationEndpoints: Set<Endpoint>,16 val notFound: Set<Endpoint>,17 val notExpected: Set<Endpoint>18)...
EndpointConverter.kt
Source:EndpointConverter.kt
1package de.codecentric.hikaku.converters2import de.codecentric.hikaku.SupportedFeatures3import de.codecentric.hikaku.SupportedFeatures.Feature4import de.codecentric.hikaku.endpoints.Endpoint5/**6 * Converts either a specific type of specification or implementation into the internal hikaku format in order to be able to perform a matching on the extracted components.7 */8interface EndpointConverter {9 /** Result of the conversion containing all extracted [Endpoint]s. */10 val conversionResult: Set<Endpoint>11 /** List of [Feature]s that this [EndpointConverter]s supports. */12 val supportedFeatures: SupportedFeatures13}...
SupportedFeatures
Using AI Code Generation
1val supportedFeatures = SupportedFeatures(2val supportedFeatures = SupportedFeatures(3val supportedFeatures = SupportedFeatures(4val supportedFeatures = SupportedFeatures(5val supportedFeatures = SupportedFeatures(6val supportedFeatures = SupportedFeatures(7val supportedMediaTypes = SupportedMediaTypes(8val supportedParameters = SupportedParameters(9 SupportedParameters.Parameter(10 SupportedParameters.Parameter(11val supportedProperties = SupportedProperties(12 SupportedProperties.Property("id", SupportedProperties.Property.Type.INTEGER),13 SupportedProperties.Property("name", SupportedProperties.Property.Type.STRING
SupportedFeatures
Using AI Code Generation
1+ @ParameterizedTest(name = "{displayName} - {argumentsWithNames}")2+ @MethodSource("de.codecentric.hikaku.converters.jaxrs.ConverterTest#supportedFeatures")3+ fun `Check if Hikaku finds all supported features`(supportedFeatures: SupportedFeatures) {4+ val specification = JaxRsConverter.convert(5+ Endpoint(6+ consumes = setOf(MediaType.APPLICATION_JSON),7+ produces = setOf(MediaType.APPLICATION_JSON),8+ parameters = setOf(9+ Parameter(10+ responses = setOf(11+ Response(12+ headers = setOf(13+ Header(14+ val result = specification.checkAgainst(supportedFeatures)15+ assertThat(result).isTrue()16+ }17+ @ParameterizedTest(name = "{displayName} - {argumentsWithNames}")18+ @MethodSource("de.codecentric.hikaku.converters.jaxrs.ConverterTest#supportedFeatures")19+ fun `Check if Hikaku finds all supported features`(supportedFeatures: SupportedFeatures) {20+ val specification = JaxRsConverter.convert(21+ Endpoint(22+ consumes = setOf(MediaType.APPLICATION_JSON),23+ produces = setOf(MediaType.APPLICATION_JSON),24+ parameters = setOf(25+ Parameter(
SupportedFeatures
Using AI Code Generation
1+ @ParameterizedTest(name = "{displayName} - {argumentsWithNames}")2+ @MethodSource("de.codecentric.hikaku.converters.jaxrs.ConverterTest#supportedFeatures")3+ fun `Check if Hikaku finds all supported features`(supportedFeatures: SupportedFeatures) {4+ val specification = JaxRsConverter.convert(5+ Endpoint(6+ consumes = setOf(MediaType.APPLICATION_JSON),7+ produces = setOf(MediaType.APPLICATION_JSON),8+ parameters = setOf(9+ Parameter(10+ responses = setOf(11+ Response(12+ headers = setOf(13+ Header(14+ val result = specification.checkAgainst(supportedFeatures)15+ assertThat(result).isTrue()16+ }17+ @ParameterizedTest(name = "{displayName} - {argumentsWithNames}")18+ @MethodSource("de.codecentric.hikaku.converters.jaxrs.ConverterTest#supportedFeatures")19+ fun `Check if Hikaku finds all supported features`(supportedFeatures: SupportedFeatures) {20+ val specification = JaxRsConverter.convert(21+ Endpoint(22+ consumes = setOf(MediaType.APPLICATION_JSON),23+ produces = setOf(MediaType.APPLICATION_JSON),24+ parameters = setOf(25+ Parameter(
SupportedFeatures
Using AI Code Generation
1val supportedFeatures = SupportedFeatures(2val converters = Converters(3 Converter("Pandoc", "1.0", supportedFeatures)4val converterEndpoint = ConverterEndpoint(5 setOf(6 RequestBody(7 MediaType("application", "octet-stream"),8 setOf(Extension("pdf"), Extension("html"), Extension("txt"))9 setOf(10 Response(11 setOf(MediaType("application", "octet-stream")),12 setOf(Extension("pdf"), Extension("html"), Extension("txt"))13val specification = Specification(14 setOf(converterEndpoint)15val specificationReader = SpecificationReader()16val converter = Converter("Pandoc", "1.0", supportedFeatures)17val converterEndpoint = ConverterEndpoint(18 setOf(19 RequestBody(20 MediaType("application", "octet-stream"),21 setOf(Extension("pdf"), Extension("html"), Extension("txt"))22 setOf(23 Response(24 setOf(MediaType("application", "octet-stream")),25 setOf(Extension("pdf"), Extension("html"), Extension("txt"))26 supp dFeatues(27 stOf(28 Featue("Dele"),29 )SuppdFaures(30 Faue("Upde31 s tOf(32 Featude("Delee."),33val implementation = ImpSuppetatdFaues(34 Fa("Upde35 setOf(converterEndpoint)36vilesappoitonFa u =aSup oetedFeatprin(37 os uOf(ConverterEndpointConverter class of de.codecentric.hikaku package38 /Fdat o ("Upua")39v o nupvertedFionodCo = SuprnredFerne()40 Faur("Dl"),41)verterEndpoint = ConverterEndpoint(42 setOf(43 RequestBody(44 MediaType("application", "octet-stream"),45 setOf(Extension("pdf"), Extension("html"), Extension("txt"))46 setOf(47 Response(48 setOf(MediaType("application", "octet-stream")),49 setOf(Extension("pdf"), Extension("html"), Extension("txt"))50val specification = Specification(51 setOf(converterEndpoint)52val specificationReader = SpecificationReader()53val converter = Converter("Pandoc", "1.0", supportedFeatures)54val converterEndpoint = ConverterEndpoint(55 setOf(56 RequestBody(57 MediaType("application", "octet-stream"),58 setOf(Extension("pdf"), Extension("html"), Extension("txt"))59 setOf(60 Response(61 setOf(MediaType("application", "octet-stream")),62 setOf(Extension("pdf"), Extension("html"), Extension("txt"))63val implementation = Implementation(64 setOf(converterEndpoint)65val implementationReader = ImplementationReader()66val endpointComparator = EndpointComparator()67val converterEndpointConverter = ConverterEndpointConverter()
SupportedFeatures
Using AI Code Generation
1val converter = SupportedFeaturesConverter()2val supportedFeatures = converter.convertFromXml("src/test/resources/contract.xml")3val converter = SupportedFeaturesConverter()4val supportedFeatures = converter.convertFromYaml("src/test/resources/contract.yaml")5- `path` (required)6- `method` (required)7- `name` (required)8- `in` (required)9- `status` (required)
SupportedFeatures
Using AI Code Generation
1val converter = SupportedFeaturesConverter()2val supportedFeatures = converter.convertFromXml("src/test/resources/contract.xml")3val converter = SupportedFeaturesConverter()4val supportedFeatures = converter.convertFromYaml("src/test/resources/contract.yaml")5- `path` (required)6- `method` (required)7- `name` (required)8- `in` (required)9- `status` (required)
SupportedFeatures
Using AI Code Generation
1val supportedFeatures = SupportedFeatures(2 setOf(3 Feature("Delete"),4 Feature("Update")5val supportedFeatures = SupportedFeatures(6 Feature("Delete"),7 Feature("Update")8val supportedFeatures = SupportedFeatures(9 setOf(10 Feature("Delete"),11 Feature("Update")
SupportedFeatures
Using AI Code Generation
1val supportedFeatures = SupportedFeatures(2 Feature("Delete"),3 Feature("Update")4val supportedFeatures = SupportedFeatures(5 Feature("Delete"),.converters6 Feature("Update")7val supportedFeatures = SupportedFeatures(8 Feature("Delete"),.converters.jackson9 Feature("Update")10val supportedFeatures = SupportedFeatures(.converters.jackson.matchers11de tssocificrtionRurde p=poercificesionRpodeeFMARKeOWNs(12 setOf(13 Feature("Delete"),14valS(15evalcodvtrrer =pCoevtr er.JACKSON,SupportedFeatures(16vpl rupportFuF.auure=uppor tF pnurh(17val supportedFeatures = SupportedFeatures(18Testing against method: TRACEFeatures = SupportedFeatures(19 Feature("Delete"),20 Feature("Update")21val supportedFeatures = SupportedFeatures(22 setOf(23 Feature("Delete"),24 Feature("Update")25val supportedFeatures = SupportedFeatures(26 Feature("Delete"),27 Feature("Update")28val supportedFeatures = SupportedFeatures(29 setOf(30 Feature("Delete"),31 Feature("Update")32val supportedFeatures = SupportedFeatures(33 Feature("Delete"),34 Feature("Update")35val supportedFeatures = SupportedFeatures(36 setOf(37 Feature("Delete"),38 Feature("Update")
SupportedFeatures
Using AI Code Generation
1val supportedFeatures: SupportedFeatures = SupportedFeatures(2Hikaku(3).run {4 println(this)5}6Testing against endpoint: /products/{id}
SupportedFeatures
Using AI Code Generation
1 val contract = SupportedFeatures(2 supportedFeatures = setOf(3 Feature("feature1"),4 Feature("feature2"),5 Feature("feature3")6 val implementation = SupportedFeatures(7 supportedFeatures = setOf(8 Feature("feature1"),9 Feature("feature2"),10 Feature("feature3")11 contract.assert(implementation)12 * Supports HTTP(S) Rest APIs
SupportedFeatures
Using AI Code Generation
1val api = SupportedFeatures.fromClass(Api::class)2val implementation = SupportedFeatures.fromClass(Implementation::class)3assertThat(api).isSupersetOf(implementation)4assertThat(implementation).isSupersetOf(api)5 <Feature>GET /api/v1/endpoint/{id}</Feature>6 <Feature>POST /api/v1/endpoint/{id}</Feature>7 <Feature>PUT /api/v1/endpoint/{id}</Feature>8 <Feature>DELETE /api/v1/endpoint/{id}</Feature>9 <Feature>GET /api/v1/endpoint/{id}/subEndpoint</Feature>10 <Feature>POST /api/v1/endpoint/{id}/subEndpoint</Feature>11 <Feature>PUT /api/v1/endpoint/{id}/subEndpoint</Feature>12 <Feature>DELETE /api/v1/endpoint/{id}/subEndpoint</Feature>13 <Feature>GET /api/v1/endpoint/{id}/subEndpoint/{id}</Feature>14 <Feature>POST /api/v1/endpoint/{id}/subEndpoint/{id}</Feature>15 <Feature>PUT /api/v1/endpoint/{id}/subEndpoint/{id}</Feature>16 <Feature>DELETE /api/v1/endpoint/{id}/subEndpoint/{id}</Feature>17 <Feature>GET /api/v1/endpoint/{id}/subEndpoint/{id}/subSubEndpoint</Feature>18 <Feature>POST /api/v1/endpoint/{id}/subEndpoint/{id}/subSubEndpoint</Feature>19 <Feature>PUT /api/v1/endpoint/{id}/subEndpoint/{id}/subSubEndpoint</Feature>20 <Feature>DELETE /api/v1/endpoint/{id}/subEndpoint/{id}/subSubEndpoint</Feature>
SupportedFeatures
Using AI Code Generation
1val contract = SupportedFeatures(2 path(3 get(4val api = SupportedFeatures(5 path(6 get(7val result = contract.isCompliantTo(api)8if (result.isCompliant) {9} else {10}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!