1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
import java.io.StringWriter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.ValidationException;
import org.xml.sax.InputSource;
public class TestMarshalIDs {
private static final Log LOG = LogFactory.getLog(TestMarshalIDs.class);
/**
* Test method.
* @throws Exception For any exception thrown.
*/
public void testMarshallingAfterManuallyNullingID() throws Exception {
Unmarshaller unmarshaller = new Unmarshaller (PartialTerminationElement.class);
PartialTerminationElement entity = (PartialTerminationElement)
unmarshaller.unmarshal(new InputSource(this.getClass().getResource("input-ok.xml").toExternalForm()));
// assertNotNull (entity);
entity.getPartyOneElement().setId("");
StringWriter out = new StringWriter();
Marshaller marshaller = new Marshaller (out);
marshaller.setValidation(true);
try {
marshaller.marshal(entity);
// fail ("ValidationException expected");
}
catch (ValidationException e) {
// nothing to check
}
}
/**
* Test method.
* @throws Exception For any exception thrown.
*/
public void testMarshallingAfterManuallySettingDuplicateID() throws Exception {
Unmarshaller unmarshaller = new Unmarshaller (PartialTerminationElement.class);
PartialTerminationElement entity = (PartialTerminationElement)
unmarshaller.unmarshal(new InputSource(getClass().getResource("input-ok.xml").toExternalForm()));
// assertNotNull (entity);
entity.getPartyOneElement().setId("ID000001");
StringWriter out = new StringWriter();
Marshaller marshaller = new Marshaller (out);
marshaller.setValidation(true);
try {
marshaller.marshal(entity);
// fail ("ValidationException expected");
}
catch (ValidationException e) {
// nothing to check
}
}
}
|