All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.ws.jaxme.junit.PrinterCreatorTest Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2003, 2004  The Apache Software Foundation
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.ws.jaxme.junit;

import java.io.StringReader;
import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

import org.apache.ws.jaxme.examples.misc.address.AddressCreator;
import org.apache.ws.jaxme.examples.misc.address.AddressPrinter;
import org.apache.ws.jaxme.impl.JMMarshallerImpl;
import org.apache.ws.jaxme.test.misc.address.Address;
import org.xml.sax.InputSource;


/** Basic test for marshalling and unmarshalling an
 * Address document.
 */
public class PrinterCreatorTest extends BaseTestCase {
	/** Creates a new instance with the given name.
	 */
	public PrinterCreatorTest(String pName) {
		super(pName);
	}
	
	private String getAddress() throws Exception {
		StringWriter sw = new StringWriter();
		AddressCreator.writeAddress(sw);
		sw.close();
		return "
\n" + " \n" + " Jane\n" + " Doe\n" + " \n" + " \n" + " 34 Main Street\n" + " 02215\n" + " Boston\n" + " MA\n" + " \n" + " \n" + " \n" + " 555.6789\n" + " \n" + " \n" + " 555.1212\n" + " \n" + " \n" + " \n" + " \n" + " [email protected]\n" + " \n" + " \n" + " [email protected]\n" + " \n" + " \n" + " [email protected]\n" + " \n" + " \n" + "
"; } /** Tests marshalling a JaxMe object. */ public void testCreate() throws Exception { StringWriter sw = new StringWriter(); AddressCreator.writeAddress(sw); sw.close(); String expect = "
\n" + " \n" + " Jane\n" + " Doe\n" + " \n" + " \n" + " 34 Main Street\n" + " 02215\n" + " Boston\n" + " MA\n" + " \n" + " \n" + " \n" + " 555.6789\n" + " \n" + " \n" + " 555.1212\n" + " \n" + " \n" + " \n" + " \n" + " [email protected]\n" + " \n" + " \n" + " [email protected]\n" + " \n" + " \n" + " [email protected]\n" + " \n" + " \n" + "
"; String got = sw.toString(); assertEquals(expect, got); } /** Tests unmarshalling a string into t JaxMe object. */ public void testPrint() throws Exception { String address = getAddress(); InputSource isource = new InputSource(new StringReader(address)); isource.setSystemId("testPrint.xml"); Address addr = AddressPrinter.getAddress(isource); JAXBContext context = JAXBContext.newInstance("org.apache.ws.jaxme.test.misc.address"); StringWriter sw = new StringWriter(); Marshaller m = context.createMarshaller(); m.setProperty(JMMarshallerImpl.JAXME_XML_DECLARATION, Boolean.FALSE); m.marshal(addr, sw); sw.close(); String got = sw.toString(); assertEquals(address, got); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy