Skip to content

Commit f9f3a54

Browse files
committed
添加测试功能,基本完成
1 parent f27cc5e commit f9f3a54

File tree

11 files changed

+138
-57
lines changed

11 files changed

+138
-57
lines changed

build.gradle

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ apply plugin: 'application'
1919
apply plugin: 'io.objectbox'
2020

2121
group 'com.longforus'
22-
version '1.0-SNAPSHOT'
22+
version '1.0'
2323

2424

2525
repositories {
@@ -49,22 +49,28 @@ dependencies {
4949
implementation "io.objectbox:objectbox-windows:$objectboxVersion"
5050
implementation "io.objectbox:objectbox-java:$objectboxVersion"
5151
kapt "io.objectbox:objectbox-processor:$objectboxVersion"
52-
// compile 'org.hamcrest:hamcrest-core:1.3'
5352
implementation 'com.google.code.gson:gson:2.8.5'
5453
implementation 'org.apache.commons:commons-lang3:3.8'
55-
implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0'
5654
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
5755
implementation 'com.jgoodies:jgoodies-forms:1.9.0'
5856
}
5957

6058

6159

60+
61+
62+
//task copyRes(type: Copy, dependsOn: compileJava) {
63+
// compileJava.getOutputs().files.forEach{f->
64+
// println(f.getAbsolutePath())
65+
// }
66+
//}
67+
6268
// enable debug output for plugin
6369
objectbox {
6470
debug true
6571
}
6672
// enable debug output for annotation processor
6773
tasks.withType(JavaCompile) {
6874
options.compilerArgs += [ "-Aobjectbox.debug=true" ]
69-
options.compilerArgs += [ "-Aobjectbox.modelPath=$projectDir/schemas/objectbox.json" ]
75+
options.encoding = "UTF-8"
7076
}

linux/META-INF/MANIFEST.MF

Lines changed: 0 additions & 3 deletions
This file was deleted.

objectbox-windows-x64.dll

-684 KB
Binary file not shown.

src/main/java/com/longforus/apidebugger/ui/DefaultParamsDialog.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414
import java.awt.event.WindowEvent;
1515
import java.util.ArrayList;
1616
import java.util.List;
17-
import java.util.stream.Collectors;
1817
import javax.swing.JButton;
1918
import javax.swing.JComponent;
2019
import javax.swing.JDialog;
2120
import javax.swing.JPanel;
2221
import javax.swing.JScrollPane;
2322
import javax.swing.JTable;
2423
import javax.swing.KeyStroke;
25-
import org.apache.commons.lang3.StringUtils;
2624

2725
public class DefaultParamsDialog extends JDialog {
2826
private JPanel contentPane;
@@ -32,7 +30,7 @@ public class DefaultParamsDialog extends JDialog {
3230
private JButton mAddRowButton;
3331
private JButton mDeleteRowButton;
3432
private JButton mClearButton;
35-
private MyParamsTableModel mModel;
33+
private ParamsTableModel mModel;
3634

3735
public DefaultParamsDialog() {
3836
setContentPane(contentPane);

src/main/java/com/longforus/apidebugger/ui/MainPanel.form

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@
208208
</constraints>
209209
<properties>
210210
<foreground color="-1"/>
211-
<text value="Concurrent test"/>
211+
<text value="Pressure test"/>
212212
</properties>
213213
</component>
214214
<component id="8ef11" class="javax.swing.JTextField" binding="tvTestCount">
@@ -221,7 +221,7 @@
221221
<toolTipText value="test count"/>
222222
</properties>
223223
</component>
224-
<component id="67965" class="javax.swing.JButton" binding="mStartButton" default-binding="true">
224+
<component id="67965" class="javax.swing.JButton" binding="mBtnStartTest">
225225
<constraints>
226226
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
227227
</constraints>
@@ -256,6 +256,16 @@
256256
<toolTipText value=" Set Current Project Default Parameter"/>
257257
</properties>
258258
</component>
259+
<component id="6bdcc" class="javax.swing.JProgressBar" binding="mPb">
260+
<constraints>
261+
<grid row="9" column="12" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
262+
<forms defaultalign-horz="false"/>
263+
</constraints>
264+
<properties>
265+
<maximumSize width="50" height="10"/>
266+
<preferredSize width="50" height="10"/>
267+
</properties>
268+
</component>
259269
</children>
260270
</grid>
261271
</form>

src/main/java/com/longforus/apidebugger/ui/MainPanel.java

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.awt.Insets;
2525
import java.awt.Toolkit;
2626
import java.awt.event.ItemEvent;
27+
import java.awt.event.KeyAdapter;
2728
import java.awt.event.KeyEvent;
2829
import java.awt.event.KeyListener;
2930
import java.awt.event.MouseEvent;
@@ -42,6 +43,7 @@
4243
import javax.swing.JMenuItem;
4344
import javax.swing.JPanel;
4445
import javax.swing.JPopupMenu;
46+
import javax.swing.JProgressBar;
4547
import javax.swing.JScrollPane;
4648
import javax.swing.JTable;
4749
import javax.swing.JTextField;
@@ -61,7 +63,7 @@
6163
*/
6264

6365
public class MainPanel extends JFrame {
64-
private MyParamsTableModel mMyParamsTableModel;
66+
private ParamsTableModel mParamsTableModel;
6567
private JComboBox mCbBaseUrl;
6668
private JButton mBtnSaveBaseUrl;
6769
private JComboBox mCbApiUrl;
@@ -80,9 +82,18 @@ public class MainPanel extends JFrame {
8082
private BrowserView mBrowserView;
8183
private JButton mbtnDp;
8284
private JTextField tvTestCount;
83-
private JButton mStartButton;
85+
private JButton mBtnStartTest;
86+
private JProgressBar mPb;
8487
private Browser mBrowser;
8588

89+
public JProgressBar getPb() {
90+
return mPb;
91+
}
92+
93+
public JTextField getTvTestCount() {
94+
return tvTestCount;
95+
}
96+
8697
public JComboBox getCbMethod() {
8798
return mCbMethod;
8899
}
@@ -91,8 +102,8 @@ public JTable getTbParams() {
91102
return mTbParams;
92103
}
93104

94-
public MyParamsTableModel getMyParamsTableModel() {
95-
return mMyParamsTableModel;
105+
public ParamsTableModel getParamsTableModel() {
106+
return mParamsTableModel;
96107
}
97108

98109
public JComboBox getCbEncrypt() {
@@ -139,6 +150,16 @@ public MainPanel(String title) throws HeadlessException {
139150
e.printStackTrace();
140151
}
141152
mCbMethod.setModel(new DefaultComboBoxModel(new String[] { "POST", "GET" }));
153+
//限制只能输入数字
154+
tvTestCount.addKeyListener(new KeyAdapter() {
155+
public void keyTyped(KeyEvent e) {
156+
int keyChar = e.getKeyChar();
157+
if (keyChar < KeyEvent.VK_0 || keyChar > KeyEvent.VK_9) {
158+
e.consume(); //关键,屏蔽掉非法输入
159+
}
160+
}
161+
});
162+
142163
setContentPane(baseP);
143164
setJMenuBar(UILifecycleHandler.INSTANCE.getMenuBar());
144165
initEvent();
@@ -152,9 +173,7 @@ public MainPanel(String title) throws HeadlessException {
152173
int y = 0;
153174
setLocation(x, y);
154175
setVisible(true);
155-
156176
browserInit();
157-
158177
//Observable.create((ObservableOnSubscribe<String>) emitter -> emitter.onNext("{}")).delay(10, TimeUnit.MILLISECONDS).subscribe(
159178
// s -> mBrowser.executeJavaScript("app.doc" + "._id || (document.location.href = document.location.pathname + \"#/new\", location.reload())"));
160179

@@ -229,6 +248,7 @@ private void initEvent() {
229248
mCbMethod.addItemListener(e -> UIActionHandler.INSTANCE.onMethodChanged(mCbMethod.getSelectedIndex()));
230249
mCbEncrypt.addItemListener(e -> UIActionHandler.INSTANCE.onEncryptTypeChanged(((IEncryptHandler) e.getItem()).getTypeCode()));
231250
mbtnDp.addActionListener(e -> showDefaultParamsDialog());
251+
mBtnStartTest.addActionListener(e -> UIActionHandler.INSTANCE.onStartTest());
232252
}
233253

234254
private void showDefaultParamsDialog() {
@@ -307,11 +327,11 @@ protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirem
307327
}
308328

309329
public void resetParamsTbModel() {
310-
mMyParamsTableModel = MainPanel.resetParamsTbModel(mTbParams);
330+
mParamsTableModel = MainPanel.resetParamsTbModel(mTbParams);
311331
}
312332

313-
public static MyParamsTableModel resetParamsTbModel(JTable table) {
314-
MyParamsTableModel model = new MyParamsTableModel();
333+
public static ParamsTableModel resetParamsTbModel(JTable table) {
334+
ParamsTableModel model = new ParamsTableModel();
315335
table.setModel(model);
316336
table.getColumnModel().getColumn(0).setPreferredWidth(50);
317337
table.getColumnModel().getColumn(1).setPreferredWidth(120);
@@ -320,7 +340,7 @@ public static MyParamsTableModel resetParamsTbModel(JTable table) {
320340
}
321341

322342
private void initTable() {
323-
mMyParamsTableModel = resetParamsTbModel(mTbParams);
343+
mParamsTableModel = resetParamsTbModel(mTbParams);
324344
mTbParams.addKeyListener(new KeyListener() {
325345
@Override
326346
public void keyTyped(KeyEvent e) {
@@ -335,18 +355,18 @@ public void keyPressed(KeyEvent e) {
335355
@Override
336356
public void keyReleased(KeyEvent e) {
337357
if (e.getKeyCode() == KeyEvent.VK_DELETE) {
338-
mMyParamsTableModel.removeRow(mTbParams.getSelectedRow());
358+
mParamsTableModel.removeRow(mTbParams.getSelectedRow());
339359
}
340360
}
341361
});
342362
btnAddRow.addActionListener(e -> {
343-
mMyParamsTableModel.addEmptyRow();
363+
mParamsTableModel.addEmptyRow();
344364
mTbParams.requestFocus();
345-
int index = mMyParamsTableModel.getRowCount() - 1;
365+
int index = mParamsTableModel.getRowCount() - 1;
346366
mTbParams.setRowSelectionInterval(index, index);//最后一行获得焦点
347367
mTbParams.editCellAt(index, 1);
348368
});
349-
btnDelRow.addActionListener(e -> mMyParamsTableModel.removeRow(mTbParams.getSelectedRow()));
369+
btnDelRow.addActionListener(e -> mParamsTableModel.removeRow(mTbParams.getSelectedRow()));
350370
btnClear.addActionListener(e -> UIActionHandler.INSTANCE.onClearParams());
351371
}
352372

@@ -471,7 +491,7 @@ public String getCurBaseUrl() {
471491
baseP.add(panel2, cc.xyw(1, 5, 3));
472492
final JLabel label3 = new JLabel();
473493
label3.setForeground(new Color(-1));
474-
label3.setText("Concurrent test");
494+
label3.setText("Pressure test");
475495
panel2.add(label3, new com.intellij.uiDesigner.core.GridConstraints(0, 0, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_WEST,
476496
com.intellij.uiDesigner.core.GridConstraints.FILL_NONE, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED,
477497
com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
@@ -480,9 +500,9 @@ public String getCurBaseUrl() {
480500
panel2.add(tvTestCount, new com.intellij.uiDesigner.core.GridConstraints(0, 1, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_WEST,
481501
com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_WANT_GROW,
482502
com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
483-
mStartButton = new JButton();
484-
mStartButton.setText("Start");
485-
panel2.add(mStartButton, new com.intellij.uiDesigner.core.GridConstraints(0, 2, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER,
503+
mBtnStartTest = new JButton();
504+
mBtnStartTest.setText("Start");
505+
panel2.add(mBtnStartTest, new com.intellij.uiDesigner.core.GridConstraints(0, 2, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER,
486506
com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL,
487507
com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW,
488508
com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
@@ -494,6 +514,10 @@ public String getCurBaseUrl() {
494514
mbtnDp.setText(" Default Parameter");
495515
mbtnDp.setToolTipText(" Set Current Project Default Parameter");
496516
baseP.add(mbtnDp, cc.xyw(7, 5, 3));
517+
mPb = new JProgressBar();
518+
mPb.setMaximumSize(new Dimension(50, 10));
519+
mPb.setPreferredSize(new Dimension(50, 10));
520+
baseP.add(mPb, cc.xy(13, 10, CellConstraints.FILL, CellConstraints.DEFAULT));
497521
}
498522

499523
/** @noinspection ALL */

src/main/java/com/longforus/apidebugger/ui/MyParamsTableModel.java renamed to src/main/java/com/longforus/apidebugger/ui/ParamsTableModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import javax.swing.table.AbstractTableModel;
88
import org.apache.commons.lang3.StringUtils;
99

10-
public class MyParamsTableModel extends AbstractTableModel {
10+
public class ParamsTableModel extends AbstractTableModel {
1111
//单元格元素类型
1212
private Class[] cellType = { Boolean.class, String.class, String.class };
1313
//表头
@@ -20,7 +20,7 @@ public class MyParamsTableModel extends AbstractTableModel {
2020

2121
private List<TableBean> data = new ArrayList<>();
2222

23-
public MyParamsTableModel() {
23+
public ParamsTableModel() {
2424
}
2525

2626
public List<TableBean> getData() {

src/main/kotlin/com/longforus/apidebugger/HttpManage.kt

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,51 @@ import java.util.concurrent.TimeUnit
1616
object HttpManage {
1717

1818
lateinit var mainPanel: MainPanel
19-
var startTime: Long = 0
2019
val okHttpClient = OkHttpClient.Builder().writeTimeout(30, TimeUnit.SECONDS)
2120
.readTimeout(30, TimeUnit.SECONDS)
2221
.connectTimeout(30, TimeUnit.SECONDS).build()
2322

2423

25-
fun sendRequest() {
24+
fun sendTestRequest(request: Request? = getRequest(), isLast: Boolean = false, allCount: Int = 0,startTime:Long = 0) {
25+
request?.let {
26+
if (!isLast) {
27+
okHttpClient.newCall(request).enqueue(object : Callback {
28+
override fun onFailure(call: Call, e: IOException) {
29+
}
30+
31+
override fun onResponse(call: Call, response: Response) {
32+
synchronized(this@HttpManage) {
33+
com.longforus.apidebugger.mainPanel.pb.value += 1
34+
}
35+
}
36+
})
37+
} else {
38+
doRequest(request,startTime,allCount)
39+
}
40+
}
41+
}
42+
43+
fun sendRequest(request: Request? = getRequest()) {
44+
request?.let {
45+
doRequest(request)
46+
}
47+
}
48+
49+
50+
fun getRequest(): Request? {
2651
val url = getAbsoluteUrl(mainPanel.curApiUrl)
2752
if (url.isEmpty()) {
28-
return
53+
return null
2954
}
30-
val request = buildRequest(url, UIActionHandler.getParamsMap(mainPanel.myParamsTableModel, false), mainPanel.curMethod, mainPanel.curEncryptCode)
31-
doRequest(request)
55+
return buildRequest(url, UIActionHandler.getParamsMap(mainPanel.paramsTableModel, false), mainPanel.curMethod, mainPanel.curEncryptCode)
3256
}
3357

3458

35-
private fun doRequest(request: Request) {
36-
37-
startTime = System.currentTimeMillis()
59+
private fun doRequest(request: Request, startTime: Long = System.currentTimeMillis(), allCount: Int = 0) {
3860
okHttpClient.newCall(request).enqueue(object : Callback {
3961
override fun onFailure(call: Call, e: IOException) {
40-
mainPanel.lbStatus.text = "onFailure message : ${e.message} "
41-
// val byteArrayOutputStream = ByteArrayOutputStream()
42-
// val ps = PrintStream(byteArrayOutputStream)
43-
// e.printStackTrace(ps)
44-
45-
mainPanel.tpInfo.append("consuming: ${System.currentTimeMillis() - startTime}ms \n ", Color.BLUE)
46-
62+
mainPanel.lbStatus.text = "onFailure message : ${e.message}\n"
63+
mainPanel.tpInfo.append("consuming: ${System.currentTimeMillis() - startTime}ms \n", Color.BLUE)
4764
}
4865

4966
@Throws(IOException::class)
@@ -65,6 +82,11 @@ object HttpManage {
6582
mainPanel.tpInfo.append("code = ${response.code()} \n ", Color.RED)
6683
mainPanel.tpInfo.append("message = ${response.message()} \n", Color.RED)
6784
}
85+
if (allCount!=0) {
86+
mainPanel.tpInfo.append("\nAll test count: $allCount \n", Color.GREEN)
87+
mainPanel.tpInfo.append("\nSuccess test count: ${mainPanel.pb.value} \n", Color.GREEN)
88+
mainPanel.tpInfo.append("\nThe total time consuming: ${System.currentTimeMillis() - startTime}ms \n", Color.GREEN)
89+
}
6890
}
6991
})
7092
}

0 commit comments

Comments
 (0)