Skip to content

Commit 2dc6ace

Browse files
add test runner panel that works outside of SQL Developer
1 parent 43a3f77 commit 2dc6ace

File tree

2 files changed

+294
-0
lines changed

2 files changed

+294
-0
lines changed
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/*
2+
* Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.utplsql.sqldev.ui.runner
17+
18+
import java.awt.Color
19+
import java.awt.Component
20+
import java.awt.GridBagConstraints
21+
import java.awt.GridBagLayout
22+
import java.awt.Insets
23+
import javax.swing.JLabel
24+
import javax.swing.JPanel
25+
import javax.swing.JProgressBar
26+
import javax.swing.plaf.basic.BasicProgressBarUI
27+
import org.utplsql.sqldev.model.LimitedLinkedHashMap
28+
import org.utplsql.sqldev.model.runner.Run
29+
import org.utplsql.sqldev.resources.UtplsqlResources
30+
31+
class RunnerPanel {
32+
LimitedLinkedHashMap<String, Run> runs = new LimitedLinkedHashMap<String, Run>(10)
33+
JPanel basePanel
34+
JLabel statusLabel
35+
JLabel testCounterValueLabel
36+
JLabel errorCounterValueLabel
37+
JLabel failureCounterValueLabel
38+
JProgressBar progressBar;
39+
40+
def Component getGUI() {
41+
if (basePanel === null) {
42+
initializeGUI()
43+
}
44+
return basePanel
45+
}
46+
47+
def setStatus(String text) {
48+
statusLabel.text = text
49+
}
50+
51+
def setModel(Run run) {
52+
runs.put(run.reporterId, run)
53+
}
54+
55+
def updateCounter() {
56+
val run = currentRun
57+
testCounterValueLabel.text = '''«run.totalNumberOfCompletedTests»/«run.totalNumberOfTests»'''
58+
errorCounterValueLabel.text = '''«run.counter.error»'''
59+
failureCounterValueLabel.text = '''«run.counter.failure»'''
60+
if (run.totalNumberOfTests == 0) {
61+
progressBar.value = 100
62+
} else {
63+
progressBar.value = 100 * run.totalNumberOfCompletedTests / run.totalNumberOfTests
64+
}
65+
if (run.counter.error > 0 || run.counter.failure > 0) {
66+
progressBar.foreground = Color.RED
67+
} else {
68+
progressBar.foreground = Color.GREEN
69+
}
70+
}
71+
72+
private def getCurrentRun() {
73+
return runs.values.get(runs.values.length - 1)
74+
}
75+
76+
private def initializeGUI() {
77+
// Base panel containing all components
78+
basePanel = new JPanel()
79+
basePanel.setLayout(new GridBagLayout())
80+
var GridBagConstraints c = new GridBagConstraints()
81+
82+
// Status line
83+
statusLabel = new JLabel
84+
c.gridx = 0
85+
c.gridy = 0
86+
c.gridwidth = 6
87+
c.gridheight = 1
88+
c.insets = new Insets(10, 10, 10, 10) // top, left, bottom, right
89+
c.anchor = GridBagConstraints::WEST
90+
c.fill = GridBagConstraints::HORIZONTAL
91+
c.weightx = 1
92+
c.weighty = 0
93+
basePanel.add(statusLabel, c)
94+
95+
// Test counter
96+
val testCounterLabel = new JLabel(UtplsqlResources.getString("RUNNER_TESTS_LABEL") + ":",
97+
UtplsqlResources.getIcon("UTPLSQL_ICON"), JLabel::LEADING)
98+
c.gridx = 0
99+
c.gridy = 1
100+
c.gridwidth = 1
101+
c.gridheight = 1
102+
c.insets = new Insets(10, 10, 10, 5) // top, left, bottom, right
103+
c.anchor = GridBagConstraints::WEST
104+
c.fill = GridBagConstraints::NONE
105+
c.weightx = 0
106+
c.weighty = 0
107+
basePanel.add(testCounterLabel, c)
108+
testCounterValueLabel = new JLabel
109+
c.gridx = 1
110+
c.gridy = 1
111+
c.gridwidth = 1
112+
c.gridheight = 1
113+
c.insets = new Insets(10, 0, 10, 10) // top, left, bottom, right
114+
c.anchor = GridBagConstraints::WEST
115+
c.fill = GridBagConstraints::NONE
116+
c.weightx = 0
117+
c.weighty = 0
118+
basePanel.add(testCounterValueLabel, c)
119+
120+
// Error counter
121+
val errorCounterLabel = new JLabel(UtplsqlResources.getString("RUNNER_ERRORS_LABEL") + ":",
122+
UtplsqlResources.getIcon("ERROR_ICON"), JLabel::LEADING)
123+
c.gridx = 2
124+
c.gridy = 1
125+
c.gridwidth = 1
126+
c.gridheight = 1
127+
c.insets = new Insets(10, 10, 10, 5) // top, left, bottom, right
128+
c.anchor = GridBagConstraints::WEST
129+
c.fill = GridBagConstraints::NONE
130+
c.weightx = 0
131+
c.weighty = 0
132+
basePanel.add(errorCounterLabel, c)
133+
errorCounterValueLabel = new JLabel
134+
c.gridx = 3
135+
c.gridy = 1
136+
c.gridwidth = 1
137+
c.gridheight = 1
138+
c.insets = new Insets(10, 0, 10, 10) // top, left, bottom, right
139+
c.anchor = GridBagConstraints::WEST
140+
c.fill = GridBagConstraints::NONE
141+
c.weightx = 0
142+
c.weighty = 0
143+
basePanel.add(errorCounterValueLabel, c)
144+
145+
// Failure counter
146+
val failureCounterLabel = new JLabel(UtplsqlResources.getString("RUNNER_FAILURES_LABEL") + ":",
147+
UtplsqlResources.getIcon("FAILURE_ICON"), JLabel::LEADING)
148+
c.gridx = 4
149+
c.gridy = 1
150+
c.gridwidth = 1
151+
c.gridheight = 1
152+
c.insets = new Insets(10, 10, 10, 5) // top, left, bottom, right
153+
c.anchor = GridBagConstraints::WEST
154+
c.fill = GridBagConstraints::NONE
155+
c.weightx = 0
156+
c.weighty = 0
157+
basePanel.add(failureCounterLabel, c)
158+
failureCounterValueLabel = new JLabel
159+
c.gridx = 5
160+
c.gridy = 1
161+
c.gridwidth = 1
162+
c.gridheight = 1
163+
c.insets = new Insets(10, 0, 10, 10) // top, left, bottom, right
164+
c.anchor = GridBagConstraints::WEST
165+
c.fill = GridBagConstraints::NONE
166+
c.weightx = 0
167+
c.weighty = 0
168+
basePanel.add(failureCounterValueLabel, c)
169+
170+
// Progress bar
171+
progressBar = new JProgressBar
172+
progressBar.stringPainted = false
173+
progressBar.foreground = Color.GREEN
174+
progressBar.UI = new BasicProgressBarUI
175+
c.gridx = 0
176+
c.gridy = 2
177+
c.gridwidth = 6
178+
c.gridheight = 1
179+
c.insets = new Insets(10, 10, 10, 10) // top, left, bottom, right
180+
c.anchor = GridBagConstraints::WEST
181+
c.fill = GridBagConstraints::HORIZONTAL
182+
c.weightx = 1
183+
c.weighty = 0
184+
basePanel.add(progressBar, c)
185+
186+
// Vertical spring
187+
val spring = new JLabel
188+
c.gridx = 0
189+
c.gridy = 3
190+
c.gridwidth = 6
191+
c.gridheight = 1
192+
c.insets = new Insets(10, 10, 10, 10) // top, left, bottom, right
193+
c.anchor = GridBagConstraints::WEST
194+
c.fill = GridBagConstraints::BOTH
195+
c.weightx = 1
196+
c.weighty = 1
197+
basePanel.add(spring, c)
198+
}
199+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2018 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.utplsql.sqldev.test.runner
17+
18+
import java.awt.Toolkit
19+
import java.util.UUID
20+
import javax.swing.JFrame
21+
import javax.swing.SwingUtilities
22+
import org.junit.Before
23+
import org.junit.Test
24+
import org.utplsql.sqldev.model.runner.Run
25+
import org.utplsql.sqldev.resources.UtplsqlResources
26+
import org.utplsql.sqldev.ui.runner.RunnerPanel
27+
28+
class UtplsqlRunnerPanelTest {
29+
var Run run
30+
31+
@Before
32+
def void setup() {
33+
val reporterId = UUID.randomUUID().toString.replace("-", "")
34+
run = new Run(null, reporterId)
35+
run.startTime = "2019-06-09T13:42:42.123456"
36+
run.counter.disabled = 0
37+
run.counter.success = 0
38+
run.counter.failure = 0
39+
run.counter.error = 0
40+
run.counter.warning = 0
41+
run.totalNumberOfTests = 5
42+
}
43+
44+
@Test
45+
def void showGUI() {
46+
val start = System.currentTimeMillis
47+
val frame = new JFrame("utPLSQL Runner Panel")
48+
frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE;
49+
val panel = new RunnerPanel
50+
panel.model = run
51+
val gui = panel.getGUI
52+
53+
SwingUtilities.invokeLater(new Runnable() {
54+
override run() {
55+
frame.add(gui)
56+
frame.pack
57+
val dim = Toolkit.getDefaultToolkit().getScreenSize();
58+
frame.setLocation(dim.width / 2 - frame.getSize().width / 2, dim.height / 2 - frame.getSize().height / 2);
59+
frame.setVisible(true)
60+
}
61+
});
62+
63+
panel.status = "starting"
64+
panel.updateCounter
65+
Thread.sleep(3000);
66+
67+
run.counter.success = run.counter.success + 1
68+
panel.status = "utplsql.test.a"
69+
panel.updateCounter
70+
Thread.sleep(500);
71+
72+
run.counter.success = run.counter.success + 1
73+
panel.status = "utplsql.test.b"
74+
panel.updateCounter
75+
Thread.sleep(500);
76+
77+
run.counter.success = run.counter.success + 1
78+
panel.status = "utplsql.test.c"
79+
panel.updateCounter
80+
Thread.sleep(500);
81+
82+
run.counter.failure = run.counter.failure + 1
83+
panel.status = "utplsql.test.d"
84+
panel.updateCounter
85+
Thread.sleep(500);
86+
87+
run.counter.success = run.counter.success + 1
88+
val end = System.currentTimeMillis
89+
panel.status = String.format(UtplsqlResources.getString("RUNNER_FINNISHED_TEXT"), new Double(end-start)/1000)
90+
panel.updateCounter
91+
Thread.sleep(2000);
92+
frame.dispose
93+
}
94+
95+
}

0 commit comments

Comments
 (0)