jdk/test/com/sun/servicetag/DuplicateNotFound.java
changeset 16802 ea3325542aa8
parent 16801 e2de240b437f
parent 16575 d7ad0dfaa411
child 16803 3bdc22a32b0e
equal deleted inserted replaced
16801:e2de240b437f 16802:ea3325542aa8
     1 /*
       
     2  * Copyright (c) 2008, 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.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 /*
       
    27  * @test
       
    28  * @bug     6622366
       
    29  * @summary Basic Test for RegistrationData.removeServiceTag and
       
    30  *          updateServiceTag.
       
    31  * @author  Mandy Chung
       
    32  *
       
    33  * @run build DuplicateNotFound Util
       
    34  * @run main DuplicateNotFound
       
    35  */
       
    36 
       
    37 import com.sun.servicetag.*;
       
    38 import java.io.*;
       
    39 import java.util.*;
       
    40 
       
    41 public class DuplicateNotFound {
       
    42     private static String servicetagDir = System.getProperty("test.src");
       
    43     private static String[] files = new String[] {
       
    44                                         "servicetag1.properties",
       
    45                                         "servicetag2.properties",
       
    46                                         "servicetag3.properties"
       
    47                                     };
       
    48 
       
    49     private static RegistrationData registration = new RegistrationData();
       
    50 
       
    51     public static void main(String[] argv) throws Exception {
       
    52         ServiceTag svcTag;
       
    53         registration.addServiceTag(loadServiceTag(files[0]));
       
    54         registration.addServiceTag(loadServiceTag(files[1]));
       
    55         testDuplicate(files[0]);
       
    56         testDuplicate(files[1]);
       
    57         testNotFound(files[2]);
       
    58     }
       
    59 
       
    60     private static void testDuplicate(String filename) throws Exception {
       
    61         boolean dup = false;
       
    62         try {
       
    63            registration.addServiceTag(loadServiceTag(filename));
       
    64         } catch (IllegalArgumentException e) {
       
    65            dup = true;
       
    66         }
       
    67         if (!dup) {
       
    68            throw new RuntimeException(filename +
       
    69                " added successfully but expected to be a duplicated.");
       
    70         }
       
    71     }
       
    72     private static void testNotFound(String filename) throws Exception {
       
    73         ServiceTag st = loadServiceTag(filename);
       
    74         ServiceTag svctag = registration.getServiceTag(st.getInstanceURN());
       
    75         if (svctag != null) {
       
    76            throw new RuntimeException(st.getInstanceURN() +
       
    77                " exists but expected not found");
       
    78         }
       
    79 
       
    80         svctag = registration.removeServiceTag(st.getInstanceURN());
       
    81         if (svctag != null) {
       
    82            throw new RuntimeException(st.getInstanceURN() +
       
    83                " exists but expected not found");
       
    84         }
       
    85 
       
    86         svctag = registration.updateServiceTag(st.getInstanceURN(), "testing");
       
    87         if (svctag != null) {
       
    88            throw new RuntimeException(st.getInstanceURN() +
       
    89                " updated successfully but expected not found.");
       
    90         }
       
    91     }
       
    92 
       
    93     private static ServiceTag loadServiceTag(String filename) throws Exception {
       
    94         File f = new File(servicetagDir, filename);
       
    95         return Util.newServiceTag(f);
       
    96     }
       
    97 }