Package org.jboss.test.xml.person

Examples of org.jboss.test.xml.person.Person


      SchemaBinding schema = XsdBinder.bind(new StringReader(xsd), null);
      Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
      Object unmarshalled = unmarshaller.unmarshal(new StringReader(xml), schema);
      assertNotNull(unmarshalled);
      assertTrue(unmarshalled instanceof Person);
      Person person = (Person)unmarshalled;
      assertEquals(firstName, person.getFirstName());
      assertEquals(lastName, person.getLastName());

      StringWriter writer = new StringWriter();
      MarshallerImpl marshaller = new MarshallerImpl();
      marshaller.marshal(schema, null, person, writer);
      String marshalled = writer.getBuffer().toString();
View Full Code Here


         fail("the xml not found");
      }

      Reader xmlReader = new java.io.InputStreamReader(url.openStream());

      Person person = unmarshalPerson(xmlReader);
      xmlReader.close();

      assertNotNull("Person is null", person);
      assertEquals(person.getFirstName(), "Vasiliy");
      assertEquals(person.getLastName(), "Poupkin");
      assertEquals(person.getDateOfBirth(), SimpleTypeBindings.JAVA_UTIL_DATE.unmarshal("1980-01-01"));

      assertEquals(person.getPhones(), Arrays.asList(new Object[]{"01", "02"}));

      ArrayList list = new ArrayList();
      Address addr1 = new Address();
      addr1.setStreet("prosp. Rad. Ukr. 11A, 70");
      list.add(addr1);
      addr1 = new Address();
      addr1.setStreet("Sky 7");
      list.add(addr1);
      assertEquals(person.getAddresses(), list);
   }
View Full Code Here

   public void testMarshalling() throws Exception
   {
      log.debug("<test-mapping-marshalling>");

      final Person person = Person.newInstance();
      StringWriter xmlOutput = new StringWriter();

      InputStream is = getResource("xml/person.dtd");
      Reader dtdReader = new InputStreamReader(is);

      // create an instance of DTD marshaller
      Marshaller marshaller = new DtdMarshaller();

      // map publicId to systemId as it should appear in the resulting XML file
      marshaller.mapPublicIdToSystemId("-//DTD Person//EN", "resources/xml/person.dtd");

      // create an instance of ObjectModelProvider with the book instance to be marshalled
      MappingObjectModelProvider provider = new MappingObjectModelProvider();
      provider.mapFieldToElement(Person.class, "dateOfBirth", "", "date-of-birth", SimpleTypeBindings.JAVA_UTIL_DATE);

      // marshal the book
      marshaller.marshal(dtdReader, provider, person, xmlOutput);

      // close DTD reader
      dtdReader.close();

      final String xml = xmlOutput.getBuffer().toString();
      log.debug("marshalled: " + xml);

      // check unmarshalled person
      Person unmarshalled = unmarshalPerson(new StringReader(xml));
      assertEquals(person, unmarshalled);

      log.debug("</test-mapping-marshalling>");
   }
View Full Code Here

      super(localName);
   }

   public void testSchemalessMarshalling() throws Exception
   {
      Person person = Person.newInstance();
      StringWriter writer = new StringWriter();

      SchemalessMarshaller marshaller = new SchemalessMarshaller();
      marshaller.marshal(person, writer);

      log.info("marshalled:\n" + writer.getBuffer());

      StringReader reader = new StringReader(writer.getBuffer().toString());
      Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
      SchemalessObjectModelFactory factory = new SchemalessObjectModelFactory();
      Person unmarshalled = (Person)unmarshaller.unmarshal(reader, factory, null);

      log.info("unmarshalled: " + unmarshalled);
      assertEquals(person, unmarshalled);
   }
View Full Code Here

         fail("the xml not found");
      }

      Reader xmlReader = new java.io.InputStreamReader(url.openStream());

      Person person = unmarshalPerson(xmlReader);
      xmlReader.close();

      assertNotNull("Person is null", person);
      assertEquals(person.getFirstName(), "Vasiliy");
      assertEquals(person.getLastName(), "Poupkin");
      assertEquals(person.getDateOfBirth(), SimpleTypeBindings.JAVA_UTIL_DATE.unmarshal("1980-01-01"));

      assertEquals(person.getPhones(), Arrays.asList(new Object[]{"01", "02"}));

      ArrayList<Address> list = new ArrayList<Address>();
      Address addr1 = new Address();
      addr1.setStreet("prosp. Rad. Ukr. 11A, 70");
      list.add(addr1);
      addr1 = new Address();
      addr1.setStreet("Sky 7");
      list.add(addr1);
      assertEquals(person.getAddresses(), list);
   }
View Full Code Here

   public void testMarshalling() throws Exception
   {
      log.debug("<test-mapping-marshalling>");

      final Person person = Person.newInstance();
      StringWriter xmlOutput = new StringWriter();

      InputStream is = getResource("xml/person.dtd");
      Reader dtdReader = new InputStreamReader(is);

      // create an instance of DTD marshaller
      Marshaller marshaller = new DtdMarshaller();

      // map publicId to systemId as it should appear in the resulting XML file
      marshaller.mapPublicIdToSystemId("-//DTD Person//EN", "resources/xml/person.dtd");

      // create an instance of ObjectModelProvider with the book instance to be marshalled
      MappingObjectModelProvider provider = new MappingObjectModelProvider();
      provider.mapFieldToElement(Person.class, "dateOfBirth", "", "date-of-birth", SimpleTypeBindings.JAVA_UTIL_DATE);

      // marshal the book
      marshaller.marshal(dtdReader, provider, person, xmlOutput);

      // close DTD reader
      dtdReader.close();

      final String xml = xmlOutput.getBuffer().toString();
      log.debug("marshalled: " + xml);

      // check unmarshalled person
      Person unmarshalled = unmarshalPerson(new StringReader(xml));
      assertEquals(person, unmarshalled);

      log.debug("</test-mapping-marshalling>");
   }
View Full Code Here

      super(localName);
   }

   public void testSchemalessMarshalling() throws Exception
   {
      Person person = Person.newInstance();
      StringWriter writer = new StringWriter();

      SchemalessMarshaller marshaller = new SchemalessMarshaller();
      marshaller.marshal(person, writer);

      StringReader reader = new StringReader(writer.getBuffer().toString());
      Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
      SchemalessObjectModelFactory factory = new SchemalessObjectModelFactory();
      Person unmarshalled = (Person)unmarshaller.unmarshal(reader, factory, null);

      assertEquals(person, unmarshalled);
   }
View Full Code Here

      SchemaBinding schema = XsdBinder.bind(new StringReader(xsd), null);
      Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
      Object unmarshalled = unmarshaller.unmarshal(new StringReader(xml), schema);
      assertNotNull(unmarshalled);
      assertTrue(unmarshalled instanceof Person);
      Person person = (Person)unmarshalled;
      assertEquals(firstName, person.getFirstName());
      assertEquals(lastName, person.getLastName());

      StringWriter writer = new StringWriter();
      MarshallerImpl marshaller = new MarshallerImpl();
      marshaller.marshal(schema, null, person, writer);
      String marshalled = writer.getBuffer().toString();
View Full Code Here

TOP

Related Classes of org.jboss.test.xml.person.Person

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.