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

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

The newest version!
package org.apache.ws.jaxme.junit;

import java.io.File;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.ValidationEvent;
import javax.xml.bind.ValidationEventHandler;
import javax.xml.namespace.QName;

import magoffin.matt.ieat.domain.impl.IngredientImpl;
import net.dspc.commons.activitymodel.TransmissionData;
import net.dspc.commons.activitymodel2.Body1;
import net.dspc.commons.activitymodel2.Body2;
import net.dspc.commons.activitymodel2.ObjectFactory;

import org.apache.ws.jaxme.generator.Generator;
import org.apache.ws.jaxme.generator.SchemaReader;
import org.apache.ws.jaxme.generator.impl.GeneratorImpl;
import org.apache.ws.jaxme.generator.sg.SchemaSG;
import org.apache.ws.jaxme.generator.sg.impl.JAXBSchemaReader;
import org.apache.ws.jaxme.generator.util.JavaNamer;
import org.apache.ws.jaxme.test.jira.jaxme65.Jaxme65;
import org.apache.ws.jaxme.test.jira.jaxme65.Jaxme65Type;
import org.apache.ws.jaxme.test.jira72.Jaxme72;
import org.apache.ws.jaxme.test.misc.types.Jira62;
import org.apache.ws.jaxme.test.misc.types.Row;
import org.apache.ws.jaxme.test.misc.types.impl.RowImpl;
import org.apache.ws.jaxme.test.misc.xsimport.a.Outer;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import com.softwareag.namespaces.de.s.xdws.soap_api.XdwsResponse;


/** Some excerpts from Jira bug reports.
 */
public class JiraTest extends BaseTestCase {
	/** Creates a new instance with the given name.
	 */
    public JiraTest(String pName) {
    	super(pName);
    }

    /** Test for JAXME-10
     */
    public void testJaxMe10() throws Exception {
		final String input1 =
            "\n" +
            "  \n" +
            "    [email protected]\n" +
            "    0793041414141\n" +
            "    \n" +
            "  \n" +
            "  \n" +
            "";
        unmarshalMarshalUnmarshal(TransmissionData.class, input1);
        final String input2 =
            "\n" +
            "  \n" +
            "    [email protected]\n" +
            "    0793041414141\n" +
            "  \n" +
            "  \n" +
            "";
        unmarshalMarshalUnmarshal(TransmissionData.class, input2);
        final String input3 =
            "\n" +
            "  \n" +
            "    0793041414141\n" +
            "  \n" +
            "  \n" +
            "";
        unmarshalMarshalUnmarshal(TransmissionData.class, input3);
    }

    /** Test for JAXME-12
     */
    public void testJaxMe12() throws Exception {
        final String[] inputs = new String[]{
            "",
            "",
            "",
            "",
            ""
        };
        for (int i = 0;  i < inputs.length;  i++) {
        	unmarshalMarshalUnmarshal(Body1.class, inputs[i]);
        }
        Body1 body1 = new ObjectFactory().createBody1();
        body1.setValue("ok");
        Body2 body2 = new ObjectFactory().createBody2();
        body2.setValue("ok");
    }

    /** Test for JAXME-38
     */
    public void testJaxMe38() throws Exception {
    	RowImpl emptyRow = new RowImpl();
        final String xml = "\n" +
        "  a\n" +
        "";
        unmarshalMarshalUnmarshal(Row.class, xml);
    }

    /** Test for JAXME-39
     */
    public void testJaxMe39() throws Exception {
    	IngredientImpl ingredientImpl = new IngredientImpl();
        assertTrue(!ingredientImpl.isSetIngredientId());
        ingredientImpl.setIngredientId(new Integer(0));
        assertTrue(ingredientImpl.isSetIngredientId());
    }

    /** Test for JAXME-45
     */
    public void testJaxMe45() throws Exception {
    	Outer outer = new org.apache.ws.jaxme.test.misc.xsimport.a.ObjectFactory().createOuter();
        outer.setInner1("ok");
        outer.setInner2(0);
        JAXBContext context = JAXBContext.newInstance("org.apache.ws.jaxme.test.misc.xsimport.a");
        StringWriter sw = new StringWriter();
        context.createMarshaller().marshal(outer, sw);
        assertEquals("\n" +
                     "\n" +
                     "  ok\n" +
                     "  0\n" +
                     "", sw.toString());
    }

	/** Test for JAXME-51.
	 */
	public void testJAXME51() throws Exception {
		final String xsSchema =
			"\n"
			+ "\n"
			+ "  \n"
			+ "    "
			+ "  \n"
			+ "  \n"
			+ "    \n"
			+ "      \n"
			+ "        \n"
			+ "        \n"
			+ "      \n"
			+ "    \n"
			+ "  \n"
			+ "\n";
		Generator g = new GeneratorImpl();
		SchemaReader sr = new JAXBSchemaReader();
		g.setSchemaReader(sr);
		sr.setGenerator(g);
		SchemaSG schema = g.getSchemaReader().parse(new InputSource(new StringReader(xsSchema)));
		assertEquals("Element1", JavaNamer.convert("element1", schema));
		assertEquals("Element_1", JavaNamer.convert("element_1", schema));
	}

	/** Test for JAXME-62.
	 */
	public void testJAXME62() throws Exception {
		for (int i = 0;  i < 6;  i++) {
			runFacetTest(i, "a", i < 5);
		}
		for (int i = 0;  i < 6;  i++) {
			runFacetTest(i, "b", i > 3);
		}
		for (int i = 0;  i < 6;  i++) {
			runFacetTest(i, "c", i == 4);
		}
	}

	private static class EventDetector implements ValidationEventHandler {
		private boolean gotEvent = false;
		public boolean handleEvent(ValidationEvent pEvent) {
			gotEvent = true;
			return true;
		}
		boolean isSuccess() { return !gotEvent; }
	};

	private void runFacetTest(int i, String pAttrName, boolean pSuccess) throws JAXBException {
		JAXBContext ctx = super.getJAXBContext(Jira62.class);
		String xml =
			"JAXME-63.
	 */
	public void testJAXME63() throws Exception {
		final String xml =
			"\n"
			+ "  \n"
			+ "    \n"
			+ "      \n"
			+ "      \n"
			+ "      \n"
			+ "    \n"
			+ "  \n"
			+ "  \n"
			+ "    \n"
			+ "      \n"
			+ "    \n"
			+ "  \n"
			+ "";
		Generator g = new GeneratorImpl();
		g.setProperty("jaxme.package.name", "org.apache.ws.jaxme.test.jira.jaxme63");
		SchemaReader sr = new JAXBSchemaReader();
		g.setSchemaReader(sr);
		sr.setGenerator(g);
		SchemaSG schema = g.getSchemaReader().parse(new InputSource(new StringReader(xml)));
		try {
			schema.generate();
			fail("Expected exception");
		} catch (SAXException e) {
			assertTrue(e.getMessage().indexOf("Model groups with maxOccurs > 1 are not yet supported.") != -1);
		}
	}

	/** Test for JAXME-65.
	 */
	public void testJAXME65() throws Exception {
		final String xml1 =
			"some texthere it ismore text";
		Jaxme65 text1 = (Jaxme65) getJAXBContext(Jaxme65.class).createUnmarshaller().unmarshal(new InputSource(new StringReader(xml1)));
		List list1 = text1.getContent();
		assertEquals(3, list1.size());
		assertEquals("some text", list1.get(0));
		Object o = list1.get(1);
		assertTrue(o instanceof Jaxme65Type.Problem);
		Jaxme65Type.Problem problem = (Jaxme65Type.Problem) o;
		assertEquals("here it is", problem.getValue());
		assertEquals("more text", list1.get(2));
		final String xml2 =
			"some text";
		Jaxme65 text2 = (Jaxme65) getJAXBContext(Jaxme65.class).createUnmarshaller().unmarshal(new InputSource(new StringReader(xml2)));
		List list2 = text2.getContent();
		assertEquals(1, list2.size());
		assertEquals("some text", list2.get(0));
	}

	/** Test for JAXME-72.
	 */
	public void testJAXME72() throws JAXBException {
		// create test structure
		org.apache.ws.jaxme.test.jira72.ObjectFactory oFact = new org.apache.ws.jaxme.test.jira72.ObjectFactory();
		Jaxme72 jaxme72  = oFact.createJaxme72();
		QName qName = new QName("http://this.namespace/must/be/declared", "jaxme72");
		jaxme72.setTest(qName);
		// try to marshal it...Jira issue 72 address the problem that this will fail.
		JAXBContext ctx = JAXBContext.newInstance("org.apache.ws.jaxme.test.jira72");
		StringWriter sw = new StringWriter();
		ctx.createMarshaller().marshal(jaxme72, sw);
		// if we get this far issue 72 shoulb be fixed. just to be sure - unmarshal and compare QNames.
		Jaxme72 jaxme72Clone = (Jaxme72) ctx.createUnmarshaller().unmarshal(new InputSource(new StringReader(sw.toString())));
		assertEquals(jaxme72.getTest(),jaxme72Clone.getTest());
	}

    /** Test for JAXME-84.
     */
    public void testJAXME84() throws Exception {
        final String xml =
            "\n"
            + "  \n"
            + "  \n"
            + "";
        unmarshalMarshalUnmarshal(XdwsResponse.class, xml);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy