public void testValidationEventHandler() throws Exception { boolean caughtException = false; File file = new File(ClassLoader.getSystemResource(CONTROL_XML_ADDRESS_FAIL).getFile()); Employee employee = (Employee) unmarshaller.unmarshal(file); try { validator.setEventHandler(new ValidationEventHandlerImpl()); validator.validate(employee.getHomeAddress()); } catch (ValidationException xmlpe) { caughtException = true; } catch (Exception ex) { } assertFalse("The event handler did not consume the exceptions as expected.", caughtException); }
public void testGetInvalidPropertyException() { boolean caughtException = false; try { validator.getProperty("thisIsAnInvalidProperty"); } catch (PropertyException e) { caughtException = true; } catch (Exception e) { } assertTrue("JAXBValidator did not throw PropertyException as expected.", caughtException); }
public void testValidateNestedComplexType() throws Exception { Job job = new Job(); try { validator.validate(job); } catch (Exception exception) { fail("JAXBValidator threw an unexpected exception." + exception.getMessage()); return; } }
public void testGetNullPropertyException() { boolean caughtException = false; try { validator.getProperty(null); } catch (IllegalArgumentException e) { caughtException = true; } catch (Exception e) { } assertTrue( "JAXBValidator did not throw IllegalArgumentException as expected.", caughtException); }
public void testValidateSimpleType() throws Exception { boolean caughtException = false; File file = new File(ClassLoader.getSystemResource(CONTROL_XML_FILE_NAME).getFile()); Employee employee = (Employee) unmarshaller.unmarshal(file); try { validator.validate(employee.getPhone()); } catch (ValidationException xmlpe) { caughtException = true; } assertFalse("Phone object did not validate.", caughtException); }
public void testValidateElementException() throws Exception { boolean caughtException = false; try { Employee employee = new Employee(); validator.validate(employee); } catch (ValidationException xmlpe) { caughtException = true; } catch (Exception ex) { } assertTrue("JAXBValidator did not throw ValidationException as expected.", caughtException); }
public void testValidateInheritanceComplexType() throws Exception { boolean caughtException = false; File file = new File(ClassLoader.getSystemResource(CONTROL_XML_INHERITANCE_FILE_NAME).getFile()); Employee employee = (Employee) unmarshaller.unmarshal(file); try { validator.validate(employee.getHomeAddress()); } catch (org.eclipse.persistence.platform.xml.XMLPlatformException xmlpe) { caughtException = true; } assertFalse("Address object did not validate.", caughtException); }
public void testValidateSimpleTypeIDException() throws Exception { boolean caughtException = false; try { Badge badge = new Badge(); badge.setNumber("11"); validator.validate(badge); } catch (ValidationException xmlpe) { caughtException = true; } catch (Exception ex) { } assertTrue("JAXBValidator did not throw ValidationException as expected.", caughtException); }
public void testValidateSimpleTypeException() throws Exception { boolean caughtException = false; try { Phone phone = new Phone(); phone.setNumber("12345678901"); validator.validate(phone); } catch (ValidationException xmlpe) { caughtException = true; } catch (Exception ex) { } assertTrue("JAXBValidator did not throw ValidationException as expected.", caughtException); }
public void testValidateAgainstWrongSchema() throws Exception { Job2 job = new Job2(); try { validator.validate(job); } catch (ValidationException validationException) { assertTrue(true); return; } catch (Exception ex) { fail("An incorrect Exception was thrown"); return; } fail("JAXBValidator did not throw ValidationException as expected."); }
public void testValidateRootException() { boolean caughtException = false; try { Car car = new Car(); validator.validateRoot(car); } catch (ValidationException e) { assertTrue(true); return; } catch (Exception e) { fail("JAXBValidator did not throw ValidationException as expected."); return; } assertTrue( "JAXBValidator did not any exceptions, expected a ValidationException.", caughtException); }
public void testValidateComplexTypeException() throws Exception { boolean caughtException = false; try { Address address = new Address(); address.setStreet("613 Cedar Lane"); address.setCity("Bangor"); address.setState("Maine"); validator.validate(address); } catch (ValidationException xmlpe) { caughtException = true; } catch (Exception ex) { } assertTrue("JAXBValidator did not throw ValidationException as expected.", caughtException); }
public void testValidateRoot() throws Exception { File file = new File(ClassLoader.getSystemResource(CONTROL_XML_FILE_NAME).getFile()); Object testObject = unmarshaller.unmarshal(file); assertTrue("Object did not validate.", validator.validateRoot(testObject)); }