Skip to content

Commit

Permalink
Fix all non-requiered and empty fields issues
Browse files Browse the repository at this point in the history
  • Loading branch information
GraciMndzSNG committed Nov 17, 2023
1 parent 565322e commit b2e5770
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
29 changes: 16 additions & 13 deletions src/main/java/com/sngular/kloadgen/processor/SchemaProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

package com.sngular.kloadgen.processor;

import java.util.*;
import java.util.ArrayDeque;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import com.sngular.kloadgen.common.SchemaTypeEnum;
Expand All @@ -17,7 +20,6 @@
import com.sngular.kloadgen.processor.util.SchemaProcessorUtils;
import com.sngular.kloadgen.schemaregistry.adapter.impl.BaseSchemaMetadata;
import com.sngular.kloadgen.schemaregistry.adapter.impl.SchemaMetadataAdapter;
import lombok.NonNull;
import lombok.SneakyThrows;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.RandomUtils;
Expand Down Expand Up @@ -168,21 +170,22 @@ private void makeFieldValueMappingRequired(final FieldValueMapping fieldValueMap

private ArrayDeque<FieldValueMapping> calculateFieldsToProcess() {

ArrayDeque<FieldValueMapping> arrayBool;
ArrayDeque<FieldValueMapping> fieldToProcess;
final ArrayDeque<FieldValueMapping> initialFieldExpMappingsQueue = new ArrayDeque<>(fieldExprMappings);
List<FieldValueMapping> fieldExprMappingAux;
arrayBool = new ArrayDeque<>(ListUtils.select(fieldExprMappings, fieldValueMapping -> shouldProcessField(fieldValueMapping, initialFieldExpMappingsQueue)));
if (arrayBool.isEmpty()) {
fieldExprMappingAux = fieldExprMappings;
arrayBool = new ArrayDeque<>(ListUtils.select(fieldExprMappingAux, this::shouldProcessFieldIfIsNonRequiered));
fieldToProcess = new ArrayDeque<>(ListUtils.select(fieldExprMappings, fieldValueMapping -> shouldProcessField(fieldValueMapping, initialFieldExpMappingsQueue)));

if (fieldToProcess.isEmpty())
fieldToProcess = new ArrayDeque<>(ListUtils.select(fieldExprMappings, this::shouldProcessFieldIfIsNonRequiered));

if(fieldToProcess.isEmpty()) {
while (initialFieldExpMappingsQueue.size()>1){
initialFieldExpMappingsQueue.removeFirst();
}
fieldToProcess = new ArrayDeque<>(initialFieldExpMappingsQueue);
}
return arrayBool;
return fieldToProcess;
}

/*private ArrayDeque<FieldValueMapping> verifyMandatoryField(ArrayDeque<FieldValueMapping> initialFieldExpMappingsQueue, ArrayDeque<FieldValueMapping> arrayBool) {
initialFieldExpMappingsQueue.
}*/

private boolean shouldProcessFieldIfIsNonRequiered(final FieldValueMapping fieldValueMapping/*, final ArrayDeque<FieldValueMapping> initialFieldExpMappingsQueue*/){
boolean shouldProcess = false;
//final String[] fields = fieldValueMapping.getFieldName().split("\\.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.sngular.kloadgen.extractor.ApiExtractor;
import com.sngular.kloadgen.extractor.asyncapi.AsyncApiExtractorImpl;
import com.sngular.kloadgen.extractor.model.AsyncApiFile;
import com.sngular.kloadgen.extractor.model.AsyncApiSR;
import com.sngular.kloadgen.loadgen.BaseLoadGenerator;
import com.sngular.kloadgen.loadgen.impl.JsonSRLoadGenerator;
import com.sngular.kloadgen.model.FieldValueMapping;
Expand Down Expand Up @@ -66,6 +65,7 @@ public final boolean applies(final ConfigTestElement configElement) {

@Override
public final SampleResult sample(final Entry entry) {

final var sampleResult = new SampleResult();
sampleResult.setThreadName("AsyncApi Sampler");
sampleResult.sampleStart();
Expand Down Expand Up @@ -206,8 +206,4 @@ private String prettyPrint(final RecordMetadata recordMetadata) {
private Object getObject(final EnrichedRecord messageVal, final boolean isKloadSerializer) {
return isKloadSerializer ? messageVal : messageVal.getGenericRecord();
}

public void setAsyncApiRegistry(AsyncApiSR selectedItem) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void modifyTestElement(final TestElement element) {
asyncApiSampler.setSchemaFieldConfiguration(mapVector(schemaFieldModel.getDataVector()));
}
}
//asyncApiSampler.setAsyncApiRegistry((AsyncApiSR) registryComboBox.getSelectedItem());
// asyncApiSampler.setAsyncApiRegistry((AsyncApiSR) registryComboBox.getSelectedItem());
}
configureTestElement(element);
}
Expand Down Expand Up @@ -198,13 +198,10 @@ private void populateData(final AsyncApiSampler element) {
.forEach(propertyMapping ->
propertyList.add(Pair.of(propertyMapping.getPropertyName(), propertyMapping.getPropertyValue())));
fillTable(brokerFieldModel, propertyList);
/* final var schemaRegistryList = asyncApiExtractor.getSchemaRegistryData(asyncApiFile);
/*final var schemaRegistryList = asyncApiExtractor.getSchemaRegistryData(asyncApiFile);
if (!schemaRegistryList.isEmpty()) {
fillTable(schemaRegistryFieldModel, prepareSRServer(schemaRegistryList.get(0)));
}
registryComboBox.removeAllItems();
asyncApiExtractor.getSchemaRegistryData(asyncApiFile);
registryComboBox.setSelectedIndex(0);*/
}*/
topicComboBox.removeAllItems();
asyncApiExtractor.getSchemaDataMap(asyncApiFile).values().forEach(topicComboBox::addItem);
topicComboBox.setSelectedIndex(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import lombok.Getter;

@Getter
public class ConfluentSchemaMetadata implements SchemaMetadataAdapter {
public class ConfluentSchemaMetadata implements SchemaMetadataAdapter {

private final Integer id;

Expand Down
18 changes: 11 additions & 7 deletions src/test/resources/asyncapi/event-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@ servers:
description: Test MQTT broker

channels:
user-signedup:
user_signedup:
publish:
operationId: onUserSignUp
message:
$ref : '#/components/messages/UserSignedUp'

components:
messages:
UserSignedUp:
name: userSignedUp
title: User signed up event
summary: Inform about a new user registration in the system
contentType: application/json
payload:
$ref: '#/components/schemas/userSignedUpPayload'

schemas:
userSignedUpPayload:
type: object
Expand All @@ -39,9 +48,4 @@ components:
createdAt:
type: string
format: date-time
description: "foo"
messages:
UserSignedUp:
payload:
$ref : '#/components/schemas/userSignedUpPayload'

description: "foo"

0 comments on commit b2e5770

Please sign in to comment.