public void testElementDefault() throws Exception { XMLValidationSchema schema = parseW3CSchema(SCHEMA_WITH_DEFAULTS); XMLStreamReader2 sr = getReader("<price>129</price>"); sr.validateAgainst(schema); // first: if explicitly defined, should show that value assertTokenType(START_ELEMENT, sr.next()); assertEquals("price", sr.getLocalName()); assertEquals("129", sr.getElementText()); assertTokenType(END_ELEMENT, sr.getEventType()); sr.close(); // then, if missing, default to given default sr = getReader("<price />"); sr.validateAgainst(schema); // first: if explicitly defined, should show that value assertTokenType(START_ELEMENT, sr.next()); assertEquals("price", sr.getLocalName()); assertEquals("10", sr.getElementText()); assertTokenType(END_ELEMENT, sr.getEventType()); sr.close(); }
public void testAttributeDefault() throws Exception { XMLValidationSchema schema = parseW3CSchema(SCHEMA_WITH_DEFAULTS); XMLStreamReader2 sr = getReader("<price currency='FIM'>129</price>"); sr.validateAgainst(schema); // first: if explicitly defined, should show that value assertTokenType(START_ELEMENT, sr.next()); assertEquals("price", sr.getLocalName()); assertEquals(1, sr.getAttributeCount()); assertEquals("FIM", sr.getAttributeValue(null, "currency")); sr.close(); // then, if missing, default to given default sr = getReader("<price>129</price>"); sr.validateAgainst(schema); // first: if explicitly defined, should show that value assertTokenType(START_ELEMENT, sr.next()); assertEquals("price", sr.getLocalName()); assertEquals(1, sr.getAttributeCount()); assertEquals("USD", sr.getAttributeValue(null, "currency")); sr.close(); }