jdk/test/java/awt/Desktop/8064934/bug8064934.java
author yan
Tue, 23 Jun 2015 11:59:27 +0300
changeset 31448 1066345d2a8a
parent 29514 973914c573fc
permissions -rw-r--r--
8076468: Add @modules to tests in jdk_desktop test group Reviewed-by: yan, alexsch
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
31448
1066345d2a8a 8076468: Add @modules to tests in jdk_desktop test group
yan
parents: 29514
diff changeset
    29
 * @modules java.desktop/sun.awt
29514
973914c573fc 8074092: Newly introduced unnecessary dependencies on internal API in client regtests
yan
parents: 29005
diff changeset
    30
 * @build jdk.testlibrary.OSInfo
29005
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    31
 * @run main bug8064934
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    32
 */
29514
973914c573fc 8074092: Newly introduced unnecessary dependencies on internal API in client regtests
yan
parents: 29005
diff changeset
    33
import jdk.testlibrary.OSInfo;
29005
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    34
import java.awt.*;
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    35
import java.io.File;
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    36
import java.io.IOException;
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    37
import java.security.AccessController;
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    38
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    39
public class bug8064934 {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    40
    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
    41
            " the specified file for this operation.";
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    42
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    43
    public static void main(String[] args) {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    44
        // This test is intended only for Windows
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    45
        if (AccessController.doPrivileged(OSInfo.getOSTypeAction()) != OSInfo.OSType.WINDOWS) {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    46
            System.out.println("The test is for Windows platform only");
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    47
            return;
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
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    50
        // Test whether Desktop is supported of not
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    51
        if (!Desktop.isDesktopSupported()) {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    52
            System.out.println("Desktop is not supported");
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    53
            return;
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
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    56
        Desktop desktop = Desktop.getDesktop();
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    57
        // Test whether open action is supported or not
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    58
        if (!desktop.isSupported(Desktop.Action.OPEN)) {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    59
            System.out.println("Desktop.Action.OPEN is not supported");
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    60
            return;
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
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    63
        File file = null;
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    64
        try {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    65
            file = File.createTempFile("test", ".foo");
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    66
            if (!file.exists()) {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    67
                throw new RuntimeException("Can not create temp file");
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    68
            }
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    69
            desktop.open(file);
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    70
        } catch (IOException ioe) {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    71
            String errorMessage = ioe.getMessage().trim();
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    72
            if (errorMessage != null && !errorMessage.endsWith(NO_ASSOCIATION_ERROR_MESSAGE)) {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    73
                throw new RuntimeException("Test FAILED! Wrong Error message: \n" +
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    74
                        "Actual " + errorMessage.substring(errorMessage.indexOf("Error message:")) + "\n" +
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    75
                        "Expected " + NO_ASSOCIATION_ERROR_MESSAGE);
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    76
            }
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    77
        } finally {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    78
            if (file != null) {
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    79
                file.delete();
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
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    83
        System.out.println("Test PASSED!");
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    84
    }
7d7a78defc8f 8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
diff changeset
    85
}