Skip to content

Commit

Permalink
#340 update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jemacineiras committed Sep 21, 2023
1 parent 55dcb94 commit 4f1ab29
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import java.awt.Color;
import java.awt.Component;
import java.util.Objects;

import com.sngular.kloadgen.extractor.model.AsyncApiSchema;
import javax.swing.JLabel;
import javax.swing.JList;

import com.sngular.kloadgen.extractor.model.AsyncApiSchema;

public class ApiSchemaRenderer extends JLabel implements javax.swing.ListCellRenderer<AsyncApiSchema> {

protected ApiSchemaRenderer() {
Expand All @@ -17,35 +17,35 @@ protected ApiSchemaRenderer() {
@Override
public final Component getListCellRendererComponent(
final JList<? extends AsyncApiSchema> list, final AsyncApiSchema value, final int index, final boolean isSelected, final boolean cellHasFocus) {

setText(value.toString());

final Color background;
final Color foreground;

// check if this cell represents the current DnD drop location
final JList.DropLocation dropLocation = list.getDropLocation();
if (dropLocation != null
&& !dropLocation.isInsert()
&& dropLocation.getIndex() == index) {

background = Color.BLUE;
foreground = Color.WHITE;

// check if this cell is selected
} else if (isSelected) {
background = Color.RED;
foreground = Color.WHITE;

// unselected, and not the DnD drop location
} else {
background = Color.WHITE;
foreground = Color.BLACK;
if (Objects.nonNull(value)) {
setText(value.getTopicName());

final Color background;
final Color foreground;

// check if this cell represents the current DnD drop location
final JList.DropLocation dropLocation = list.getDropLocation();
if (dropLocation != null
&& !dropLocation.isInsert()
&& dropLocation.getIndex() == index) {

background = Color.BLUE;
foreground = Color.WHITE;

// check if this cell is selected
} else if (isSelected) {
background = Color.RED;
foreground = Color.WHITE;

// unselected, and not the DnD drop location
} else {
background = Color.WHITE;
foreground = Color.BLACK;
}

setBackground(background);
setForeground(foreground);
}

setBackground(background);
setForeground(foreground);

return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import java.awt.Color;
import java.awt.Component;
import java.util.Objects;

import com.sngular.kloadgen.extractor.model.AsyncApiServer;
import javax.swing.JLabel;
import javax.swing.JList;

import com.sngular.kloadgen.extractor.model.AsyncApiServer;

public class ApiServerRenderer extends JLabel implements javax.swing.ListCellRenderer<AsyncApiServer> {

protected ApiServerRenderer() {
Expand All @@ -18,34 +18,35 @@ protected ApiServerRenderer() {
public final Component getListCellRendererComponent(
final JList<? extends AsyncApiServer> list, final AsyncApiServer value, final int index, final boolean isSelected, final boolean cellHasFocus) {

setText(value.toString());
if (Objects.nonNull(value)) {
setText(value.getName());

final Color background;
final Color foreground;
final Color background;
final Color foreground;

// check if this cell represents the current DnD drop location
final JList.DropLocation dropLocation = list.getDropLocation();
if (dropLocation != null
&& !dropLocation.isInsert()
&& dropLocation.getIndex() == index) {
// check if this cell represents the current DnD drop location
final JList.DropLocation dropLocation = list.getDropLocation();
if (dropLocation != null
&& !dropLocation.isInsert()
&& dropLocation.getIndex() == index) {

background = Color.BLUE;
foreground = Color.WHITE;
background = Color.BLUE;
foreground = Color.WHITE;

// check if this cell is selected
} else if (isSelected) {
background = Color.RED;
foreground = Color.WHITE;
// check if this cell is selected
} else if (isSelected) {
background = Color.RED;
foreground = Color.WHITE;

// unselected, and not the DnD drop location
} else {
background = Color.WHITE;
foreground = Color.BLACK;
}

setBackground(background);
setForeground(foreground);
// unselected, and not the DnD drop location
} else {
background = Color.WHITE;
foreground = Color.BLACK;
}

setBackground(background);
setForeground(foreground);
}
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.List;
import java.util.Objects;

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;
Expand All @@ -34,7 +34,9 @@
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
Expand All @@ -45,13 +47,9 @@
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.gui.JLabeledTextField;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;

public final class AsyncApiConfigGui extends AbstractSamplerGui {

private static final Logger log = LoggingManager.getLoggerForClass();

private final JFileChooser fileChooser = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());

private final ApiExtractor asyncApiExtractor = new AsyncApiExtractorImpl();
Expand Down Expand Up @@ -93,7 +91,7 @@ private void init() {
.createTitledBorder(BorderFactory.createLoweredBevelBorder(), "AsyncApi Module", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));

mainPanel.add(createAsyncApiFileSelectPanel(), BorderLayout.NORTH);
mainPanel.add(createAsyncApiTabs(), BorderLayout.SOUTH);
mainPanel.add(createAsyncApiTabs(), BorderLayout.CENTER);
add(mainPanel);
}

Expand Down Expand Up @@ -146,13 +144,17 @@ public void actionFileChooser(final ActionEvent event) {
final int returnValue = fileChooser.showDialog(mainPanel, JMeterUtils.getResString("file_visualizer_open"));

if (JFileChooser.APPROVE_OPTION == returnValue) {
final File apiFile = Objects.requireNonNull(fileChooser.getSelectedFile());
asyncApiFileTextField.setText(apiFile.getAbsolutePath());
final var asyncApiFile = asyncApiExtractor.processFile(apiFile);
asyncApiFile.getApiServerList().forEach(serverComboBox::addItem);
fillTable(brokerFieldModel, asyncApiExtractor.getBrokerData(asyncApiFile));
fillTable(schemaRegistryFieldModel, asyncApiExtractor.getSchemaRegistryData(asyncApiFile));
asyncApiExtractor.getSchemaDataMap(asyncApiFile).values().forEach(topicComboBox::addItem);
try {
final File apiFile = Objects.requireNonNull(fileChooser.getSelectedFile());
asyncApiFileTextField.setText(apiFile.getAbsolutePath());
final var asyncApiFile = asyncApiExtractor.processFile(apiFile);
asyncApiFile.getApiServerList().forEach(serverComboBox::addItem);
fillTable(brokerFieldModel, asyncApiExtractor.getBrokerData(asyncApiFile));
fillTable(schemaRegistryFieldModel, asyncApiExtractor.getSchemaRegistryData(asyncApiFile));
asyncApiExtractor.getSchemaDataMap(asyncApiFile).values().forEach(topicComboBox::addItem);
} catch (KLoadGenException ex) {
JOptionPane.showMessageDialog(mainPanel, "Error has occurred: " + ex.getMessage(), "Weird Error", JOptionPane.ERROR_MESSAGE);
}
}
}

Expand Down Expand Up @@ -188,54 +190,31 @@ private JPanel createBrokerPanel() {
brokerPanel.add(new JLabeledTextField("Broker Server"));
serverComboBox = new JComboBox<>();
serverComboBox.setRenderer(new ApiServerRenderer());
brokerPanel.add(serverComboBox);
brokerPanel.add(new JTable(brokerFieldModel), BorderLayout.CENTER);
brokerPanel.add(serverComboBox, BorderLayout.NORTH);
brokerPanel.add(new JScrollPane(new JTable(brokerFieldModel)), BorderLayout.CENTER);
return brokerPanel;
}

private JPanel createRegistryTab() {
final JPanel registryUrlPanel = new JPanel();
registryUrlPanel.setLayout(new GridBagLayout());
registryUrlPanel.setMinimumSize(new Dimension(45, 45));
registryUrlPanel.setPreferredSize(new Dimension(800, 600));
final JLabel label2 = new JLabel();
label2.setText("Schema Registry URL");
var gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = GridBagConstraints.WEST;
registryUrlPanel.add(label2, gridBagConstraints);
registryUrlPanel.setLayout(new BorderLayout(0, 0));
registryUrlPanel.add(new JLabeledTextField("Schema Registry URL"));
this.registryUrl = new JTextField();
this.registryUrl.setPreferredSize(new Dimension(249, 30));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = GridBagConstraints.WEST;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
registryUrlPanel.add(this.registryUrl, gridBagConstraints);
final JPanel panel5 = new JPanel();
panel5.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = GridBagConstraints.BOTH;
registryUrlPanel.add(panel5, gridBagConstraints);
final JLabel label3 = new JLabel();
label3.setText("Security Options");
panel5.add(label3);
panel5.add(new JTable(schemaRegistryFieldModel));
registryUrlPanel.add(this.registryUrl, BorderLayout.NORTH);
registryUrlPanel.add(new JScrollPane(new JTable(schemaRegistryFieldModel)), BorderLayout.CENTER);
return registryUrlPanel;
}

private JPanel createSchemaTab() {
final JPanel schemaTab = new JPanel();
schemaTab.setLayout(new BorderLayout(5, 5));
schemaTab.setLayout(new BorderLayout(0, 0));
schemaTab.add(new JLabeledTextField("Schema Configuration"));
topicComboBox = new JComboBox<>();
topicComboBox.setRenderer(new ApiSchemaRenderer());
topicComboBox.addActionListener(this::topicComboActionListener);
schemaTab.add(topicComboBox);
schemaTab.add(new JTable(schemaFieldModel));
schemaTab.add(topicComboBox, BorderLayout.NORTH);
schemaTab.add(new JScrollPane(new JTable(schemaFieldModel)), BorderLayout.CENTER);
return schemaTab;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
Expand Down Expand Up @@ -78,7 +79,7 @@ private AsyncApiSchema mapNodeToSchema(final Map<String, JsonNode> components, f
private List<FieldValueMapping> messageToFieldList(final JsonNode message, final Map<String, JsonNode> components, final List<String> antiLoopList) {
var payload = ApiTool.getNode(message, "payload");
if (ApiTool.hasRef(message)) {
payload = solveRef(message, components, antiLoopList, "messages");
payload = ApiTool.getNode(solveRef(message, components, antiLoopList, "messages"), "payload");
} else if (!ApiTool.hasNode(message, "payload")) {
throw new KLoadGenException("AsyncApi format still not supported");
}
Expand Down
51 changes: 51 additions & 0 deletions src/test/resources/asyncapi/event-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
asyncapi: 2.0.0
info:
title: Email Service
version: '1.0.0'
description: |
Sends emails upon certain events
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0

servers:
production:
url: mqtt://test.mosquitto.org
protocol: mqtt
description: Test MQTT broker

channels:
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
properties:
firstName:
type: string
description: "foo"
lastName:
type: string
description: "bar"
email:
type: string
format: email
description: "baz"
createdAt:
type: string
format: date-time
description: "foo"

0 comments on commit 4f1ab29

Please sign in to comment.