Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ab284fe1
提交
ab284fe1
authored
12月 05, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve code coverage (test H2 Console).
上级
a72020a7
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
121 行增加
和
34 行删除
+121
-34
DbContents.java
h2/src/main/org/h2/server/web/DbContents.java
+0
-21
WebThread.java
h2/src/main/org/h2/server/web/WebThread.java
+1
-1
Server.java
h2/src/main/org/h2/tools/Server.java
+3
-1
TestWeb.java
h2/src/test/org/h2/test/server/TestWeb.java
+73
-3
WebClient.java
h2/src/test/org/h2/test/server/WebClient.java
+44
-8
没有找到文件。
h2/src/main/org/h2/server/web/DbContents.java
浏览文件 @
ab284fe1
...
...
@@ -234,25 +234,4 @@ public class DbContents {
return
StringUtils
.
toUpperEnglish
(
identifier
);
}
/**
* Check whether an identifier from the database meta data needs to be
* quoted. This depends on how the database stores the identifiers ("test"
* doesn't need to be quoted if the database stores identifiers lowercase)
*
* @param identifier the identifier
* @return true if the identifier needs to be quoted
*/
boolean
needsQuotes
(
String
identifier
)
{
if
(
storedUpperCaseIdentifiers
)
{
if
(
identifier
.
equals
(
identifier
.
toUpperCase
()))
{
return
false
;
}
}
else
{
if
(
identifier
.
equals
(
identifier
.
toLowerCase
()))
{
return
false
;
}
}
return
true
;
}
}
h2/src/main/org/h2/server/web/WebThread.java
浏览文件 @
ab284fe1
...
...
@@ -371,7 +371,7 @@ class WebThread extends WebApp implements Runnable {
f
.
seek
(
f
.
length
()
-
testSize
);
f
.
readFully
(
bytes
,
0
,
testSize
);
String
s
=
new
String
(
bytes
,
"ASCII"
);
int
x
=
s
.
i
ndexOf
(
boundary
);
int
x
=
s
.
lastI
ndexOf
(
boundary
);
f
.
setLength
(
f
.
length
()
-
testSize
+
x
-
2
);
f
.
close
();
}
...
...
h2/src/main/org/h2/tools/Server.java
浏览文件 @
ab284fe1
...
...
@@ -411,7 +411,9 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
*/
public
void
stop
()
{
started
=
false
;
service
.
stop
();
if
(
service
!=
null
)
{
service
.
stop
();
}
}
/**
...
...
h2/src/test/org/h2/test/server/TestWeb.java
浏览文件 @
ab284fe1
...
...
@@ -6,8 +6,10 @@
*/
package
org
.
h2
.
test
.
server
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.PrintStream
;
...
...
@@ -15,6 +17,7 @@ import java.sql.Connection;
import
org.h2.constant.SysProperties
;
import
org.h2.test.TestBase
;
import
org.h2.tools.Server
;
import
org.h2.util.IOUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Task
;
...
...
@@ -35,6 +38,7 @@ public class TestWeb extends TestBase {
}
public
void
test
()
throws
Exception
{
testTools
();
testTransfer
();
testAlreadyRunning
();
testStartWebServerWithConnection
();
...
...
@@ -57,6 +61,44 @@ public class TestWeb extends TestBase {
server
.
stop
();
}
private
void
testTools
()
throws
Exception
{
deleteDb
(
"web"
);
Connection
conn
=
getConnection
(
"web"
);
conn
.
createStatement
().
execute
(
"create table test(id int) as select 1"
);
conn
.
close
();
Server
server
=
new
Server
();
server
.
setOut
(
new
PrintStream
(
new
ByteArrayOutputStream
()));
server
.
runTool
(
"-web"
,
"-webPort"
,
"8182"
,
"-properties"
,
"null"
,
"-tcp"
,
"-tcpPort"
,
"9001"
);
try
{
String
url
=
"http://localhost:8182"
;
WebClient
client
;
String
result
;
client
=
new
WebClient
();
result
=
client
.
get
(
url
);
client
.
readSessionId
(
result
);
result
=
client
.
get
(
url
,
"tools.jsp"
);
IOUtils
.
delete
(
getBaseDir
()
+
"/backup.zip"
);
result
=
client
.
get
(
url
,
"tools.do?tool=Backup&args=-dir,"
+
getBaseDir
()
+
",-db,web,-file,"
+
getBaseDir
()
+
"/backup.zip"
);
deleteDb
(
"web"
);
assertTrue
(
IOUtils
.
exists
(
getBaseDir
()
+
"/backup.zip"
));
result
=
client
.
get
(
url
,
"tools.do?tool=DeleteDbFiles&args=-dir,"
+
getBaseDir
()
+
",-db,web"
);
assertFalse
(
IOUtils
.
exists
(
getBaseDir
()
+
"/web.h2.db"
));
result
=
client
.
get
(
url
,
"tools.do?tool=Restore&args=-dir,"
+
getBaseDir
()
+
",-db,web,-file,"
+
getBaseDir
()
+
"/backup.zip"
);
assertTrue
(
IOUtils
.
exists
(
getBaseDir
()
+
"/web.h2.db"
));
IOUtils
.
delete
(
getBaseDir
()
+
"/web.h2.sql"
);
IOUtils
.
delete
(
getBaseDir
()
+
"/backup.zip"
);
result
=
client
.
get
(
url
,
"tools.do?tool=Recover&args=-dir,"
+
getBaseDir
()
+
",-db,web"
);
assertTrue
(
IOUtils
.
exists
(
getBaseDir
()
+
"/web.h2.sql"
));
IOUtils
.
delete
(
getBaseDir
()
+
"/web.h2.sql"
);
result
=
client
.
get
(
url
,
"tools.do?tool=RunScript&args=-script,"
+
getBaseDir
()
+
"/web.h2.sql,-url,"
+
getURL
(
"web"
,
true
)
+
",-user,"
+
getUser
()
+
",-password,"
+
getPassword
());
IOUtils
.
delete
(
getBaseDir
()
+
"/web.h2.sql"
);
assertTrue
(
IOUtils
.
exists
(
getBaseDir
()
+
"/web.h2.db"
));
deleteDb
(
"web"
);
}
finally
{
server
.
shutdown
();
}
}
private
void
testTransfer
()
throws
Exception
{
Server
server
=
new
Server
();
server
.
setOut
(
new
PrintStream
(
new
ByteArrayOutputStream
()));
...
...
@@ -73,8 +115,13 @@ public class TestWeb extends TestBase {
client
.
readSessionId
(
result
);
String
test
=
client
.
get
(
url
,
"transfer/test.txt"
);
assertEquals
(
"Hello World"
,
test
);
server
.
shutdown
();
new
File
(
"transfer/testUpload.txt"
).
delete
();
client
.
upload
(
url
+
"/transfer/testUpload.txt"
,
"testUpload.txt"
,
new
ByteArrayInputStream
(
"Hallo Welt"
.
getBytes
()));
byte
[]
d
=
IOUtils
.
readBytesAndClose
(
new
FileInputStream
(
"transfer/testUpload.txt"
),
-
1
);
assertEquals
(
"Hallo Welt"
,
new
String
(
d
));
new
File
(
"transfer/testUpload.txt"
).
delete
();
}
finally
{
server
.
shutdown
();
transfer
.
delete
();
}
}
...
...
@@ -84,8 +131,17 @@ public class TestWeb extends TestBase {
server
.
setOut
(
new
PrintStream
(
new
ByteArrayOutputStream
()));
server
.
runTool
(
"-web"
,
"-webPort"
,
"8182"
,
"-properties"
,
"null"
,
"-tcp"
,
"-tcpPort"
,
"9001"
);
String
url
=
"http://localhost:8182"
;
WebClient
client
=
new
WebClient
();
String
result
=
client
.
get
(
url
);
WebClient
client
;
String
result
;
client
=
new
WebClient
();
client
.
setAcceptLanguage
(
"de-de,de;q=0.5"
);
result
=
client
.
get
(
url
);
client
.
readSessionId
(
result
);
result
=
client
.
get
(
url
,
"login.jsp"
);
assertContains
(
result
,
"Einstellung"
);
client
=
new
WebClient
();
result
=
client
.
get
(
url
);
client
.
readSessionId
(
result
);
client
.
get
(
url
,
"login.jsp"
);
client
.
get
(
url
,
"stylesheet.css"
);
...
...
@@ -115,6 +171,16 @@ public class TestWeb extends TestBase {
result
=
client
.
get
(
url
,
"query.do?sql=@LOOP 1000 insert into test values(?, 'Hello ' || ?/*RND*/)"
);
assertContains
(
result
,
"1000 * (Prepared)"
);
result
=
client
.
get
(
url
,
"query.do?sql=select * from test"
);
result
=
client
.
get
(
url
,
"query.do?sql=@list select * from test"
);
assertContains
(
result
,
"Row #"
);
result
=
client
.
get
(
url
,
"query.do?sql=@parameter_meta select * from test where id = ?"
);
assertContains
(
result
,
"INTEGER"
);
result
=
client
.
get
(
url
,
"query.do?sql=@edit select * from test"
);
assertContains
(
result
,
"editResult.do"
);
result
=
client
.
get
(
url
,
"query.do?sql="
+
StringUtils
.
urlEncode
(
"select space(100001) a, 1 b"
));
assertContains
(
result
,
"..."
);
result
=
client
.
get
(
url
,
"query.do?sql="
+
StringUtils
.
urlEncode
(
"call '<&>'"
));
assertContains
(
result
,
"<&>"
);
result
=
client
.
get
(
url
,
"query.do?sql=@HISTORY"
);
result
=
client
.
get
(
url
,
"getHistory.do?id=4"
);
assertContains
(
result
,
"select * from test"
);
...
...
@@ -202,6 +268,9 @@ public class TestWeb extends TestBase {
result
=
client
.
get
(
url
,
"query.do?sql=@INFO"
);
assertContains
(
result
,
"getCatalog"
);
result
=
client
.
get
(
url
,
"logout.do"
);
result
=
client
.
get
(
url
,
"login.do?driver=org.h2.Driver&url=jdbc:h2:mem:web&user=sa&password=sa&name=_test_"
);
result
=
client
.
get
(
url
,
"logout.do"
);
result
=
client
.
get
(
url
,
"settingRemove.do?name=_test_"
);
...
...
@@ -255,6 +324,7 @@ public class TestWeb extends TestBase {
}
else
{
System
.
clearProperty
(
SysProperties
.
H2_BROWSER
);
}
deleteDb
(
"testWeb"
);
}
}
...
...
h2/src/test/org/h2/test/server/WebClient.java
浏览文件 @
ab284fe1
...
...
@@ -6,12 +6,13 @@
*/
package
org
.
h2
.
test
.
server
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.UUID
;
import
org.h2.util.IOUtils
;
/**
...
...
@@ -20,6 +21,7 @@ import org.h2.util.IOUtils;
public
class
WebClient
{
private
String
sessionId
;
private
String
acceptLanguage
;
/**
* Open an URL and get the HTML data.
...
...
@@ -28,20 +30,54 @@ public class WebClient {
* @return the HTML as a string
*/
String
get
(
String
url
)
throws
IOException
{
HttpURLConnection
connection
=
(
HttpURLConnection
)
new
URL
(
url
).
openConnection
();
connection
.
setRequestMethod
(
"GET"
);
connection
.
setInstanceFollowRedirects
(
true
);
connection
.
connect
();
int
code
=
connection
.
getResponseCode
();
HttpURLConnection
conn
=
(
HttpURLConnection
)
new
URL
(
url
).
openConnection
();
conn
.
setRequestMethod
(
"GET"
);
conn
.
setInstanceFollowRedirects
(
true
);
if
(
acceptLanguage
!=
null
)
{
conn
.
setRequestProperty
(
"accept-language"
,
acceptLanguage
);
}
conn
.
connect
();
int
code
=
conn
.
getResponseCode
();
if
(
code
!=
HttpURLConnection
.
HTTP_OK
)
{
throw
new
IOException
(
"Result code: "
+
code
);
}
InputStream
in
=
conn
ection
.
getInputStream
();
InputStream
in
=
conn
.
getInputStream
();
String
result
=
IOUtils
.
readStringAndClose
(
new
InputStreamReader
(
in
),
-
1
);
conn
ection
.
disconnect
();
conn
.
disconnect
();
return
result
;
}
String
upload
(
String
url
,
String
fileName
,
InputStream
in
)
throws
IOException
{
HttpURLConnection
conn
=
(
HttpURLConnection
)
new
URL
(
url
).
openConnection
();
conn
.
setDoOutput
(
true
);
conn
.
setDoInput
(
true
);
conn
.
setUseCaches
(
false
);
conn
.
setRequestMethod
(
"POST"
);
conn
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
String
boundary
=
UUID
.
randomUUID
().
toString
();
conn
.
setRequestProperty
(
"Content-Type"
,
"multipart/form-data;boundary="
+
boundary
);
conn
.
connect
();
DataOutputStream
out
=
new
DataOutputStream
(
conn
.
getOutputStream
());
out
.
writeBytes
(
"--"
+
boundary
+
"--\r\n"
);
out
.
writeBytes
(
"Content-Disposition: form-data; name=\"upload\";"
+
" filename=\""
+
fileName
+
"\"\r\n\r\n"
);
IOUtils
.
copyAndCloseInput
(
in
,
out
);
out
.
writeBytes
(
"\r\n--"
+
boundary
+
"--\r\n"
);
out
.
close
();
int
code
=
conn
.
getResponseCode
();
if
(
code
!=
HttpURLConnection
.
HTTP_OK
)
{
throw
new
IOException
(
"Result code: "
+
code
);
}
in
=
conn
.
getInputStream
();
String
result
=
IOUtils
.
readStringAndClose
(
new
InputStreamReader
(
in
),
-
1
);
conn
.
disconnect
();
return
result
;
}
void
setAcceptLanguage
(
String
acceptLanguage
)
{
this
.
acceptLanguage
=
acceptLanguage
;
}
/**
* Read the session ID from a URL.
*
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论