Skip to content

Commit

Permalink
#332 Fix checkstyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jemacineiras committed Oct 19, 2023
1 parent 09acc9c commit e78d570
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 80 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
<junit-jupiter-api.version>5.8.2</junit-jupiter-api.version>
<kafka-schema-registry-client.version>7.1.1</kafka-schema-registry-client.version>
<apicurio-registry.version>2.4.1.Final</apicurio-registry.version>
<kafka.version>3.1.0</kafka.version>
<kafka.version>3.5.1</kafka.version>
<lombok.version>1.18.22</lombok.version>
<minimal-json.version>0.9.5</minimal-json.version>
<mockito-core.version>4.2.0</mockito-core.version>
Expand Down Expand Up @@ -464,7 +464,7 @@
<dependency>
<groupId>com.github.everit-org.json-schema</groupId>
<artifactId>org.everit.json.schema</artifactId>
<version>1.14.0</version>
<version>1.14.2</version>
</dependency>
<!-- Options -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class AsyncApiExtractorImpl implements ApiExtractor {

@Override
public final AsyncApiFile processFile(final File apiFile) {
AsyncApiFile asyncApiFile = null;
AsyncApiFile asyncApiFile;
try {
final JsonNode openApi = om.readTree(apiFile);
asyncApiFile = processNode(openApi);
Expand Down Expand Up @@ -80,7 +80,7 @@ private AsyncApiSchema mapNodeToSchema(final Map<String, JsonNode> components, f
final var message = ApiTool.findNodeValue(node, "message");
if (ApiTool.hasNode(message, "bindings")) {
builder.key(true);
// builder.keyType(ApiTool.findValue(message, "key"));
// builder.keyType(ApiTool.findValue(message, "key"));
}
builder.model(messageToFieldList(message, components, antiLoopList));
return builder.build();
Expand Down Expand Up @@ -138,7 +138,7 @@ private List<FieldValueMapping> processPayload(final JsonNode finalPayload, fina
.fieldName(propertyName)
.fieldType(getType(propertyDef))
.fieldValueList(hasValues(propertyDef))
.required(ApiTool.checkIfRequired(propertyDef, property.getKey()))
.required(ApiTool.checkIfRequired(finalPayload, property.getKey()))
.constraints(getConstraints(propertyDef))
.build());
}
Expand Down Expand Up @@ -172,8 +172,8 @@ private String getType(final JsonNode finalPayload) {
return type;
}

private Map<ConstraintTypeEnum, String> getConstraints(JsonNode finalPayload) {
Map<ConstraintTypeEnum, String> constraints = new EnumMap<>(ConstraintTypeEnum.class);
private Map<ConstraintTypeEnum, String> getConstraints(final JsonNode finalPayload) {
final Map<ConstraintTypeEnum, String> constraints = new EnumMap<>(ConstraintTypeEnum.class);
if (ApiTool.hasNode(finalPayload, "minLength")) {
constraints.put(ConstraintTypeEnum.MIN_LENGTH, ApiTool.getNodeAsString(finalPayload, "minLength"));
}
Expand All @@ -199,7 +199,7 @@ private Map<ConstraintTypeEnum, String> getConstraints(JsonNode finalPayload) {
return constraints;
}

private String hasValues(JsonNode propertyDef) {
private String hasValues(final JsonNode propertyDef) {
String values = null;
if (ApiTool.isEnum(propertyDef)) {
values = String.join(",", ApiTool.getEnumValues(propertyDef));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,31 @@
import org.apache.jmeter.threads.JMeterContextService;

public final class ExtractorFactory {
private static AvroExtractor avroExtractor = new AvroExtractor();
private static final AvroExtractor avroExtractor = new AvroExtractor();

private static JsonExtractor jsonExtractor = new JsonExtractor();
private static final JsonExtractor jsonExtractor = new JsonExtractor();

private static ProtobuffExtractor protobuffExtractor = new ProtobuffExtractor();
private static final ProtobuffExtractor protobuffExtractor = new ProtobuffExtractor();

private ExtractorFactory() {
}

public static ExtractorRegistry getExtractor(final String schemaType, final String schemaRegistryEnum) {

SchemaRegistryEnum registryEnum = getSchemaRegistry(schemaRegistryEnum);

if (schemaType != null && EnumUtils.isValidEnum(SchemaTypeEnum.class, schemaType.toUpperCase())) {
final ExtractorRegistry response;
switch (SchemaTypeEnum.valueOf(schemaType.toUpperCase())) {
case JSON:
response = jsonExtractor;
break;
case AVRO:
response = avroExtractor;
break;
case PROTOBUF:
response = protobuffExtractor;
break;
default:
throw new KLoadGenException(String.format("Schema type not supported %s", schemaType));
}
final ExtractorRegistry response = switch (SchemaTypeEnum.valueOf(schemaType.toUpperCase())) {
case JSON -> jsonExtractor;
case AVRO -> avroExtractor;
case PROTOBUF -> protobuffExtractor;
default -> throw new KLoadGenException(String.format("Schema type not supported %s", schemaType));
};
return response;
} else {
throw new KLoadGenException(String.format("Schema type not supported %s", schemaType));
}
}

public static SchemaRegistryEnum getSchemaRegistry(String schemaRegistryEnum) {
public static SchemaRegistryEnum getSchemaRegistry(final String schemaRegistryEnum) {
if (schemaRegistryEnum != null && EnumUtils.isValidEnum(SchemaRegistryEnum.class, schemaRegistryEnum.toUpperCase())) {
return SchemaRegistryEnum.valueOf(schemaRegistryEnum.toUpperCase());
} else {
Expand All @@ -67,27 +57,21 @@ public static Pair<String, List<FieldValueMapping>> flatPropertiesList(final Str
final Properties properties = JMeterContextService.getContext().getProperties();
final var schemaParsed = JMeterHelper.getParsedSchema(subjectName, properties);
final String registryName = properties.getProperty(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME);
String schemaType = null;
final ParsedSchemaAdapter parsedSchemaAdapter = schemaParsed.getParsedSchemaAdapter();
schemaType = parsedSchemaAdapter.getType();
final String schemaType = parsedSchemaAdapter.getType();

List<FieldValueMapping> attributeList = new ArrayList<>();
SchemaRegistryEnum schemaRegistryEnum = SchemaRegistryEnum.valueOf(registryName.toUpperCase());

Object schema = null;
if (Objects.nonNull(registryName)) {
//TODO change parser
switch (schemaRegistryEnum) {
case APICURIO:
schema = ((ApicurioParsedSchemaMetadata) parsedSchemaAdapter).getSchema();
break;
case CONFLUENT:
schema = parsedSchemaAdapter.getRawSchema();
break;
default:
throw new KLoadGenException("Schema Registry Type nos supported " + registryName.toUpperCase());
}
attributeList = getExtractor(schemaType,registryName.toUpperCase()).processSchema(schema, schemaRegistryEnum);
schema = switch (schemaRegistryEnum) {
case APICURIO -> ((ApicurioParsedSchemaMetadata) parsedSchemaAdapter).getSchema();
case CONFLUENT -> parsedSchemaAdapter.getRawSchema();
default -> throw new KLoadGenException("Schema Registry Type nos supported " + registryName.toUpperCase());
};
attributeList = getExtractor(schemaType, registryName.toUpperCase()).processSchema(schema, schemaRegistryEnum);
}
return Pair.of(schemaType, attributeList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import com.sngular.kloadgen.extractor.extractors.Extractor;
import com.sngular.kloadgen.model.FieldValueMapping;
import io.confluent.kafka.schemaregistry.avro.AvroSchema;
import org.apache.avro.Schema;

public class AvroConfluentExtractor extends AbstractAvroFileExtractor implements Extractor<AvroSchema> {
public class AvroConfluentExtractor extends AbstractAvroFileExtractor implements Extractor<Schema> {

public final List<FieldValueMapping> processSchema(final AvroSchema schema) {
return this.processSchemaDefault(schema.rawSchema());
public final List<FieldValueMapping> processSchema(final Schema schema) {
return this.processSchemaDefault(schema);
}

public final List<String> getSchemaNameList(final String schema) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ public final List<FieldValueMapping> getSchemaFieldConfiguration() {
.builder()
.fieldName(elementProperty.getElement().getPropertyAsString("fieldName"))
.fieldType(elementProperty.getElement().getPropertyAsString("fieldType"))
.required(elementProperty.getElement().getPropertyAsBoolean("required", false))
.required(elementProperty.getElement().getPropertyAsBoolean("required", true))
.valueLength(elementProperty.getElement().getPropertyAsInt("valueLength", 0))
.fieldValueList(elementProperty.getElement().getPropertyAsString("fieldValueList"))
.fieldValueList(elementProperty.getElement().getPropertyAsString("fieldValuesList"))
.build());
}
return propertyList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import com.sngular.kloadgen.exception.KLoadGenException;
import com.sngular.kloadgen.extractor.ApiExtractor;
import com.sngular.kloadgen.extractor.asyncapi.AsyncApiExtractorImpl;
import com.sngular.kloadgen.extractor.model.AsyncApiAbstract;
import com.sngular.kloadgen.extractor.model.AsyncApiFile;
import com.sngular.kloadgen.extractor.model.AsyncApiSR;
import com.sngular.kloadgen.extractor.model.AsyncApiSchema;
Expand All @@ -55,15 +54,13 @@
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.jmeter.config.Argument;
import org.apache.jmeter.gui.TestElementMetadata;
import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.property.JMeterProperty;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.gui.JLabeledTextField;
import org.apache.kafka.clients.producer.ProducerConfig;

@TestElementMetadata(labelResource = "async_api_sampler")
public final class AsyncApiSamplerGui extends AbstractSamplerGui {

private final JFileChooser fileChooser = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());
Expand Down Expand Up @@ -185,7 +182,7 @@ private void actionFileChooser(final ActionEvent event) {
asyncApiFileTextField.setText(apiFile.getAbsolutePath());
asyncApiFile = asyncApiExtractor.processFile(apiFile);
populateData();
} catch (KLoadGenException ex) {
} catch (final KLoadGenException ex) {
JOptionPane.showMessageDialog(mainPanel, "Error has occurred: " + ex.getMessage(), "Weird Error", JOptionPane.ERROR_MESSAGE);
}
}
Expand Down Expand Up @@ -230,7 +227,7 @@ private Collection<Pair<String, String>> prepareSRServer(final AsyncApiSR schema
final var propertyList = new ArrayList<Pair<String, String>>();
propertyList.add(Pair.of(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_URL, srPropoMap.get("url")));
propertyList.add(Pair.of(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME, srPropoMap.get("type")));
SchemaRegistryProperties.DEFAULTS.forEach(jMeterProperty -> propertyList.add(Pair.of(jMeterProperty.getName(), jMeterProperty.getPropertyValue())));
SchemaRegistryProperties.DEFAULTS.forEach(jmeterproperty -> propertyList.add(Pair.of(jmeterproperty.getName(), jmeterproperty.getPropertyValue())));
return propertyList;
}

Expand All @@ -242,14 +239,14 @@ private Collection<Pair<String, String>> prepareServer(final AsyncApiServer asyn
CollectionUtils.select(SamplerUtil
.getCommonProducerDefaultParameters(),
property -> !property.getName().equalsIgnoreCase(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG))
.forEach(jMeterProperty -> extractArgument(jMeterProperty, propertyList));
.forEach(jmeterproperty -> extractArgument(jmeterproperty, propertyList));
}
return propertyList;
}

private static boolean extractArgument(final JMeterProperty jMeterProperty, final ArrayList<Pair<String, String>> propertyList) {
final var argument = (Argument) jMeterProperty.getObjectValue();
return propertyList.add(Pair.of(argument.getPropertyAsString("Argument.name"), argument.getPropertyAsString("Argument.value")));
private static void extractArgument(final JMeterProperty jmeterproperty, final ArrayList<Pair<String, String>> propertyList) {
final var argument = (Argument) jmeterproperty.getObjectValue();
propertyList.add(Pair.of(argument.getPropertyAsString("Argument.name"), argument.getPropertyAsString("Argument.value")));
}

private void init() {
Expand Down Expand Up @@ -311,7 +308,7 @@ private JTabbedPane createAsyncApiTabs() {
return tabbedPanel;
}

private <T extends AsyncApiAbstract> void fillTable(final DefaultTableModel schemaFields, final Collection<Pair<String, String>> schemaData) {
private void fillTable(final DefaultTableModel schemaFields, final Collection<Pair<String, String>> schemaData) {
if (Objects.nonNull(schemaData)) {
final var count = schemaFields.getRowCount();
for (var i = 0; i < count; i++) {
Expand All @@ -321,7 +318,7 @@ private <T extends AsyncApiAbstract> void fillTable(final DefaultTableModel sche
}
}

private <T extends AsyncApiAbstract> void fillTable(final DefaultTableModel schemaFields, final Object[] schemaData) {
private void fillTable(final DefaultTableModel schemaFields, final Object[] schemaData) {
if (Objects.nonNull(schemaData)) {
final var count = schemaFields.getRowCount();
for (var i = 0; i < count; i++) {
Expand All @@ -333,7 +330,7 @@ private <T extends AsyncApiAbstract> void fillTable(final DefaultTableModel sche
}
}

private <T extends AsyncApiAbstract> void fillTable(final DefaultTableModel schemaFields, final List<FieldValueMapping> schemaData) {
private void fillTable(final DefaultTableModel schemaFields, final List<FieldValueMapping> schemaData) {
if (Objects.nonNull(schemaData)) {
final var count = schemaFields.getRowCount();
for (var i = 0; i < count; i++) {
Expand Down Expand Up @@ -395,10 +392,10 @@ private void topicComboActionListener(final ActionEvent event) {
}
}

private void registryComboActionListener(ActionEvent actionEvent) {
private void registryComboActionListener(final ActionEvent actionEvent) {
}

private void serverChooseActionListener(ActionEvent actionEvent) {
private void serverChooseActionListener(final ActionEvent actionEvent) {
final JComboBox serverChoose = (JComboBox)actionEvent.getSource();
if (Objects.nonNull(serverChoose)) {
fillTable(brokerFieldModel, prepareServer((AsyncApiServer) serverChoose.getSelectedItem()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,46 @@ public class ConfluentParsedSchemaMetadata extends ParsedSchemaAdapter {

private String canonicalString;

private Object rawSchema;
private Object rawSchema;

private ConfluentParsedSchemaMetadata(ParsedSchema parsedSchema){
private ConfluentParsedSchemaMetadata(final ParsedSchema parsedSchema) {
this.schemaType = parsedSchema.schemaType();
this.name = parsedSchema.name();
this.canonicalString = parsedSchema.canonicalString();
this.rawSchema = parsedSchema.rawSchema();
}

private ConfluentParsedSchemaMetadata(Schema schema){
private ConfluentParsedSchemaMetadata(final Schema schema) {
this.schemaType = schema.getType().getName();
this.name = schema.getName();
}

public ConfluentParsedSchemaMetadata(ProtobufSchema schema){
public ConfluentParsedSchemaMetadata(final ProtobufSchema schema) {
this.schemaType = schema.schemaType();
this.name = schema.name();
this.rawSchema = schema.rawSchema();
this.canonicalString = schema.canonicalString();
}

public ConfluentParsedSchemaMetadata() {

}

public static ParsedSchemaAdapter parse(final ParsedSchema parsedSchema) {
return new ConfluentParsedSchemaMetadata(parsedSchema);
}

public static ParsedSchemaAdapter parse(final Schema schema) {
return new ConfluentParsedSchemaMetadata(schema);
}
public static ParsedSchemaAdapter parse (final ProtobufSchema schema){

public static ParsedSchemaAdapter parse (final ProtobufSchema schema) {
return new ConfluentParsedSchemaMetadata(schema);
}

@Override
public String getType() {
public final String getType() {
return this.schemaType;
}

@Override
public Object getRawSchema() {
public final Object getRawSchema() {
return this.rawSchema;
}
}
Loading

0 comments on commit e78d570

Please sign in to comment.