jdk/test/sun/jvmstat/monitor/VmIdentifier/VmIdentifierCreateResolve.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4990825
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary test that VmIdentifier objects get created as expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.xml.parsers.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import org.xml.sax.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import org.xml.sax.helpers.DefaultHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.jvmstat.monitor.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class VmIdentifierCreateResolve {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        File testcases =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                new File(System.getProperty("test.src", "."), "testcases");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        SAXParserFactory spf = SAXParserFactory.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        SAXParser sp = spf.newSAXParser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        DefaultHandler dh = new VmIdentifierTestHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        sp.parse(testcases, dh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
class VmIdentifierTestHandler extends DefaultHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static final boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static final int START                     = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static final int VMIDENTIFIER_TESTS        = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static final int TESTCASE                  = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static final int DESCRIPTION               = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static final int VMIDENTIFIER              = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static final int HOSTIDENTIFIER            = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static final int RESOLVED                  = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private TestCase test;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private String value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private int state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private Attributes attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public VmIdentifierTestHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public void characters(char[] ch, int start, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        String s = new String(ch, start, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            System.out.println("characters: start = " + start +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                               " length = " + length +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                               " chars = " + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            value = s.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            value = value + s.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                System.out.println("characters: appended characters to "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                   + "previous value: new value = " + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public void endDocument() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            System.out.println("endDocument()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public void endElement(String namespaceURI, String localName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                           String qName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                throws SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            System.out.println("endElement(): namespaceURI = " + namespaceURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                               + " localName = " + localName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                               + " qName = " + qName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                               + " state = " + state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        case START:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            throw new RuntimeException("Unexpected state: " + state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        case VMIDENTIFIER_TESTS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            state = START;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        case TESTCASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            if (test == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                throw new RuntimeException("Unexpected thread state");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
              System.out.println("running test case " + test.id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
              test.run();            // run the test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
              throw new SAXException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            state = VMIDENTIFIER_TESTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            test = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        case DESCRIPTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            test.setDescription(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            state = TESTCASE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        case VMIDENTIFIER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            test.setExpectedVmIdentifier(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            state = TESTCASE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        case HOSTIDENTIFIER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            test.setExpectedHostIdentifier(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            state = TESTCASE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        case RESOLVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            test.setResolvedVmIdentifier(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            state = TESTCASE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            throw new RuntimeException("Unexpected state: " + state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public void endPrefixMapping(String prefix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            System.out.println("endPrefixMapping(): prefix = " + prefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public void ignorableWhitespace(char[] ch, int start, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            System.out.println("ignoreableWhitespace():"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                               + " ch = " + new String(ch, start, length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                               + " start = " + start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                               + " length = " + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public void processingInstruction(String target, String data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            System.out.println("processingInstruction():"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                               + " target = " + target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                               + " data = " + data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public void setDocumentLocator(Locator locator) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            System.out.println("setDocumentLocator(): locator = " + locator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public void skippedEntity(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            System.out.println("skippedEntity(): name = " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public void startDocument() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            System.out.println("startDocument():");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public void startElement(String namespaceURI, String localName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                             String qName, Attributes attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            System.out.println("startElement():"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                               + " namespaceURI = " + namespaceURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                               + " localName = " + localName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                               + " qName = " + qName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                               + " state = " + state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            System.out.println("   Attributes(" + attributes.getLength() + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            for (int i = 0; i < attributes.getLength(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                System.out.println("     name = " + attributes.getQName(i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                   + " value = " + attributes.getValue(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        this.attributes = attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        case START:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            if (qName.compareTo("VmIdentifierTests") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                state = VMIDENTIFIER_TESTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                System.err.println("unexpected input: state = " + state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                   + " input = " + qName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        case VMIDENTIFIER_TESTS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            if (qName.compareTo("testcase") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                state = TESTCASE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                int id_n = attributes.getIndex("id");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                if (id_n == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    throw new RuntimeException("id attribute expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                int vmid_n = attributes.getIndex("VmIdentifierInput");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                if (vmid_n == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                            "VmIdentifier attribute expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                String hostid_input = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                int hostid_n = attributes.getIndex("HostIdentifierInput");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                if (hostid_n != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    hostid_input = attributes.getValue(hostid_n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                String vmid_input = attributes.getValue(vmid_n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                String id = attributes.getValue(id_n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                test = new TestCase(id, vmid_input, hostid_input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                System.err.println("unexpected input: state = " + state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                   + " input = " + qName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        case TESTCASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            if (test == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                throw new RuntimeException("TestCase null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            if (qName.compareTo("description") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                state = DESCRIPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            } else if (qName.compareTo("VmIdentifier") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                state = VMIDENTIFIER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            } else if (qName.compareTo("HostIdentifier") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                state = HOSTIDENTIFIER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            } else if (qName.compareTo("Resolved") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                state = RESOLVED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                System.err.println("unexpected input: state = " + state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                                   + " input = " + qName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        case DESCRIPTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        case VMIDENTIFIER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        case HOSTIDENTIFIER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        case RESOLVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            if (test == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                throw new RuntimeException("TestCase null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            System.err.println("Unexpected state: " + state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public void startPrefixMapping(String prefix, String uri) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            System.out.println("startPrefixMapping():"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                               + " prefix = " + prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                               + " uri = " + uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
class VmIdentifierException extends Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    String result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    TestCase test;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    VmIdentifierException(TestCase test, String result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        this.test = test;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        this.result = result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public String getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        return "Test " + test.id + " " + "Failed: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
               + "Expected = " + test.expectedVmIdentifier + " "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
               + "Actual = " + result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
class HostIdentifierException extends Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    String result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    TestCase test;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    HostIdentifierException(TestCase test, String result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        this.test = test;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        this.result = result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public String getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return "Test " + test.id + " " + "Failed: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
               + "Expected = " + test.expectedHostIdentifier + " "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
               + "Actual = " + result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
class ResolvedVmIdentifierException extends Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    String result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    TestCase test;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    ResolvedVmIdentifierException(TestCase test, String result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        this.test = test;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        this.result = result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public String getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return "Test " + test.id + " " + "Failed: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
               + "Expected = " + test.resolvedVmIdentifier + " "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
               + "Actual = " + result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
class TestCase {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    private static final boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    String id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    String vmid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    String hostid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    String expectedVmIdentifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    String expectedHostIdentifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    String resolvedVmIdentifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    String description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public TestCase(String id, String vmid, String hostid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        this.vmid = vmid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        this.hostid = hostid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public void run() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (expectedVmIdentifier == null || expectedHostIdentifier == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                || resolvedVmIdentifier == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    "expected values not initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        VmIdentifier test_vmid = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        HostIdentifier test_hostid = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        VmIdentifier resolved_vmid =  null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            System.out.println("creating VmIdentifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        test_vmid = new VmIdentifier(vmid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            System.out.println("creating HostIdentifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        if (hostid != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            test_hostid = new HostIdentifier(hostid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            test_hostid = new HostIdentifier(test_vmid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            System.out.println("resolving VmIdentifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        resolved_vmid =  test_hostid.resolve(test_vmid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        String test_vmid_str = test_vmid.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        String test_hostid_str = test_hostid.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        String resolved_vmid_str = resolved_vmid.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            System.out.println("comparing VmIdentifier result");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        if (test_vmid_str.compareTo(expectedVmIdentifier) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            throw new VmIdentifierException(this, test_vmid_str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            System.out.println("comparing HostIdentifier result");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        if (test_hostid_str.compareTo(expectedHostIdentifier) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            throw new HostIdentifierException(this, test_hostid_str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            System.out.println("comparing VmIdentifier result");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        if (resolved_vmid_str.compareTo(resolvedVmIdentifier) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            throw new ResolvedVmIdentifierException(this, resolved_vmid_str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    public void setDescription(String description) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        this.description = description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    public void setExpectedVmIdentifier(String expectedVmIdentifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            System.out.println("setting vmidentifier string to " + vmid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        this.expectedVmIdentifier = expectedVmIdentifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    public void setExpectedHostIdentifier(String expectedHostIdentifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        this.expectedHostIdentifier = expectedHostIdentifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    public void setResolvedVmIdentifier(String resolvedVmIdentifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        this.resolvedVmIdentifier = resolvedVmIdentifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
}