forked from citrusframework/citrus
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(citrusframework#1169): openapi uses explicitly declared values in…
…stead of random values * fix: use explicitly declared values instead of random values * fix: use explicitly declared values instead of random values * fix: payload is by default an empty string * Add test for OpenApiClientRequestMessageBuilder --------- Co-authored-by: Ralf Ueberfuhr <[email protected]>
- Loading branch information
Showing
3 changed files
with
249 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...test/java/org/citrusframework/openapi/actions/OpenApiClientRequestMessageBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.citrusframework.openapi.actions; | ||
|
||
import org.citrusframework.context.TestContext; | ||
import org.citrusframework.http.message.HttpMessage; | ||
import org.citrusframework.message.Message; | ||
import org.citrusframework.openapi.OpenApiSpecification; | ||
import org.citrusframework.spi.Resources; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.citrusframework.openapi.actions.OpenApiActionBuilder.openapi; | ||
|
||
public class OpenApiClientRequestMessageBuilderTest { | ||
|
||
private final OpenApiSpecification petstoreSpec = OpenApiSpecification.from( | ||
Resources.create("classpath:org/citrusframework/openapi/petstore/petstore-derivation-for-message-builder-test.json")); | ||
|
||
|
||
@Test | ||
public void shouldAddRandomDataForOperation() { | ||
Message message = openapi() | ||
.specification(petstoreSpec) | ||
.client() | ||
.send("addPet") // operationId | ||
.build() | ||
.getMessageBuilder() | ||
.build(new TestContext(), ""); | ||
Assert.assertTrue(message instanceof HttpMessage); | ||
HttpMessage httpMessage = (HttpMessage) message; | ||
// test payload | ||
Object payload = httpMessage.getPayload(); | ||
Assert.assertNotNull(payload); | ||
Assert.assertTrue(payload instanceof String); | ||
// test header | ||
Object header = httpMessage.getHeader("X-SAMPLE-HEADER"); | ||
Assert.assertNotNull(header); | ||
} | ||
|
||
@Test | ||
public void shouldAddCustomDataForOperation() { | ||
String body = "{\"a\":\"b\"}"; | ||
String sampleHeader = "X-SAMPLE-HEADER-VALUE"; | ||
Message message = openapi() | ||
.specification(petstoreSpec) | ||
.client() | ||
.send("addPet") // operationId | ||
.message() | ||
.body(body) | ||
.header("X-SAMPLE-HEADER", sampleHeader) | ||
.build() | ||
.getMessageBuilder() | ||
.build(new TestContext(), ""); | ||
Assert.assertTrue(message instanceof HttpMessage); | ||
HttpMessage httpMessage = (HttpMessage) message; | ||
// test payload | ||
Object payload = httpMessage.getPayload(); | ||
Assert.assertEquals(payload, body); | ||
// test header | ||
Object header = httpMessage.getHeader("X-SAMPLE-HEADER"); | ||
Assert.assertEquals(header, sampleHeader); | ||
} | ||
|
||
} |
164 changes: 164 additions & 0 deletions
164
...es/org/citrusframework/openapi/petstore/petstore-derivation-for-message-builder-test.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
{ | ||
"openapi": "3.0.2", | ||
"info": { | ||
"title": "Swagger Petstore", | ||
"version": "1.0.1", | ||
"description": "This is a sample server Petstore server.", | ||
"license": { | ||
"name": "Apache 2.0", | ||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html" | ||
} | ||
}, | ||
"servers": [ | ||
{ | ||
"url": "http://localhost/petstore/v3" | ||
} | ||
], | ||
"paths": { | ||
"/pet": { | ||
"post": { | ||
"requestBody": { | ||
"description": "Pet object that needs to be added to the store", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/Pet" | ||
} | ||
}, | ||
"application/xml": { | ||
"schema": { | ||
"$ref": "#/components/schemas/Pet" | ||
} | ||
} | ||
}, | ||
"required": true | ||
}, | ||
"parameters": [ | ||
{ | ||
"name": "X-SAMPLE-HEADER", | ||
"required": true, | ||
"in": "header", | ||
"schema": { | ||
"type": "string" | ||
} | ||
}, | ||
{ | ||
"name": "sample-param", | ||
"required": true, | ||
"in": "query", | ||
"schema": { | ||
"type": "string" | ||
} | ||
} | ||
], | ||
"tags": [ | ||
"pet" | ||
], | ||
"responses": { | ||
"201": { | ||
"description": "Created" | ||
}, | ||
"405": { | ||
"description": "Invalid input" | ||
} | ||
}, | ||
"operationId": "addPet", | ||
"summary": "Add a new pet to the store", | ||
"description": "" | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"Category": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"format": "int64", | ||
"type": "integer" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
}, | ||
"xml": { | ||
"name": "Category" | ||
} | ||
}, | ||
"Tag": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"format": "int64", | ||
"type": "integer" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
}, | ||
"xml": { | ||
"name": "Tag" | ||
} | ||
}, | ||
"Pet": { | ||
"required": [ | ||
"category", | ||
"name", | ||
"status" | ||
], | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"format": "int64", | ||
"type": "integer" | ||
}, | ||
"category": { | ||
"$ref": "#/components/schemas/Category" | ||
}, | ||
"name": { | ||
"type": "string", | ||
"example": "doggie" | ||
}, | ||
"photoUrls": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"xml": { | ||
"name": "photoUrl", | ||
"wrapped": true | ||
} | ||
}, | ||
"tags": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/components/schemas/Tag" | ||
}, | ||
"xml": { | ||
"name": "tag", | ||
"wrapped": true | ||
} | ||
}, | ||
"status": { | ||
"description": "pet status in the store", | ||
"enum": [ | ||
"available", | ||
"pending", | ||
"sold" | ||
], | ||
"type": "string" | ||
} | ||
}, | ||
"xml": { | ||
"name": "Pet" | ||
} | ||
} | ||
} | ||
}, | ||
"tags": [ | ||
{ | ||
"name": "pet", | ||
"description": "Everything about your Pets" | ||
} | ||
] | ||
} |