File: derbyrunjartest.java

package info (click to toggle)
derby 10.14.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 78,896 kB
  • sloc: java: 691,930; sql: 42,686; xml: 20,511; sh: 3,373; sed: 96; makefile: 60
file content (158 lines) | stat: -rw-r--r-- 6,551 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*

   Derby - Class org.apache.derbyTesting.functionTests.tests.tools.derbyrunjartest

   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

 */

package org.apache.derbyTesting.functionTests.tests.tools;

import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import junit.framework.Test;
import org.apache.derbyTesting.junit.BaseTestCase;
import org.apache.derbyTesting.junit.BaseTestSuite;
import org.apache.derbyTesting.junit.Derby;
import org.apache.derbyTesting.junit.SecurityManagerSetup;

/**
 * Basic tests for exercising the {@code org.apache.derby.iapi.tools.run}
 * class found in {@code derbyrun.jar}.
 */
public class derbyrunjartest extends BaseTestCase {

    public derbyrunjartest(String name) {
        super(name);
    }

    public static Test suite() {
        Class cl = derbyrunjartest.class;

        BaseTestSuite suite = new BaseTestSuite(cl);

        // The server command can only be used on platforms that support
        // the network server.
        if (Derby.hasServer()) {
            suite.addTest(new derbyrunjartest("xtestServer"));
        }

        return new SecurityManagerSetup(
                suite,
                cl.getName().replace('.', '/') + ".policy",
                true);
    }

    /**
     * Invoke {@code org.apache.derby.iapi.tools.run} in a sub-process.
     *
     * @param toolArgs the arguments to pass to derbyrun.jar
     * @param output expected lines of output
     * @param exitCode expected exit code for the command
     */
    private void runtool(String[] toolArgs, String[] output, int exitCode)
            throws Exception {
        String runClassName = org.apache.derby.iapi.tools.run.class.getName();
        URL result = SecurityManagerSetup.getURL(runClassName);
        String derbyrunloc = null;

        if (result.toString().endsWith(".jar")) {
            derbyrunloc = result.toString().substring(5);
            if (System.getProperty("os.name").startsWith("Windows"))
              derbyrunloc = derbyrunloc.substring(1);
        }

        ArrayList<String> cmdArgs = new ArrayList<String>();

        // Invoke java -jar derbyrun.jar if we are running from jars, or
        // with fully qualified class name if we are running from classes.
        if (derbyrunloc == null) {
            cmdArgs.add(runClassName);
        } else {
            cmdArgs.add("-jar");
            cmdArgs.add(derbyrunloc);
        }

        cmdArgs.addAll(Arrays.asList(toolArgs));

        String[] cmd = cmdArgs.toArray(new String[cmdArgs.size()]);
        assertExecJavaCmdAsExpected(output, cmd, exitCode);
    }

    public void testIJ() throws Exception {
        String[] cmd = { "ij", "--help" };
        String[] output = {
            "Usage: java org.apache.derby.tools.ij [-p propertyfile] [inputfile]"
        };
        runtool(cmd, output, 0);
    }

    public void testSysinfo() throws Exception {
        String[] cmd = { "sysinfo", "-cp", "help" };
        String[] output = {
            "Usage: java org.apache.derby.tools.sysinfo -cp [ [ embedded ][ server ][ client] [ tools ] [ anyClass.class ] ]"
        };
        runtool(cmd, output, 0);
    }

    public void testDblook() throws Exception {
        String[] cmd = { "dblook" };
        String[] output = {
            " Usage:",
            " java org.apache.derby.tools.dblook -d <source database url> [options]",
            " 	where the source URL is the full URL, including the connection protocol",
            " 	and any connection attributes that might apply.  For example, use",
            " 	options include:",
            " 	-z <schema name> to specify a schema to which the DDL generation",
            " 	 should be limited.  Only database objects with that schema will have",
            " 	 their DDL generated.",
            " 	-t <table one> <table two> ... to specify a list of tables for which",
            " 	 the DDL will be generated; any tables not in the list will be ignored.",
            " 	-td <value> to specify what should be appended to the end",
            " 	 of each DDL statement.",
            "		This defaults to ';'.",
            " 	-noview to prevent the generation of DDL for views.",
            " 	-append to keep from overwriting the output files.",
            " 	-verbose to have error messages printed to the console (in addition",
            " 	 to the log file).  If not specified, errors will only be printed to the",
            " 	 log file.",
            " 	-o <filename> to specify the file name to which the generated DDL",
            " 	 will be written.",
            " 		If not specified, default is the console.",
        };
        runtool(cmd, output, 0);
    }

    public void xtestServer() throws Exception {
        String[] cmd = { "server" };
        String[] output = {
            "Usage: NetworkServerControl <commands> ",
            "Commands:",
            "start [-h <host>] [-p <port number>] [-noSecurityManager] [-ssl <ssl mode>]",
            "shutdown [-h <host>][-p <port number>] [-ssl <ssl mode>] [-user <username>] [-password <password>]",
            "ping [-h <host>][-p <port number>] [-ssl <ssl mode>]",
            "sysinfo [-h <host>][-p <port number>] [-ssl <ssl mode>]",
            "runtimeinfo [-h <host>][-p <port number>] [-ssl <ssl mode>]",
            "logconnections { on|off } [-h <host>][-p <port number>] [-ssl <ssl mode>]",
            "maxthreads <max>[-h <host>][-p <port number>] [-ssl <ssl mode>]",
            "timeslice <milliseconds>[-h <host>][-p <port number>] [-ssl <ssl mode>]",
            "trace { on|off } [-s <session id>][-h <host>][-p <port number>] [-ssl <ssl mode>]",
            "tracedirectory <trace directory>[-h <host>][-p <port number>] [-ssl <ssl mode>]",
        };
        runtool(cmd, output, 1);
    }
}