jdk/test/java/awt/Desktop/8064934/bug8064934.java
author yan
Thu, 05 Mar 2015 11:07:48 +0300
changeset 29514 973914c573fc
parent 29005 7d7a78defc8f
child 31448 1066345d2a8a
permissions -rw-r--r--
8074092: Newly introduced unnecessary dependencies on internal API in client regtests Reviewed-by: serb, azvegint
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29005
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
     1
/*
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
     4
 *
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
     8
 *
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    13
 * accompanied this code).
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    14
 *
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    18
 *
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    21
 * questions.
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    22
 */
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    23
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    24
/* @test
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    25
 * @bug 8064934
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    26
 * @summary Incorrect Exception message from java.awt.Desktop.open()
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    27
 * @author Dmitry Markov
29514
973914c573fc 8074092: Newly introduced unnecessary dependencies on internal API in client regtests
yan
parents: 29005
diff changeset
    28
 * @library ../../../../lib/testlibrary
973914c573fc 8074092: Newly introduced unnecessary dependencies on internal API in client regtests
yan
parents: 29005
diff changeset
    29
 * @build jdk.testlibrary.OSInfo
29005
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    30
 * @run main bug8064934
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    31
 */
29514
973914c573fc 8074092: Newly introduced unnecessary dependencies on internal API in client regtests
yan
parents: 29005
diff changeset
    32
import jdk.testlibrary.OSInfo;
29005
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    33
import java.awt.*;
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    34
import java.io.File;
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    35
import java.io.IOException;
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    36
import java.security.AccessController;
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    37
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    38
public class bug8064934 {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    39
    private static final String NO_ASSOCIATION_ERROR_MESSAGE = "Error message: No application is associated with" +
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    40
            " the specified file for this operation.";
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    41
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    42
    public static void main(String[] args) {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    43
        // This test is intended only for Windows
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    44
        if (AccessController.doPrivileged(OSInfo.getOSTypeAction()) != OSInfo.OSType.WINDOWS) {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    45
            System.out.println("The test is for Windows platform only");
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    46
            return;
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    47
        }
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    48
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    49
        // Test whether Desktop is supported of not
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    50
        if (!Desktop.isDesktopSupported()) {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    51
            System.out.println("Desktop is not supported");
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    52
            return;
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    53
        }
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    54
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    55
        Desktop desktop = Desktop.getDesktop();
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    56
        // Test whether open action is supported or not
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    57
        if (!desktop.isSupported(Desktop.Action.OPEN)) {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    58
            System.out.println("Desktop.Action.OPEN is not supported");
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    59
            return;
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    60
        }
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    61
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    62
        File file = null;
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    63
        try {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    64
            file = File.createTempFile("test", ".foo");
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    65
            if (!file.exists()) {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    66
                throw new RuntimeException("Can not create temp file");
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    67
            }
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    68
            desktop.open(file);
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    69
        } catch (IOException ioe) {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    70
            String errorMessage = ioe.getMessage().trim();
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    71
            if (errorMessage != null && !errorMessage.endsWith(NO_ASSOCIATION_ERROR_MESSAGE)) {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    72
                throw new RuntimeException("Test FAILED! Wrong Error message: \n" +
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    73
                        "Actual " + errorMessage.substring(errorMessage.indexOf("Error message:")) + "\n" +
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    74
                        "Expected " + NO_ASSOCIATION_ERROR_MESSAGE);
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    75
            }
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    76
        } finally {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    77
            if (file != null) {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    78
                file.delete();
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    79
            }
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    80
        }
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    81
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    82
        System.out.println("Test PASSED!");
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    83
    }
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    84
}