From 06d0dde7a6000afbc731c10aa6d2e8258b5f77d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Enrique=20Garc=C3=ADa=20Maci=C3=B1eiras?= Date: Fri, 24 Nov 2023 14:58:21 +0100 Subject: [PATCH] #384 fix style codacy --- .../extractors/ExtractorRegistry.java | 5 +- .../protobuf/ProtobufExtractor.java | 8 +- .../sampler/gui/AsyncApiSamplerGui.java | 7 +- .../asyncapi/AsyncApiExtractorImplTest.java | 86 +++++++++---------- .../processor/JsonSchemaProcessorTest.java | 6 +- .../kloadgen/sampler/AsyncApiSamplerTest.java | 4 - 6 files changed, 55 insertions(+), 61 deletions(-) delete mode 100644 src/test/java/com/sngular/kloadgen/sampler/AsyncApiSamplerTest.java 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 27026c59..2024f088 100644 --- a/src/main/java/com/sngular/kloadgen/extractor/extractors/ExtractorRegistry.java +++ b/src/main/java/com/sngular/kloadgen/extractor/extractors/ExtractorRegistry.java @@ -4,11 +4,12 @@ import com.sngular.kloadgen.common.SchemaRegistryEnum; import com.sngular.kloadgen.model.FieldValueMapping; +import com.sngular.kloadgen.parsedschema.ParsedSchema; -public interface ExtractorRegistry { +public interface ExtractorRegistry { List processSchema(final T schema, SchemaRegistryEnum registry); - Object processSchema(final String fileContent); + T processSchema(final String fileContent); List getSchemaNameList(final String schema, SchemaRegistryEnum registryEnum); diff --git a/src/main/java/com/sngular/kloadgen/extractor/extractors/protobuf/ProtobufExtractor.java b/src/main/java/com/sngular/kloadgen/extractor/extractors/protobuf/ProtobufExtractor.java index 456d876a..8a9436c0 100644 --- a/src/main/java/com/sngular/kloadgen/extractor/extractors/protobuf/ProtobufExtractor.java +++ b/src/main/java/com/sngular/kloadgen/extractor/extractors/protobuf/ProtobufExtractor.java @@ -10,17 +10,17 @@ import com.sngular.kloadgen.model.FieldValueMapping; import com.sngular.kloadgen.parsedschema.ParsedSchema; -public class ProtobuffExtractor implements ExtractorRegistry { +public class ProtobufExtractor implements ExtractorRegistry { private static final Map SCHEMA_REGISTRY_MAP = Map.of(SchemaRegistryEnum.CONFLUENT, new ProtoBufConfluentExtractor(), SchemaRegistryEnum.APICURIO, new ProtoBufApicurioExtractor()); - public final List processSchema(final ParsedSchema schemaReceived, final SchemaRegistryEnum registryEnum) { + public final List processSchema(final T schemaReceived, final SchemaRegistryEnum registryEnum) { return new ArrayList(SCHEMA_REGISTRY_MAP.get(registryEnum).processSchema(schemaReceived)); } - public final ParsedSchema processSchema(final String fileContent) { - return new ParsedSchema(fileContent, "PROTOBUF"); + public final T processSchema(final String fileContent) { + return (T) new ParsedSchema(fileContent, "PROTOBUF"); } public final List getSchemaNameList(final String schema, final SchemaRegistryEnum registryEnum) { diff --git a/src/main/java/com/sngular/kloadgen/sampler/gui/AsyncApiSamplerGui.java b/src/main/java/com/sngular/kloadgen/sampler/gui/AsyncApiSamplerGui.java index 1f56866d..5edfcd21 100644 --- a/src/main/java/com/sngular/kloadgen/sampler/gui/AsyncApiSamplerGui.java +++ b/src/main/java/com/sngular/kloadgen/sampler/gui/AsyncApiSamplerGui.java @@ -61,6 +61,7 @@ import org.apache.jorphan.gui.JLabeledTextField; import org.apache.kafka.clients.producer.ProducerConfig; +@SuppressWarnings("checkstyle:ClassDataAbstractionCoupling") public final class AsyncApiSamplerGui extends AbstractSamplerGui { private final JFileChooser fileChooser = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory()); @@ -81,8 +82,6 @@ public final class AsyncApiSamplerGui extends AbstractSamplerGui { private JComboBox topicComboBox; - private JComboBox registryComboBox; - private AsyncApiFile asyncApiFile; public AsyncApiSamplerGui() { @@ -362,10 +361,10 @@ private JPanel createRegistryTab() { final JPanel registryUrlPanel = new JPanel(); registryUrlPanel.setLayout(new BorderLayout(0, 0)); registryUrlPanel.add(new JLabeledTextField("Schema Registry URL")); - registryComboBox = new JComboBox<>(); + final JComboBox registryComboBox = new JComboBox<>(); registryComboBox.setRenderer(new AsyncApiSRRenderer()); registryComboBox.addActionListener(this::registryComboActionListener); - registryUrlPanel.add(this.registryComboBox, BorderLayout.NORTH); + registryUrlPanel.add(registryComboBox, BorderLayout.NORTH); registryUrlPanel.add(new JScrollPane(new JTable(schemaRegistryFieldModel)), BorderLayout.CENTER); return registryUrlPanel; } diff --git a/src/test/java/com/sngular/kloadgen/extractor/asyncapi/AsyncApiExtractorImplTest.java b/src/test/java/com/sngular/kloadgen/extractor/asyncapi/AsyncApiExtractorImplTest.java index b2b9b0c7..25a9f63c 100644 --- a/src/test/java/com/sngular/kloadgen/extractor/asyncapi/AsyncApiExtractorImplTest.java +++ b/src/test/java/com/sngular/kloadgen/extractor/asyncapi/AsyncApiExtractorImplTest.java @@ -1,5 +1,9 @@ package com.sngular.kloadgen.extractor.asyncapi; +import java.io.File; +import java.io.IOException; +import java.util.Locale; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; @@ -9,56 +13,50 @@ import org.apache.jmeter.threads.JMeterContextService; import org.apache.jmeter.threads.JMeterVariables; import org.apache.jmeter.util.JMeterUtils; -import static org.assertj.core.api.Assertions.*; - import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.io.File; -import java.io.IOException; -import java.util.*; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - class AsyncApiExtractorImplTest { - private FileHelper fileHelper = new FileHelper(); - private final ObjectMapper om = new ObjectMapper(new YAMLFactory()); - - @BeforeEach - public final void setUp() { - final File file = new File("src/test/resources"); - final String absolutePath = file.getAbsolutePath(); - JMeterUtils.loadJMeterProperties(absolutePath + "/kloadgen.properties"); - final JMeterContext jmcx = JMeterContextService.getContext(); - jmcx.setVariables(new JMeterVariables()); - JMeterUtils.setLocale(Locale.ENGLISH); - } - - @Test - @DisplayName("Should extract asyncapi file") - void testExtractFile() throws IOException { - final File testFile = fileHelper.getFile("/asyncapi/event-api.yml"); - final AsyncApiFile asapfle = new AsyncApiExtractorImpl().processFile(testFile); - assertNotNull(asapfle); - assertEquals("{user_signedup=user_signedup}",asapfle.getApiSchemaList().toString()); - assertEquals("{production=AsyncApiServer(name=production, url=mqtt://test.mosquitto.org, protocol=mqtt, description=Test MQTT broker)}", - asapfle.getApiServerMap().toString()); - } - @Test - @DisplayName("Should extract basic asyncapi schema") - void testExtractAsyncapiSchema() throws IOException { - final File testFile = fileHelper.getFile("/asyncapi/event-api.yml"); - final JsonNode openApi = om.readTree(testFile); - final AsyncApiFile asapfle = new AsyncApiExtractorImpl().processNode(openApi); - JsonNode propertiesSchema = asapfle.getAsyncApiFileNode().path("components").path("schemas").path("userSignedUpPayload").path("properties"); - Assertions.assertThat(asapfle).isNotNull(); - assertThat(propertiesSchema) - .hasSize(4) - .isSubsetOf(openApi.get("components").get("schemas").get("userSignedUpPayload").get("properties")); - } + private final ObjectMapper om = new ObjectMapper(new YAMLFactory()); + + private final FileHelper fileHelper = new FileHelper(); + + @BeforeEach + public final void setUp() { + final File file = new File("src/test/resources"); + final String absolutePath = file.getAbsolutePath(); + JMeterUtils.loadJMeterProperties(absolutePath + "/kloadgen.properties"); + final JMeterContext jmcx = JMeterContextService.getContext(); + jmcx.setVariables(new JMeterVariables()); + JMeterUtils.setLocale(Locale.ENGLISH); + } + + @Test + @DisplayName("Should extract asyncapi file") + void testExtractFile() throws IOException { + final File testFile = fileHelper.getFile("/asyncapi/event-api.yml"); + final AsyncApiFile asapfle = new AsyncApiExtractorImpl().processFile(testFile); + + org.junit.jupiter.api.Assertions.assertNotNull(asapfle); + org.junit.jupiter.api.Assertions.assertEquals("{user_signedup=user_signedup}", asapfle.getApiSchemaList().toString()); + org.junit.jupiter.api.Assertions.assertEquals("{production=AsyncApiServer(name=production, url=mqtt://test.mosquitto.org, protocol=mqtt, description=Test MQTT broker)}", + asapfle.getApiServerMap().toString()); + } + + @Test + @DisplayName("Should extract basic asyncapi schema") + void testExtractAsyncapiSchema() throws IOException { + final File testFile = fileHelper.getFile("/asyncapi/event-api.yml"); + final JsonNode openApi = om.readTree(testFile); + final AsyncApiFile asapfle = new AsyncApiExtractorImpl().processNode(openApi); + final JsonNode propertiesSchema = asapfle.getAsyncApiFileNode().path("components").path("schemas").path("userSignedUpPayload").path("properties"); + Assertions.assertThat(asapfle).isNotNull(); + Assertions.assertThat(propertiesSchema) + .hasSize(4) + .isSubsetOf(openApi.get("components").get("schemas").get("userSignedUpPayload").get("properties")); + } } \ No newline at end of file diff --git a/src/test/java/com/sngular/kloadgen/processor/JsonSchemaProcessorTest.java b/src/test/java/com/sngular/kloadgen/processor/JsonSchemaProcessorTest.java index 04c236fa..b05d5b24 100644 --- a/src/test/java/com/sngular/kloadgen/processor/JsonSchemaProcessorTest.java +++ b/src/test/java/com/sngular/kloadgen/processor/JsonSchemaProcessorTest.java @@ -33,7 +33,7 @@ private static Stream parametersForTestBasicStructure() { return Stream.of(Arguments.of(JsonSchemaFixturesConstants.SIMPLE_SCHEMA_REQUIRED, JsonSchemaFixturesConstants.SIMPLE_SCHEMA_REQUIRED_EXPECTED)); } - private static Stream parametersForTestOptionalFieldNonEmpty(){ + private static Stream parametersForTestOptionalFieldNonEmpty() { return Stream.of(Arguments.of(JsonSchemaFixturesConstants.SIMPLE_SCHEMA_NONREQUIRED, JsonSchemaFixturesConstants.SIMPLE_SCHEMA_NONREQUIRED_EXPECTED)); } @@ -125,11 +125,11 @@ final void testNestedComplexLevels() { @ParameterizedTest @DisplayName("Should process non-required fields if it is not empty") @MethodSource("parametersForTestOptionalFieldNonEmpty") - final void testOptionalFieldNonEmpty(final List schemaAsJson, final String expected){ + final void testOptionalFieldNonEmpty(final List schemaAsJson, final String expected) { final SchemaProcessor jsonSchemaProcessor = new SchemaProcessor(); - jsonSchemaProcessor.processSchema(SchemaTypeEnum.JSON,null,null,schemaAsJson); + jsonSchemaProcessor.processSchema(SchemaTypeEnum.JSON, null, null, schemaAsJson); final ObjectNode message = (ObjectNode) jsonSchemaProcessor.next(); Assertions.assertThat(message.toString()).isEqualTo(expected); diff --git a/src/test/java/com/sngular/kloadgen/sampler/AsyncApiSamplerTest.java b/src/test/java/com/sngular/kloadgen/sampler/AsyncApiSamplerTest.java deleted file mode 100644 index 6d5c6274..00000000 --- a/src/test/java/com/sngular/kloadgen/sampler/AsyncApiSamplerTest.java +++ /dev/null @@ -1,4 +0,0 @@ -import static org.junit.jupiter.api.Assertions.*; -class AsyncApiSamplerTest { - -} \ No newline at end of file