Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Edgar Rios Navarro
Edgar Rios Navarro

Posted on

     

Mock Service with Groovy

Cuando dependemos de una servicio de tercero, nos encontraremos con la situación que dicho servicio no está disponible por un tiempo. Para eliminar esa dependencia, podemos crear unMockService por nuestra cuenta.

En el ecosistema deGroovy, existe una librería que nos facilita: RatPack.


En una solo archivo, configuramos los métodos y las respuestas. Es posible agregarle lógica, pero la intención es que tengamos respuesta.

@Grab("io.ratpack:ratpack-groovy:1.3.3")importstaticratpack.groovy.Groovy.ratpackratpack{handlers{path("Transaccion.asmx/getAffiliationSearch"){byMethod{get{response.contentType"text/xml"response.send'''<?xml version="1.0" encoding="utf-8"?>            <ArrayOfStAffiliationSearch xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="https://mifarmaws02.orbisfarma.com.mx/">                <stAffiliationSearch>                    <transactionid>183477976581</transactionid>                    <cardnumber>D007330811</cardnumber>                    <accountnumber>D007330811</accountnumber>                    <cardname>VILMA ALEJANDRINA</cardname>                    <cardlastname>FERNANDEZ@RUIZ</cardlastname>                    <cardbirthdate>19641008</cardbirthdate>                    <cardgender>F</cardgender>                    <carddoctor />                    <cardcontactpreferences>1</cardcontactpreferences>                    <cardemail />                    <cardphone />                    <cardcellphone />                    <cardaddress>| | | | | |</cardaddress>                    <cardrelated>8601080650271</cardrelated>                    <cardfields>0</cardfields>                    <errorid>0</errorid>                    <message />                    <transactiondate>2022-11-24 18:00:00</transactiondate>                </stAffiliationSearch>            </ArrayOfStAffiliationSearch>'''
Enter fullscreen modeExit fullscreen mode
groovymock-service.groovy
Enter fullscreen modeExit fullscreen mode

Al consultar:
Image description


Documentación

https://ratpack.io/

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Tech Lead | Backend | CI/CD | Cloud
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp