This file contains hidden or 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
var tagId = response.jsonPath().getInt("tags[0].id"); | |
assertEquals(tagId,2); |
This file contains hidden or 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
var responseMap = given() | |
.basePath("{version}/pet") | |
.pathParam("version", "v2") | |
.contentType(ContentType.JSON) | |
.body(payload) | |
.when() | |
.post() | |
.as(new TypeRef<List<Map<String, Object>>>() { | |
}); |
This file contains hidden or 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
var responseMap = given() | |
.basePath("{version}/pet") | |
.pathParam("version", "v2") | |
.contentType(ContentType.JSON) | |
.body(payload) | |
.when() | |
.post() | |
.as(new TypeRef<Map<String, Object>>() { | |
}); | |
assertEquals(responseMap.get("id"), 1); |
This file contains hidden or 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
@Test | |
public void managingPayload(){ | |
var fileHelper = new FileHelper(); | |
var payload = fileHelper.getFile("pet.json"); | |
var jsonHelper = new JSONHelper(); | |
payload = jsonHelper.updateJsonValue(payload,"id","10"); | |
payload = jsonHelper.updateJsonValue(payload,"category.id","1"); |
This file contains hidden or 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
-- payload | |
{ | |
"id": 0, | |
"category": { | |
"id": 0, | |
"name": "string" | |
}, | |
"name": "doggie", | |
"photoUrls": [ | |
"string" |
This file contains hidden or 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
public String updateJsonValue(String json, String jsonKey, Object newValue) { | |
DocumentContext context = getJsonDocumentContext(json); | |
ParseHelper parseHelper = new ParseHelper(); | |
try { | |
var o = read(json, jsonKey); | |
var valueType = o.getClass().getSimpleName(); | |
switch (valueType) { | |
case "Integer" -> { | |
Integer integerValue = parseHelper.parsStringToInt(String.valueOf(newValue)); |
This file contains hidden or 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
private DocumentContext getJsonDocumentContext(String json) { | |
var configuration = Configuration.builder() | |
.jsonProvider(new JacksonJsonNodeJsonProvider()) | |
.mappingProvider(new JacksonMappingProvider()) | |
.build(); | |
return using(configuration).parse(json); | |
} |
This file contains hidden or 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
public String getFile(String fileName) { | |
var is = Objects.requireNonNull( | |
getClass() | |
.getClassLoader() | |
.getResourceAsStream("payloads/" + fileName)); | |
try { | |
return new String(is.readAllBytes()); | |
} catch (IOException e) { | |
throw new RuntimeException(String.format("An error occurred message:%s", e.getMessage())); | |
} |
This file contains hidden or 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
interface Player { | |
play(): void; | |
} | |
class Goalkeeper implements Player { | |
public play(): void { | |
this.stopShoots(); | |
} |
This file contains hidden or 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
class Goalkeeper { | |
public stopShoots(): void { | |
// some method | |
} | |
} | |
class Defender { | |
public defend(): void { | |
// some method | |
} |
NewerOlder