Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ba877c18
提交
ba877c18
authored
10月 16, 2013
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improved test coverage
上级
4204251c
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
549 行增加
和
3 行删除
+549
-3
WebServlet.java
h2/src/main/org/h2/server/web/WebServlet.java
+3
-2
TestWeb.java
h2/src/test/org/h2/test/server/TestWeb.java
+546
-1
没有找到文件。
h2/src/main/org/h2/server/web/WebServlet.java
浏览文件 @
ba877c18
...
@@ -86,7 +86,7 @@ public class WebServlet extends HttpServlet {
...
@@ -86,7 +86,7 @@ public class WebServlet extends HttpServlet {
}
}
@Override
@Override
p
rotected
void
doGet
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
throws
IOException
{
p
ublic
void
doGet
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
throws
IOException
{
req
.
setCharacterEncoding
(
"utf-8"
);
req
.
setCharacterEncoding
(
"utf-8"
);
String
file
=
req
.
getPathInfo
();
String
file
=
req
.
getPathInfo
();
if
(
file
==
null
)
{
if
(
file
==
null
)
{
...
@@ -157,7 +157,8 @@ public class WebServlet extends HttpServlet {
...
@@ -157,7 +157,8 @@ public class WebServlet extends HttpServlet {
}
}
@Override
@Override
p
rotected
void
doPost
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
throws
IOException
{
p
ublic
void
doPost
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
throws
IOException
{
doGet
(
req
,
resp
);
doGet
(
req
,
resp
);
}
}
}
}
h2/src/test/org/h2/test/server/TestWeb.java
浏览文件 @
ba877c18
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
*/
*/
package
org
.
h2
.
test
.
server
;
package
org
.
h2
.
test
.
server
;
import
java.io.BufferedReader
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.File
;
...
@@ -13,10 +14,30 @@ import java.io.FileInputStream;
...
@@ -13,10 +14,30 @@ import java.io.FileInputStream;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.PrintStream
;
import
java.io.PrintStream
;
import
java.io.PrintWriter
;
import
java.io.UnsupportedEncodingException
;
import
java.security.Principal
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Vector
;
import
javax.servlet.RequestDispatcher
;
import
javax.servlet.ServletConfig
;
import
javax.servlet.ServletInputStream
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
javax.servlet.ServletContext
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.constant.SysProperties
;
import
org.h2.server.web.WebServlet
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
import
org.h2.test.utils.AssertThrows
;
import
org.h2.test.utils.AssertThrows
;
...
@@ -43,6 +64,7 @@ public class TestWeb extends TestBase {
...
@@ -43,6 +64,7 @@ public class TestWeb extends TestBase {
@Override
@Override
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testServlet
();
testWrongParameters
();
testWrongParameters
();
testTools
();
testTools
();
testTransfer
();
testTransfer
();
...
@@ -53,6 +75,49 @@ public class TestWeb extends TestBase {
...
@@ -53,6 +75,49 @@ public class TestWeb extends TestBase {
testIfExists
();
testIfExists
();
}
}
private
void
testServlet
()
throws
Exception
{
WebServlet
servlet
=
new
WebServlet
();
final
HashMap
<
String
,
String
>
configMap
=
new
HashMap
<
String
,
String
>();
configMap
.
put
(
"ifExists"
,
""
);
configMap
.
put
(
""
,
""
);
configMap
.
put
(
""
,
""
);
configMap
.
put
(
""
,
""
);
ServletConfig
config
=
new
ServletConfig
()
{
@Override
public
String
getServletName
()
{
return
"H2Console"
;
}
@Override
public
Enumeration
<
String
>
getInitParameterNames
()
{
return
new
Vector
<
String
>(
configMap
.
keySet
()).
elements
();
}
@Override
public
String
getInitParameter
(
String
name
)
{
return
configMap
.
get
(
name
);
}
@Override
public
ServletContext
getServletContext
()
{
return
null
;
}
};
servlet
.
init
(
config
);
TestHttpServletRequest
request
=
new
TestHttpServletRequest
();
request
.
setPathInfo
(
"/"
);
TestHttpServletResponse
response
=
new
TestHttpServletResponse
();
TestServletOutputStream
out
=
new
TestServletOutputStream
();
response
.
setServletOutputStream
(
out
);
servlet
.
doGet
(
request
,
response
);
assertContains
(
out
.
toString
(),
"location.href = 'login.jsp"
);
servlet
.
destroy
();
}
private
static
void
testWrongParameters
()
{
private
static
void
testWrongParameters
()
{
new
AssertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
)
{
new
AssertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
)
{
@Override
@Override
...
@@ -497,4 +562,484 @@ public class TestWeb extends TestBase {
...
@@ -497,4 +562,484 @@ public class TestWeb extends TestBase {
lastUrl
=
url
;
lastUrl
=
url
;
}
}
/**
* A HTTP servlet request for testing.
*/
static
class
TestHttpServletRequest
implements
HttpServletRequest
{
private
String
pathInfo
;
void
setPathInfo
(
String
pathInfo
)
{
this
.
pathInfo
=
pathInfo
;
}
@Override
public
Object
getAttribute
(
String
name
)
{
return
null
;
}
@Override
public
Enumeration
<
String
>
getAttributeNames
()
{
return
new
Vector
<
String
>().
elements
();
}
@Override
public
String
getCharacterEncoding
()
{
return
null
;
}
@Override
public
int
getContentLength
()
{
return
0
;
}
@Override
public
String
getContentType
()
{
return
null
;
}
@Override
public
ServletInputStream
getInputStream
()
throws
IOException
{
return
null
;
}
@Override
public
String
getLocalAddr
()
{
return
null
;
}
@Override
public
String
getLocalName
()
{
return
null
;
}
@Override
public
int
getLocalPort
()
{
return
0
;
}
@Override
public
Locale
getLocale
()
{
return
null
;
}
@Override
public
Enumeration
<
Locale
>
getLocales
()
{
return
null
;
}
@Override
public
String
getParameter
(
String
name
)
{
return
null
;
}
@Override
public
Map
<
String
,
String
>
getParameterMap
()
{
return
null
;
}
@Override
public
Enumeration
<
String
>
getParameterNames
()
{
return
new
Vector
<
String
>().
elements
();
}
@Override
public
String
[]
getParameterValues
(
String
name
)
{
return
null
;
}
@Override
public
String
getProtocol
()
{
return
null
;
}
@Override
public
BufferedReader
getReader
()
throws
IOException
{
return
null
;
}
@Override
public
String
getRealPath
(
String
path
)
{
return
null
;
}
@Override
public
String
getRemoteAddr
()
{
return
null
;
}
@Override
public
String
getRemoteHost
()
{
return
null
;
}
@Override
public
int
getRemotePort
()
{
return
0
;
}
@Override
public
RequestDispatcher
getRequestDispatcher
(
String
name
)
{
return
null
;
}
@Override
public
String
getScheme
()
{
return
null
;
}
@Override
public
String
getServerName
()
{
return
null
;
}
@Override
public
int
getServerPort
()
{
return
0
;
}
@Override
public
boolean
isSecure
()
{
return
false
;
}
@Override
public
void
removeAttribute
(
String
name
)
{
// ignore
}
@Override
public
void
setAttribute
(
String
name
,
Object
value
)
{
// ignore
}
@Override
public
void
setCharacterEncoding
(
String
encoding
)
throws
UnsupportedEncodingException
{
// ignore
}
@Override
public
String
getAuthType
()
{
return
null
;
}
@Override
public
String
getContextPath
()
{
return
null
;
}
@Override
public
Cookie
[]
getCookies
()
{
return
null
;
}
@Override
public
long
getDateHeader
(
String
x
)
{
return
0
;
}
@Override
public
String
getHeader
(
String
name
)
{
return
null
;
}
@Override
public
Enumeration
<
String
>
getHeaderNames
()
{
return
null
;
}
@Override
public
Enumeration
<
String
>
getHeaders
(
String
name
)
{
return
null
;
}
@Override
public
int
getIntHeader
(
String
name
)
{
return
0
;
}
@Override
public
String
getMethod
()
{
return
null
;
}
@Override
public
String
getPathInfo
()
{
return
pathInfo
;
}
@Override
public
String
getPathTranslated
()
{
return
null
;
}
@Override
public
String
getQueryString
()
{
return
null
;
}
@Override
public
String
getRemoteUser
()
{
return
null
;
}
@Override
public
String
getRequestURI
()
{
return
null
;
}
@Override
public
StringBuffer
getRequestURL
()
{
return
null
;
}
@Override
public
String
getRequestedSessionId
()
{
return
null
;
}
@Override
public
String
getServletPath
()
{
return
null
;
}
@Override
public
HttpSession
getSession
()
{
return
null
;
}
@Override
public
HttpSession
getSession
(
boolean
x
)
{
return
null
;
}
@Override
public
Principal
getUserPrincipal
()
{
return
null
;
}
@Override
public
boolean
isRequestedSessionIdFromCookie
()
{
return
false
;
}
@Override
public
boolean
isRequestedSessionIdFromURL
()
{
return
false
;
}
@Override
public
boolean
isRequestedSessionIdFromUrl
()
{
return
false
;
}
@Override
public
boolean
isRequestedSessionIdValid
()
{
return
false
;
}
@Override
public
boolean
isUserInRole
(
String
x
)
{
return
false
;
}
}
/**
* A HTTP servlet response for testing.
*/
static
class
TestHttpServletResponse
implements
HttpServletResponse
{
ServletOutputStream
servletOutputStream
;
void
setServletOutputStream
(
ServletOutputStream
servletOutputStream
)
{
this
.
servletOutputStream
=
servletOutputStream
;
}
@Override
public
void
flushBuffer
()
throws
IOException
{
// ignore
}
@Override
public
int
getBufferSize
()
{
return
0
;
}
@Override
public
String
getCharacterEncoding
()
{
return
null
;
}
@Override
public
String
getContentType
()
{
return
null
;
}
@Override
public
Locale
getLocale
()
{
return
null
;
}
@Override
public
ServletOutputStream
getOutputStream
()
throws
IOException
{
return
servletOutputStream
;
}
@Override
public
PrintWriter
getWriter
()
throws
IOException
{
return
null
;
}
@Override
public
boolean
isCommitted
()
{
return
false
;
}
@Override
public
void
reset
()
{
// ignore
}
@Override
public
void
resetBuffer
()
{
// ignore
}
@Override
public
void
setBufferSize
(
int
arg0
)
{
// ignore
}
@Override
public
void
setCharacterEncoding
(
String
arg0
)
{
// ignore
}
@Override
public
void
setContentLength
(
int
arg0
)
{
// ignore
}
@Override
public
void
setContentType
(
String
arg0
)
{
// ignore
}
@Override
public
void
setLocale
(
Locale
arg0
)
{
// ignore
}
@Override
public
void
addCookie
(
Cookie
arg0
)
{
// ignore
}
@Override
public
void
addDateHeader
(
String
arg0
,
long
arg1
)
{
// ignore
}
@Override
public
void
addHeader
(
String
arg0
,
String
arg1
)
{
// ignore
}
@Override
public
void
addIntHeader
(
String
arg0
,
int
arg1
)
{
// ignore
}
@Override
public
boolean
containsHeader
(
String
arg0
)
{
return
false
;
}
@Override
public
String
encodeRedirectURL
(
String
arg0
)
{
return
null
;
}
@Override
public
String
encodeRedirectUrl
(
String
arg0
)
{
return
null
;
}
@Override
public
String
encodeURL
(
String
arg0
)
{
return
null
;
}
@Override
public
String
encodeUrl
(
String
arg0
)
{
return
null
;
}
@Override
public
void
sendError
(
int
arg0
)
throws
IOException
{
// ignore
}
@Override
public
void
sendError
(
int
arg0
,
String
arg1
)
throws
IOException
{
// ignore
}
@Override
public
void
sendRedirect
(
String
arg0
)
throws
IOException
{
// ignore
}
@Override
public
void
setDateHeader
(
String
arg0
,
long
arg1
)
{
// ignore
}
@Override
public
void
setHeader
(
String
arg0
,
String
arg1
)
{
// ignore
}
@Override
public
void
setIntHeader
(
String
arg0
,
int
arg1
)
{
// ignore
}
@Override
public
void
setStatus
(
int
arg0
)
{
// ignore
}
@Override
public
void
setStatus
(
int
arg0
,
String
arg1
)
{
// ignore
}
}
/**
* A servlet output stream for testing.
*/
static
class
TestServletOutputStream
extends
ServletOutputStream
{
ByteArrayOutputStream
buff
=
new
ByteArrayOutputStream
();
@Override
public
void
write
(
int
b
)
throws
IOException
{
buff
.
write
(
b
);
}
@Override
public
String
toString
()
{
try
{
return
new
String
(
buff
.
toByteArray
(),
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
return
e
.
toString
();
}
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论