A Parser That parses OpenAPI definitions in JSON or YAML format and Generates Pact files That contain HTTP request/response interactions by parsing Given Open API specifications

Overview

pact-openapi-core

This code base can be used in a project as a library to create pact JSON file from an Open API Specification file that contains HTTP request/response interactions by parsing the given Open API specifications.

NOTE: This is a prototype application. We covered only happy cases and are working to add more functionalities like MatchingRules and Interactions with other response codes. For now, some things are hard coded thing but will later be made to be configurable such as generated file name, directory creation path, etc.

Kindly validate's file format using https://editor.swagger.io/. It will automatically generate Pact file in json format in "target/pacts/".

Requirements

  • Java 1.8 or higher
  • Maven

Step to configure this library

step 1: Add Maven dependency


   
        
    
     com.expediagroup
    
        
    
     pact-core
    
        
    
     0.0.9-SNAPSHOT
    
    
   

step 2: Add maven pact plugin https://docs.pact.io/implementation_guides/jvm/provider/maven/


   
            
            
    
     au.com.dius.pact.provider
    
            
    
     maven
    
            
    
     4.1.11
    
            
    
                
     
                    
      
       console
      
                    
      
       json
      
                    
      
       markdown
      
                
     
                
     
      ${pactBrokerUrl}
                                      
                
                 
     
      Bearer
     -->

                
                
     
                    
      
                        
       
        ${stateChangeUrl}/v1/pact-state
               
                        
       
        ${providerName}
       
                    
      
                
     
                
     
                    
      
       false
      
                    
      
       true
      
                
     
            
    
        
   

this plugin has the configuration below

- a: pact broker            ## https://******.pactflow.io/ to pull pact file for verification 
- b: state change url       ## http://localhost:8080/v1/pact-state
- c: provider name          ## provider
- d: to publish the result  ## true

step 3: now come to java part, invoke below code snippet to kick start pact file creation

override fun run(vararg args: String?) {
   		 val pactGeneratorService = PactGeneratorService.builder()
      	  			.consumerName("partner_consumer")     			 // by default consumer
       				.providerName("partner_provider")    			 // by default provider
       				.pactSpecificationVersion("2.0.0")   			 // by default V3
        				.authenticationList(null)             			 // by default null
       				.pactPath(null)                     			 // by default 'target/pacts'
       				.resourcePath("src/main/resources/partner.yaml")		 // *Mandatory field* "http://localhost:8080/api-docs" "/Users/ratngupta/github/openapi.yaml"
       				.build()

   		 pactGeneratorService.run()

   		 val tryingCoroutine = runBlocking {
     		  		 coroutineScope { 
        		   			 launch {
          		 			  var result =  providerSetUp()                      // providerSetUp method used to create dummy data for the application, you can use DB script but it must have insert statements to insert test entries in underline Database on the basis of requirement. 
           					 }
      				  }
   				      }
		      }

step 4: Add a endpoint/controller for pact state change url

The pact state change URL is a hook that you have to create on the provider to allow Pact to tell the provider what state it should be in at the start of the test. Before each test runs, the mock consumer taps the state change URL on your provider, and tells it the name of the state the test expects.

> set ... $state") return state }">
@PostMapping("/v1/pact-state")
	suspend fun providerState(@RequestBody state: PactState): Any? {
   			 PactStateChangeController.LOGGER.info("Pact State Change >> set ... $state")
    			return state
	  }

step 5: use below command to upload pact file to pact broker

mvn pact:publish -DpactBrokerUrl=${pactBrokerUrl} -DstateChangeUrl=${stateChangeUrl}  -DproviderName=${providerName}

Congratulations!!! Your pact file is published onto the provided pact broker.

step 6: use below command to verify pact file

Now we have to verify same pact generated from OAS document against provider service implementations.

mvn pact:verify -DpactBrokerUrl=${pactBrokerUrl} -DstateChangeUrl=${stateChangeUrl}  -DproviderName=${providerName}

It will verify the pact. This command replays each Interaction from the Pact file against the provider API in real-time, records the response, and then compares both responses (the first one that is already in the pact file and the second response we received from the provider API). It generates the report and will update the result status back to the pact broker.

*Make sure you have to add same ID's in specification file by using Schema's variable named 'example' property i.e.

parameters:
      - name: partner_id
        in: path
        required: true
        example: 0a1ea7ec-d847-441e-8db6-b60b524f23a7
        schema:
          type: string

https://github.expedia.biz/eg-platform-test-automation/pact-openapi-core/tree/master/src/resource/data.js

You might also like...

This API provides functionalities to lookup and manage user accounts

This API provides functionalities to lookup and manage user accounts. Any human or computer system that will interact with any of the API's requires being authenticated as a user. The API allows for common functionalities such as creating a new user account, resetting passwords and generating JWT tokens.

Jan 22, 2022

Simple, server side api for drawing on maps with runtime only state and no id collisions

Simple, server side api for drawing on maps with runtime only state and no id collisions! It can be used in non-main/server threads for better performance/more fps.

Sep 2, 2022

Simple API, Complex Emails (JavaMail smtp wrapper)

Simple Java Mail Simple Java Mail is the simplest to use lightweight mailing library for Java, while being able to send complex emails including CLI s

Jan 5, 2023

A high level API to express vectorized operations in Java

vector-handle A high level API to express vectorized operations on primitive arrays in Java allowing to specify the vectorized operations as a simple

Oct 5, 2022

JPassport works like Java Native Access (JNA) but uses the Foreign Linker API instead of JNI. Similar to JNA, you declare a Java interface that is bound to the external C library using method names.

JPassport works like Java Native Access (JNA) but uses the Foreign Linker API instead of JNI. Similar to JNA, you declare a Java interface that is bound to the external C library using method names.

JPassport works like Java Native Access (JNA) but uses the Foreign Linker API instead of JNI. Similar to JNA, you declare a Java interface t

Dec 30, 2022

Leveraging Java 8, create an API with a multi-tier user system.

Project 0 Description Leveraging Java 8, create an API with a multi-tier user system. You may choose the actual use case for your application as long

Jan 9, 2022

Jiskord is a selfbot wrapper for Discord with almost every API endpoint accessible

Jiskord Jiskord is a selfbot wrapper for Discord with almost every API endpoint accessible. This library is inspired by Discum. It is made using Java

Feb 28, 2022

SpringBoot Micro Services, Discovery Server, Discovery Client, API-Gateway

SpringBoot Micro Services, Discovery Server, Discovery Client, API-Gateway

SpringBoot Micro Services, Discovery Server, Discovery Client, API-Gateway

Jan 26, 2022

Simple way of causing a bsod using the native api implemented into a 1.12.2 Forge mod

Simple-BSOD-Mod Simple way of causing a bsod using the native api implemented into a 1.12.2 Forge mod. Dowload It HERE To make your own you can go to

Dec 28, 2022
Owner
dev-rgupta
dev-rgupta
Helper tool to calculate the price for a given amount of users within a graduated pricing model.

Lithic Hi Lithic, This small piece of software is a coding exercise I asked some candidates to solve and is based on the pricing model of Atlassian pr

Stefan Antal 1 Feb 27, 2022
Tripoli imports raw mass spectrometer data files and supports interactive review and archiving of isotopic data.

Tripoli imports raw mass spectrometer data files and supports interactive review and archiving of isotopic data. Tripoli facilitates visualization of temporal trends and scatter during measurement, statistically rigorous filtering of data, and calculation of statistical parameters.

CIRDLES 7 Dec 15, 2022
An open-source component of TabLight project "Base-API"

DataAddons is a library (or framework?) created for Minecraft providing comfortable abstractions making additions over already existing data, generally, it is anti-pattern ans YOU SHOULDN'T USE IT in normal programms.

XXR 3 Mar 8, 2022
Support alternative markup for Apache Maven POM files

Overview Polyglot for Maven is a set of extensions for Maven 3.3.1+ that allows the POM model to be written in dialects other than XML. Several of the

null 828 Dec 17, 2022
A plugin for the ja-netfilter, it can delete expired log files

A plugin for the ja-netfilter, it can delete expired log files

EFL 3 Feb 14, 2022
The open-source Java obfuscation tool working with Ant and Gradle by yWorks - the diagramming experts

yGuard yGuard is an open-source Java obfuscation tool. With yGuard it is easy as pie ( ?? ) to configure obfuscation through an extensive ant task. yG

yWorks GmbH 265 Jan 2, 2023
An open source, modular alternative of sketchware. Create your own app in android using block programming like scratch!

OpenBlocks An open source, modular alternative of sketchware. Create your own app in android using block programming like scratch! What is OpenBlocks?

OpenBlocks 30 Dec 16, 2022
RealmeDirac - an open-source Android application written in java

RealmeDirac is an open-source Android application written in java. RealmeDirac is a feature introduced by realme & dirac in realmeUI for sound optimisation, trying to recreate same thing, this is scratch written app aiming to provide same features as realmeDirac..

psionicprjkt 4 Feb 21, 2022
API gateway for REST and SOAP written in Java.

Membrane Service Proxy Reverse HTTP proxy (framework) written in Java, that can be used as an API gateway as a security proxy for HTTP based integrati

predic8 GmbH 389 Dec 31, 2022
This service checks the Co-WIN public API at a specific interval and send update to users specified telegram bot.

COVID VACCINE TELEGRAM BOT USING SPRING BOOT This application is a covid vaccine slot notifier via telegram bot. This application uses public CO-WIN A

Hardeek Sharma 6 Oct 4, 2022