Skip to content

Commit 42d571a

Browse files
committed
Implement Copilot Chat GUI and Test Element for JMeter integration
1 parent 70c987f commit 42d571a

3 files changed

Lines changed: 22 additions & 44 deletions

File tree

src/main/java/org/apache/jmeter/plugins/copilot/CopilotChatVisualizer.java renamed to src/main/java/org/apache/jmeter/plugins/copilot/CopilotChatConfigGui.java

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,39 @@
2020

2121
import javax.swing.BorderFactory;
2222
import javax.swing.Box;
23-
import javax.swing.JComponent;
2423
import javax.swing.JPanel;
2524

25+
import org.apache.jmeter.config.gui.AbstractConfigGui;
2626
import org.apache.jmeter.plugins.copilot.gui.CopilotChatPanel;
27-
import org.apache.jmeter.samplers.SampleResult;
2827
import org.apache.jmeter.testelement.TestElement;
29-
import org.apache.jmeter.visualizers.gui.AbstractVisualizer;
3028
import org.slf4j.Logger;
3129
import org.slf4j.LoggerFactory;
3230

3331
import com.google.auto.service.AutoService;
3432

3533
/**
36-
* JMeter Visualizer plugin that provides a GitHub Copilot Chat interface
34+
* JMeter Config Element plugin that provides a GitHub Copilot Chat interface
3735
* for generating JMeter test plans through natural language conversation.
3836
*
3937
* This plugin allows users to describe the tests they want to create, and
4038
* Copilot will generate the appropriate JMeter elements and add them to
4139
* the test plan.
4240
*/
4341
@AutoService(org.apache.jmeter.gui.JMeterGUIComponent.class)
44-
public class CopilotChatVisualizer extends AbstractVisualizer {
42+
public class CopilotChatConfigGui extends AbstractConfigGui {
4543

4644
private static final long serialVersionUID = 1L;
47-
private static final Logger log = LoggerFactory.getLogger(CopilotChatVisualizer.class);
45+
private static final Logger log = LoggerFactory.getLogger(CopilotChatConfigGui.class);
4846

4947
private CopilotChatPanel chatPanel;
5048
private JPanel mainPanel;
5149

5250
/**
53-
* Creates a new CopilotChatVisualizer instance.
51+
* Creates a new CopilotChatConfigGui instance.
5452
*/
55-
public CopilotChatVisualizer() {
53+
public CopilotChatConfigGui() {
5654
super();
57-
log.info("Initializing Copilot Chat Visualizer");
55+
log.info("Initializing Copilot Chat Config Element");
5856
init();
5957
}
6058

@@ -89,8 +87,6 @@ private void init() {
8987
*/
9088
private void onTestPlanGenerated(String testPlanXml) {
9189
log.info("Test plan generated by Copilot");
92-
// This will be implemented to integrate with JMeter's GUI
93-
// to add the generated elements to the test plan tree
9490
try {
9591
JMeterTestPlanIntegrator.integrateTestPlan(testPlanXml);
9692
} catch (Exception e) {
@@ -110,31 +106,16 @@ public String getStaticLabel() {
110106
}
111107

112108
@Override
113-
public void add(SampleResult sample) {
114-
// This visualizer doesn't process sample results
115-
// It's used for test generation, not result visualization
116-
}
117-
118-
@Override
119-
public void clearData() {
120-
// Clear the chat history if needed
121-
if (chatPanel != null) {
122-
chatPanel.clearChat();
123-
}
124-
}
125-
126-
@Override
127-
public TestElement makeTestElement() {
109+
public TestElement createTestElement() {
128110
CopilotChatTestElement element = new CopilotChatTestElement();
129111
modifyTestElement(element);
130112
return element;
131113
}
132114

133115
@Override
134116
public void modifyTestElement(TestElement element) {
135-
super.modifyTestElement(element);
117+
configureTestElement(element);
136118
if (element instanceof CopilotChatTestElement copilotElement) {
137-
// Save any configuration from the GUI to the test element
138119
copilotElement.setModel(chatPanel.getSelectedModel());
139120
}
140121
}
@@ -143,18 +124,20 @@ public void modifyTestElement(TestElement element) {
143124
public void configure(TestElement element) {
144125
super.configure(element);
145126
if (element instanceof CopilotChatTestElement copilotElement) {
146-
// Load configuration from the test element to the GUI
147127
chatPanel.setSelectedModel(copilotElement.getModel());
148128
}
149129
}
150130

151131
@Override
152-
public JComponent getPrintableComponent() {
153-
return mainPanel;
132+
public void clearGui() {
133+
super.clearGui();
134+
if (chatPanel != null) {
135+
chatPanel.clearChat();
136+
}
154137
}
155138

156139
/**
157-
* Clean up resources when the visualizer is being disposed.
140+
* Clean up resources when the config element is being disposed.
158141
*/
159142
public void dispose() {
160143
if (chatPanel != null) {

src/main/java/org/apache/jmeter/plugins/copilot/CopilotChatTestElement.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
*/
1717
package org.apache.jmeter.plugins.copilot;
1818

19-
import org.apache.jmeter.testelement.AbstractTestElement;
19+
import org.apache.jmeter.config.ConfigTestElement;
2020

2121
/**
22-
* Test element that holds configuration for the Copilot Chat visualizer.
23-
* This element stores settings like the selected AI model and chat history.
22+
* Test element that holds configuration for the Copilot Chat config element.
23+
* This element stores settings like the selected AI model.
2424
*/
25-
public class CopilotChatTestElement extends AbstractTestElement {
25+
public class CopilotChatTestElement extends ConfigTestElement {
2626

2727
private static final long serialVersionUID = 1L;
2828

src/main/java/org/apache/jmeter/plugins/copilot/gui/CopilotChatPanel.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import java.awt.FlowLayout;
2323
import java.awt.Font;
2424
import java.awt.event.ActionEvent;
25-
import java.awt.event.KeyAdapter;
26-
import java.awt.event.KeyEvent;
2725
import java.io.File;
2826
import java.nio.charset.StandardCharsets;
2927
import java.nio.file.Files;
@@ -169,12 +167,9 @@ private JPanel createInputPanel() {
169167
// Input field
170168
inputField = new JTextField();
171169
inputField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 14));
172-
inputField.addKeyListener(new KeyAdapter() {
173-
@Override
174-
public void keyPressed(KeyEvent e) {
175-
if (e.getKeyCode() == KeyEvent.VK_ENTER && !isProcessing) {
176-
sendMessage();
177-
}
170+
inputField.addActionListener(e -> {
171+
if (!isProcessing) {
172+
sendMessage();
178173
}
179174
});
180175

0 commit comments

Comments
 (0)