use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class ParserInputStreamDataSourceTests method _testPEDS.
/**
* @param behavior Behavior (DESTRUCTIVE, NOT_DESTRUCTIVE, ONE_USE_UNSAFE)
* @param markSupported (indicates if InputStream should be markable)
* @param scnenario Scenario
* @return numReads
* @throws Exception
*/
public int _testPEDS(int behavior, boolean markSupported, int scenario) throws Exception {
// Create an InputStream
InputStream is = null;
if (markSupported) {
is = new ByteArrayInputStream(payloadText.getBytes("UTF-8"));
} else {
is = new NotMarkableInputStream(payloadText.getBytes("UTF-8"));
}
// Create a PEDS with the indicated behavior
ParserInputStreamDataSource peds = new ParserInputStreamDataSource(is, "UTF-8", behavior);
// Create a OM tree with a root that contains an OMSourcedElement with a PADS
OMFactory factory = OMAbstractFactory.getOMFactory();
OMNamespace ns = factory.createOMNamespace("urn://sample", "my");
OMElement om = factory.createOMElement(peds, "payload", ns);
QName rootQName = new QName("urn://root", "root", "pre");
OMElement root = factory.createOMElement(rootQName);
root.addChild(om);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Apply the scenario
if (scenario == Scenario.SER) {
root.serialize(baos);
String result = baos.toString("UTF-8");
assertResult(result);
} else if (scenario == Scenario.SER_SER) {
root.serialize(baos);
String result = baos.toString("UTF-8");
assertResult(result);
baos.reset();
root.serialize(baos);
result = baos.toString("UTF-8");
assertResult(result);
} else if (scenario == Scenario.SAC) {
root.serializeAndConsume(baos);
String result = baos.toString("UTF-8");
assertResult(result);
} else if (scenario == Scenario.SER_SAC) {
root.serialize(baos);
String result = baos.toString("UTF-8");
assertResult(result);
baos.reset();
root.serializeAndConsume(baos);
result = baos.toString("UTF-8");
assertResult(result);
} else if (scenario == Scenario.SAC_SAC) {
root.serializeAndConsume(baos);
String result = baos.toString("UTF-8");
assertResult(result);
baos.reset();
root.serializeAndConsume(baos);
// This second serializeAndConsume is expected to throw an exception.
}
return peds.numReads();
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestAddAttributeWithExistingNamespaceDeclarationOnSameElement method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement(new QName("test"));
OMNamespace ns = factory.createOMNamespace("urn:ns", "p");
element.declareNamespace(ns);
strategy.addAttribute(element, "test", ns, "test");
Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
assertTrue(it.hasNext());
assertEquals(ns, it.next());
assertFalse(it.hasNext());
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestAddAttributeWithInvalidNamespace2 method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement(new QName("test"));
OMNamespace ns = factory.createOMNamespace("urn:test", "");
try {
element.addAttribute("attr", "value", ns);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException ex) {
assertEquals("Cannot create an unprefixed attribute with a namespace", ex.getMessage());
// No namespace declaration should have been added before throwing the exception
assertFalse(element.getAllDeclaredNamespaces().hasNext());
}
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestAddAttributeWithInvalidNamespace1 method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement(new QName("test"));
OMNamespace ns = factory.createOMNamespace("", "p");
try {
element.addAttribute("attr", "value", ns);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException ex) {
assertEquals("Cannot create a prefixed attribute with an empty namespace name", ex.getMessage());
// No namespace declaration should have been added before throwing the exception
assertFalse(element.getAllDeclaredNamespaces().hasNext());
}
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestAddAttributeWithMaskedNamespaceDeclaration method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMNamespace ns1 = factory.createOMNamespace("urn:ns1", "p");
OMNamespace ns2 = factory.createOMNamespace("urn:ns2", "p");
OMElement element1 = factory.createOMElement(new QName("a"));
element1.declareNamespace(ns1);
OMElement element2 = factory.createOMElement(new QName("b"), element1);
element2.declareNamespace(ns2);
OMElement element3 = factory.createOMElement(new QName("c"), element2);
strategy.addAttribute(element3, "attr", ns1, "test");
Iterator<OMNamespace> it = element3.getAllDeclaredNamespaces();
assertTrue(it.hasNext());
assertEquals(ns1, it.next());
assertFalse(it.hasNext());
}
Aggregations