KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > tools > sysinfo_api


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.tests.tools.sysinfo_api
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derbyTesting.functionTests.tests.tools;
23
24 import java.io.IOException JavaDoc;
25 import java.io.BufferedReader JavaDoc;
26 import java.io.PipedReader JavaDoc;
27 import java.io.PipedWriter JavaDoc;
28 import java.io.PrintWriter JavaDoc;
29 import java.sql.Connection JavaDoc;
30 import java.sql.DatabaseMetaData JavaDoc;
31 import java.sql.SQLException JavaDoc;
32 import org.apache.derby.tools.sysinfo;
33 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
34
35 /**
36  * Test all the static public methods of the sysinfo class.
37  */

38
39 public class sysinfo_api extends BaseJDBCTestCase {
40
41     DatabaseMetaData JavaDoc dm;
42
43     public sysinfo_api(String JavaDoc name) {
44         super(name);
45     }
46
47     /*
48      * getMajorVersion()
49      */

50     public void testMajorVersion() {
51         int dmMajor = dm.getDriverMajorVersion();
52         assertEquals(dmMajor, sysinfo.getMajorVersion());
53         assertEquals(dmMajor, sysinfo.getMajorVersion(sysinfo.DBMS));
54         assertEquals(dmMajor, sysinfo.getMajorVersion(sysinfo.TOOLS));
55         assertEquals(dmMajor, sysinfo.getMajorVersion(sysinfo.NET));
56         assertEquals(dmMajor, sysinfo.getMajorVersion(sysinfo.CLIENT));
57         // bad usage
58
assertEquals(-1, sysinfo.getMajorVersion("foo"));
59         assertEquals(-1, sysinfo.getMajorVersion(null));
60     }
61
62     /*
63      * getMinorVersion()
64      */

65     public void testMinorVersion() {
66         int dmMinor = dm.getDriverMinorVersion();
67         assertEquals(dmMinor, sysinfo.getMinorVersion());
68         assertEquals(dmMinor, sysinfo.getMinorVersion(sysinfo.DBMS));
69         assertEquals(dmMinor, sysinfo.getMinorVersion(sysinfo.TOOLS));
70         assertEquals(dmMinor, sysinfo.getMinorVersion(sysinfo.NET));
71         assertEquals(dmMinor, sysinfo.getMinorVersion(sysinfo.CLIENT));
72         // bad usage
73
assertEquals(-1, sysinfo.getMinorVersion("foo"));
74         assertEquals(-1, sysinfo.getMinorVersion(null));
75     }
76
77     /*
78      * getProductName()
79      */

80     public void testProductName() {
81         assertEquals("Apache Derby", sysinfo.getProductName());
82         assertEquals("Apache Derby", sysinfo.getProductName(sysinfo.DBMS));
83         assertEquals("Apache Derby", sysinfo.getProductName(sysinfo.TOOLS));
84         assertEquals("Apache Derby", sysinfo.getProductName(sysinfo.NET));
85         assertEquals("Apache Derby", sysinfo.getProductName(sysinfo.CLIENT));
86         // bad usage
87
assertEquals("<no name found>", sysinfo.getProductName("foo"));
88         assertEquals("<no name found>", sysinfo.getProductName(null));
89     }
90
91     /*
92      * getVersionString()
93      */

94     public void testVersionString() throws SQLException JavaDoc {
95         String JavaDoc dmPv = dm.getDatabaseProductVersion();
96         assertEquals(dmPv, sysinfo.getVersionString());
97         assertEquals(dmPv, sysinfo.getVersionString(sysinfo.DBMS));
98         assertEquals(dmPv, sysinfo.getVersionString(sysinfo.TOOLS));
99         assertEquals(dmPv, sysinfo.getVersionString(sysinfo.NET));
100         assertEquals(dmPv, sysinfo.getVersionString(sysinfo.CLIENT));
101         // bad usage
102
assertEquals("<no name found>", sysinfo.getVersionString("foo"));
103         assertEquals("<no name found>", sysinfo.getVersionString(null));
104     }
105
106     /*
107      * getBuildNumber()
108      *
109      * Currently no test for sysinfo.getBuildNumber().
110      * There is not currently a way to get this information from another
111      * different public interface.
112      */

113
114     /*
115      * getInfo()
116      *
117      * Currently only tests getInfo() by comparing the first line with the
118      * expected first line in English. Because so much of sysinfo changes from
119      * machine-to-machine, writing a better test may be difficult.
120      *
121      * Test spawns a separate thread in which to call sysinfo and feed the
122      * PipedWriter. Using PipedWriter and PipedReader from the same thread
123      * can cause a deadlock.
124      */

125     public void testGetInfo() throws IOException JavaDoc {
126         sysinfo_api_helper sah = new sysinfo_api_helper();
127         sah.start();
128         PipedReader JavaDoc pipeR = new PipedReader JavaDoc(sah.getPipedWriter());
129         BufferedReader JavaDoc br = new BufferedReader JavaDoc(pipeR);
130         assertEquals("------------------ Java Information ------------------",
131                      br.readLine());
132         br.close();
133         pipeR.close();
134     }
135
136     /*
137      * testSetup - get a DatabaseMetadata object with which to compare info
138      * with sysinfo
139      */

140     public void setUp() throws SQLException JavaDoc {
141         dm = getConnection().getMetaData();
142     }
143
144
145 }
146
147 class sysinfo_api_helper extends Thread JavaDoc {
148     
149     private static PipedWriter JavaDoc pipeW = new PipedWriter JavaDoc();
150
151     public void run() {
152         PrintWriter JavaDoc pw = new PrintWriter JavaDoc(pipeW, true);
153         sysinfo.getInfo(pw);
154         try {
155             pw.close();
156             pipeW.close();
157         } catch (IOException JavaDoc e) {
158             e.printStackTrace();
159         }
160     }
161
162    public PipedWriter JavaDoc getPipedWriter() {
163        return pipeW;
164    }
165 }
166
Popular Tags