Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
7b1b777e
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7b1b777e
编写于
2月 05, 2016
作者:
A
aefimov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8144593: Suppress not recognized property/feature warning messages from SAXParser
Reviewed-by: joehw
上级
831ff018
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
358 addition
and
0 deletion
+358
-0
test/javax/xml/jaxp/common/8144593/TestSAXDriver.java
test/javax/xml/jaxp/common/8144593/TestSAXDriver.java
+56
-0
test/javax/xml/jaxp/common/8144593/TransformationWarningsTest.java
...x/xml/jaxp/common/8144593/TransformationWarningsTest.java
+92
-0
test/javax/xml/jaxp/common/8144593/ValidationWarningsTest.java
...javax/xml/jaxp/common/8144593/ValidationWarningsTest.java
+76
-0
test/javax/xml/jaxp/common/8144593/WarningsTestBase.java
test/javax/xml/jaxp/common/8144593/WarningsTestBase.java
+134
-0
未找到文件。
test/javax/xml/jaxp/common/8144593/TestSAXDriver.java
0 → 100644
浏览文件 @
7b1b777e
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl
;
import
javax.xml.XMLConstants
;
import
org.xml.sax.SAXNotRecognizedException
;
import
org.xml.sax.SAXNotSupportedException
;
/*
* Test implementation of SAXParser. It is extended from JDK parser and two methods
* are overriden to disable support of specific features and properties.
* This class is used in ValidationWarningsTest and TransformationWarningsTest
* to generate multiple warnings during xml validation and transformation processes.
*/
public
class
TestSAXDriver
extends
SAXParserImpl
.
JAXPSAXParser
{
@Override
public
synchronized
void
setFeature
(
String
name
,
boolean
value
)
throws
SAXNotRecognizedException
,
SAXNotSupportedException
{
if
(
XMLConstants
.
FEATURE_SECURE_PROCESSING
.
equals
(
name
))
{
throw
new
SAXNotRecognizedException
(
name
+
" feature is not recognised by test SAX parser intentionally."
);
}
else
{
super
.
setFeature
(
name
,
value
);
}
}
@Override
public
synchronized
void
setProperty
(
String
name
,
Object
value
)
throws
SAXNotRecognizedException
,
SAXNotSupportedException
{
if
(
XMLConstants
.
ACCESS_EXTERNAL_DTD
.
equals
(
name
)
||
ENT_EXP_LIMIT_PROP
.
equals
(
name
))
{
throw
new
SAXNotRecognizedException
(
name
+
" property is not recognised by test SAX parser intentionally."
);
}
else
{
super
.
setProperty
(
name
,
value
);
}
}
private
static
final
String
ENT_EXP_LIMIT_PROP
=
"http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit"
;
}
test/javax/xml/jaxp/common/8144593/TransformationWarningsTest.java
0 → 100644
浏览文件 @
7b1b777e
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import
java.io.StringReader
;
import
java.io.StringWriter
;
import
javax.xml.transform.Source
;
import
javax.xml.transform.Transformer
;
import
javax.xml.transform.TransformerFactory
;
import
javax.xml.transform.stream.StreamResult
;
import
javax.xml.transform.stream.StreamSource
;
import
org.testng.annotations.Test
;
import
org.testng.annotations.BeforeClass
;
/*
* @test
* @bug 8144593
* @summary Check that warnings about unsupported properties from parsers
* are suppressed during the transformation process.
* @compile -XDignore.symbol.file TestSAXDriver.java
* @run testng/othervm TransformationWarningsTest
*/
public
class
TransformationWarningsTest
extends
WarningsTestBase
{
@BeforeClass
public
void
setup
()
{
//Set test SAX driver implementation.
System
.
setProperty
(
"org.xml.sax.driver"
,
"TestSAXDriver"
);
}
@Test
public
void
testTransformation
()
throws
Exception
{
startTest
();
}
//One iteration of xml transformation test case. It will be called from each
//TestWorker task defined in WarningsTestBase class.
void
doOneTestIteration
()
throws
Exception
{
// Prepare output stream
StringWriter
xmlResultString
=
new
StringWriter
();
StreamResult
xmlResultStream
=
new
StreamResult
(
xmlResultString
);
// Prepare xml source stream
Source
src
=
new
StreamSource
(
new
StringReader
(
xml
));
Transformer
t
=
createTransformer
();
//Transform the xml
t
.
transform
(
src
,
xmlResultStream
);
}
//Create transformer from xsl test string
Transformer
createTransformer
()
throws
Exception
{
// Prepare sources for transormation
Source
xslsrc
=
new
StreamSource
(
new
StringReader
(
xsl
));
// Create factory and transformer
TransformerFactory
tf
=
TransformerFactory
.
newInstance
();
Transformer
t
=
tf
.
newTransformer
(
xslsrc
);
// Set URI Resolver to return the newly constructed xml
// stream source object from xml test string
t
.
setURIResolver
((
String
href
,
String
base
)
->
new
StreamSource
(
new
StringReader
(
xml
)));
return
t
;
}
//Xsl and Xml contents used in the transformation test
private
static
final
String
xsl
=
"<xsl:stylesheet version='2.0'"
+
" xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>"
+
" <xsl:output method='xml' indent='yes' omit-xml-declaration='yes'/>"
+
" <xsl:template match='/'>"
+
" <test>Simple Transformation Result. No warnings should be printed to console</test>"
+
" </xsl:template>"
+
"</xsl:stylesheet>"
;
private
static
final
String
xml
=
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>"
;
}
test/javax/xml/jaxp/common/8144593/ValidationWarningsTest.java
0 → 100644
浏览文件 @
7b1b777e
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import
java.io.ByteArrayInputStream
;
import
java.io.StringReader
;
import
javax.xml.XMLConstants
;
import
javax.xml.transform.Source
;
import
javax.xml.transform.sax.SAXSource
;
import
javax.xml.transform.stream.StreamSource
;
import
javax.xml.validation.Schema
;
import
javax.xml.validation.SchemaFactory
;
import
javax.xml.validation.Validator
;
import
org.testng.annotations.Test
;
import
org.testng.annotations.BeforeClass
;
import
org.xml.sax.InputSource
;
/*
* @test
* @bug 8144593
* @summary Check that warnings about unsupported properties from SAX
* parsers are suppressed during the xml validation process.
* @compile -XDignore.symbol.file TestSAXDriver.java
* @run testng/othervm ValidationWarningsTest
*/
public
class
ValidationWarningsTest
extends
WarningsTestBase
{
@BeforeClass
public
void
setup
()
{
//Set test SAX driver implementation.
System
.
setProperty
(
"org.xml.sax.driver"
,
"TestSAXDriver"
);
}
@Test
public
void
testValidation
()
throws
Exception
{
startTest
();
}
//One iteration of xml validation test case. It will be called from each
//TestWorker task defined in WarningsTestBase class.
void
doOneTestIteration
()
throws
Exception
{
Source
src
=
new
StreamSource
(
new
StringReader
(
xml
));
SchemaFactory
schemaFactory
=
SchemaFactory
.
newInstance
(
XMLConstants
.
W3C_XML_SCHEMA_NS_URI
);
SAXSource
xsdSource
=
new
SAXSource
(
new
InputSource
(
new
ByteArrayInputStream
(
xsd
.
getBytes
())));
Schema
schema
=
schemaFactory
.
newSchema
(
xsdSource
);
Validator
v
=
schema
.
newValidator
();
v
.
validate
(
src
);
}
//Xsd and Xml contents used in the validation test
private
static
final
String
xsd
=
"<?xml version='1.0'?>"
+
" <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>"
+
" <xs:element name='test' type='xs:string'/>\n"
+
" </xs:schema>"
;
private
static
final
String
xml
=
"<?xml version='1.0'?><test>Element</test>"
;
}
test/javax/xml/jaxp/common/8144593/WarningsTestBase.java
0 → 100644
浏览文件 @
7b1b777e
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import
java.io.ByteArrayOutputStream
;
import
java.io.PrintStream
;
import
java.util.concurrent.CyclicBarrier
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.TimeUnit
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
javax.xml.XMLConstants
;
import
org.testng.Assert
;
/*
* This class helps to test suppression of unsupported parser properties
* messages printed to standard error output.
* It launches THREADS_COUNT tasks. Each task does ITERATIONS_PER_THREAD
* sequential calls to doOneIteration method implemented by specific test class.
*/
public
abstract
class
WarningsTestBase
{
/*
* Abstract method that should be implemented by test class.
* It is repeatedly called by each TestWorker task.
*/
abstract
void
doOneTestIteration
()
throws
Exception
;
/*
* Launches parallel test tasks and check the output for the number of
* generated warning messages. There should be no more than one message of
* each type.
*/
void
startTest
()
throws
Exception
{
//Save standard error stream
PrintStream
defStdErr
=
System
.
err
;
//Set new byte array stream as standard error stream
ByteArrayOutputStream
byteStream
=
new
ByteArrayOutputStream
(
5000
);
System
.
setErr
(
new
PrintStream
(
byteStream
));
//Execute multiple TestWorker tasks
for
(
int
id
=
0
;
id
<
THREADS_COUNT
;
id
++)
{
EXECUTOR
.
execute
(
new
TestWorker
(
id
));
}
//Initiate shutdown of previously submitted task
EXECUTOR
.
shutdown
();
//Wait for termination of submitted tasks
if
(!
EXECUTOR
.
awaitTermination
(
THREADS_COUNT
,
TimeUnit
.
SECONDS
))
{
//If not all tasks terminates during the time out force them to shutdown
EXECUTOR
.
shutdownNow
();
}
//Restore default standard error stream
System
.
setErr
(
defStdErr
);
//Print tasks stderr output
String
errContent
=
byteStream
.
toString
();
System
.
out
.
println
(
"Standard error output content:"
);
System
.
out
.
println
(
errContent
);
//Check tasks stderr output for quatity of warning messages
Assert
.
assertTrue
(
warningPrintedOnce
(
XMLConstants
.
ACCESS_EXTERNAL_DTD
,
errContent
));
Assert
.
assertTrue
(
warningPrintedOnce
(
ENT_EXP_PROPERTY
,
errContent
));
Assert
.
assertTrue
(
warningPrintedOnce
(
XMLConstants
.
FEATURE_SECURE_PROCESSING
,
errContent
));
}
// Count occurences of warning messages in standard error and check if warning is printed
// not more than once
private
boolean
warningPrintedOnce
(
String
propertyName
,
String
testOutput
)
{
//Count for property name in test output
Pattern
p
=
Pattern
.
compile
(
propertyName
);
Matcher
m
=
p
.
matcher
(
testOutput
);
int
count
=
0
;
while
(
m
.
find
())
{
count
+=
1
;
}
System
.
out
.
println
(
"'"
+
propertyName
+
"' print count: "
+
count
);
//If count is more than 1 then consider test failed
return
count
<=
1
;
}
//TestWorker task that sequentially calls test method
private
class
TestWorker
implements
Runnable
{
// Task id
private
final
int
id
;
TestWorker
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
run
()
{
try
{
System
.
out
.
printf
(
"%d: waiting for barrier%n"
,
id
);
//Synchronize startup of all tasks
BARRIER
.
await
();
System
.
out
.
printf
(
"%d: starting iterations%n"
,
id
);
//Call test method multiple times
for
(
int
i
=
0
;
i
<
ITERATIONS_PER_THREAD
;
i
++)
{
doOneTestIteration
();
}
}
catch
(
Exception
ex
)
{
throw
new
RuntimeException
(
"TestWorker id:"
+
id
+
" failed"
,
ex
);
}
}
}
//Entity expansion limit property name
private
static
final
String
ENT_EXP_PROPERTY
=
"http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit"
;
//Number of simultaneous test threads
private
static
final
int
THREADS_COUNT
=
10
;
//Number of iterations per one thread
private
static
final
int
ITERATIONS_PER_THREAD
=
4
;
//Test thread pool
private
static
final
ExecutorService
EXECUTOR
=
Executors
.
newCachedThreadPool
();
//Cyclic barrier for threads startup synchronisation
private
static
final
CyclicBarrier
BARRIER
=
new
CyclicBarrier
(
THREADS_COUNT
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录