use of org.codice.ddf.parser.xml.domain.MotherElement in project ddf by codice.
the class TestXmlParser method testUnmarshal.
@Test
public void testUnmarshal() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream();
parser.marshal(configurator, mother, os);
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
MotherElement unmarshal = parser.unmarshal(configurator, MotherElement.class, is);
assertEquals(mother.getAge(), unmarshal.getAge());
assertEquals(mother.getFirstname(), unmarshal.getFirstname());
assertEquals(mother.getLastname(), unmarshal.getLastname());
assertEquals(mother.getChild().size(), unmarshal.getChild().size());
assertEquals(luke.getFirstname(), unmarshal.getChild().get(0).getFirstname());
assertEquals(leia.getAge(), unmarshal.getChild().get(1).getAge());
configurator.setHandler(new DefaultValidationEventHandler());
is = new ByteArrayInputStream(os.toByteArray());
unmarshal = parser.unmarshal(configurator, MotherElement.class, is);
assertEquals(mother.getAge(), unmarshal.getAge());
configurator.addProperty("UnknownProperty", Boolean.TRUE);
is = new ByteArrayInputStream(os.toByteArray());
thrown.expect(ParserException.class);
parser.unmarshal(configurator, MotherElement.class, is);
}
use of org.codice.ddf.parser.xml.domain.MotherElement in project ddf by codice.
the class TestXmlParser method setUp.
@Before
public void setUp() throws Exception {
parser = new XmlParser();
List<String> ctxPath = ImmutableList.of(MotherElement.class.getPackage().getName());
configurator = parser.configureParser(ctxPath, TestXmlParser.class.getClassLoader());
mother = new MotherElement();
mother.setFirstname("Padme");
mother.setLastname("Skywalker");
mother.setAge(25);
luke = new ChildElement();
luke.setAge(2);
luke.setFirstname("Luke");
luke.setLastname("Skywalker");
leia = new ChildElement();
leia.setAge(2);
leia.setFirstname("Leia");
leia.setLastname("Organa");
mother.getChild().add(luke);
mother.getChild().add(leia);
}
use of org.codice.ddf.parser.xml.domain.MotherElement in project ddf by codice.
the class TestXmlParser method testUnmarshalSource.
@Test
public void testUnmarshalSource() throws Exception {
JAXBContext motherContext = JAXBContext.newInstance(MotherElement.class);
@SuppressWarnings("unchecked") JAXBElement<MotherElement> motherElementJAXBElement = new JAXBElement(new QName("mother"), MotherElement.class, mother);
JAXBSource motherSource = new JAXBSource(motherContext, motherElementJAXBElement);
MotherElement unmarshal = parser.unmarshal(configurator, MotherElement.class, motherSource);
assertEquals(mother.getAge(), unmarshal.getAge());
assertEquals(mother.getFirstname(), unmarshal.getFirstname());
assertEquals(mother.getLastname(), unmarshal.getLastname());
assertEquals(mother.getChild().size(), unmarshal.getChild().size());
assertEquals(luke.getFirstname(), unmarshal.getChild().get(0).getFirstname());
assertEquals(leia.getAge(), unmarshal.getChild().get(1).getAge());
}
use of org.codice.ddf.parser.xml.domain.MotherElement in project ddf by codice.
the class TestXmlParser method testUnmarshalSourceJAXBException.
@Test
public void testUnmarshalSourceJAXBException() throws Exception {
JAXBContext motherContext = JAXBContext.newInstance(MotherElement.class);
@SuppressWarnings("unchecked") JAXBElement<MotherElement> motherElementJAXBElement = new JAXBElement(new QName("mother"), MotherElement.class, mother);
JAXBSource motherSource = new JAXBSource(motherContext, motherElementJAXBElement);
configurator.addProperty("BadKey", "BadValue");
thrown.expect(ParserException.class);
parser.unmarshal(configurator, MotherElement.class, motherSource);
}
use of org.codice.ddf.parser.xml.domain.MotherElement in project ddf by codice.
the class TestXmlParser method testUnmarshalNode.
@Test
public void testUnmarshalNode() throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc = builder.newDocument();
parser.marshal(configurator, mother, doc);
MotherElement unmarshal = parser.unmarshal(configurator, MotherElement.class, doc);
assertEquals(mother.getAge(), unmarshal.getAge());
assertEquals(mother.getFirstname(), unmarshal.getFirstname());
assertEquals(mother.getLastname(), unmarshal.getLastname());
assertEquals(mother.getChild().size(), unmarshal.getChild().size());
assertEquals(luke.getFirstname(), unmarshal.getChild().get(0).getFirstname());
assertEquals(leia.getAge(), unmarshal.getChild().get(1).getAge());
}
Aggregations