From b5cb414eef5e7e2407bd19e7de7c03c79079d729 Mon Sep 17 00:00:00 2001 From: Madalin Ilie Date: Fri, 1 Apr 2022 09:22:06 +0300 Subject: [PATCH] Add more debug logs when creating payload examples --- .../endava/cats/model/generator/PayloadGenerator.java | 7 ++++--- .../com/endava/cats/args/FilterArgumentsTest.java | 11 ++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/endava/cats/model/generator/PayloadGenerator.java b/src/main/java/com/endava/cats/model/generator/PayloadGenerator.java index 689df4d7f..2dc3d076b 100644 --- a/src/main/java/com/endava/cats/model/generator/PayloadGenerator.java +++ b/src/main/java/com/endava/cats/model/generator/PayloadGenerator.java @@ -122,7 +122,6 @@ public List> generate(List mediaTypes, String modelN } private Object resolvePropertyToExample(String propertyName, String mediaType, Schema property) { - LOGGER.trace("Resolving example for property {}...", property); if (property.getExample() != null && canUseExamples(property)) { LOGGER.trace("Example set in swagger spec, returning example: '{}'", property.getExample()); return property.getExample(); @@ -170,7 +169,7 @@ private Object getExampleForObjectSchema(Schema property) { } private Object getExampleFromStringSchema(String propertyName, Schema property) { - LOGGER.trace("String property"); + LOGGER.trace("String property {}", propertyName); String defaultValue = property.getDefault(); if (StringUtils.isNotBlank(defaultValue)) { @@ -296,6 +295,7 @@ private Object resolveModelToExample(String name, String mediaType, Schema schem LOGGER.trace("Resolving model '{}' to example", name); if (schema.getProperties() != null) { + LOGGER.trace("Schema properties not null {}: {}", name, schema.getProperties().keySet()); this.processSchemaProperties(name, mediaType, schema, values); } if (schema instanceof ComposedSchema) { @@ -308,7 +308,7 @@ private Object resolveModelToExample(String name, String mediaType, Schema schem } private void processSchemaProperties(String name, String mediaType, Schema schema, Map values) { - LOGGER.trace("Creating example from model values"); + LOGGER.trace("Creating example from model values {}", name); if (schema.getDiscriminator() != null) { globalContext.getDiscriminators().add(currentProperty + "#" + schema.getDiscriminator().getPropertyName()); } @@ -339,6 +339,7 @@ private void parseFromInnerSchema(String name, String mediaType, Schema schema, values.put(propertyName.toString(), innerSchema.getEnum().stream().filter(value -> name.contains(value.toString())).findFirst().orElse("")); globalContext.getRequestDataTypes().put(currentProperty, innerSchema); } else { + LOGGER.trace("Resolving {}", propertyName); Object example = this.resolvePropertyToExample(propertyName.toString(), mediaType, innerSchema); values.put(propertyName.toString(), example); globalContext.getRequestDataTypes().put(currentProperty, innerSchema); diff --git a/src/test/java/com/endava/cats/args/FilterArgumentsTest.java b/src/test/java/com/endava/cats/args/FilterArgumentsTest.java index 68881e3ab..7715481cc 100644 --- a/src/test/java/com/endava/cats/args/FilterArgumentsTest.java +++ b/src/test/java/com/endava/cats/args/FilterArgumentsTest.java @@ -44,8 +44,7 @@ void setup() { @ParameterizedTest @CsvSource({"checkHeaders,CheckSecurityHeadersFuzzer,RemoveFieldsFuzzer", "checkFields,RemoveFieldsFuzzer,CheckSecurityHeadersFuzzer", - "checkHttp,HappyFuzzer,CheckSecurityHeadersFuzzer", - "checkContract,TopLevelElementsContractInfoFuzzer,CheckSecurityHeadersFuzzer"}) + "checkHttp,HappyFuzzer,CheckSecurityHeadersFuzzer"}) void shouldReturnCheckHeadersFuzzers(String argument, String matching, String notMatching) { ReflectionTestUtils.setField(checkArguments, argument, true); @@ -58,7 +57,8 @@ void shouldReturnCheckHeadersFuzzers(String argument, String matching, String no @ParameterizedTest @CsvSource({"includeControlChars,LeadingControlCharsInHeadersFuzzer,LeadingWhitespacesInHeadersFuzzer", "includeEmojis,LeadingMultiCodePointEmojisInFieldsTrimValidateFuzzer,LeadingControlCharsInHeadersFuzzer", - "includeWhitespaces,LeadingWhitespacesInFieldsTrimValidateFuzzer,LeadingControlCharsInHeadersFuzzer"}) + "includeWhitespaces,LeadingWhitespacesInFieldsTrimValidateFuzzer,LeadingControlCharsInHeadersFuzzer", + "includeContract,TopLevelElementsContractInfoFuzzer,LeadingWhitespacesInHeadersFuzzer"}) void shouldIncludeLengthyFuzzers(String argument, String matching, String notMatching) { ReflectionTestUtils.setField(checkArguments, argument, true); @@ -72,6 +72,7 @@ void shouldIncludeAllFuzzers() { ReflectionTestUtils.setField(checkArguments, "includeControlChars", true); ReflectionTestUtils.setField(checkArguments, "includeEmojis", true); ReflectionTestUtils.setField(checkArguments, "includeWhitespaces", true); + ReflectionTestUtils.setField(checkArguments, "includeContract", true); List fuzzers = filterArguments.getFuzzersForPath(); Assertions.assertThat(fuzzers).contains("LeadingControlCharsInHeadersFuzzer", "LeadingWhitespacesInHeadersFuzzer", "LeadingMultiCodePointEmojisInFieldsTrimValidateFuzzer" @@ -82,7 +83,7 @@ void shouldIncludeAllFuzzers() { void shouldReturnAllFuzzersWhenNoCheckSupplied() { List fuzzers = filterArguments.getFuzzersForPath(); - Assertions.assertThat(fuzzers).contains("TopLevelElementsContractInfoFuzzer", "CheckSecurityHeadersFuzzer", "HappyFuzzer", "RemoveFieldsFuzzer"); + Assertions.assertThat(fuzzers).contains("CheckSecurityHeadersFuzzer", "HappyFuzzer", "RemoveFieldsFuzzer"); } @Test @@ -110,7 +111,7 @@ void shouldRemoveSkippedFuzzers() { ReflectionTestUtils.setField(filterArguments, "skipFuzzers", List.of("VeryLarge", "SecurityHeaders", "Jumbo")); List fuzzers = filterArguments.getFuzzersForPath(); - Assertions.assertThat(fuzzers).contains("TopLevelElementsContractInfoFuzzer", "HappyFuzzer", "RemoveFieldsFuzzer") + Assertions.assertThat(fuzzers).contains("HappyFuzzer", "RemoveFieldsFuzzer") .doesNotContain("CheckSecurityHeadersFuzzer", "VeryLargeValuesInFieldsFuzzer", "Jumbo"); }