1 package org.apache.ws.jaxme.junit; 2 3 import java.io.StringReader ; 4 import java.io.StringWriter ; 5 6 import javax.xml.bind.JAXBContext; 7 8 import magoffin.matt.ieat.domain.impl.IngredientImpl; 9 import net.dspc.commons.activitymodel.TransmissionData; 10 import net.dspc.commons.activitymodel2.Body1; 11 import net.dspc.commons.activitymodel2.Body2; 12 import net.dspc.commons.activitymodel2.ObjectFactory; 13 14 import org.apache.ws.jaxme.generator.Generator; 15 import org.apache.ws.jaxme.generator.SchemaReader; 16 import org.apache.ws.jaxme.generator.impl.GeneratorImpl; 17 import org.apache.ws.jaxme.generator.sg.SchemaSG; 18 import org.apache.ws.jaxme.generator.sg.impl.JAXBSchemaReader; 19 import org.apache.ws.jaxme.generator.sg.impl.JAXBSchemaSG; 20 import org.apache.ws.jaxme.generator.util.JavaNamer; 21 import org.apache.ws.jaxme.test.misc.types.Row; 22 import org.apache.ws.jaxme.test.misc.types.impl.RowImpl; 23 import org.apache.ws.jaxme.test.misc.xsimport.a.Outer; 24 import org.apache.ws.jaxme.xs.xml.XsQName; 25 import org.xml.sax.InputSource ; 26 27 28 30 public class JiraTest extends BaseTestCase { 31 33 public JiraTest(String pName) { 34 super(pName); 35 } 36 37 39 public void testJaxMe10() throws Exception { 40 final String input1 = 41 "<TransmissionData mail-id=\"mail456.test-account@dspc.net\" xmlns=\"http://commons.dspc.net/activitymodel\">\n" + 42 " <sender account-id=\"test-account@dspc.net\" name=\"Joe Tester\">\n" + 43 " <e-mail>test-account@bluprints.com</e-mail>\n" + 44 " <phone>0793041414141</phone>\n" + 45 " <crypt-signature/>\n" + 46 " </sender>\n" + 47 " <recipient account-id=\"hvendelbo@bluprints.com\" name=\"Henrik Vendelbo\"/>\n" + 48 "</TransmissionData>"; 49 unmarshalMarshalUnmarshal(TransmissionData.class, input1); 50 final String input2 = 51 "<TransmissionData mail-id=\"mail456.test-account@dspc.net\" xmlns=\"http://commons.dspc.net/activitymodel\">\n" + 52 " <sender account-id=\"test-account@dspc.net\" name=\"Joe Tester\">\n" + 53 " <e-mail>test-account@bluprints.com</e-mail>\n" + 54 " <phone>0793041414141</phone>\n" + 55 " </sender>\n" + 56 " <recipient account-id=\"hvendelbo@bluprints.com\" name=\"Henrik Vendelbo\"/>\n" + 57 "</TransmissionData>"; 58 unmarshalMarshalUnmarshal(TransmissionData.class, input2); 59 final String input3 = 60 "<TransmissionData mail-id=\"mail456.test-account@dspc.net\" xmlns=\"http://commons.dspc.net/activitymodel\">\n" + 61 " <sender account-id=\"test-account@dspc.net\" name=\"Joe Tester\"/>\n" + 62 " <recipient account-id=\"hvendelbo@bluprints.com\" name=\"Henrik Vendelbo\"/>\n" + 63 "</TransmissionData>"; 64 unmarshalMarshalUnmarshal(TransmissionData.class, input2); 65 } 66 67 69 public void testJaxMe12() throws Exception { 70 final String [] inputs = new String []{ 71 "<Body1 text-template=\"y\" html-template=\"x\" xmlns=\"http://commons.dspc.net/activitymodel2\"/>", 72 "<Body1 text-template=\"y\" xmlns=\"http://commons.dspc.net/activitymodel2\"/>", 73 "<Body1 html-template=\"x\" xmlns=\"http://commons.dspc.net/activitymodel2\"/>", 74 "<Body1 xmlns=\"http://commons.dspc.net/activitymodel2\"/>", 75 "<Body2 xmlns=\"http://commons.dspc.net/activitymodel2\"/>" 76 }; 77 for (int i = 0; i < inputs.length; i++) { 78 unmarshalMarshalUnmarshal(Body1.class, inputs[i]); 79 } 80 Body1 body1 = new ObjectFactory().createBody1(); 81 body1.setValue("ok"); 82 Body2 body2 = new ObjectFactory().createBody2(); 83 body2.setValue("ok"); 84 } 85 86 88 public void testJaxMe38() throws Exception { 89 RowImpl emptyRow = new RowImpl(); 90 final String xml = "<ex:row xmlns:ex=\"" + getNamespaceURI(emptyRow) + "\">\n" + 91 " <ex:cell id=\"1\">a</ex:cell>\n" + 92 "</ex:row>"; 93 unmarshalMarshalUnmarshal(Row.class, xml); 94 } 95 96 98 public void testJaxMe39() throws Exception { 99 IngredientImpl ingredientImpl = new IngredientImpl(); 100 assertTrue(!ingredientImpl.isSetIngredientId()); 101 ingredientImpl.setIngredientId(new Integer (0)); 102 assertTrue(ingredientImpl.isSetIngredientId()); 103 } 104 105 107 public void testJaxMe45() throws Exception { 108 Outer outer = new org.apache.ws.jaxme.test.misc.xsimport.a.ObjectFactory().createOuter(); 109 outer.setInner1("ok"); 110 outer.setInner2(0); 111 JAXBContext context = JAXBContext.newInstance("org.apache.ws.jaxme.test.misc.xsimport.a"); 112 StringWriter sw = new StringWriter (); 113 context.createMarshaller().marshal(outer, sw); 114 assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n" + 115 "<a:outer xmlns:a=\"http://ws.apache.org/jaxme/test/misc/xsimport/a\">\n" + 116 " <b:inner1 xmlns:b=\"http://ws.apache.org/jaxme/test/misc/xsimport/b\">ok</b:inner1>\n" + 117 " <b:inner2 xmlns:b=\"http://ws.apache.org/jaxme/test/misc/xsimport/b\">0</b:inner2>\n" + 118 "</a:outer>", sw.toString()); 119 } 120 121 123 public void testJAXME51() throws Exception { 124 final String xsSchema = 125 "<?xml version='1.0' encoding='utf-8'?>\n" 126 + "<xs:schema\n" 127 + " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" 128 + " elementFormDefault='qualified'\n" 129 + " xmlns='http://ws.apache.org/jaxme/test/jira/jaxme51'\n" 130 + " xmlns:jaxb='http://java.sun.com/xml/ns/jaxb'\n" 131 + " targetNamespace='http://ws.apache.org/jaxme/test/jira/jaxme51'" 132 + " jaxb:version='1.0'>\n" 133 + " <xs:annotation><xs:appinfo>\n" 134 + " <jaxb:globalBindings underscoreBinding='asCharInWord'/>" 135 + " </xs:appinfo></xs:annotation>\n" 136 + " <xs:element name='bug'>\n" 137 + " <xs:complexType>\n" 138 + " <xs:all>\n" 139 + " <xs:element name='element1' type='xs:string'/>\n" 140 + " <xs:element name='element_1' type='xs:string'/>\n" 141 + " </xs:all>\n" 142 + " </xs:complexType>\n" 143 + " </xs:element>\n" 144 + "</xs:schema>\n"; 145 Generator g = new GeneratorImpl(); 146 SchemaReader sr = new JAXBSchemaReader(); 147 g.setSchemaReader(sr); 148 sr.setGenerator(g); 149 SchemaSG schema = g.getSchemaReader().parse(new InputSource (new StringReader (xsSchema))); 150 assertEquals("Element1", JavaNamer.convert("element1", schema)); 151 assertEquals("Element_1", JavaNamer.convert("element_1", schema)); 152 } 153 } 154 | Popular Tags |