Search in sources :

Example 1 with PayloadGenerator

use of com.endava.cats.model.generator.PayloadGenerator in project cats by Endava.

the class PayloadGeneratorTest method shouldRecognizeEmail.

@ParameterizedTest
@CsvSource({ "email,true", "emailAddress,true", "notEmail,true", "myEmailAddress,true", "randomField,false" })
void shouldRecognizeEmail(String property, boolean expected) {
    StringSchema schema = new StringSchema();
    PayloadGenerator generator = new PayloadGenerator(globalContext, true);
    boolean isEmail = generator.isEmailAddress(schema, property);
    Assertions.assertThat(isEmail).isEqualTo(expected);
}
Also used : StringSchema(io.swagger.v3.oas.models.media.StringSchema) PayloadGenerator(com.endava.cats.model.generator.PayloadGenerator) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with PayloadGenerator

use of com.endava.cats.model.generator.PayloadGenerator in project cats by Endava.

the class PayloadGeneratorTest method shouldRecognizeIpV6AddressFromPropertyName.

@Test
void shouldRecognizeIpV6AddressFromPropertyName() {
    StringSchema schema = new StringSchema();
    PayloadGenerator generator = new PayloadGenerator(globalContext, true);
    boolean isIp = generator.isIPV6(schema, "ipv6");
    Assertions.assertThat(isIp).isTrue();
}
Also used : StringSchema(io.swagger.v3.oas.models.media.StringSchema) PayloadGenerator(com.endava.cats.model.generator.PayloadGenerator) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with PayloadGenerator

use of com.endava.cats.model.generator.PayloadGenerator in project cats by Endava.

the class PayloadGeneratorTest method givenASimpleOpenAPIContract_whenGeneratingAPayload_thenTheExampleIsProperlyGenerated.

@Test
void givenASimpleOpenAPIContract_whenGeneratingAPayload_thenTheExampleIsProperlyGenerated() throws Exception {
    PayloadGenerator generator = setupPayloadGenerator();
    List<Map<String, String>> example = generator.generate(null, "Pet");
    String exampleJson = example.get(0).get("example");
    Assertions.assertThat(exampleJson).contains("ALL_OF").contains("breedONE_OF#/components/schemas/Husky").contains("breedONE_OF#/components/schemas/Labrador");
}
Also used : PayloadGenerator(com.endava.cats.model.generator.PayloadGenerator) Map(java.util.Map) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with PayloadGenerator

use of com.endava.cats.model.generator.PayloadGenerator in project cats by Endava.

the class PayloadGeneratorTest method shouldRecognizeUrlFromPropertyName.

@ParameterizedTest
@CsvSource({ "url,true", "uri,true", "addressurl,true", "addressuri,true", "not,false" })
void shouldRecognizeUrlFromPropertyName(String property, boolean expected) {
    StringSchema schema = new StringSchema();
    PayloadGenerator generator = new PayloadGenerator(globalContext, true);
    boolean isIp = generator.isURI(schema, property);
    Assertions.assertThat(isIp).isEqualTo(expected);
}
Also used : StringSchema(io.swagger.v3.oas.models.media.StringSchema) PayloadGenerator(com.endava.cats.model.generator.PayloadGenerator) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with PayloadGenerator

use of com.endava.cats.model.generator.PayloadGenerator in project cats by Endava.

the class PayloadGeneratorTest method shouldGenerateFromAllOfAndPreserveRootElement.

@Test
void shouldGenerateFromAllOfAndPreserveRootElement() throws Exception {
    PayloadGenerator generator = setupPayloadGenerator();
    List<Map<String, String>> example = generator.generate(null, "MiniPet");
    String exampleJson = example.get(0).get("example");
    Assertions.assertThat(exampleJson).contains("color").contains("red").contains("green").contains("blue");
}
Also used : PayloadGenerator(com.endava.cats.model.generator.PayloadGenerator) Map(java.util.Map) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

PayloadGenerator (com.endava.cats.model.generator.PayloadGenerator)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 StringSchema (io.swagger.v3.oas.models.media.StringSchema)8 QuarkusTest (io.quarkus.test.junit.QuarkusTest)6 Test (org.junit.jupiter.api.Test)6 CsvSource (org.junit.jupiter.params.provider.CsvSource)5 Map (java.util.Map)3 OpenAPIParser (io.swagger.parser.OpenAPIParser)1 OpenAPI (io.swagger.v3.oas.models.OpenAPI)1 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)1 Schema (io.swagger.v3.oas.models.media.Schema)1 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1