-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: NPE in case of response header without required attribute (#1171)
* fix: NPE in case of response header without required attribute in OpenAPI * Remove @author tag * Add test for Oas30ModelHelper.getRequiredHeaders(..) --------- Co-authored-by: Ralf Ueberfuhr <[email protected]>
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
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
54 changes: 54 additions & 0 deletions
54
...trus-openapi/src/test/java/org/citrusframework/openapi/model/v3/Oas30ModelHelperTest.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,54 @@ | ||
package org.citrusframework.openapi.model.v3; | ||
|
||
import io.apicurio.datamodels.openapi.models.OasSchema; | ||
import io.apicurio.datamodels.openapi.v3.models.Oas30Header; | ||
import io.apicurio.datamodels.openapi.v3.models.Oas30Response; | ||
import io.apicurio.datamodels.openapi.v3.models.Oas30Schema; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Map; | ||
|
||
public class Oas30ModelHelperTest { | ||
|
||
@Test | ||
public void shouldNotFindRequiredHeadersWithoutRequiredAttribute() { | ||
var header = new Oas30Header("X-TEST"); | ||
header.schema = new Oas30Schema(); | ||
header.required = null; // explicitely assigned because this is test case | ||
var response = new Oas30Response("200"); | ||
response.headers.put(header.getName(), header); | ||
|
||
Map<String, OasSchema> result = Oas30ModelHelper.getRequiredHeaders(response); | ||
|
||
Assert.assertEquals(result.size(), 0); | ||
} | ||
|
||
@Test | ||
public void shouldFindRequiredHeaders() { | ||
var header = new Oas30Header("X-TEST"); | ||
header.schema = new Oas30Schema(); | ||
header.required = Boolean.TRUE; // explicitely assigned because this is test case | ||
var response = new Oas30Response("200"); | ||
response.headers.put(header.getName(), header); | ||
|
||
Map<String, OasSchema> result = Oas30ModelHelper.getRequiredHeaders(response); | ||
|
||
Assert.assertEquals(result.size(), 1); | ||
Assert.assertSame(result.get(header.getName()), header.schema); | ||
} | ||
|
||
@Test | ||
public void shouldNotFindOptionalHeaders() { | ||
var header = new Oas30Header("X-TEST"); | ||
header.schema = new Oas30Schema(); | ||
header.required = Boolean.FALSE; // explicitely assigned because this is test case | ||
var response = new Oas30Response("200"); | ||
response.headers.put(header.getName(), header); | ||
|
||
Map<String, OasSchema> result = Oas30ModelHelper.getRequiredHeaders(response); | ||
|
||
Assert.assertEquals(result.size(), 0); | ||
} | ||
|
||
} |