Skip to content

Commit

Permalink
Updated version and checkstyle fixes in test
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoSngular committed Nov 15, 2023
1 parent 475c982 commit dd0d794
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 84 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<artifactId>kloadgen</artifactId>

<version>5.6.10</version>
<version>5.6.11</version>

<name>KLoadGen</name>
<description>Load Generation Jmeter plugin for Kafka Cluster. Supporting AVRO, JSON Schema and Protobuf schema types. Generate Artificial
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public static BaseLoadGenerator configureValueGenerator(final Properties props)
}
generator.setUpGenerator(schema, (List<FieldValueMapping>) jMeterVariables.getObject(PropsKeysHelper.VALUE_SCHEMA_PROPERTIES));
} catch (final SchemaParseException exc) {
generator.setUpGenerator(jMeterVariables.get(PropsKeysHelper.VALUE_SCHEMA), (List<FieldValueMapping>) jMeterVariables.getObject(PropsKeysHelper.VALUE_SCHEMA_PROPERTIES));
generator.setUpGenerator(jMeterVariables.get(PropsKeysHelper.VALUE_SCHEMA), (List<FieldValueMapping>) jMeterVariables.getObject(PropsKeysHelper.VALUE_SCHEMA_PROPERTIES));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@
import org.apache.jmeter.threads.JMeterVariables;
import org.apache.jmeter.util.JMeterUtils;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

Expand All @@ -37,77 +34,69 @@
import java.util.Locale;
import java.util.Properties;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.when;

class ExtractorFactoryTest {

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

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

private static ProtobuffExtractor protobuffExtractor = new ProtobuffExtractor();
@Captor
private ArgumentCaptor<Schema> argumentCaptor = ArgumentCaptor.forClass(Schema.class);

@Captor
private ArgumentCaptor<Schema> argumentCaptor = ArgumentCaptor.forClass(Schema.class);
private final Properties properties = new Properties();

private final Properties properties = new Properties();
private final FileHelper fileHelper = new FileHelper();

private ExtractorFactory extractorFactory;
private final Extractor<Schema> avroConfluentExtractor = new AvroConfluentExtractor();

private final FileHelper fileHelper = new FileHelper();
private MockedStatic<JMeterHelper> jMeterHelperMockedStatic;

private final Extractor<Schema> avroConfluentExtractor = new AvroConfluentExtractor();
private MockedStatic<JMeterContextService> jMeterContextServiceMockedStatic;

private MockedStatic<JMeterHelper> jMeterHelperMockedStatic;
@BeforeEach
public void init() {
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);

private MockedStatic<JMeterContextService> jMeterContextServiceMockedStatic;
jMeterHelperMockedStatic = Mockito.mockStatic(JMeterHelper.class);
jMeterContextServiceMockedStatic = Mockito.mockStatic(JMeterContextService.class, Answers.RETURNS_DEEP_STUBS);
argumentCaptor = ArgumentCaptor.forClass(Schema.class);
}

@BeforeEach
public void init() {
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);
@AfterEach
public void tearDown() {
properties.clear();
jMeterHelperMockedStatic.close();
jMeterContextServiceMockedStatic.close();
}

jMeterHelperMockedStatic = Mockito.mockStatic(JMeterHelper.class);
jMeterContextServiceMockedStatic = Mockito.mockStatic(JMeterContextService.class, Answers.RETURNS_DEEP_STUBS);
argumentCaptor = ArgumentCaptor.forClass(Schema.class);
}
@Test
void flatPropertiesList() throws IOException {
AvroExtractor avroExtractor = Mockito.mock(AvroExtractor.class);
ExtractorFactory.configExtractorFactory(avroExtractor, jsonExtractor, protobuffExtractor);

@AfterEach
public void tearDown() {
properties.clear();
jMeterHelperMockedStatic.close();
jMeterContextServiceMockedStatic.close();
}
final File testFile = fileHelper.getFile("/avro-files/embedded-avros-example-test.avsc");
properties.setProperty(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME, SchemaRegistryEnum.CONFLUENT.toString());

@Test
void flatPropertiesList() throws IOException {
avroExtractor = Mockito.mock(AvroExtractor.class);
ExtractorFactory.configExtractorFactory(avroExtractor, jsonExtractor, protobuffExtractor);
final ParsedSchema parsedSchema = new ParsedSchema(testFile, "AVRO");
final var baseParsedSchema = new BaseParsedSchema<>(ConfluentAbstractParsedSchemaMetadata.parse(parsedSchema));

final File testFile = fileHelper.getFile("/avro-files/embedded-avros-example-test.avsc");
properties.setProperty(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_NAME, SchemaRegistryEnum.CONFLUENT.toString());
jMeterHelperMockedStatic.when(() -> JMeterHelper.getParsedSchema(Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(baseParsedSchema);
jMeterContextServiceMockedStatic.when(() -> JMeterContextService.getContext().getProperties()).thenReturn(properties);

final ParsedSchema parsedSchema = new ParsedSchema(testFile, "AVRO");
final var baseParsedSchema = new BaseParsedSchema<>(ConfluentAbstractParsedSchemaMetadata.parse(parsedSchema));
final Schema schema = new Schema.Parser().parse(testFile);
final List<FieldValueMapping> fieldValueMappingList = avroConfluentExtractor.processSchema(schema);

jMeterHelperMockedStatic.when(() -> JMeterHelper.getParsedSchema(Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(baseParsedSchema);
jMeterContextServiceMockedStatic.when(() -> JMeterContextService.getContext().getProperties()).thenReturn(properties);
when(avroExtractor.processSchema(new ParsedSchema(argumentCaptor.capture(), ""), isA(SchemaRegistryEnum.class))).thenReturn(fieldValueMappingList);
final var result = SchemaExtractor.flatPropertiesList(schema.getName());

final Schema schema = new Schema.Parser().parse(testFile);
final List<FieldValueMapping> fieldValueMappingList = avroConfluentExtractor.processSchema(schema);

when(avroExtractor.processSchema(new ParsedSchema(argumentCaptor.capture(), ""), isA(SchemaRegistryEnum.class))).thenReturn(fieldValueMappingList);
final var result = SchemaExtractor.flatPropertiesList(schema.getName());

Assertions.assertThat(result).isNotNull();
}
Assertions.assertThat(result).isNotNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ void testFlatPropertiesEmbeddedAvros() throws Exception {
void testOptionalEnum() throws Exception {

final String testFile = fileHelper.getContent("/avro-files/optionalEnum.avsc");
//final ParsedSchema parsedSchema = avroConfluentExtractor.getSchemaNameList(testFile);

final Schema schema = new Schema.Parser().parse(testFile);
final List<FieldValueMapping> fieldValueMappingList = avroApicurioExtractor.processSchema(schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
import com.sngular.kloadgen.extractor.extractors.Extractor;
import com.sngular.kloadgen.model.FieldValueMapping;
import com.sngular.kloadgen.testutil.FileHelper;
import org.apache.avro.Schema;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.apache.avro.Schema;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;


class AvroConfluentExtractorTest {
Expand Down Expand Up @@ -230,18 +229,19 @@ void testFlatPropertiesRecordUnionReverseOrder() throws Exception {
FieldValueMapping.builder().fieldName("products[].Price.price").fieldType("string").fieldValueList("").valueLength(0).required(true).isAncestorRequired(true)
.build());
}

@Test
@DisplayName("Should Extract Schema instead AvroSchema")
void testCastException() throws Exception{
AvroConfluentExtractor avroce = mock(AvroConfluentExtractor.class);
ArgumentCaptor<Schema> argumentCaptor = ArgumentCaptor.forClass(Schema.class);
void testCastException() throws Exception {
final AvroConfluentExtractor avroCE = Mockito.mock(AvroConfluentExtractor.class);
final ArgumentCaptor<Schema> argumentCaptor = ArgumentCaptor.forClass(Schema.class);
final String testFile = fileHelper.getContent("/avro-files/testCastIssue.avsc");
final Schema schema = new Schema.Parser().parse(testFile);
avroce.processSchema(schema);
verify(avroce).processSchema(argumentCaptor.capture());
Schema captureSchema = argumentCaptor.getValue();
assertEquals(schema, captureSchema);
}
avroCE.processSchema(schema);

Mockito.verify(avroCE).processSchema(argumentCaptor.capture());
final Schema captureSchema = argumentCaptor.getValue();
Assertions.assertThat(schema).isEqualTo(captureSchema);
}

}

This file was deleted.

0 comments on commit dd0d794

Please sign in to comment.