jdk/test/javax/xml/bind/xjc/8032884/XjcOptionalPropertyTest.java
changeset 23713 d3927a03a94e
child 37779 7c84df693837
equal deleted inserted replaced
23712:d46a902c1aed 23713:d3927a03a94e
       
     1 /*
       
     2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     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 8032884
       
    27  * @summary Globalbindings optionalProperty="primitive" does not work when minOccurs=0
       
    28  * @run shell compile-schema.sh
       
    29  * @run main/othervm XjcOptionalPropertyTest
       
    30  */
       
    31 
       
    32 import java.io.IOException;
       
    33 import java.lang.reflect.Method;
       
    34 
       
    35 public class XjcOptionalPropertyTest {
       
    36 
       
    37     public static void main(String[] args) throws IOException {
       
    38 
       
    39         generated.Foo foo = new generated.Foo();
       
    40         log("foo = " + foo);
       
    41         Method[] methods = foo.getClass().getMethods();
       
    42         log("Found [" + methods.length + "] methods");
       
    43         for (int i = 0; i < methods.length; i++) {
       
    44             Method method = methods[i];
       
    45             if (method.getName().equals("setFoo")) {
       
    46                 log("Checking method [" + method.getName() + "]");
       
    47                 Class[] parameterTypes = method.getParameterTypes();
       
    48                 if (parameterTypes.length != 1)
       
    49                     fail("more than 1 parameter");
       
    50                 if (!parameterTypes[0].isPrimitive()) {
       
    51                     fail("Found [" + parameterTypes[0].getName() + "], but expected primitive!");
       
    52                 }
       
    53                 break;
       
    54             }
       
    55         }
       
    56         log("TEST PASSED.");
       
    57 
       
    58     }
       
    59 
       
    60     private static void fail(String message) {
       
    61         throw new RuntimeException(message);
       
    62     }
       
    63 
       
    64     private static void log(String msg) {
       
    65         System.out.println(msg);
       
    66     }
       
    67 
       
    68 }