hw4: finalize selenoid and ansible workflow with citrus tests

This commit is contained in:
2026-02-27 01:38:06 +03:00
parent c06e9a89f1
commit 7ddea2e997
36 changed files with 1171 additions and 122 deletions
@@ -0,0 +1,57 @@
package ru.kovbasa.citrus;
import com.consol.citrus.annotations.CitrusTest;
import com.consol.citrus.message.MessageType;
import com.consol.citrus.testng.spring.TestNGCitrusSpringSupport;
import org.springframework.http.HttpStatus;
import org.testng.annotations.Test;
import java.util.concurrent.ThreadLocalRandom;
import static com.consol.citrus.http.actions.HttpActionBuilder.http;
import static com.consol.citrus.validation.json.JsonPathMessageValidationContext.Builder.jsonPath;
public class PetstoreNegativeScenariosTest extends TestNGCitrusSpringSupport {
@CitrusTest
@Test(description = "GET /pet/{id} returns 404 for unknown id")
public void getMissingPetReturnsNotFound() {
long petId = ThreadLocalRandom.current().nextLong(1_000_000L, Integer.MAX_VALUE);
variable("petId", String.valueOf(petId));
run(http()
.client("petstoreClient")
.send()
.get("/pet/${petId}"));
run(http()
.client("petstoreClient")
.receive()
.response(HttpStatus.NOT_FOUND)
.message()
.validate(jsonPath().expression("$.message", "Pet not found")));
}
@CitrusTest
@Test(description = "POST /pet with malformed JSON returns 400")
public void createPetWithMalformedJsonReturnsError() {
run(http()
.client("petstoreClient")
.send()
.post("/pet")
.message()
.type(MessageType.JSON)
.header("Content-Type", "application/json")
.body("""
{
"id": 123456,
"name": "Broken pet",
"photoUrls": ["https://petstore.test/photo.jpg"]
"""));
run(http()
.client("petstoreClient")
.receive()
.response(HttpStatus.BAD_REQUEST));
}
}
@@ -0,0 +1,81 @@
package ru.kovbasa.citrus;
import com.consol.citrus.annotations.CitrusTest;
import com.consol.citrus.message.MessageType;
import com.consol.citrus.testng.spring.TestNGCitrusSpringSupport;
import org.springframework.http.HttpStatus;
import org.testng.annotations.Test;
import java.util.concurrent.ThreadLocalRandom;
import static com.consol.citrus.http.actions.HttpActionBuilder.http;
import static com.consol.citrus.validation.json.JsonPathMessageValidationContext.Builder.jsonPath;
public class PetstorePositiveScenariosTest extends TestNGCitrusSpringSupport {
@CitrusTest
@Test(description = "POST /pet creates resource and GET /pet/{id} returns created pet")
public void createPetAndGetById() {
long petId = ThreadLocalRandom.current().nextLong(1_000_000L, Integer.MAX_VALUE);
String petName = "Rex-" + petId;
variable("petId", String.valueOf(petId));
variable("petName", petName);
run(http()
.client("petstoreClient")
.send()
.post("/pet")
.message()
.type(MessageType.JSON)
.header("Content-Type", "application/json")
.body("""
{
"id": ${petId},
"category": {
"id": 1,
"name": "Dogs"
},
"name": "${petName}",
"photoUrls": ["https://petstore.test/photo.jpg"],
"tags": [{
"id": 1,
"name": "api-test"
}],
"status": "available"
}
"""));
run(http()
.client("petstoreClient")
.receive()
.response(HttpStatus.OK)
.message()
.validate(jsonPath().expression("$.id", "${petId}"))
.validate(jsonPath().expression("$.name", "${petName}"))
.validate(jsonPath().expression("$.status", "available")));
run(http()
.client("petstoreClient")
.send()
.get("/pet/${petId}"));
run(http()
.client("petstoreClient")
.receive()
.response(HttpStatus.OK)
.message()
.validate(jsonPath().expression("$.id", "${petId}"))
.validate(jsonPath().expression("$.name", "${petName}")));
run(http()
.client("petstoreClient")
.send()
.delete("/pet/${petId}"));
run(http()
.client("petstoreClient")
.receive()
.response(HttpStatus.OK));
}
}
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:citrus="http://www.citrusframework.org/schema/config"
xmlns:citrus-http="http://www.citrusframework.org/schema/http/config"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.citrusframework.org/schema/config http://www.citrusframework.org/schema/config/citrus-config.xsd
http://www.citrusframework.org/schema/http/config http://www.citrusframework.org/schema/http/config/citrus-http-config.xsd">
<context:property-placeholder location="classpath:citrus.properties"/>
<citrus:global-variables>
<citrus:file path="classpath:citrus.properties"/>
</citrus:global-variables>
<citrus-http:client id="petstoreClient"
request-url="${petstore.base.url}${petstore.base.path}"
timeout="10000"/>
</beans>
@@ -0,0 +1,5 @@
default.test.author=spawn
default.test.package=ru.kovbasa.citrus
petstore.base.url=https://petstore.swagger.io
petstore.base.path=/v2
@@ -0,0 +1,11 @@
status = WARN
name = citrus-log4j2
appender.console.type = Console
appender.console.name = Console
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{HH:mm:ss.SSS} %-5p %c{1} - %m%n
rootLogger.level = INFO
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = Console