Return-Path: Delivered-To: apmail-incubator-wink-commits-archive@minotaur.apache.org Received: (qmail 26331 invoked from network); 17 Dec 2009 18:15:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 17 Dec 2009 18:15:23 -0000 Received: (qmail 54400 invoked by uid 500); 17 Dec 2009 18:15:23 -0000 Delivered-To: apmail-incubator-wink-commits-archive@incubator.apache.org Received: (qmail 54326 invoked by uid 500); 17 Dec 2009 18:15:22 -0000 Mailing-List: contact wink-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: wink-dev@incubator.apache.org Delivered-To: mailing list wink-commits@incubator.apache.org Received: (qmail 54218 invoked by uid 99); 17 Dec 2009 18:15:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Dec 2009 18:15:22 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Dec 2009 18:15:19 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id E726C2388ABB; Thu, 17 Dec 2009 18:14:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r891814 [2/2] - in /incubator/wink/trunk/wink-providers/wink-jaxbcollection-provider: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/wink/ src/main/java/org/apache/wink/providers/ src/... Date: Thu, 17 Dec 2009 18:14:58 -0000 To: wink-commits@incubator.apache.org From: jramos@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091217181458.E726C2388ABB@eris.apache.org> Added: incubator/wink/trunk/wink-providers/wink-jaxbcollection-provider/src/test/java/org/apache/wink/providers/internal/JAXBCollectionXMLProviderTest.java URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-jaxbcollection-provider/src/test/java/org/apache/wink/providers/internal/JAXBCollectionXMLProviderTest.java?rev=891814&view=auto ============================================================================== --- incubator/wink/trunk/wink-providers/wink-jaxbcollection-provider/src/test/java/org/apache/wink/providers/internal/JAXBCollectionXMLProviderTest.java (added) +++ incubator/wink/trunk/wink-providers/wink-jaxbcollection-provider/src/test/java/org/apache/wink/providers/internal/JAXBCollectionXMLProviderTest.java Thu Dec 17 18:14:57 2009 @@ -0,0 +1,704 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.wink.providers.internal; + +import java.io.ByteArrayInputStream; +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.GenericEntity; +import javax.ws.rs.core.MediaType; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; + +import org.apache.wink.common.annotations.Asset; +import org.apache.wink.common.model.atom.AtomFeed; +import org.apache.wink.common.model.atom.ObjectFactory; +import org.apache.wink.providers.xml.JAXBArrayXmlProvider; +import org.apache.wink.providers.xml.JAXBCollectionXmlProvider; +import org.apache.wink.server.internal.servlet.MockServletInvocationTest; +import org.apache.wink.test.mock.MockRequestConstructor; +import org.apache.wink.test.mock.TestUtils; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; + +public class JAXBCollectionXMLProviderTest extends MockServletInvocationTest { + + public static final String SOURCE_REQUEST = + "012"; + public static final byte[] SOURCE_REQUEST_BYTES = SOURCE_REQUEST.getBytes(); + public static final String SOURCE_RESPONSE = + "010110210"; + public static final String JAXBXmlType_REQUEST = + "001122"; + public static final byte[] JAXBXmlType_REQUEST_BYTES = JAXBXmlType_REQUEST.getBytes(); + public static final String JAXBXmlType_RESPONSE = + "ID0NAME0ID1NAME1ID2NAME2"; + public static final String JAXBXmlRootElement_REQUEST = + "001122"; + public static final byte[] JAXBXmlRootElement_BYTES = JAXBXmlRootElement_REQUEST.getBytes(); + public static final String JAXBXmlRootElement_RESPONSE = + "ID0NAME0ID1NAME1ID2NAME2"; + + @Override + protected Class[] getClasses() { + return new Class[] {Resource.class}; + } + + @Path("jaxbresource") + public static class Resource { + + @POST + @Path("jaxbelement") + public List> createWrapped(List> feedList) { + List> wrappedFeeds = new ArrayList>(); + for (JAXBElement feed : feedList) { + AtomFeed atomFeed = new AtomFeed(); + atomFeed.setId(feed.getValue().getId() + 10); + JAXBElement wrappedFeed = new ObjectFactory().createFeed(atomFeed); + wrappedFeeds.add(wrappedFeed); + } + return wrappedFeeds; + } + + @POST + @Path("xmlrootwithfactorycollection") + public List createBareCollection(List feedList) { + List feeds = new ArrayList(); + for (AtomFeed feed : feedList) { + AtomFeed atomFeed = new AtomFeed(); + atomFeed.setId(feed.getId() + 10); + feeds.add(atomFeed); + } + return feeds; + } + + @POST + @Path("xmlrootwithfactoryarray") + public AtomFeed[] createBareArray(AtomFeed[] feedList) { + List feeds = new ArrayList(); + for (AtomFeed feed : feedList) { + AtomFeed atomFeed = new AtomFeed(); + atomFeed.setId(feed.getId() + 10); + feeds.add(atomFeed); + } + return feeds.toArray(new AtomFeed[] {}); + } + + @POST + @Path("xmltypecollection") + public List> createxmltypeCollection(List resource) { + List> ret = new ArrayList>(); + JAXBXmlType s = null; + for (JAXBXmlType type : resource) { + s = new JAXBXmlType(); + s.setId("ID" + type.getId()); + s.setName("NAME" + type.getName()); + JAXBElement element = + new JAXBElement(new QName("JAXBXmlType"), JAXBXmlType.class, s); + ret.add(element); + } + return ret; + } + + @POST + @Path("xmltypearray") + public JAXBXmlType[] createxmltypeArray(JAXBXmlType[] resource) { + JAXBXmlType[] ret = new JAXBXmlType[resource.length]; + JAXBXmlType s = null; + int i = 0; + for (JAXBXmlType type : resource) { + s = new JAXBXmlType(); + s.setId("ID" + type.getId()); + s.setName("NAME" + type.getId()); + ret[i++] = s; + } + return ret; + } + + @POST + @Path("xmlrootnofactorycollection") + public List createXmlRoot(List resource) { + List ret = new ArrayList(); + JAXBXmlRootElement s = null; + for (int i = 0; i < resource.size(); ++i) { + s = new JAXBXmlRootElement(); + s.setId("ID" + resource.get(i).getId()); + s.setName("NAME" + resource.get(i).getName()); + ret.add(s); + } + return ret; + } + + @POST + @Path("xmlrootnofactoryarray") + public JAXBXmlRootElement[] createXmlRoot(JAXBXmlRootElement[] resource) { + JAXBXmlRootElement[] ret = new JAXBXmlRootElement[resource.length]; + JAXBXmlRootElement s = null; + for (int i = 0; i < resource.length; ++i) { + s = new JAXBXmlRootElement(); + s.setId("ID" + resource[i].getId()); + s.setName("NAME" + resource[i].getName()); + ret[i] = s; + } + return ret; + } + + @GET + @Path("xmltypenofactorycollection") + public List getXmltypeNoFactoryCollection() { + List ret = new ArrayList(); + JAXBXmlType s = null; + for (int i = 0; i < 3; ++i) { + s = new JAXBXmlType(); + s.setId("ID" + i); + s.setName("NAME" + i); + ret.add(s); + } + return ret; + } + + @GET + @Path("xmltypenofactoryarray") + public JAXBXmlType[] getXmltypeNoFactoryArray() { + List ret = new ArrayList(); + JAXBXmlType s = null; + for (int i = 0; i < 3; ++i) { + s = new JAXBXmlType(); + s.setId("ID" + i); + s.setName("NAME" + i); + ret.add(s); + } + return ret.toArray(new JAXBXmlType[] {}); + } + + @POST + @Path("xmlassetcollection") + public List getAsset(List asset) { + return asset; + } + } + + @Asset + public static class TestAsset { + + JAXBXmlType xml; + + @Produces(MediaType.TEXT_XML) + public JAXBXmlType getJAXB() { + return xml; + } + + @Consumes(MediaType.TEXT_XML) + public void setJAXB(JAXBXmlType jaxbObject) { + xml = jaxbObject; + } + } + + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "JAXBXmlType", propOrder = {"id", "name"}) + public static class JAXBXmlType { + + @XmlElement(required = true) + private String id; + @XmlElement(required = true) + private String name; + + public JAXBXmlType() { + } + + public void setId(String id) { + this.id = id; + } + + public String getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + } + + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "JAXBXmlRootElement", propOrder = {"id", "name"}) + @XmlRootElement(name = "JAXBXmlRootElement") + public static class JAXBXmlRootElement { + + @XmlElement(required = true) + private String id; + @XmlElement(required = true) + private String name; + + public JAXBXmlRootElement() { + } + + public void setId(String id) { + this.id = id; + } + + public String getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + } + + public void testJAXBCollectionXMLProviderIsReadableCollection() throws Exception { + JAXBCollectionXmlProvider provider = new JAXBCollectionXmlProvider(); + + GenericEntity> type1 = + new GenericEntity>(new ArrayList()) { + }; + assertTrue(provider.isReadable(type1.getRawType(), + type1.getType(), + null, + new MediaType("text", "xml"))); + assertTrue(provider.isReadable(type1.getRawType(), + type1.getType(), + null, + new MediaType("application", "xml"))); + assertTrue(provider.isReadable(type1.getRawType(), + type1.getType(), + null, + new MediaType("application", "atom+xml"))); + assertTrue(provider.isReadable(type1.getRawType(), + type1.getType(), + null, + new MediaType("application", "atomsvc+xml"))); + + GenericEntity>> type2 = + new GenericEntity>>(new ArrayList>()) { + }; + assertTrue(provider.isReadable(type2.getRawType(), + type2.getType(), + null, + new MediaType("text", "xml"))); + assertTrue(provider.isReadable(type2.getRawType(), + type2.getType(), + null, + new MediaType("application", "xml"))); + assertTrue(provider.isReadable(type2.getRawType(), + type2.getType(), + null, + new MediaType("application", "atom+xml"))); + assertTrue(provider.isReadable(type2.getRawType(), + type2.getType(), + null, + new MediaType("application", "atomsvc+xml"))); + + GenericEntity> type3 = + new GenericEntity>(new ArrayList()) { + }; + assertFalse(provider.isReadable(type3.getRawType(), + type3.getType(), + null, + new MediaType("text", "xml"))); + assertFalse(provider.isReadable(type3.getRawType(), + type3.getType(), + null, + new MediaType("application", "xml"))); + assertFalse(provider.isReadable(type3.getRawType(), + type3.getType(), + null, + new MediaType("application", "atom+xml"))); + assertFalse(provider.isReadable(type3.getRawType(), + type3.getType(), + null, + new MediaType("application", "atomsvc+xml"))); + } + + public void testJAXBCollectionXMLProviderIsReadableArray() throws Exception { + JAXBArrayXmlProvider provider = new JAXBArrayXmlProvider(); + + assertTrue(provider.isReadable(AtomFeed[].class, + AtomFeed[].class, + null, + new MediaType("text", "xml"))); + assertTrue(provider.isReadable(AtomFeed[].class, + AtomFeed[].class, + null, + new MediaType("application", "xml"))); + assertTrue(provider.isReadable(AtomFeed[].class, + AtomFeed[].class, + null, + new MediaType("application", "atom+xml"))); + assertTrue(provider.isReadable(AtomFeed[].class, + AtomFeed[].class, + null, + new MediaType("application", "atomsvc+xml"))); + + assertFalse(provider.isReadable(JAXBElement[].class, + JAXBElement[].class, + null, + new MediaType("text", "xml"))); + assertFalse(provider.isReadable(JAXBElement[].class, + JAXBElement[].class, + null, + new MediaType("application", "xml"))); + assertFalse(provider.isReadable(JAXBElement[].class, + JAXBElement[].class, + null, + new MediaType("application", "atom+xml"))); + assertFalse(provider.isReadable(JAXBElement[].class, + JAXBElement[].class, + null, + new MediaType("application", "atomsvc+xml"))); + + assertFalse(provider.isReadable(String[].class, String[].class, null, new MediaType("text", + "xml"))); + assertFalse(provider.isReadable(String[].class, + String[].class, + null, + new MediaType("application", "xml"))); + assertFalse(provider.isReadable(String[].class, + String[].class, + null, + new MediaType("application", "atom+xml"))); + assertFalse(provider.isReadable(String[].class, + String[].class, + null, + new MediaType("application", "atomsvc+xml"))); + } + + public void testJAXBCollectionXMLProviderIsWritableCollection() throws Exception { + JAXBCollectionXmlProvider provider = new JAXBCollectionXmlProvider(); + + GenericEntity> type1 = + new GenericEntity>(new ArrayList()) { + }; + assertTrue(provider.isWriteable(type1.getRawType(), + type1.getType(), + null, + new MediaType("text", "xml"))); + assertTrue(provider.isWriteable(type1.getRawType(), + type1.getType(), + null, + new MediaType("application", "xml"))); + assertTrue(provider.isWriteable(type1.getRawType(), + type1.getType(), + null, + new MediaType("application", "atom+xml"))); + assertTrue(provider.isWriteable(type1.getRawType(), + type1.getType(), + null, + new MediaType("application", "atomsvc+xml"))); + + GenericEntity>> type2 = + new GenericEntity>>(new ArrayList>()) { + }; + assertTrue(provider.isWriteable(type2.getRawType(), + type2.getType(), + null, + new MediaType("text", "xml"))); + assertTrue(provider.isWriteable(type2.getRawType(), + type2.getType(), + null, + new MediaType("application", "xml"))); + assertTrue(provider.isWriteable(type2.getRawType(), + type2.getType(), + null, + new MediaType("application", "atom+xml"))); + assertTrue(provider.isWriteable(type2.getRawType(), + type2.getType(), + null, + new MediaType("application", "atomsvc+xml"))); + + GenericEntity> type3 = + new GenericEntity>(new ArrayList()) { + }; + assertFalse(provider.isWriteable(type3.getRawType(), + type3.getType(), + null, + new MediaType("text", "xml"))); + assertFalse(provider.isWriteable(type3.getRawType(), + type3.getType(), + null, + new MediaType("application", "xml"))); + assertFalse(provider.isWriteable(type3.getRawType(), + type3.getType(), + null, + new MediaType("application", "atom+xml"))); + assertFalse(provider.isWriteable(type3.getRawType(), + type3.getType(), + null, + new MediaType("application", "atomsvc+xml"))); + } + + public void testJAXBCollectionXMLProviderIsWritableArray() throws Exception { + JAXBArrayXmlProvider provider = new JAXBArrayXmlProvider(); + + assertTrue(provider.isWriteable(AtomFeed[].class, + AtomFeed[].class, + null, + new MediaType("text", "xml"))); + assertTrue(provider.isWriteable(AtomFeed[].class, + AtomFeed[].class, + null, + new MediaType("application", "xml"))); + assertTrue(provider.isWriteable(AtomFeed[].class, + AtomFeed[].class, + null, + new MediaType("application", "atom+xml"))); + assertTrue(provider.isWriteable(AtomFeed[].class, + AtomFeed[].class, + null, + new MediaType("application", "atomsvc+xml"))); + + assertFalse(provider.isWriteable(JAXBElement[].class, + JAXBElement[].class, + null, + new MediaType("text", "xml"))); + assertFalse(provider.isWriteable(JAXBElement[].class, + JAXBElement[].class, + null, + new MediaType("application", "xml"))); + assertFalse(provider.isWriteable(JAXBElement[].class, + JAXBElement[].class, + null, + new MediaType("application", "atom+xml"))); + assertFalse(provider.isWriteable(JAXBElement[].class, + JAXBElement[].class, + null, + new MediaType("application", "atomsvc+xml"))); + + assertFalse(provider.isWriteable(String[].class, + String[].class, + null, + new MediaType("text", "xml"))); + assertFalse(provider.isWriteable(String[].class, + String[].class, + null, + new MediaType("application", "xml"))); + assertFalse(provider.isWriteable(String[].class, + String[].class, + null, + new MediaType("application", "atom+xml"))); + assertFalse(provider.isWriteable(String[].class, + String[].class, + null, + new MediaType("application", "atomsvc+xml"))); + } + + public void testJAXBElementCollection() throws Exception { + MockHttpServletRequest request = + MockRequestConstructor.constructMockRequest("POST", + "/jaxbresource/jaxbelement", + "text/xml", + "text/xml", + SOURCE_REQUEST_BYTES); + MockHttpServletResponse invoke = invoke(request); + assertEquals(200, invoke.getStatus()); + + String[] elements = + getElementsFromList("", "", ")unmarshallElement(AtomFeed.class, "", "", ")unmarshallElement(AtomFeed.class, "", "", ")unmarshallElement(AtomFeed.class, " type, String response) throws JAXBException { + JAXBContext context = JAXBContext.newInstance(type); + Unmarshaller unmarshaller = context.createUnmarshaller(); + return unmarshaller.unmarshal(new ByteArrayInputStream(response.getBytes())); + } +} Added: incubator/wink/trunk/wink-providers/wink-jaxbcollection-provider/src/test/java/org/apache/wink/providers/internal/jaxb/ObjectFactory.java URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-jaxbcollection-provider/src/test/java/org/apache/wink/providers/internal/jaxb/ObjectFactory.java?rev=891814&view=auto ============================================================================== --- incubator/wink/trunk/wink-providers/wink-jaxbcollection-provider/src/test/java/org/apache/wink/providers/internal/jaxb/ObjectFactory.java (added) +++ incubator/wink/trunk/wink-providers/wink-jaxbcollection-provider/src/test/java/org/apache/wink/providers/internal/jaxb/ObjectFactory.java Thu Dec 17 18:14:57 2009 @@ -0,0 +1,30 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.wink.providers.internal.jaxb; + +import javax.xml.bind.annotation.XmlRegistry; + +@XmlRegistry +public class ObjectFactory { + + public Person createPerson() { + return new Person(); + } +} Added: incubator/wink/trunk/wink-providers/wink-jaxbcollection-provider/src/test/java/org/apache/wink/providers/internal/jaxb/Person.java URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-jaxbcollection-provider/src/test/java/org/apache/wink/providers/internal/jaxb/Person.java?rev=891814&view=auto ============================================================================== --- incubator/wink/trunk/wink-providers/wink-jaxbcollection-provider/src/test/java/org/apache/wink/providers/internal/jaxb/Person.java (added) +++ incubator/wink/trunk/wink-providers/wink-jaxbcollection-provider/src/test/java/org/apache/wink/providers/internal/jaxb/Person.java Thu Dec 17 18:14:57 2009 @@ -0,0 +1,47 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.wink.providers.internal.jaxb; + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class Person { + + private String name; + + private String desc; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + +}