SetAttributeNSpublic final class SetAttributeNS extends DOMTestCase The "setAttributeNS(namespaceURI,qualifiedName,Value)" method raises a
INVALID_CHARACTER_ERR DOMException if the specified prefix contains an
illegal character.
Attempt to add a new attribute on the first employee node. An exception
should be raised since the "qualifiedName" has an invalid character. |
Fields Summary |
---|
DOMDocumentBuilderFactory | factory | DocumentBuilder | builder |
Methods Summary |
---|
protected void | setUp()
super.setUp();
try {
factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
.getConfiguration1());
builder = factory.getBuilder();
} catch (Exception e) {
fail("Unexpected exception" + e.getMessage());
}
| protected void | tearDown()
factory = null;
builder = null;
super.tearDown();
| public void | testSetAttributeNS1()Runs the test case.
String namespaceURI = "http://www.nist.gov";
String qualifiedName = "emp:qual?name";
Document doc;
NodeList elementList;
Node testAddr;
doc = (Document) load("staffNS", builder);
elementList = doc.getElementsByTagName("employee");
testAddr = elementList.item(0);
{
boolean success = false;
try {
((Element) /* Node */testAddr).setAttributeNS(namespaceURI,
qualifiedName, "newValue");
} catch (DOMException ex) {
success = (ex.code == DOMException.INVALID_CHARACTER_ERR);
}
assertTrue("throw_INVALID_CHARACTER_ERR", success);
}
| public void | testSetAttributeNS10()
String namespaceURI = "http://www.example.gov";
Document doc;
NodeList elementList;
Node testAddr;
doc = (Document) load("hc_staff", builder);
elementList = doc.getElementsByTagName("em");
testAddr = elementList.item(0);
{
boolean success = false;
try {
((Element) /* Node */testAddr).setAttributeNS(namespaceURI, "",
"newValue");
} catch (DOMException ex) {
success = (ex.code == DOMException.NAMESPACE_ERR);
}
assertTrue("throw_NAMESPACE_ERR", success);
}
| public void | testSetAttributeNS2()
String namespaceURI = "http://www.nist.gov";
String qualifiedName = "emp:";
Document doc;
NodeList elementList;
Node testAddr;
doc = (Document) load("staffNS", builder);
elementList = doc.getElementsByTagName("emp:employee");
testAddr = elementList.item(0);
{
boolean success = false;
try {
((Element) /* Node */testAddr).setAttributeNS(namespaceURI,
qualifiedName, "newValue");
} catch (DOMException ex) {
success = (ex.code == DOMException.NAMESPACE_ERR);
}
assertTrue("throw_NAMESPACE_ERR", success);
}
| public void | testSetAttributeNS4()
Document doc;
NodeList elementList;
Node testAddr;
Attr addrAttr;
String resultAttr;
String resultNamespaceURI;
String resultLocalName;
String resultPrefix;
doc = (Document) load("staffNS", builder);
elementList = doc.getElementsByTagName("emp:address");
testAddr = elementList.item(0);
assertNotNull("empAddrNotNull", testAddr);
((Element) /* Node */testAddr).setAttributeNS("http://www.nist.gov",
"newprefix:zone", "newValue");
addrAttr = ((Element) /* Node */testAddr).getAttributeNodeNS(
"http://www.nist.gov", "zone");
resultAttr = ((Element) /* Node */testAddr).getAttributeNS(
"http://www.nist.gov", "zone");
assertEquals("attrValue", "newValue", resultAttr);
resultNamespaceURI = addrAttr.getNamespaceURI();
assertEquals("nsuri", "http://www.nist.gov", resultNamespaceURI);
resultLocalName = addrAttr.getLocalName();
assertEquals("lname", "zone", resultLocalName);
resultPrefix = addrAttr.getPrefix();
assertEquals("prefix", "newprefix", resultPrefix);
| public void | testSetAttributeNS5()
String localName = "newAttr";
String namespaceURI = "http://www.newattr.com";
String qualifiedName = "emp:newAttr";
Document doc;
NodeList elementList;
Node testAddr;
String resultAttr;
doc = (Document) load("staffNS", builder);
elementList = doc.getElementsByTagName("emp:address");
testAddr = elementList.item(0);
assertNotNull("empAddrNotNull", testAddr);
((Element) /* Node */testAddr).setAttributeNS(namespaceURI,
qualifiedName, "<newValue>");
resultAttr = ((Element) /* Node */testAddr).getAttributeNS(
namespaceURI, localName);
assertEquals("throw_Equals", "<newValue>", resultAttr);
| public void | testSetAttributeNS6()
String namespaceURI = "http://www.nist.gov";
String qualifiedName = "xml:qualifiedName";
Document doc;
NodeList elementList;
Node testAddr;
doc = (Document) load("staffNS", builder);
elementList = doc.getElementsByTagName("employee");
testAddr = elementList.item(0);
{
boolean success = false;
try {
((Element) /* Node */testAddr).setAttributeNS(namespaceURI,
qualifiedName, "newValue");
} catch (DOMException ex) {
success = (ex.code == DOMException.NAMESPACE_ERR);
}
assertTrue("throw_NAMESPACE_ERR", success);
}
| public void | testSetAttributeNS7()
String namespaceURI = "http://www.nist.gov";
String qualifiedName = "xmlns";
Document doc;
NodeList elementList;
Node testAddr;
doc = (Document) load("staffNS", builder);
elementList = doc.getElementsByTagName("employee");
testAddr = elementList.item(0);
{
boolean success = false;
try {
((Element) /* Node */testAddr).setAttributeNS(namespaceURI,
qualifiedName, "newValue");
} catch (DOMException ex) {
success = (ex.code == DOMException.NAMESPACE_ERR);
}
assertTrue("throw_NAMESPACE_ERR", success);
}
| public void | testSetAttributeNS9()
String localName = "newAttr";
String namespaceURI = "http://www.newattr.com";
String qualifiedName = "emp:newAttr";
Document doc;
NodeList elementList;
Node testAddr;
Attr addrAttr;
String resultAttr;
String resultNamespaceURI;
String resultLocalName;
String resultPrefix;
doc = (Document) load("staffNS", builder);
elementList = doc.getElementsByTagName("emp:address");
testAddr = elementList.item(0);
assertNotNull("empAddrNotNull", testAddr);
((Element) /* Node */testAddr).setAttributeNS(namespaceURI,
qualifiedName, "newValue");
addrAttr = ((Element) /* Node */testAddr).getAttributeNodeNS(
namespaceURI, localName);
resultAttr = ((Element) /* Node */testAddr).getAttributeNS(
namespaceURI, localName);
assertEquals("attrValue", "newValue", resultAttr);
resultNamespaceURI = addrAttr.getNamespaceURI();
assertEquals("nsuri", "http://www.newattr.com", resultNamespaceURI);
resultLocalName = addrAttr.getLocalName();
assertEquals("lname", "newAttr", resultLocalName);
resultPrefix = addrAttr.getPrefix();
assertEquals("prefix", "emp", resultPrefix);
|
|