⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testverifier.java

📁 一个java操作xml的完整示例
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	public void test_TCM__String_checkAttributeName_String() {
		//check out of range values
		assertNotNull("validated invalid null", Verifier.checkAttributeName(null));
		assertNotNull("validated invalid name with null", Verifier.checkAttributeName("test" + (char)0x0));
		assertNotNull("validated invalid name with null", Verifier.checkAttributeName("test" + (char)0x0 + "ing"));
		assertNotNull("validated invalid name with null", Verifier.checkAttributeName((char)0x0 + "test"));
		assertNotNull("validated invalid name with 0x01", Verifier.checkAttributeName((char)0x01 + "test"));
		assertNotNull("validated invalid name with 0xD800", Verifier.checkAttributeName("test" + (char)0xD800));
		assertNotNull("validated invalid name with 0xD800", Verifier.checkAttributeName("test" + (char)0xD800 + "ing"));
		assertNotNull("validated invalid name with 0xD800", Verifier.checkAttributeName((char)0xD800 + "test"));
		assertNotNull("validated invalid name with :", Verifier.checkAttributeName("test" + ':' + "local"));
		assertNotNull("validated invalid name with xml:lang", Verifier.checkAttributeName("xml:lang"));
		assertNotNull("validated invalid name with xml:space", Verifier.checkAttributeName("xml:space"));

		//invalid start characters
		assertNotNull("validated invalid name with startin -", Verifier.checkAttributeName('-' + "test"));
		assertNotNull("validated invalid name with xmlns", Verifier.checkAttributeName("xmlns"));
		assertNotNull("validated invalid name with startin :", Verifier.checkAttributeName(':' + "test"));

		//valid tests
		assertNull("invalidated valid name with starting _", Verifier.checkAttributeName('_' + "test"));
		assertNull("invalidated valid name with _", Verifier.checkAttributeName("test" + '_'));
		assertNull("invalidated valid name with .", Verifier.checkAttributeName("test" + '.' + "name"));
		assertNull("invalidated valid name with 0x00B7", Verifier.checkAttributeName("test" + (char)0x00B7));
		assertNull("invalidated valid name with 0x4E01", Verifier.checkAttributeName("test" + (char)0x4E01));
		assertNull("invalidated valid name with 0x0301", Verifier.checkAttributeName("test" + (char)0x0301));

	}
	/**
	 * Test that checkCDATASection verifies CDATA excluding
	 * the closing delimiter.
	 */
	public void test_TCM__String_checkCDATASection_String() {
		//check out of range values
		assertNotNull("validated invalid null", Verifier.checkCDATASection(null));
		assertNotNull("validated invalid string with null", Verifier.checkCDATASection("test" + (char)0x0));
		assertNotNull("validated invalid string with null", Verifier.checkCDATASection("test" + (char)0x0 + "ing"));
		assertNotNull("validated invalid string with null", Verifier.checkCDATASection((char)0x0 + "test"));
		assertNotNull("validated invalid string with 0x01", Verifier.checkCDATASection((char)0x01 + "test"));
		assertNotNull("validated invalid string with 0xD800", Verifier.checkCDATASection("test" + (char)0xD800));
		assertNotNull("validated invalid string with 0xD800", Verifier.checkCDATASection("test" + (char)0xD800 + "ing"));
		assertNotNull("validated invalid string with 0xD800", Verifier.checkCDATASection((char)0xD800 + "test"));
		assertNotNull("validated invalid string with ]]>", Verifier.checkCDATASection("test]]>"));

		//various valid strings
		assertNull("invalidated valid string with \n", Verifier.checkCDATASection("test" + '\n' + "ing"));
		assertNull("invalidated valid string with 0x29", Verifier.checkCDATASection("test" +(char)0x29));
		assertNull("invalidated valid string with ]", Verifier.checkCDATASection("test]"));
		assertNull("invalidated valid string with [", Verifier.checkCDATASection("test["));
		//a few higher values
		assertNull("invalidated valid string with 0x0B08", Verifier.checkCDATASection("test" + (char)0x0B08));
		assertNull("invalidated valid string with \t", Verifier.checkCDATASection("test" + '\t'));
		//xml letter
		assertNull("invalidated valid string with 0x42", Verifier.checkCDATASection("test" + (char)0x42));
		assertNull("invalidated valid string with 0x4E01", Verifier.checkCDATASection("test" + (char)0x4E01));

	}
	/**
	 * Test that a String contains only xml characters.  The method under
	 * only checks for null values and then character by character scans
	 * the string so this test is not exhaustive
	 */
	public void test_TCM__String_checkCharacterData_String() {
		//check out of range values
		assertNotNull("validated invalid null", Verifier.checkCharacterData(null));
		assertNotNull("validated invalid string with null", Verifier.checkCharacterData("test" + (char)0x0));
		assertNotNull("validated invalid string with null", Verifier.checkCharacterData("test" + (char)0x0 + "ing"));
		assertNotNull("validated invalid string with null", Verifier.checkCharacterData((char)0x0 + "test"));
		assertNotNull("validated invalid string with 0x01", Verifier.checkCharacterData((char)0x01 + "test"));
		assertNotNull("validated invalid string with 0xD800", Verifier.checkCharacterData("test" + (char)0xD800));
		assertNotNull("validated invalid string with 0xD800", Verifier.checkCharacterData("test" + (char)0xD800 + "ing"));
		assertNotNull("validated invalid string with 0xD800", Verifier.checkCharacterData((char)0xD800 + "test"));

		//various valid strings
		assertNull("invalidated valid string with \n", Verifier.checkCharacterData("test" + '\n' + "ing"));
		assertNull("invalidated valid string with 0x29", Verifier.checkCharacterData("test" +(char)0x29));
		//a few higher values
		assertNull("invalidated valid string with 0x0B08", Verifier.checkCharacterData("test" + (char)0x0B08));
		assertNull("invalidated valid string with \t", Verifier.checkCharacterData("test" + '\t'));
		//xml letter
		assertNull("invalidated valid string with 0x42", Verifier.checkCharacterData("test" + (char)0x42));
		assertNull("invalidated valid string with 0x4E01", Verifier.checkCharacterData("test" + (char)0x4E01));

	}
	/**
	 * Test checkCommentData such that a comment is validated as an
	 * xml comment consisting of xml characters with the following caveats.
	 * The comment must not contain a double hyphen.
	 */
	public void test_TCM__String_checkCommentData_String() {
		//check out of range values
		assertNotNull("validated invalid null", Verifier.checkCommentData(null));
		assertNotNull("validated invalid string with null", Verifier.checkCommentData("test" + (char)0x0));
		assertNotNull("validated invalid string with null", Verifier.checkCommentData("test" + (char)0x0 + "ing"));
		assertNotNull("validated invalid string with null", Verifier.checkCommentData((char)0x0 + "test"));
		assertNotNull("validated invalid string with 0x01", Verifier.checkCommentData((char)0x01 + "test"));
		assertNotNull("validated invalid string with 0xD800", Verifier.checkCommentData("test" + (char)0xD800));
		assertNotNull("validated invalid string with 0xD800", Verifier.checkCommentData("test" + (char)0xD800 + "ing"));
		assertNotNull("validated invalid string with 0xD800", Verifier.checkCommentData((char)0xD800 + "test"));
		assertNotNull("validated invalid string with --", Verifier.checkCommentData("--test"));

		//various valid strings
		assertNull("invalidated valid string with \n", Verifier.checkCommentData("test" + '\n' + "ing"));
		assertNull("invalidated valid string with 0x29", Verifier.checkCommentData("test" +(char)0x29));
		//a few higher values
		assertNull("invalidated valid string with 0x0B08", Verifier.checkCommentData("test" + (char)0x0B08));
		assertNull("invalidated valid string with \t", Verifier.checkCommentData("test" + '\t'));
		//xml letter
		assertNull("invalidated valid string with 0x42", Verifier.checkCommentData("test" + (char)0x42));
		assertNull("invalidated valid string with 0x4E01", Verifier.checkCommentData("test" + (char)0x4E01));

	}
	/**
	 * Test checkElementName such that a name is validated as an
	 * xml name with the following caveats.
	 * The name must not start with "-" or ":".
	 */
	public void test_TCM__String_checkElementName_String() {
		//check out of range values
		assertNotNull("validated invalid null", Verifier.checkElementName(null));
		assertNotNull("validated invalid name with null", Verifier.checkElementName("test" + (char)0x0));
		assertNotNull("validated invalid name with null", Verifier.checkElementName("test" + (char)0x0 + "ing"));
		assertNotNull("validated invalid name with null", Verifier.checkElementName((char)0x0 + "test"));
		assertNotNull("validated invalid name with 0x01", Verifier.checkElementName((char)0x01 + "test"));
		assertNotNull("validated invalid name with 0xD800", Verifier.checkElementName("test" + (char)0xD800));
		assertNotNull("validated invalid name with 0xD800", Verifier.checkElementName("test" + (char)0xD800 + "ing"));
		assertNotNull("validated invalid name with 0xD800", Verifier.checkElementName((char)0xD800 + "test"));
		assertNotNull("validated invalid name with :", Verifier.checkElementName("test" + ':' + "local"));

		//invalid start characters
		assertNotNull("validated invalid name with startin -", Verifier.checkElementName('-' + "test"));
		assertNotNull("validated invalid name with startin :", Verifier.checkElementName(':' + "test"));

		//valid tests
		assertNull("invalidated valid name with starting _", Verifier.checkElementName('_' + "test"));
		assertNull("invalidated valid name with _", Verifier.checkElementName("test" + '_'));
		assertNull("invalidated valid name with .", Verifier.checkElementName("test" + '.' + "name"));
		assertNull("invalidated valid name with 0x00B7", Verifier.checkElementName("test" + (char)0x00B7));
		assertNull("invalidated valid name with 0x4E01", Verifier.checkElementName("test" + (char)0x4E01));
		assertNull("invalidated valid name with 0x0301", Verifier.checkElementName("test" + (char)0x0301));

	}
	/**
	 * Test that checkNamespacePrefix validates against xml names
	 * with the following exceptions.  Prefix names must not start
	 * with "-", "xmlns", digits, "$", or "." and must not contain
	 * ":"
	 */
	public void test_TCM__String_checkNamespacePrefix_String() {
		//check out of range values
		assertNotNull("validated invalid name with null", Verifier.checkNamespacePrefix("test" + (char)0x0));
		assertNotNull("validated invalid name with null", Verifier.checkNamespacePrefix("test" + (char)0x0 + "ing"));
		assertNotNull("validated invalid name with null", Verifier.checkNamespacePrefix((char)0x0 + "test"));
		assertNotNull("validated invalid name with 0x01", Verifier.checkNamespacePrefix((char)0x01 + "test"));
		assertNotNull("validated invalid name with 0xD800", Verifier.checkNamespacePrefix("test" + (char)0xD800));
		assertNotNull("validated invalid name with 0xD800", Verifier.checkNamespacePrefix("test" + (char)0xD800 + "ing"));
		assertNotNull("validated invalid name with 0xD800", Verifier.checkNamespacePrefix((char)0xD800 + "test"));
		assertNotNull("validated invalid name with :", Verifier.checkNamespacePrefix("test" + ':' + "local"));

		//invalid start characters
		assertNotNull("validated invalid name with startin -", Verifier.checkNamespacePrefix('-' + "test"));
		assertNotNull("validated invalid name with xmlns", Verifier.checkNamespacePrefix("xmlns"));
		assertNotNull("validated invalid name with startin :", Verifier.checkNamespacePrefix(':' + "test"));
		assertNotNull("validated invalid name with starting digit", Verifier.checkNamespacePrefix("9"));
		assertNotNull("validated invalid name with starting $", Verifier.checkNamespacePrefix("$"));
		assertNotNull("validated invalid name with starting .", Verifier.checkNamespacePrefix("."));

		//valid tests
		assertNull("invalidated valid null", Verifier.checkNamespacePrefix(null));
		assertNull("invalidated valid name with starting _", Verifier.checkNamespacePrefix('_' + "test"));
		assertNull("invalidated valid name with _", Verifier.checkNamespacePrefix("test" + '_'));
		assertNull("invalidated valid name with .", Verifier.checkNamespacePrefix("test" + '.' + "name"));
		assertNull("invalidated valid name with digit", Verifier.checkNamespacePrefix("test9"));
		assertNull("invalidated valid name with 0x00B7", Verifier.checkNamespacePrefix("test" + (char)0x00B7));
		assertNull("invalidated valid name with 0x4E01", Verifier.checkNamespacePrefix("test" + (char)0x4E01));
		assertNull("invalidated valid name with 0x0301", Verifier.checkNamespacePrefix("test" + (char)0x0301));

	}
	/**
	 * Tests that checkNamespaceURI validates xml uri's.
	 * A valid URI is alphanumeric characters and the reserved characters:
	 * ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |  "$" | ","
	 *            
	 * The URI cannot begin with a digit, "-" or "$".  It must have at least
	 * one ":" separating the scheme from the scheme specific part
	 *
	 * XXX:TODO make this match the eventual specs for the Verifier class which is incomplete
	 */
	public void test_TCM__String_checkNamespaceURI_String() {
		//invalid start characters
		assertNotNull("validated invalid URI with startin -", Verifier.checkNamespaceURI('-' + "test"));
		assertNotNull("validated invalid URI with starting digit", Verifier.checkNamespaceURI("9"));
		assertNotNull("validated invalid URI with starting $", Verifier.checkNamespaceURI("$"));

		//valid tests
		assertNull("invalidated valid null", Verifier.checkNamespaceURI(null));
		assertNull("invalidated valid URI with :", Verifier.checkNamespaceURI("test" + ':' + "local"));
		assertNull("invalidated valid URI with _", Verifier.checkNamespaceURI("test" + '_'));
		assertNull("invalidated valid URI with .", Verifier.checkNamespaceURI("test" + '.' + "URI"));
		assertNull("invalidated valid URI with digit", Verifier.checkNamespaceURI("test9"));
		assertNull("invalidated valid URI with 0x00B7", Verifier.checkNamespaceURI("test" + (char)0x00B7));
		assertNull("invalidated valid URI with 0x4E01", Verifier.checkNamespaceURI("test" + (char)0x4E01));
		assertNull("invalidated valid URI with 0x0301", Verifier.checkNamespaceURI("test" + (char)0x0301));

		//check out of range values

		/** skip these tests until the time the checks are implemented
		assertNull("validated invalid URI with xmlns", Verifier.checkNamespaceURI("xmlns"));
		assertNull("validated invalid URI with startin :", Verifier.checkNamespaceURI(':' + "test"));
		assertNull("validated invalid URI with starting .", Verifier.checkNamespaceURI("."));
		
		assertNull("validated invalid URI with null", Verifier.checkNamespaceURI("test" + (char)0x0));
		assertNull("validated invalid URI with null", Verifier.checkNamespaceURI("test" + (char)0x0 + "ing"));
		assertNull("validated invalid URI with null", Verifier.checkNamespaceURI((char)0x0 + "test"));
		assertNull("validated invalid URI with 0x01", Verifier.checkNamespaceURI((char)0x01 + "test"));
		assertNull("validated invalid URI with 0xD800", Verifier.checkNamespaceURI("test" + (char)0xD800));
		assertNull("validated invalid URI with 0xD800", Verifier.checkNamespaceURI("test" + (char)0xD800 + "ing"));
		assertNull("validated invalid URI with 0xD800", Verifier.checkNamespaceURI((char)0xD800 + "test"));
		*/


	}
	/**
	 * Test that checkProcessintInstructionTarget validates the name
	 * of a processing instruction.  This name must be a normal xml
	 * and cannot have ":" or "xml" in the name.
	 */
	public void test_TCM__String_checkProcessingInstructionTarget_String() {
		//check out of range values
		assertNotNull("validated invalid null", Verifier.checkProcessingInstructionTarget(null));
		assertNotNull("validated invalid name with null", Verifier.checkProcessingInstructionTarget("test" + (char)0x0));
		assertNotNull("validated invalid name with null", Verifier.checkProcessingInstructionTarget("test" + (char)0x0 + "ing"));
		assertNotNull("validated invalid name with null", Verifier.checkProcessingInstructionTarget((char)0x0 + "test"));
		assertNotNull("validated invalid name with 0x01", Verifier.checkProcessingInstructionTarget((char)0x01 + "test"));
		assertNotNull("validated invalid name with 0xD800", Verifier.checkProcessingInstructionTarget("test" + (char)0xD800));
		assertNotNull("validated invalid name with 0xD800", Verifier.checkProcessingInstructionTarget("test" + (char)0xD800 + "ing"));
		assertNotNull("validated invalid name with 0xD800", Verifier.checkProcessingInstructionTarget((char)0xD800 + "test"));
		assertNotNull("validated invalid name with :", Verifier.checkProcessingInstructionTarget("test" + ':' + "local"));
		assertNotNull("validated invalid name with xml:space", Verifier.checkProcessingInstructionTarget("xml:space"));
		assertNotNull("validated invalid name with xml:lang", Verifier.checkProcessingInstructionTarget("xml:lang"));
		assertNotNull("validated invalid name with xml", Verifier.checkProcessingInstructionTarget("xml"));
		assertNotNull("validated invalid name with xMl", Verifier.checkProcessingInstructionTarget("xMl"));

		//invalid start characters
		assertNotNull("validated invalid name with startin -", Verifier.checkProcessingInstructionTarget('-' + "test"));
		assertNotNull("validated invalid name with startin :", Verifier.checkProcessingInstructionTarget(':' + "test"));
		//valid tests
		assertNull("invalidated valid name with starting _", Verifier.checkProcessingInstructionTarget('_' + "test"));
		assertNull("invalidated valid name with _", Verifier.checkProcessingInstructionTarget("test" + '_'));
		assertNull("invalidated valid name with .", Verifier.checkProcessingInstructionTarget("test" + '.' + "name"));
		assertNull("invalidated valid name with 0x00B7", Verifier.checkProcessingInstructionTarget("test" + (char)0x00B7));
		assertNull("invalidated valid name with 0x4E01", Verifier.checkProcessingInstructionTarget("test" + (char)0x4E01));
		assertNull("invalidated valid name with 0x0301", Verifier.checkProcessingInstructionTarget("test" + (char)0x0301));

	}
	/**
	 * This test is a noop.  The method is for development only
	 * It will remain in the suite until it is removed from the
	 * Verifier class
	 */
	public void test_TCM__void_main_ArrayString() {
		//this test is a noop.  The method is for development only
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -