6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8153732 8212202 8221263 8221412
27 * @requires (os.family == "Windows")
28 * @summary Windows remote printer changes do not reflect in lookupPrintServices()
29 * @run main/manual RemotePrinterStatusRefresh
30 */
31
32 import java.awt.BorderLayout;
33 import java.awt.Color;
34 import java.awt.Component;
35 import java.awt.GridLayout;
36 import java.awt.event.ActionEvent;
37 import java.awt.event.WindowAdapter;
38 import java.awt.event.WindowEvent;
39 import java.util.ArrayList;
40 import java.util.Collections;
41 import java.util.List;
42 import java.util.concurrent.CountDownLatch;
43 import javax.print.PrintService;
44 import javax.print.PrintServiceLookup;
45 import javax.swing.AbstractListModel;
46 import javax.swing.BorderFactory;
47 import javax.swing.Box;
48 import javax.swing.BoxLayout;
49 import javax.swing.DefaultListCellRenderer;
50 import javax.swing.GroupLayout;
51 import javax.swing.JButton;
52 import javax.swing.JFrame;
53 import javax.swing.JLabel;
54 import javax.swing.JList;
55 import javax.swing.JPanel;
56 import javax.swing.JScrollPane;
57 import javax.swing.JTextArea;
58 import javax.swing.JTextField;
59 import javax.swing.SwingUtilities;
60 import javax.swing.Timer;
61
62 import static javax.swing.BorderFactory.createTitledBorder;
63
64 public class RemotePrinterStatusRefresh extends WindowAdapter {
65
66 private static final long refreshTime = getRefreshTime();
67
68 private static final long TIMEOUT = refreshTime * 4 + 60;
69
70
71 private static final CountDownLatch latch = new CountDownLatch(1);
72 private static volatile RemotePrinterStatusRefresh test;
73
74 private volatile boolean testResult;
75 private volatile boolean testTimedOut;
76
77 private final JFrame frame;
78
79 private JButton refreshButton;
80 private JButton passButton;
81 private JButton failButton;
82
83 private final ServiceItemListModel beforeList;
84 private final ServiceItemListModel afterList;
85
164 component.setForeground(Color.WHITE);
165 break;
166 case ADDED:
167 component.setBackground(Color.GREEN);
168 component.setForeground(Color.BLACK);
169 break;
170 case UNCHANGED:
171 default:
172 break;
173 }
174 return component;
175 }
176 }
177
178 private static final String INSTRUCTIONS_TEXT =
179 "Please follow the steps for this manual test:\n"
180 + "Step 0: \"Before\" list is populated with currently "
181 + "configured printers.\n"
182 + "Step 1: Add or Remove a network printer using "
183 + "Windows Control Panel.\n"
184 + "Step 2: Wait for 4 minutes after adding or removing.\n"
185 + " \"Next printer refresh in\" gives you a "
186 + "rough estimation on when update will happen.\n"
187 + "Step 3: Click Refresh."
188 + "\"After\" list is populated with updated list "
189 + "of printers.\n"
190 + "Step 4: Compare the list of printers in \"Before\" and "
191 + "\"After\" lists.\n"
192 + " Added printers are highlighted with "
193 + "green color, removed ones \u2014 with "
194 + "red color.\n"
195 + "Step 5: Click Pass if the list of printers is correctly "
196 + "updated.\n"
197 + "Step 6: If the list is not updated, wait for another "
198 + "4 minutes, and then click Refresh again.\n"
199 + "Step 7: If the list does not update, click Fail.\n"
200 + "\n"
201 + "You have to click Refresh to enable Pass and Fail buttons. "
202 + "If no button is pressed,\n"
203 + "the test will time out. "
204 + "Closing the window also fails the test.";
205
206 public static void main(String[] args) throws Exception {
207 SwingUtilities.invokeAndWait(RemotePrinterStatusRefresh::createUI);
208
209 latch.await();
210 if (!test.testResult) {
211 throw new RuntimeException("Test failed"
212 + (test.testTimedOut ? " because of time out" : ""));
213 }
214 }
215
216 private static long getRefreshTime() {
217 String refreshTime =
218 System.getProperty("sun.java2d.print.minRefreshTime", "240");
219 try {
220 long value = Long.parseLong(refreshTime);
221 return value < 240L ? 240L : value;
222 } catch (NumberFormatException e) {
223 return 240L;
224 }
225 }
226
227 private static void createUI() {
228 test = new RemotePrinterStatusRefresh();
229 }
230
231 private RemotePrinterStatusRefresh() {
232 frame = new JFrame("RemotePrinterStatusRefresh");
233 frame.addWindowListener(this);
234
235
236 JPanel northPanel = new JPanel(new BorderLayout());
237 northPanel.add(createInfoPanel(), BorderLayout.NORTH);
238 northPanel.add(createInstructionsPanel(), BorderLayout.SOUTH);
239
240
241 beforeList = new ServiceItemListModel(
242 Collections.unmodifiableList(collectPrinterList()));
243 afterList = new ServiceItemListModel(new ArrayList<>());
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8153732 8212202 8221263 8221412 8222108
27 * @requires (os.family == "Windows")
28 * @summary Windows remote printer changes do not reflect in lookupPrintServices()
29 * @run main/manual/othervm -Dsun.java2d.print.minRefreshTime=120 RemotePrinterStatusRefresh
30 */
31
32 import java.awt.BorderLayout;
33 import java.awt.Color;
34 import java.awt.Component;
35 import java.awt.GridLayout;
36 import java.awt.event.ActionEvent;
37 import java.awt.event.WindowAdapter;
38 import java.awt.event.WindowEvent;
39 import java.util.ArrayList;
40 import java.util.Collections;
41 import java.util.List;
42 import java.util.concurrent.CountDownLatch;
43 import javax.print.PrintService;
44 import javax.print.PrintServiceLookup;
45 import javax.swing.AbstractListModel;
46 import javax.swing.BorderFactory;
47 import javax.swing.Box;
48 import javax.swing.BoxLayout;
49 import javax.swing.DefaultListCellRenderer;
50 import javax.swing.GroupLayout;
51 import javax.swing.JButton;
52 import javax.swing.JFrame;
53 import javax.swing.JLabel;
54 import javax.swing.JList;
55 import javax.swing.JPanel;
56 import javax.swing.JScrollPane;
57 import javax.swing.JTextArea;
58 import javax.swing.JTextField;
59 import javax.swing.SwingUtilities;
60 import javax.swing.Timer;
61
62 import static javax.swing.BorderFactory.createTitledBorder;
63
64 public class RemotePrinterStatusRefresh extends WindowAdapter {
65
66 private static final long DEFAULT_REFRESH_TIME = 240L;
67 private static final long MINIMAL_REFRESH_TIME = 120L;
68
69 private static final long refreshTime = getRefreshTime();
70
71 private static final long TIMEOUT = refreshTime * 4 + 60;
72
73
74 private static final CountDownLatch latch = new CountDownLatch(1);
75 private static volatile RemotePrinterStatusRefresh test;
76
77 private volatile boolean testResult;
78 private volatile boolean testTimedOut;
79
80 private final JFrame frame;
81
82 private JButton refreshButton;
83 private JButton passButton;
84 private JButton failButton;
85
86 private final ServiceItemListModel beforeList;
87 private final ServiceItemListModel afterList;
88
167 component.setForeground(Color.WHITE);
168 break;
169 case ADDED:
170 component.setBackground(Color.GREEN);
171 component.setForeground(Color.BLACK);
172 break;
173 case UNCHANGED:
174 default:
175 break;
176 }
177 return component;
178 }
179 }
180
181 private static final String INSTRUCTIONS_TEXT =
182 "Please follow the steps for this manual test:\n"
183 + "Step 0: \"Before\" list is populated with currently "
184 + "configured printers.\n"
185 + "Step 1: Add or Remove a network printer using "
186 + "Windows Control Panel.\n"
187 + "Step 2: Wait for 2\u20134 minutes after adding or removing.\n"
188 + " \"Next printer refresh in\" gives you a "
189 + "rough estimation on when update will happen.\n"
190 + "Step 3: Click Refresh."
191 + "\"After\" list is populated with updated list "
192 + "of printers.\n"
193 + "Step 4: Compare the list of printers in \"Before\" and "
194 + "\"After\" lists.\n"
195 + " Added printers are highlighted with "
196 + "green color, removed ones \u2014 with "
197 + "red color.\n"
198 + "Step 5: Click Pass if the list of printers is correctly "
199 + "updated.\n"
200 + "Step 6: If the list is not updated, wait for another "
201 + "2\u20134 minutes, and then click Refresh again.\n"
202 + "Step 7: If the list does not update, click Fail.\n"
203 + "\n"
204 + "You have to click Refresh to enable Pass and Fail buttons. "
205 + "If no button is pressed,\n"
206 + "the test will time out. "
207 + "Closing the window also fails the test.";
208
209 public static void main(String[] args) throws Exception {
210 SwingUtilities.invokeAndWait(RemotePrinterStatusRefresh::createUI);
211
212 latch.await();
213 if (!test.testResult) {
214 throw new RuntimeException("Test failed"
215 + (test.testTimedOut ? " because of time out" : ""));
216 }
217 }
218
219 private static long getRefreshTime() {
220 String refreshTime =
221 System.getProperty("sun.java2d.print.minRefreshTime",
222 Long.toString(DEFAULT_REFRESH_TIME));
223 try {
224 long value = Long.parseLong(refreshTime);
225 return value < MINIMAL_REFRESH_TIME ? MINIMAL_REFRESH_TIME : value;
226 } catch (NumberFormatException e) {
227 return DEFAULT_REFRESH_TIME;
228 }
229 }
230
231 private static void createUI() {
232 test = new RemotePrinterStatusRefresh();
233 }
234
235 private RemotePrinterStatusRefresh() {
236 frame = new JFrame("RemotePrinterStatusRefresh");
237 frame.addWindowListener(this);
238
239
240 JPanel northPanel = new JPanel(new BorderLayout());
241 northPanel.add(createInfoPanel(), BorderLayout.NORTH);
242 northPanel.add(createInstructionsPanel(), BorderLayout.SOUTH);
243
244
245 beforeList = new ServiceItemListModel(
246 Collections.unmodifiableList(collectPrinterList()));
247 afterList = new ServiceItemListModel(new ArrayList<>());
|