diff --git a/docs/_Sidebar.md b/docs/_Sidebar.md index d6dc8f20..ba20f1d8 100644 --- a/docs/_Sidebar.md +++ b/docs/_Sidebar.md @@ -24,3 +24,4 @@ # [Additional information](additional-information.md) - [Contributing](contributing.md) - [Release notes](release-notes.md) + - [Debugging](debugging.md) diff --git a/docs/debugging.md b/docs/debugging.md new file mode 100644 index 00000000..8137e85e --- /dev/null +++ b/docs/debugging.md @@ -0,0 +1,32 @@ +# Debuging + +This guide helps you debug KLoadGen in plugin mode with an IDE. + +## Using IntelliJ IDEA + +- Create a remote JVM configuration, should look like this: + +![debug-configuration.png](images%2Fdebug-configuration.png) + +- Now copy the Command line argument. + +## - Windows + +Open the file: `apache-jmeter-\bin\jmeter.bat` whit any editor and paste the command on this 2 lines: + +![debug-jmeter-bat.png](images%2Fdebug-jmeter-bat.png) + + +## - MacOS + +Open the file: `apache-jmeter-\bin\jmeter.sh` whit any editor and paste the command on this line: + +![debug-jmeter-sh.png](images%2Fdebug-jmeter-sh.png) + + +## While Debuging + +Now you can debug while you ejecute Jmeter. + +Remember to create a new `kloadgen-.jar` file and move it to Jmeter files, to apply +the changes you made in the code. \ No newline at end of file diff --git a/docs/getting-started.md b/docs/getting-started.md index 316a2b9a..02f5bdaf 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -6,8 +6,10 @@ Now that you know what KLoadGen is and that you are familiar with its components You will need these tools to start using the plugin: -- JDK/JRE 11+ +- JDK/JRE 11+ + - (17 recommended) - JMeter 5.4+ + - (5.6.2 recommended) - Maven ## Quickstart diff --git a/docs/images/debug-configuration.png b/docs/images/debug-configuration.png new file mode 100644 index 00000000..1a94ddda Binary files /dev/null and b/docs/images/debug-configuration.png differ diff --git a/docs/images/debug-jmeter-bat.png b/docs/images/debug-jmeter-bat.png new file mode 100644 index 00000000..718667cd Binary files /dev/null and b/docs/images/debug-jmeter-bat.png differ diff --git a/docs/images/debug-jmeter-sh.png b/docs/images/debug-jmeter-sh.png new file mode 100644 index 00000000..bae063f6 Binary files /dev/null and b/docs/images/debug-jmeter-sh.png differ diff --git a/pom.xml b/pom.xml index deb1aaac..05532f26 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ kloadgen - 5.6.8 + 5.6.9 KLoadGen Load Generation Jmeter plugin for Kafka Cluster. Supporting AVRO, JSON Schema and Protobuf schema types. Generate Artificial @@ -301,6 +301,17 @@ Europe/Madrid + + RobertoSngular + Roberto Riveira Veiga + roberto.riveira@sngular.com + Sngular + https://www.sngular.com + + Trainee Backend Developer + + Europe/Madrid + diff --git a/src/main/java/com/sngular/kloadgen/config/schemaregistry/SchemaRegistryConfigElementBeanInfo.java b/src/main/java/com/sngular/kloadgen/config/schemaregistry/SchemaRegistryConfigElementBeanInfo.java index 772fe2c6..8cfeae30 100644 --- a/src/main/java/com/sngular/kloadgen/config/schemaregistry/SchemaRegistryConfigElementBeanInfo.java +++ b/src/main/java/com/sngular/kloadgen/config/schemaregistry/SchemaRegistryConfigElementBeanInfo.java @@ -22,8 +22,8 @@ public SchemaRegistryConfigElementBeanInfo() { super(SchemaRegistryConfigElement.class); - createPropertyGroup("schema_registry_config", new String[]{SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_NAME, SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_PROPERTIES, - SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_URL}); + createPropertyGroup("schema_registry_config", new String[]{SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_NAME, + SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_PROPERTIES, SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_URL}); final PropertyDescriptor schemaRegistryName = property(SchemaRegistryConfigElementValue.SCHEMA_REGISTRY_NAME); schemaRegistryName.setPropertyEditorClass(SchemaRegistryNamePropertyEditor.class); diff --git a/src/main/java/com/sngular/kloadgen/extractor/SchemaExtractor.java b/src/main/java/com/sngular/kloadgen/extractor/SchemaExtractor.java index a7a7b760..79de69a9 100644 --- a/src/main/java/com/sngular/kloadgen/extractor/SchemaExtractor.java +++ b/src/main/java/com/sngular/kloadgen/extractor/SchemaExtractor.java @@ -1,6 +1,5 @@ package com.sngular.kloadgen.extractor; -import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -35,9 +34,8 @@ public static List flatPropertiesList(final ParsedSchema pars return ExtractorFactory.getExtractor(parserSchema.schemaType()).processSchema(parserSchema, SchemaRegistryEnum.CONFLUENT); } - public static List schemaTypesList(final File schemaFile, final String schemaType, final String registry) throws IOException { - return ExtractorFactory.getExtractor(schemaType).getSchemaNameList(readLineByLine(schemaFile.getPath()), - ExtractorFactory.getSchemaRegistry(registry)); + public static String readSchemaFile(final String filePath) throws IOException { + return readLineByLine(filePath); } private static String readLineByLine(final String filePath) throws IOException { diff --git a/src/main/java/com/sngular/kloadgen/extractor/extractors/ExtractorFactory.java b/src/main/java/com/sngular/kloadgen/extractor/extractors/ExtractorFactory.java index 371d2de4..fdf8700c 100644 --- a/src/main/java/com/sngular/kloadgen/extractor/extractors/ExtractorFactory.java +++ b/src/main/java/com/sngular/kloadgen/extractor/extractors/ExtractorFactory.java @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.Properties; import com.sngular.kloadgen.common.SchemaRegistryEnum; @@ -53,14 +52,6 @@ public static ExtractorRegistry getExtractor(final String schemaType) { } } - public static SchemaRegistryEnum getSchemaRegistry(final String schemaRegistryEnum) { - if (schemaRegistryEnum != null && EnumUtils.isValidEnum(SchemaRegistryEnum.class, schemaRegistryEnum.toUpperCase())) { - return SchemaRegistryEnum.valueOf(schemaRegistryEnum.toUpperCase()); - } else { - throw new KLoadGenException(String.format("Schema Registry type not supported %s", schemaRegistryEnum)); - } - } - public static Pair> flatPropertiesList(final String subjectName) { final Properties properties = JMeterContextService.getContext().getProperties(); final var schemaParsed = JMeterHelper.getParsedSchema(subjectName, properties); @@ -72,14 +63,12 @@ public static Pair> flatPropertiesList(final Str final SchemaRegistryEnum schemaRegistryEnum = SchemaRegistryEnum.valueOf(registryName.toUpperCase()); final Object schema; - if (Objects.nonNull(registryName)) { - //TODO change parser - schema = switch (schemaRegistryEnum) { - case APICURIO -> ((ApicurioAbstractParsedSchemaMetadata) abstractParsedSchemaAdapter).getSchema(); - case CONFLUENT -> abstractParsedSchemaAdapter.getRawSchema(); - }; - attributeList.addAll(getExtractor(schemaType).processSchema(schema, schemaRegistryEnum)); - } + //TODO change parser + schema = switch (schemaRegistryEnum) { + case APICURIO -> ((ApicurioAbstractParsedSchemaMetadata) abstractParsedSchemaAdapter).getSchema(); + case CONFLUENT -> abstractParsedSchemaAdapter.getRawSchema(); + }; + attributeList.addAll(getExtractor(schemaType).processSchema(schema, schemaRegistryEnum)); return Pair.of(schemaType, attributeList); } } \ No newline at end of file diff --git a/src/main/java/com/sngular/kloadgen/extractor/extractors/ExtractorRegistry.java b/src/main/java/com/sngular/kloadgen/extractor/extractors/ExtractorRegistry.java index 99f0a803..27026c59 100644 --- a/src/main/java/com/sngular/kloadgen/extractor/extractors/ExtractorRegistry.java +++ b/src/main/java/com/sngular/kloadgen/extractor/extractors/ExtractorRegistry.java @@ -8,6 +8,8 @@ public interface ExtractorRegistry { List processSchema(final T schema, SchemaRegistryEnum registry); + Object processSchema(final String fileContent); + List getSchemaNameList(final String schema, SchemaRegistryEnum registryEnum); } diff --git a/src/main/java/com/sngular/kloadgen/extractor/extractors/avro/AvroExtractor.java b/src/main/java/com/sngular/kloadgen/extractor/extractors/avro/AvroExtractor.java index 88e48b8d..32594da3 100644 --- a/src/main/java/com/sngular/kloadgen/extractor/extractors/avro/AvroExtractor.java +++ b/src/main/java/com/sngular/kloadgen/extractor/extractors/avro/AvroExtractor.java @@ -7,18 +7,24 @@ import com.sngular.kloadgen.extractor.extractors.Extractor; import com.sngular.kloadgen.extractor.extractors.ExtractorRegistry; import com.sngular.kloadgen.model.FieldValueMapping; +import io.confluent.kafka.schemaregistry.ParsedSchema; +import io.confluent.kafka.schemaregistry.avro.AvroSchema; public class AvroExtractor implements ExtractorRegistry { - private static Map schemaRegistryMap = Map.of(SchemaRegistryEnum.CONFLUENT, new AvroConfluentExtractor(), SchemaRegistryEnum.APICURIO, - new AvroApicurioExtractor()); + private static final Map SCHEMA_REGISTRY_MAP = Map.of(SchemaRegistryEnum.CONFLUENT, new AvroConfluentExtractor(), SchemaRegistryEnum.APICURIO, + new AvroApicurioExtractor()); public final List processSchema(final Object schema, final SchemaRegistryEnum registryEnum) { - return schemaRegistryMap.get(registryEnum).processSchema(schema); + return SCHEMA_REGISTRY_MAP.get(registryEnum).processSchema(schema); + } + + public final ParsedSchema processSchema(final String fileContent) { + return new AvroSchema(fileContent); } public final List getSchemaNameList(final String schema, final SchemaRegistryEnum registryEnum) { - return schemaRegistryMap.get(registryEnum).getSchemaNameList(schema); + return SCHEMA_REGISTRY_MAP.get(registryEnum).getSchemaNameList(schema); } } \ No newline at end of file diff --git a/src/main/java/com/sngular/kloadgen/extractor/extractors/json/AbstractJsonExtractor.java b/src/main/java/com/sngular/kloadgen/extractor/extractors/json/AbstractJsonExtractor.java index a1aa15f9..65a87fb4 100644 --- a/src/main/java/com/sngular/kloadgen/extractor/extractors/json/AbstractJsonExtractor.java +++ b/src/main/java/com/sngular/kloadgen/extractor/extractors/json/AbstractJsonExtractor.java @@ -23,10 +23,10 @@ public abstract class AbstractJsonExtractor { - private final JSONSchemaParser jsonSchemaParser = new JSONSchemaParser(); + private static final JSONSchemaParser JSON_SCHEMA_PARSER = new JSONSchemaParser(); protected final JSONSchemaParser getSchemaParser() { - return jsonSchemaParser; + return JSON_SCHEMA_PARSER; } private static String extractFieldName(final String fieldName) { @@ -90,9 +90,9 @@ public final List processField(final Field innerField, final completeFieldList.add(builder.build()); } else if (innerField instanceof StringField) { final FieldValueMapping.FieldValueMappingBuilder builder = FieldValueMapping - .builder() - .fieldName(innerField.getName()) - .fieldType(innerField.getType()); + .builder() + .fieldName(innerField.getName()) + .fieldType(innerField.getType()); addConstraint(builder, ConstraintTypeEnum.REGEX, ((StringField) innerField).getRegex()); addConstraint(builder, ConstraintTypeEnum.MAXIMUM_VALUE, getSafeNumberAsString(((StringField) innerField).getMaxlength())); @@ -169,9 +169,9 @@ private List extractArrayInternalFields( @NotNull private static String calculateFieldType(final String breadCrumb, final Field value) { - return value.getType() + return value.getType() + SchemaExtractorUtil.ARRAY_TYPE_POSTFIX - + ((StringUtils.isNotEmpty(breadCrumb) + + ((StringUtils.isNotEmpty(breadCrumb) && breadCrumb.endsWith("[]")) ? SchemaExtractorUtil.ARRAY_TYPE_POSTFIX : (StringUtils.isNotEmpty(breadCrumb) && breadCrumb.endsWith("[:]")) ? "-map" @@ -207,9 +207,9 @@ private List extractMapInternalFields( @NotNull private static String getFieldType(final String breadCrumb, final Field value) { - return value.getType() - + "-map" - + ((StringUtils.isNotEmpty(breadCrumb) + return value.getType() + + "-map" + + ((StringUtils.isNotEmpty(breadCrumb) && breadCrumb.endsWith("[:]")) ? "-map" : (StringUtils.isNotEmpty(breadCrumb) && breadCrumb.endsWith("[]")) ? SchemaExtractorUtil.ARRAY_TYPE_POSTFIX diff --git a/src/main/java/com/sngular/kloadgen/extractor/extractors/json/JsonDefaultExtractor.java b/src/main/java/com/sngular/kloadgen/extractor/extractors/json/JsonDefaultExtractor.java index 528e836c..618cbce9 100644 --- a/src/main/java/com/sngular/kloadgen/extractor/extractors/json/JsonDefaultExtractor.java +++ b/src/main/java/com/sngular/kloadgen/extractor/extractors/json/JsonDefaultExtractor.java @@ -11,10 +11,10 @@ import com.sngular.kloadgen.model.json.Field; import com.sngular.kloadgen.model.json.Schema; -public class JsonDefaultExtractor extends AbstractJsonExtractor implements Extractor { +public class JsonDefaultExtractor extends AbstractJsonExtractor implements Extractor { @Override - public final List processSchema(final org.everit.json.schema.Schema schema) { + public final List processSchema(final String schema) { final Schema parsed = getSchemaParser().parse(schema.toString()); diff --git a/src/main/java/com/sngular/kloadgen/extractor/extractors/json/JsonExtractor.java b/src/main/java/com/sngular/kloadgen/extractor/extractors/json/JsonExtractor.java index 1f754f2b..28ddd3fe 100644 --- a/src/main/java/com/sngular/kloadgen/extractor/extractors/json/JsonExtractor.java +++ b/src/main/java/com/sngular/kloadgen/extractor/extractors/json/JsonExtractor.java @@ -7,6 +7,8 @@ import com.sngular.kloadgen.extractor.extractors.Extractor; import com.sngular.kloadgen.extractor.extractors.ExtractorRegistry; import com.sngular.kloadgen.model.FieldValueMapping; +import io.confluent.kafka.schemaregistry.ParsedSchema; +import io.confluent.kafka.schemaregistry.json.JsonSchema; public class JsonExtractor implements ExtractorRegistry { @@ -15,7 +17,11 @@ public class JsonExtractor implements ExtractorRegistry { SchemaRegistryEnum.APICURIO, new JsonDefaultExtractor()); public final List processSchema(final Object schemaReceived, final SchemaRegistryEnum registryEnum) { - return SCHEMA_REGISTRY_MAP.get(registryEnum).processSchema(schemaReceived); + return SCHEMA_REGISTRY_MAP.get(registryEnum).processSchema(schemaReceived.toString()); + } + + public final ParsedSchema processSchema(final String fileContent) { + return new JsonSchema(fileContent); } public final List getSchemaNameList(final String schema, final SchemaRegistryEnum registryEnum) { diff --git a/src/main/java/com/sngular/kloadgen/extractor/extractors/protobuff/ProtobuffExtractor.java b/src/main/java/com/sngular/kloadgen/extractor/extractors/protobuff/ProtobuffExtractor.java index d95212cc..651e32c9 100644 --- a/src/main/java/com/sngular/kloadgen/extractor/extractors/protobuff/ProtobuffExtractor.java +++ b/src/main/java/com/sngular/kloadgen/extractor/extractors/protobuff/ProtobuffExtractor.java @@ -9,6 +9,8 @@ import com.sngular.kloadgen.extractor.extractors.ExtractorRegistry; import com.sngular.kloadgen.model.FieldValueMapping; import com.squareup.wire.schema.internal.parser.ProtoFileElement; +import io.confluent.kafka.schemaregistry.ParsedSchema; +import io.confluent.kafka.schemaregistry.protobuf.ProtobufSchema; public class ProtobuffExtractor implements ExtractorRegistry { @@ -25,6 +27,10 @@ public final List processSchema(final Object schemaReceived, return resultSchema; } + public final ParsedSchema processSchema(final String fileContent) { + return new ProtobufSchema(fileContent); + } + public final List getSchemaNameList(final String schema, final SchemaRegistryEnum registryEnum) { return SCHEMA_REGISTRY_MAP.get(registryEnum).getSchemaNameList(schema); } diff --git a/src/main/java/com/sngular/kloadgen/processor/objectcreatorfactory/impl/AvroObjectCreatorFactory.java b/src/main/java/com/sngular/kloadgen/processor/objectcreatorfactory/impl/AvroObjectCreatorFactory.java index c92f8344..49c69fc0 100644 --- a/src/main/java/com/sngular/kloadgen/processor/objectcreatorfactory/impl/AvroObjectCreatorFactory.java +++ b/src/main/java/com/sngular/kloadgen/processor/objectcreatorfactory/impl/AvroObjectCreatorFactory.java @@ -178,8 +178,7 @@ public boolean isOptionalFieldAccordingToSchema(final String completeFieldName, return isOptionalField(subSchema); } - @Override - public Object getRootNode(final String rootNode) { + public final Object getRootNode(final String rootNode) { return entity.get(rootNode); } diff --git a/src/main/java/com/sngular/kloadgen/property/editor/FileSubjectPropertyEditor.java b/src/main/java/com/sngular/kloadgen/property/editor/FileSubjectPropertyEditor.java index 091135d1..b1aa7409 100644 --- a/src/main/java/com/sngular/kloadgen/property/editor/FileSubjectPropertyEditor.java +++ b/src/main/java/com/sngular/kloadgen/property/editor/FileSubjectPropertyEditor.java @@ -9,9 +9,6 @@ import java.awt.BorderLayout; import java.awt.Component; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; import java.beans.PropertyDescriptor; import java.beans.PropertyEditor; import java.beans.PropertyEditorSupport; @@ -22,7 +19,6 @@ import java.util.List; import java.util.Objects; -import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFileChooser; @@ -30,12 +26,13 @@ import javax.swing.JPanel; import javax.swing.filechooser.FileSystemView; +import com.sngular.kloadgen.common.SchemaRegistryEnum; import com.sngular.kloadgen.common.SchemaTypeEnum; import com.sngular.kloadgen.extractor.SchemaExtractor; +import com.sngular.kloadgen.extractor.extractors.ExtractorFactory; +import com.sngular.kloadgen.extractor.extractors.ExtractorRegistry; import com.sngular.kloadgen.model.FieldValueMapping; -import com.sngular.kloadgen.util.AutoCompletion; import com.sngular.kloadgen.util.PropsKeysHelper; -import com.sngular.kloadgen.util.SchemaRegistryKeyHelper; import io.confluent.kafka.schemaregistry.ParsedSchema; import lombok.extern.slf4j.Slf4j; import org.apache.avro.AvroRuntimeException; @@ -49,7 +46,7 @@ import org.apache.jmeter.util.JMeterUtils; @Slf4j -public class FileSubjectPropertyEditor extends PropertyEditorSupport implements ActionListener, TestBeanPropertyEditor, ClearGui { +public class FileSubjectPropertyEditor extends PropertyEditorSupport implements TestBeanPropertyEditor, ClearGui { public static final String ERROR_FAILED_TO_RETRIEVE_PROPERTIES = "ERROR: Failed to retrieve properties!"; @@ -59,12 +56,10 @@ public class FileSubjectPropertyEditor extends PropertyEditorSupport implements private final JButton openFileDialogButton = new JButton(JMeterUtils.getResString("file_visualizer_open")); - private List parserSchema; + private ParsedSchema parserSchema; private JComboBox schemaTypeComboBox; - private JComboBox subjectNameComboBox; - public FileSubjectPropertyEditor() { this.init(); } @@ -87,15 +82,10 @@ private void init() { schemaTypeComboBox.insertItemAt(SchemaTypeEnum.JSON.name(), 1); schemaTypeComboBox.insertItemAt(SchemaTypeEnum.PROTOBUF.name(), 2); schemaTypeComboBox.setSelectedIndex(0); - subjectNameComboBox = new JComboBox<>(); - subjectNameComboBox.setEditable(true); panel.setLayout(new BorderLayout()); openFileDialogButton.addActionListener(this::actionFileChooser); panel.add(openFileDialogButton, BorderLayout.LINE_END); - panel.add(subjectNameComboBox); panel.add(schemaTypeComboBox); - AutoCompletion.enable(subjectNameComboBox); - this.subjectNameComboBox.addActionListener(this); } public final void actionFileChooser(final ActionEvent event) { @@ -103,26 +93,24 @@ public final void actionFileChooser(final ActionEvent event) { final int returnValue = fileChooser.showDialog(panel, JMeterUtils.getResString("file_visualizer_open")); if (JFileChooser.APPROVE_OPTION == returnValue) { - final File subjectName = Objects.requireNonNull(fileChooser.getSelectedFile()); + final File schemaFile = Objects.requireNonNull(fileChooser.getSelectedFile()); try { final String schemaType = schemaTypeComboBox.getSelectedItem().toString(); - parserSchema = SchemaExtractor.schemaTypesList(subjectName, schemaType, "CONFLUENT"); //TODO CHANGE - subjectNameComboBox.removeAllItems(); - subjectNameComboBox.addItem(parserSchema.get(0)); - subjectNameComboBox.setSelectedItem(parserSchema.get(0)); + final ExtractorRegistry extractor = ExtractorFactory.getExtractor(schemaType); + final String fileContent = SchemaExtractor.readSchemaFile(schemaFile.getPath()); + this.parserSchema = (ParsedSchema) extractor.processSchema(fileContent); + final List schemaFieldList = extractor.processSchema(parserSchema, SchemaRegistryEnum.CONFLUENT); + buildTable(schemaFieldList); + JMeterContextService.getContext().getProperties().setProperty(PropsKeysHelper.VALUE_SCHEMA, fileContent); + JMeterContextService.getContext().getProperties().setProperty(PropsKeysHelper.VALUE_SCHEMA_TYPE, schemaType); } catch (final IOException e) { JOptionPane.showMessageDialog(panel, "Can't read a file : " + e.getMessage(), ERROR_FAILED_TO_RETRIEVE_PROPERTIES, - JOptionPane.ERROR_MESSAGE); + JOptionPane.ERROR_MESSAGE); log.error(e.getMessage(), e); } - subjectNameComboBox.addFocusListener(new ComboFiller()); } } - public final String getSelectedSchema(final String name) { - return parserSchema.indexOf(name) > 0 ? parserSchema.get(parserSchema.indexOf(name)) : null; - } - public final List getAttributeList(final ParsedSchema selectedSchema) { final List result = new ArrayList<>(); if (Objects.nonNull(selectedSchema)) { @@ -131,55 +119,44 @@ public final List getAttributeList(final ParsedSchema selecte return result; } - @Override - public final void actionPerformed(final ActionEvent event) { - - if (subjectNameComboBox.getItemCount() != 0) { - final String schemaType = (String) schemaTypeComboBox.getSelectedItem(); - final String selectedItem = (String) subjectNameComboBox.getSelectedItem(); - final String selectedSchema = getSelectedSchema(selectedItem); - final List attributeList = SchemaExtractor.flatPropertiesList(selectedSchema).getValue(); - - if (!attributeList.isEmpty()) { - try { - //Get current test GUI component - final TestBeanGUI testBeanGUI = (TestBeanGUI) GuiPackage.getInstance().getCurrentGui(); - final Field customizer = TestBeanGUI.class.getDeclaredField(PropsKeysHelper.CUSTOMIZER); - customizer.setAccessible(true); - - //From TestBeanGUI retrieve Bean Customizer as it includes all editors like ClassPropertyEditor, TableEditor - final GenericTestBeanCustomizer testBeanCustomizer = (GenericTestBeanCustomizer) customizer.get(testBeanGUI); - final Field editors = GenericTestBeanCustomizer.class.getDeclaredField(PropsKeysHelper.EDITORS); - editors.setAccessible(true); - - //Retrieve TableEditor and set all fields with default values to it - final PropertyEditor[] propertyEditors = (PropertyEditor[]) editors.get(testBeanCustomizer); - for (PropertyEditor propertyEditor : propertyEditors) { - if (propertyEditor instanceof TableEditor) { - propertyEditor.setValue(attributeList); - } else if (propertyEditor instanceof SchemaConverterPropertyEditor) { - propertyEditor.setValue(selectedSchema); - } else if (propertyEditor instanceof SchemaTypePropertyEditor) { - propertyEditor.setValue(schemaType); - } + public final void buildTable(final List attributeList) { + + if (!attributeList.isEmpty()) { + try { + //Get current test GUI component + final TestBeanGUI testBeanGUI = (TestBeanGUI) GuiPackage.getInstance().getCurrentGui(); + final Field customizer = TestBeanGUI.class.getDeclaredField(PropsKeysHelper.CUSTOMIZER); + customizer.setAccessible(true); + + //From TestBeanGUI retrieve Bean Customizer as it includes all editors like ClassPropertyEditor, TableEditor + final GenericTestBeanCustomizer testBeanCustomizer = (GenericTestBeanCustomizer) customizer.get(testBeanGUI); + final Field editors = GenericTestBeanCustomizer.class.getDeclaredField(PropsKeysHelper.EDITORS); + editors.setAccessible(true); + + //Retrieve TableEditor and set all fields with default values to it + final PropertyEditor[] propertyEditors = (PropertyEditor[]) editors.get(testBeanCustomizer); + for (PropertyEditor propertyEditor : propertyEditors) { + if (propertyEditor instanceof TableEditor) { + propertyEditor.setValue(attributeList); } - } catch (NoSuchFieldException | IllegalAccessException e) { - JOptionPane - .showMessageDialog(panel, "Failed to retrieve schema : " + e.getMessage(), ERROR_FAILED_TO_RETRIEVE_PROPERTIES, - JOptionPane.ERROR_MESSAGE); - log.error(e.getMessage(), e); - } catch (final AvroRuntimeException ex) { - JOptionPane - .showMessageDialog(panel, "Failed to process schema : " + ex.getMessage(), ERROR_FAILED_TO_RETRIEVE_PROPERTIES, - JOptionPane.ERROR_MESSAGE); - log.error(ex.getMessage(), ex); } - } else { + } catch (NoSuchFieldException | IllegalAccessException e) { JOptionPane - .showMessageDialog(panel, "No schema has been loaded, we cannot extract properties", ERROR_FAILED_TO_RETRIEVE_PROPERTIES, - JOptionPane.WARNING_MESSAGE); + .showMessageDialog(panel, "Failed to retrieve schema : " + e.getMessage(), ERROR_FAILED_TO_RETRIEVE_PROPERTIES, + JOptionPane.ERROR_MESSAGE); + log.error(e.getMessage(), e); + } catch (final AvroRuntimeException ex) { + JOptionPane + .showMessageDialog(panel, "Failed to process schema : " + ex.getMessage(), ERROR_FAILED_TO_RETRIEVE_PROPERTIES, + JOptionPane.ERROR_MESSAGE); + log.error(ex.getMessage(), ex); } + } else { + JOptionPane + .showMessageDialog(panel, "No schema has been loaded, we cannot extract properties", ERROR_FAILED_TO_RETRIEVE_PROPERTIES, + JOptionPane.WARNING_MESSAGE); } + } @Override @@ -192,50 +169,15 @@ public final void setDescriptor(final PropertyDescriptor propertyDescriptor) { super.setSource(propertyDescriptor); } - @Override - public final String getAsText() { - return Objects.requireNonNull(this.subjectNameComboBox.getSelectedItem()).toString(); - } @Override public final Component getCustomEditor() { return this.panel; } - @Override - public final void setAsText(final String text) throws IllegalArgumentException { - this.subjectNameComboBox.setSelectedItem(text); - super.setValue(text); - } - - @Override - public final void setValue(final Object value) { - this.subjectNameComboBox.setSelectedItem(Objects.requireNonNullElse(value, "")); - super.setValue(value); - } - - @Override - public final Object getValue() { - return this.subjectNameComboBox.getSelectedItem(); - } - @Override public final boolean supportsCustomEditor() { return true; } - class ComboFiller implements FocusListener { - - @Override - public void focusGained(final FocusEvent e) { - final String subjects = JMeterContextService.getContext().getProperties().getProperty(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_SUBJECTS); - subjectNameComboBox.setModel(new DefaultComboBoxModel<>(subjects.split(","))); - } - - @Override - public void focusLost(final FocusEvent e) { - // Override but not used. Implementation not needed. - } - } - } diff --git a/src/main/java/com/sngular/kloadgen/randomtool/random/RandomObject.java b/src/main/java/com/sngular/kloadgen/randomtool/random/RandomObject.java index 02dbde14..0a959b62 100644 --- a/src/main/java/com/sngular/kloadgen/randomtool/random/RandomObject.java +++ b/src/main/java/com/sngular/kloadgen/randomtool/random/RandomObject.java @@ -33,7 +33,7 @@ public final class RandomObject { - private Random rand = new Random(); + private final Random rand = new Random(); public boolean isTypeValid(final String type) { return ValidTypeConstants.VALID_OBJECT_TYPES.contains(type); diff --git a/src/main/java/com/sngular/kloadgen/sampler/KafkaProducerSampler.java b/src/main/java/com/sngular/kloadgen/sampler/KafkaProducerSampler.java index 16e78dfa..edac1f44 100644 --- a/src/main/java/com/sngular/kloadgen/sampler/KafkaProducerSampler.java +++ b/src/main/java/com/sngular/kloadgen/sampler/KafkaProducerSampler.java @@ -25,7 +25,6 @@ import com.sngular.kloadgen.serializer.ProtobufSerializer; import com.sngular.kloadgen.util.ProducerKeysHelper; import com.sngular.kloadgen.util.PropsKeysHelper; -import io.apicurio.registry.resolver.SchemaResolverConfig; import io.apicurio.registry.serde.Legacy4ByteIdHandler; import io.apicurio.registry.serde.SerdeConfig; import io.apicurio.registry.serde.avro.AvroKafkaSerializer; @@ -71,7 +70,7 @@ public final class KafkaProducerSampler extends AbstractJavaSamplerClient implem @Override public void setupTest(final JavaSamplerContext context) { - props = properties(context); + props = JMeterContextService.getContext().getProperties(); generator = SamplerUtil.configureValueGenerator(props); @@ -99,13 +98,11 @@ public void setupTest(final JavaSamplerContext context) { topic = context.getParameter(ProducerKeysHelper.KAFKA_TOPIC_CONFIG); try { - final Properties props2 = new Properties(); - - props2.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, context.getParameter(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG)); - props2.put(ProducerConfig.CLIENT_ID_CONFIG, context.getParameter(ProducerConfig.CLIENT_ID_CONFIG)); - props2.putIfAbsent(ProducerConfig.ACKS_CONFIG, "all"); - props2.putIfAbsent(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); - props2.putIfAbsent(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, AvroKafkaSerializer.class.getName()); + props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, context.getParameter(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG)); + props.put(ProducerConfig.CLIENT_ID_CONFIG, context.getParameter(ProducerConfig.CLIENT_ID_CONFIG)); + props.putIfAbsent(ProducerConfig.ACKS_CONFIG, "all"); + props.putIfAbsent(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); + props.putIfAbsent(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, AvroKafkaSerializer.class.getName()); producer = new KafkaProducer<>(props); } catch (final KafkaException ex) { @@ -113,19 +110,6 @@ public void setupTest(final JavaSamplerContext context) { } } - private Properties properties(final JavaSamplerContext context) { - final var commonProps = SamplerUtil.setupCommonProperties(context); - - final String artifactResolverStrategy = context.getParameter(ProducerKeysHelper.VALUE_NAME_STRATEGY); - if (Objects.nonNull(artifactResolverStrategy)) { - commonProps.put(ProducerKeysHelper.VALUE_NAME_STRATEGY, artifactResolverStrategy); - } - if (Objects.nonNull(context.getParameter(SchemaResolverConfig.ARTIFACT_RESOLVER_STRATEGY))) { - commonProps.put(SchemaResolverConfig.ARTIFACT_RESOLVER_STRATEGY, artifactResolverStrategy); - } - return commonProps; - } - @Override public void teardownTest(final JavaSamplerContext context) { if (Objects.nonNull(producer)) { @@ -209,10 +193,10 @@ private Boolean enrichedValueFlag() { } private void fillSamplerResult(final ProducerRecord producerRecord, final SampleResult sampleResult) { - final StringBuilder result = new StringBuilder(); - result.append("key: ").append(producerRecord.key()) - .append(", payload: ").append(producerRecord.value()); - sampleResult.setSamplerData(result.toString()); + final String result = "key: " + + producerRecord.key() + + ", payload: " + producerRecord.value(); + sampleResult.setSamplerData(result); } private void fillSampleResult(final SampleResult sampleResult, final String respondeData, final boolean successful) { diff --git a/src/main/java/com/sngular/kloadgen/sampler/SamplerUtil.java b/src/main/java/com/sngular/kloadgen/sampler/SamplerUtil.java index a8712639..4878decb 100644 --- a/src/main/java/com/sngular/kloadgen/sampler/SamplerUtil.java +++ b/src/main/java/com/sngular/kloadgen/sampler/SamplerUtil.java @@ -35,6 +35,7 @@ import io.apicurio.registry.resolver.SchemaResolverConfig; import io.apicurio.registry.serde.SerdeConfig; import io.confluent.kafka.schemaregistry.client.SchemaRegistryClientConfig; +import org.apache.avro.SchemaParseException; import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.config.Arguments; import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; @@ -359,7 +360,7 @@ public static BaseLoadGenerator configureValueGenerator(final Properties props) props.put(ProducerKeysHelper.VALUE_NAME_STRATEGY, Objects.nonNull(valueNameStrategy) ? valueNameStrategy : ProducerKeysHelper.TOPIC_NAME_STRATEGY_CONFLUENT); } - generator = getLoadGenerator(jMeterVariables); + generator = getLoadGenerator(); if (generator.getClass().equals(PlainTextLoadGenerator.class)) { final List list = new ArrayList<>(); @@ -387,7 +388,17 @@ public static BaseLoadGenerator configureValueGenerator(final Properties props) } } } else { - generator.setUpGenerator(jMeterVariables.get(PropsKeysHelper.VALUE_SCHEMA), (List) jMeterVariables.getObject(PropsKeysHelper.VALUE_SCHEMA_PROPERTIES)); + try { + final String schema; + if (jMeterVariables.get(PropsKeysHelper.VALUE_SCHEMA).isEmpty()) { + schema = props.getProperty(PropsKeysHelper.VALUE_SCHEMA); + } else { + schema = jMeterVariables.get(PropsKeysHelper.VALUE_SCHEMA); + } + generator.setUpGenerator(schema, (List) jMeterVariables.getObject(PropsKeysHelper.VALUE_SCHEMA_PROPERTIES)); + } catch (final SchemaParseException exc) { + generator.setUpGenerator(props.getProperty(PropsKeysHelper.VALUE_SCHEMA), (List) jMeterVariables.getObject(PropsKeysHelper.VALUE_SCHEMA_PROPERTIES)); + } } return generator; @@ -465,17 +476,17 @@ public static List populateHeaders(final List kafkaHeader return headersSB; } - private static BaseLoadGenerator getLoadGenerator(final JMeterVariables jmeterVariables) { + private static BaseLoadGenerator getLoadGenerator() { final BaseLoadGenerator generator; - - if (Objects.nonNull(jmeterVariables.get(PropsKeysHelper.VALUE_SCHEMA_TYPE))) { - if (JSON_TYPE_SET.contains(jmeterVariables.get(PropsKeysHelper.VALUE_SCHEMA_TYPE).toLowerCase())) { + final String schemaType = JMeterContextService.getContext().getProperties().getProperty(PropsKeysHelper.VALUE_SCHEMA_TYPE); + if (Objects.nonNull(schemaType)) { + if (JSON_TYPE_SET.contains(schemaType.toLowerCase())) { generator = new JsonSRLoadGenerator(); - } else if (jmeterVariables.get(PropsKeysHelper.VALUE_SCHEMA_TYPE).equalsIgnoreCase("avro")) { + } else if ("avro".equalsIgnoreCase(schemaType)) { generator = new AvroSRLoadGenerator(); - } else if (jmeterVariables.get(PropsKeysHelper.VALUE_SCHEMA_TYPE).equalsIgnoreCase("Protobuf")) { + } else if ("Protobuf".equalsIgnoreCase(schemaType)) { generator = new ProtobufLoadGenerator(); - } else if (jmeterVariables.get(PropsKeysHelper.VALUE_SCHEMA_TYPE).equalsIgnoreCase("NoSchema")) { + } else if ("NoSchema".equalsIgnoreCase(schemaType)) { generator = new PlainTextLoadGenerator(); } else { throw new KLoadGenException("Unsupported Serializer"); diff --git a/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/GenericSchemaRegistryAdapter.java b/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/GenericSchemaRegistryAdapter.java index c04b8c6d..9fdffb18 100644 --- a/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/GenericSchemaRegistryAdapter.java +++ b/src/main/java/com/sngular/kloadgen/schemaregistry/adapter/impl/GenericSchemaRegistryAdapter.java @@ -1,7 +1,6 @@ package com.sngular.kloadgen.schemaregistry.adapter.impl; public interface GenericSchemaRegistryAdapter { - T getId(); T getVersion(); diff --git a/src/main/java/com/sngular/kloadgen/util/JMeterHelper.java b/src/main/java/com/sngular/kloadgen/util/JMeterHelper.java index ba029b23..0115fb62 100644 --- a/src/main/java/com/sngular/kloadgen/util/JMeterHelper.java +++ b/src/main/java/com/sngular/kloadgen/util/JMeterHelper.java @@ -8,7 +8,6 @@ import java.util.Properties; -import com.sngular.kloadgen.exception.KLoadGenException; import com.sngular.kloadgen.schemaregistry.SchemaRegistryAdapter; import com.sngular.kloadgen.schemaregistry.SchemaRegistryManagerFactory; import com.sngular.kloadgen.schemaregistry.adapter.impl.BaseParsedSchema; @@ -24,11 +23,12 @@ private JMeterHelper() { } public static BaseParsedSchema getParsedSchema(final String subjectName, final Properties properties) { - final String schemaRegistryName = properties.getProperty(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME); - final SchemaRegistryAdapter schemaRegistryManager = SchemaRegistryManagerFactory.getSchemaRegistry(schemaRegistryName); - if (schemaRegistryManager == null || StringUtils.isEmpty(schemaRegistryName)) { - throw new KLoadGenException("Schema registry name is required"); + String schemaRegistryName = properties.getProperty(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME); + if (schemaRegistryName == null || StringUtils.isEmpty(schemaRegistryName)) { + schemaRegistryName = SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME_DEFAULT; } + final SchemaRegistryAdapter schemaRegistryManager = SchemaRegistryManagerFactory.getSchemaRegistry(schemaRegistryName); + return schemaRegistryManager.getSchemaBySubject(subjectName); } diff --git a/src/test/java/com/sngular/kloadgen/config/kafkaheaders/KafkaHeadersConfigElementBeanInfoTest.java b/src/test/java/com/sngular/kloadgen/config/kafkaheaders/KafkaHeadersConfigElementBeanInfoTest.java index cc7579d2..a950dd82 100644 --- a/src/test/java/com/sngular/kloadgen/config/kafkaheaders/KafkaHeadersConfigElementBeanInfoTest.java +++ b/src/test/java/com/sngular/kloadgen/config/kafkaheaders/KafkaHeadersConfigElementBeanInfoTest.java @@ -17,7 +17,8 @@ class KafkaHeadersConfigElementBeanInfoTest { private static final String KAFKA_HEADERS = "kafkaHeaders"; - + private static final String PROPERTIES = "props"; + private static final String SCHEMA = "schema"; private KafkaHeadersConfigElementBeanInfo kafkaHeadersConfigElementBeanInfo; @BeforeEach @@ -31,5 +32,7 @@ final void shouldGenerateElements() { final PropertyDescriptor[] propertyDescriptors = kafkaHeadersConfigElementBeanInfo.getPropertyDescriptors(); Assertions.assertThat(propertyDescriptors).hasSize(3); Assertions.assertThat(propertyDescriptors[0].getName()).isEqualTo(KAFKA_HEADERS); + Assertions.assertThat(propertyDescriptors[1].getName()).isEqualTo(PROPERTIES); + Assertions.assertThat(propertyDescriptors[2].getName()).isEqualTo(SCHEMA); } } \ No newline at end of file diff --git a/src/test/java/com/sngular/kloadgen/config/keyserialized/KeySerializedConfigElementBeanInfoTest.java b/src/test/java/com/sngular/kloadgen/config/keyserialized/KeySerializedConfigElementBeanInfoTest.java index f5433c59..a9057b4c 100644 --- a/src/test/java/com/sngular/kloadgen/config/keyserialized/KeySerializedConfigElementBeanInfoTest.java +++ b/src/test/java/com/sngular/kloadgen/config/keyserialized/KeySerializedConfigElementBeanInfoTest.java @@ -25,6 +25,8 @@ class KeySerializedConfigElementBeanInfoTest { private static final String KEY_NAME_STRATEGY = "keyNameStrategy"; private static final String KEY_SERIALIZER_CONFIGURATION = "keySerializerConfiguration"; + private static final String PROPERTIES = "props"; + private static final String SCHEMA = "schema"; private KeySerializedConfigElementBeanInfo keySerializedConfigElementBeanInfo; @@ -43,5 +45,7 @@ void shouldGenerateElements() { Assertions.assertThat(propertyDescriptors[2].getName()).isEqualTo(KEY_SCHEMA_TYPE); Assertions.assertThat(propertyDescriptors[3].getName()).isEqualTo(KEY_SERIALIZER_CONFIGURATION); Assertions.assertThat(propertyDescriptors[4].getName()).isEqualTo(KEY_SUBJECT_NAME); + Assertions.assertThat(propertyDescriptors[5].getName()).isEqualTo(PROPERTIES); + Assertions.assertThat(propertyDescriptors[6].getName()).isEqualTo(SCHEMA); } } \ No newline at end of file diff --git a/src/test/java/com/sngular/kloadgen/extractor/SchemaExtractorTest.java b/src/test/java/com/sngular/kloadgen/extractor/SchemaExtractorTest.java index 9f62af25..1e6587db 100644 --- a/src/test/java/com/sngular/kloadgen/extractor/SchemaExtractorTest.java +++ b/src/test/java/com/sngular/kloadgen/extractor/SchemaExtractorTest.java @@ -114,6 +114,15 @@ void testFlatPropertiesListWithProtobuf() throws IOException { Assertions.assertThat(result).isNotNull(); } + @Test + @DisplayName("Test readSchemaFile with AVRO") + void testReadSchemaFile() throws IOException { + final String testFilePath = fileHelper.getFile("/avro-files/embedded-avros-example-test.avsc").toPath().toString(); + + final var result = SchemaExtractor.readSchemaFile(testFilePath); + Assertions.assertThat(result).isNotNull(); + } + @Test @DisplayName("Test flatPropertiesList throws exception schema type not supported") void testFlatPropertiesListWithException() { diff --git a/src/test/java/com/sngular/kloadgen/extractor/extractors/json/JsonDefaultTest.java b/src/test/java/com/sngular/kloadgen/extractor/extractors/json/JsonDefaultTest.java index b4f0898e..dccd6efb 100644 --- a/src/test/java/com/sngular/kloadgen/extractor/extractors/json/JsonDefaultTest.java +++ b/src/test/java/com/sngular/kloadgen/extractor/extractors/json/JsonDefaultTest.java @@ -20,7 +20,7 @@ class JsonDefaultTest { private final FileHelper fileHelper = new FileHelper(); - private final Extractor jsonDefaultExtractor = new JsonDefaultExtractor(); + private final Extractor jsonDefaultExtractor = new JsonDefaultExtractor(); @Test @DisplayName("Should extract basic types") @@ -30,7 +30,7 @@ void testBasic() throws Exception { final Map constraints = Map.of(ConstraintTypeEnum.MINIMUM_VALUE, "0", ConstraintTypeEnum.MAXIMUM_VALUE, "0"); final JSONObject jsonObject = new JSONObject(testFile); final Schema schema = SchemaLoader.load(jsonObject); - final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema); + final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema.toString()); Assertions.assertThat(fieldValueMappingList) .hasSize(3) @@ -48,7 +48,7 @@ void testBasicArray() throws Exception { final Map constraints = Map.of(ConstraintTypeEnum.MINIMUM_VALUE, "0", ConstraintTypeEnum.MAXIMUM_VALUE, "0"); final JSONObject jsonObject = new JSONObject(testFile); final Schema schema = SchemaLoader.load(jsonObject); - final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema); + final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema.toString()); Assertions.assertThat(fieldValueMappingList) .hasSize(3) @@ -73,7 +73,7 @@ void testBasicNumber() throws Exception { final JSONObject jsonObject = new JSONObject(testFile); final Schema schema = SchemaLoader.load(jsonObject); - final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema); + final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema.toString()); Assertions.assertThat(fieldValueMappingList) .hasSize(2) @@ -91,7 +91,7 @@ void testFlatPropertiesOptionalCollections() throws Exception { final JSONObject jsonObject = new JSONObject(testFile); final Schema schema = SchemaLoader.load(jsonObject); - final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema); + final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema.toString()); Assertions.assertThat(fieldValueMappingList) .hasSize(12) @@ -128,7 +128,7 @@ void testComplexDefinitions() throws Exception { final JSONObject jsonObject = new JSONObject(testFile); final Schema schema = SchemaLoader.load(jsonObject); - final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema); + final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema.toString()); Assertions.assertThat(fieldValueMappingList) .hasSize(8) @@ -157,7 +157,7 @@ void testRequiredPropagationChildrenFields() throws Exception { final JSONObject jsonObject = new JSONObject(testFile); final Schema schema = SchemaLoader.load(jsonObject); - final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema); + final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema.toString()); Assertions.assertThat(fieldValueMappingList) .contains( @@ -180,7 +180,7 @@ void testShouldExtractJsonSchemaDefinitions() throws Exception { final JSONObject jsonObject = new JSONObject(testFile); final Schema schema = SchemaLoader.load(jsonObject); - final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema); + final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema.toString()); Assertions.assertThat(fieldValueMappingList) .contains( @@ -196,7 +196,7 @@ void testMultipleType() throws Exception { final JSONObject jsonObject = new JSONObject(testFile); final Schema schema = SchemaLoader.load(jsonObject); - final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema); + final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema.toString()); Assertions.assertThat(fieldValueMappingList) .hasSize(1) @@ -213,7 +213,7 @@ void testFlatPropertiesOptionalNestedCollections() throws Exception { final JSONObject jsonObject = new JSONObject(testFile); final Schema schema = SchemaLoader.load(jsonObject); - final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema); + final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema.toString()); Assertions.assertThat(fieldValueMappingList) .hasSize(8) @@ -241,7 +241,7 @@ void testShouldExtractMapSimpleDataType() throws Exception { final JSONObject jsonObject = new JSONObject(testFile); final Schema schema = SchemaLoader.load(jsonObject); - final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema); + final List fieldValueMappingList = jsonDefaultExtractor.processSchema(schema.toString()); Assertions.assertThat(fieldValueMappingList).contains( FieldValueMapping.builder().fieldName("firstName").fieldType("string").constraints(constraints).required(false).isAncestorRequired(false).build(), @@ -260,7 +260,7 @@ void testFlatPropertiesCaptureThreeLevelException() throws Exception { final Schema schema = SchemaLoader.load(jsonObject); Assertions.assertThatExceptionOfType(KLoadGenException.class) - .isThrownBy(() -> jsonDefaultExtractor.processSchema(schema)) + .isThrownBy(() -> jsonDefaultExtractor.processSchema(schema.toString())) .withMessage("Wrong Json Schema, 3+ consecutive nested collections are not allowed"); }