コード例 #1
0
  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);
  }
コード例 #2
0
 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);
 }
コード例 #3
0
  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;
    }
  }
コード例 #4
0
 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);
 }
コード例 #5
0
  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);
  }
コード例 #6
0
  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);
  }
コード例 #7
0
  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);
  }
コード例 #8
0
  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);
  }
コード例 #9
0
  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);
  }
コード例 #10
0
  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.");
  }
コード例 #11
0
 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);
 }
コード例 #12
0
  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);
  }
コード例 #13
0
  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));
  }