Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java?rev=633633&r1=633632&r2=633633&view=diff ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java (original) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java Tue Mar 4 12:47:58 2008 @@ -23,19 +23,29 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.ws.rs.ConsumeMime; +import javax.ws.rs.HeaderParam; import javax.ws.rs.ProduceMime; import javax.ws.rs.QueryParam; +import javax.ws.rs.core.HttpContext; +import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Request; +import javax.ws.rs.core.UriInfo; import org.apache.cxf.jaxrs.model.ClassResourceInfo; import org.apache.cxf.jaxrs.model.MethodDispatcher; import org.apache.cxf.jaxrs.model.OperationResourceInfo; import org.apache.cxf.jaxrs.model.URITemplate; +import org.apache.cxf.jaxrs.provider.HttpHeadersImpl; +import org.apache.cxf.jaxrs.provider.RequestImpl; +import org.apache.cxf.jaxrs.provider.UriInfoImpl; import org.apache.cxf.message.Message; import org.apache.cxf.message.MessageImpl; +import org.easymock.classextension.EasyMock; +import org.easymock.classextension.IMocksControl; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -43,6 +53,23 @@ public class JAXRSUtilsTest extends Assert { public class Customer { + + @HttpContext private UriInfo uriInfo; + @HttpContext private HttpHeaders headers; + @HttpContext private Request request; + + public UriInfo getUriInfo() { + return uriInfo; + } + + public HttpHeaders getHeaders() { + return headers; + } + + public Request getRequest() { + return request; + } + @ProduceMime("text/xml") @ConsumeMime("text/xml") public void test() { @@ -59,7 +86,8 @@ } @ProduceMime("text/xml") - public void testQuery(@QueryParam("query") String queryString, @QueryParam("query") int queryInt) { + public void testQuery(@QueryParam("query") String queryString, + @QueryParam("query") int queryInt) { // complete } @@ -68,6 +96,13 @@ String queryString, @QueryParam("query2") String queryString2) { // complete } + + public void testParams(@HttpContext UriInfo info, + @HttpContext HttpHeaders hs, + @HttpContext Request r, + @HeaderParam("Foo") String h) { + // complete + } }; @Before @@ -81,7 +116,7 @@ sf.create(); List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos(); - Map<String, String> values = new HashMap<String, String>(); + MultivaluedMap<String, String> values = new MetadataMap<String, String>(); String contentTypes = "*/*"; String acceptContentTypes = "*/*"; @@ -139,7 +174,7 @@ sf.create(); List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos(); - Map<String, String> values = new HashMap<String, String>(); + MultivaluedMap<String, String> values = new MetadataMap<String, String>(); String contentTypes = "*/*"; String acceptContentTypes = "*/*"; @@ -418,5 +453,56 @@ "*/*", "*,x/y,text/xml,text/plain"); assertSame(ori, ori2); + } + + @Test + public void testHttpContextParameters() throws Exception { + + ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true); + OperationResourceInfo ori = + new OperationResourceInfo( + Customer.class.getMethod("testParams", + new Class[]{UriInfo.class, + HttpHeaders.class, + Request.class, + String.class}), + cri); + ori.setHttpMethod("GET"); + MultivaluedMap<String, String> headers = new MetadataMap<String, String>(); + headers.add("Foo", "bar"); + headers.add("Foo", "baz"); + + Message m = new MessageImpl(); + m.put(Message.PROTOCOL_HEADERS, headers); + + List<Object> params = + JAXRSUtils.processParameters(ori, new MetadataMap<String, String>(), m); + assertEquals("4 parameters expected", 4, params.size()); + assertSame(UriInfoImpl.class, params.get(0).getClass()); + assertSame(HttpHeadersImpl.class, params.get(1).getClass()); + assertSame(RequestImpl.class, params.get(2).getClass()); + assertSame(String.class, params.get(3).getClass()); + assertEquals("Wrong header param", "bar,baz", params.get(3)); + } + + @Test + public void testHttpContextFields() throws Exception { + + ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true); + OperationResourceInfo ori = new OperationResourceInfo(null, cri); + + Customer c = new Customer(); + + IMocksControl control = EasyMock.createNiceControl(); + Message m = control.createMock(Message.class); + m.get(Message.PROTOCOL_HEADERS); + EasyMock.expectLastCall().andReturn(new HashMap<String, List<String>>()); + + JAXRSUtils.injectHttpContextValues(c, ori, m); + assertSame(UriInfoImpl.class, c.getUriInfo().getClass()); + assertSame(HttpHeadersImpl.class, c.getHeaders().getClass()); + assertSame(RequestImpl.class, c.getRequest().getClass()); + + } }
Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java?rev=633633&view=auto ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java (added) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java Tue Mar 4 12:47:58 2008 @@ -0,0 +1,56 @@ +/** + * 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.cxf.jaxrs.model; + +import java.lang.reflect.Field; +import java.util.List; + +import javax.ws.rs.core.HttpContext; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.UriInfo; + +import org.junit.Assert; +import org.junit.Test; + +public class ClassResourceInfoTest extends Assert { + + private static class TestClass { + @HttpContext UriInfo u; + @HttpContext HttpHeaders h; + int i; + } + + @Test + public void testGetHttpContexts() { + ClassResourceInfo c = new ClassResourceInfo(TestClass.class); + List<Field> fields = c.getHttpContexts(); + assertEquals("Only root classes should check these fields", 0, fields.size()); + + c = new ClassResourceInfo(TestClass.class, true); + fields = c.getHttpContexts(); + assertEquals("2 http context fields available", 2, fields.size()); + assertTrue("Wrong fields selected", + (fields.get(0).getType() == UriInfo.class + || fields.get(1).getType() == UriInfo.class) + && (fields.get(0).getType() == HttpHeaders.class + || fields.get(1).getType() == HttpHeaders.class)); + + } +} Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java?rev=633633&r1=633632&r2=633633&view=diff ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java (original) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java Tue Mar 4 12:47:58 2008 @@ -19,9 +19,9 @@ package org.apache.cxf.jaxrs.model; -import java.util.HashMap; -import java.util.Map; +import javax.ws.rs.core.MultivaluedMap; +import org.apache.cxf.jaxrs.MetadataMap; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -37,11 +37,11 @@ public void testMatchBasic() throws Exception { URITemplate uriTemplate = new URITemplate("/customers/{id}", URITemplate.UNLIMITED_REGEX_SUFFIX); - Map<String, String> values = new HashMap<String, String>(); + MultivaluedMap<String, String> values = new MetadataMap<String, String>(); boolean match = uriTemplate.match("/customers/123/", values); assertTrue(match); - String value = values.get("id"); + String value = values.getFirst("id"); assertEquals("123", value); } @@ -49,12 +49,12 @@ public void testMatchBasicTwoParametersVariation1() throws Exception { URITemplate uriTemplate = new URITemplate("/customers/{name}/{department}", URITemplate.UNLIMITED_REGEX_SUFFIX); - Map<String, String> values = new HashMap<String, String>(); + MultivaluedMap<String, String> values = new MetadataMap<String, String>(); boolean match = uriTemplate.match("/customers/john/CS", values); assertTrue(match); - String name = values.get("name"); - String department = values.get("department"); + String name = values.getFirst("name"); + String department = values.getFirst("department"); assertEquals("john", name); assertEquals("CS", department); } @@ -63,12 +63,12 @@ public void testMatchBasicTwoParametersVariation2() throws Exception { URITemplate uriTemplate = new URITemplate("/customers/name/{name}/dep/{department}", URITemplate.UNLIMITED_REGEX_SUFFIX); - Map<String, String> values = new HashMap<String, String>(); + MultivaluedMap<String, String> values = new MetadataMap<String, String>(); boolean match = uriTemplate.match("/customers/name/john/dep/CS", values); assertTrue(match); - String name = values.get("name"); - String department = values.get("department"); + String name = values.getFirst("name"); + String department = values.getFirst("department"); assertEquals("john", name); assertEquals("CS", department); } @@ -77,11 +77,11 @@ public void testURITemplateWithSubResource() throws Exception { //So "/customers" is the URITemplate for the root resource class URITemplate uriTemplate = new URITemplate("/customers", URITemplate.LIMITED_REGEX_SUFFIX); - Map<String, String> values = new HashMap<String, String>(); + MultivaluedMap<String, String> values = new MetadataMap<String, String>(); boolean match = uriTemplate.match("/customers/123", values); assertTrue(match); - String subResourcePath = values.get(URITemplate.RIGHT_HAND_VALUE); + String subResourcePath = values.getFirst(URITemplate.RIGHT_HAND_VALUE); assertEquals("/123", subResourcePath); } @@ -89,11 +89,11 @@ public void testURITemplateWithSubResourceVariation2() throws Exception { //So "/customers" is the URITemplate for the root resource class URITemplate uriTemplate = new URITemplate("/customers", URITemplate.LIMITED_REGEX_SUFFIX); - Map<String, String> values = new HashMap<String, String>(); + MultivaluedMap<String, String> values = new MetadataMap<String, String>(); boolean match = uriTemplate.match("/customers/name/john/dep/CS", values); assertTrue(match); - String subResourcePath = values.get(URITemplate.RIGHT_HAND_VALUE); + String subResourcePath = values.getFirst(URITemplate.RIGHT_HAND_VALUE); assertEquals("/name/john/dep/CS", subResourcePath); } @@ -104,11 +104,11 @@ */ public void testURITemplateWithSubResourceVariation3() throws Exception { URITemplate uriTemplate = new URITemplate("/books/{bookId}/", URITemplate.LIMITED_REGEX_SUFFIX); - Map<String, String> values = new HashMap<String, String>(); - + MultivaluedMap<String, String> values = new MetadataMap<String, String>(); + boolean match = uriTemplate.match("/books/123/chapter/1", values); assertTrue(match); - String subResourcePath = values.get(URITemplate.RIGHT_HAND_VALUE); + String subResourcePath = values.getFirst(URITemplate.RIGHT_HAND_VALUE); assertEquals("/chapter/1", subResourcePath); } } Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java?rev=633633&view=auto ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java (added) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java Tue Mar 4 12:47:58 2008 @@ -0,0 +1,82 @@ +/** + * 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.cxf.jaxrs.provider; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.InputStream; +import java.util.Arrays; + +import javax.ws.rs.ext.MessageBodyReader; +import javax.ws.rs.ext.MessageBodyWriter; + +import org.apache.cxf.helpers.IOUtils; +import org.junit.Assert; +import org.junit.Test; + +public class BinaryDataProviderTest extends Assert { + + @Test + public void testIsWriteable() { + MessageBodyWriter<Object> p = new BinaryDataProvider(); + assertTrue(p.isWriteable(byte[].class) + && p.isWriteable(InputStream.class) + && p.isWriteable(File.class) + && !p.isWriteable(int[].class)); + } + + @Test + public void testIsReadable() { + MessageBodyReader<Object> p = new BinaryDataProvider(); + assertTrue(p.isReadable(byte[].class) + && p.isReadable(InputStream.class) + && !p.isReadable(File.class) + && !p.isReadable(int[].class)); + } + + @SuppressWarnings("unchecked") + @Test + public void testReadFrom() throws Exception { + MessageBodyReader p = new BinaryDataProvider(); + byte[] bytes = (byte[])p.readFrom(byte[].class, null, null, + new ByteArrayInputStream("hi".getBytes())); + assertTrue(Arrays.equals(new String("hi").getBytes(), bytes)); + + InputStream is = (InputStream)p.readFrom(InputStream.class, null, null, + new ByteArrayInputStream("hi".getBytes())); + bytes = IOUtils.readBytesFromStream(is); + assertTrue(Arrays.equals(new String("hi").getBytes(), bytes)); + } + + @SuppressWarnings("unchecked") + @Test + public void testWriteTo() throws Exception { + MessageBodyWriter p = new BinaryDataProvider(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + p.writeTo(new byte[]{'h', 'i'}, null, null, os); + assertTrue(Arrays.equals(new String("hi").getBytes(), os.toByteArray())); + ByteArrayInputStream is = new ByteArrayInputStream("hi".getBytes()); + os = new ByteArrayOutputStream(); + p.writeTo(is, null, null, os); + assertTrue(Arrays.equals(os.toByteArray(), new String("hi").getBytes())); + } + +} Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/CookieHeaderProviderTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/CookieHeaderProviderTest.java?rev=633633&view=auto ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/CookieHeaderProviderTest.java (added) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/CookieHeaderProviderTest.java Tue Mar 4 12:47:58 2008 @@ -0,0 +1,65 @@ +/** + * 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.cxf.jaxrs.provider; + +import javax.ws.rs.core.Cookie; + +import org.junit.Assert; +import org.junit.Test; + +public class CookieHeaderProviderTest extends Assert { + + @Test + public void testSupports() { + assertTrue(new CookieHeaderProvider().supports(Cookie.class)); + } + + @Test + public void testFromSimpleString() { + Cookie c = Cookie.parse("foo=bar"); + assertTrue("bar".equals(c.getValue()) + && "foo".equals(c.getName())); + } + + @Test + public void testNoValue() { + Cookie c = Cookie.parse("foo="); + assertTrue("".equals(c.getValue()) + && "foo".equals(c.getName())); + } + + @Test + public void testFromComplexString() { + Cookie c = Cookie.parse("$Version=2;foo=bar;$Path=path;$Domain=domain"); + assertTrue("bar".equals(c.getValue()) + && "foo".equals(c.getName()) + && 2 == c.getVersion() + && "path".equals(c.getPath()) + && "domain".equals(c.getDomain())); + } + + @Test + public void testToString() { + Cookie c = new Cookie("foo", "bar", "path", "domain", 2); + assertEquals("$Version=2;foo=bar;$Path=path;$Domain=domain", + c.toString()); + + } +} Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/CookieHeaderProviderTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/CookieHeaderProviderTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/EntityTagHeaderProviderTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/EntityTagHeaderProviderTest.java?rev=633633&view=auto ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/EntityTagHeaderProviderTest.java (added) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/EntityTagHeaderProviderTest.java Tue Mar 4 12:47:58 2008 @@ -0,0 +1,54 @@ +/** + * 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.cxf.jaxrs.provider; + +import javax.ws.rs.core.EntityTag; + +import org.junit.Assert; +import org.junit.Test; + +public class EntityTagHeaderProviderTest extends Assert { + + @Test + public void testSupports() { + assertTrue(new EntityTagHeaderProvider().supports(EntityTag.class)); + } + + @Test + public void testFromString() { + EntityTag tag = EntityTag.parse(""); + assertTrue(!tag.isWeak() && "".equals(tag.getValue())); + tag = EntityTag.parse("W/"); + assertTrue(tag.isWeak() && "".equals(tag.getValue())); + tag = EntityTag.parse("W/12345"); + assertTrue(tag.isWeak() && "12345".equals(tag.getValue())); + tag = EntityTag.parse("12345"); + assertTrue(!tag.isWeak() && "12345".equals(tag.getValue())); + } + + @Test + public void testToString() { + EntityTag tag = new EntityTag(""); + assertEquals("", tag.toString()); + tag = new EntityTag("", true); + assertEquals("W/", tag.toString()); + + } +} Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/EntityTagHeaderProviderTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/EntityTagHeaderProviderTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/HttpHeadersImplTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/HttpHeadersImplTest.java?rev=633633&view=auto ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/HttpHeadersImplTest.java (added) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/HttpHeadersImplTest.java Tue Mar 4 12:47:58 2008 @@ -0,0 +1,76 @@ +/** + * 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.cxf.jaxrs.provider; + +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MultivaluedMap; + +import org.apache.cxf.jaxrs.MetadataMap; +import org.apache.cxf.message.Message; +import org.easymock.classextension.EasyMock; +import org.easymock.classextension.IMocksControl; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class HttpHeadersImplTest extends Assert { + + private IMocksControl control; + + @Before + public void setUp() { + control = EasyMock.createNiceControl(); + } + + @Test + public void testGetHeaders() throws Exception { + + Message m = control.createMock(Message.class); + m.get(Message.PROTOCOL_HEADERS); + EasyMock.expectLastCall().andReturn(createHeaders()); + control.replay(); + HttpHeaders h = new HttpHeadersImpl(m); + MultivaluedMap<String, String> hs = h.getRequestHeaders(); + assertEquals(hs.getFirst("Accept"), "text/*"); + assertEquals(hs.getFirst("Content-Type"), "*/*"); + } + + @Test + public void testGetLanguage() throws Exception { + + Message m = control.createMock(Message.class); + m.get(Message.PROTOCOL_HEADERS); + EasyMock.expectLastCall().andReturn(createHeaders()); + control.replay(); + HttpHeaders h = new HttpHeadersImpl(m); + assertEquals("UTF-8", h.getLanguage()); + } + + + private Map<String, List<String>> createHeaders() { + MetadataMap<String, String> hs = new MetadataMap<String, String>(); + hs.putSingle("Accept", "text/*"); + hs.putSingle("Content-Type", "*/*"); + return hs; + } +} Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/HttpHeadersImplTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/HttpHeadersImplTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryImplTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryImplTest.java?rev=633633&r1=633632&r2=633633&view=diff ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryImplTest.java (original) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryImplTest.java Tue Mar 4 12:47:58 2008 @@ -18,6 +18,7 @@ */ package org.apache.cxf.jaxrs.provider; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -25,8 +26,14 @@ import javax.ws.rs.ConsumeMime; import javax.ws.rs.ProduceMime; +import javax.ws.rs.core.CacheControl; +import javax.ws.rs.core.Cookie; +import javax.ws.rs.core.EntityTag; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.Variant.VariantListBuilder; import javax.ws.rs.ext.MessageBodyReader; import javax.ws.rs.ext.MessageBodyWriter; import javax.ws.rs.ext.ProviderFactory; @@ -35,6 +42,7 @@ import org.apache.abdera.model.Entry; import org.apache.abdera.model.Feed; import org.apache.cxf.helpers.IOUtils; +import org.apache.cxf.jaxrs.JAXRSUtils; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -47,6 +55,35 @@ } @Test + public void testCreateInstance() throws Exception { + assertSame(BuilderImpl.class, + new ProviderFactoryImpl(). + createInstance(Response.Builder.class).getClass()); + assertSame(UriBuilderImpl.class, + new ProviderFactoryImpl(). + createInstance(UriBuilder.class).getClass()); + assertSame(VariantListBuilderImpl.class, + new ProviderFactoryImpl(). + createInstance(VariantListBuilder.class).getClass()); + } + + @Test + public void testCreateHeaderProvider() throws Exception { + assertSame(MediaTypeHeaderProvider.class, + new ProviderFactoryImpl(). + createHeaderProvider(MediaType.class).getClass()); + assertSame(EntityTagHeaderProvider.class, + new ProviderFactoryImpl(). + createHeaderProvider(EntityTag.class).getClass()); + assertSame(CacheControlHeaderProvider.class, + new ProviderFactoryImpl(). + createHeaderProvider(CacheControl.class).getClass()); + assertSame(CookieHeaderProvider.class, + new ProviderFactoryImpl(). + createHeaderProvider(Cookie.class).getClass()); + } + + @Test public void testSortEntityProviders() throws Exception { ProviderFactoryImpl pf = new ProviderFactoryImpl(); pf.registerUserEntityProvider(new TestStringProvider()); @@ -71,6 +108,14 @@ verifyProvider(String.class, StringProvider.class, "text/html"); } + @Test + public void testGetBinaryProvider() throws Exception { + verifyProvider(byte[].class, BinaryDataProvider.class, "*/*"); + verifyProvider(InputStream.class, BinaryDataProvider.class, "image/png"); + MessageBodyWriter writer = ProviderFactory.getInstance() + .createMessageBodyWriter(File.class, JAXRSUtils.ALL_TYPES); + assertTrue(BinaryDataProvider.class == writer.getClass()); + } private void verifyProvider(Class<?> type, Class<?> provider, String mediaType, String errorMessage) Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java?rev=633633&view=auto ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java (added) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java Tue Mar 4 12:47:58 2008 @@ -0,0 +1,87 @@ +/** + * 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.cxf.jaxrs.provider; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import javax.ws.rs.ext.MessageBodyReader; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamSource; + +import org.junit.Assert; +import org.junit.Test; + +public class SourceProviderTest extends Assert { + + + @Test + public void testIsWriteable() { + SourceProvider p = new SourceProvider(); + assertTrue(p.isWriteable(StreamSource.class) + && p.isWriteable(DOMSource.class) + && p.isWriteable(Source.class)); + } + + @Test + public void testIsReadable() { + SourceProvider p = new SourceProvider(); + assertTrue(p.isReadable(StreamSource.class) + && p.isReadable(DOMSource.class) + && p.isReadable(Source.class)); + } + + @Test + public void testReadFrom() throws Exception { + SourceProvider p = new SourceProvider(); + assertSame(StreamSource.class, verifyRead(p, StreamSource.class).getClass()); + assertSame(StreamSource.class, verifyRead(p, Source.class).getClass()); + assertSame(DOMSource.class, verifyRead(p, DOMSource.class).getClass()); + } + + @Test + public void testWriteTo() throws Exception { + SourceProvider p = new SourceProvider(); + StreamSource s = new StreamSource(new ByteArrayInputStream("<test/>".getBytes())); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + p.writeTo(s, null, null, os); + assertTrue(os.toString().contains("<test/>")); + os = new ByteArrayOutputStream(); + p.writeTo(createDomSource(), null, null, os); + assertTrue(os.toString().contains("<test/>")); + } + + @SuppressWarnings("unchecked") + private <T> Object verifyRead(MessageBodyReader p, Class<T> type) throws Exception { + return p.readFrom(type, + null, null, + new ByteArrayInputStream("<test/>".getBytes())); + } + + private DOMSource createDomSource() throws Exception { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder; + builder = factory.newDocumentBuilder(); + return new DOMSource(builder.parse(new ByteArrayInputStream("<test/>".getBytes()))); + } +} Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriBuilderImplTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriBuilderImplTest.java?rev=633633&view=auto ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriBuilderImplTest.java (added) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriBuilderImplTest.java Tue Mar 4 12:47:58 2008 @@ -0,0 +1,57 @@ +/** + * 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.cxf.jaxrs.provider; + +import java.net.URI; + +import org.junit.Assert; +import org.junit.Test; + +public class UriBuilderImplTest extends Assert { + + @Test + public void testUri() throws Exception { + URI uri = new URI("http://foo/bar/baz?query=1#fragment"); + URI newUri = new UriBuilderImpl().uri(uri).build(); + assertEquals("URI is not built correctly", newUri, uri); + } + + @Test + public void testAddPath() throws Exception { + URI uri = new URI("http://foo/bar"); + URI newUri = new UriBuilderImpl().uri(uri).path("baz").build(); + assertEquals("URI is not built correctly", newUri, + new URI("http://foo/bar/baz")); + newUri = new UriBuilderImpl().uri(uri).path("baz", "/1", "/2").build(); + assertEquals("URI is not built correctly", newUri, + new URI("http://foo/bar/baz/1/2")); + } + + @Test + public void testSchemeHostPortQueryFragment() throws Exception { + URI uri = new URI("http://foo:1234/bar?n1=v1&n2=v2#fragment"); + URI newUri = new UriBuilderImpl().scheme("http").host("foo") + .port(1234).path("bar") + .queryParam("n1", "v1").queryParam("n2", "v2") + .fragment("fragment").build(); + assertEquals("URI is not built correctly", newUri, uri); + } + +} Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriBuilderImplTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriBuilderImplTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriInfoImplTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriInfoImplTest.java?rev=633633&view=auto ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriInfoImplTest.java (added) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriInfoImplTest.java Tue Mar 4 12:47:58 2008 @@ -0,0 +1,177 @@ +/** + * 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.cxf.jaxrs.provider; + +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.UriInfo; + +import org.apache.cxf.jaxrs.model.URITemplate; +import org.apache.cxf.message.Exchange; +import org.apache.cxf.message.Message; +import org.apache.cxf.transport.Destination; +import org.apache.cxf.ws.addressing.AttributedURIType; +import org.apache.cxf.ws.addressing.EndpointReferenceType; +import org.easymock.classextension.EasyMock; +import org.easymock.classextension.IMocksControl; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class UriInfoImplTest extends Assert { + + private IMocksControl control; + + @Before + public void setUp() { + control = EasyMock.createNiceControl(); + } + + @Test + public void testGetAbsolutePath() { + + UriInfoImpl u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar"), + null); + assertEquals("Wrong absolute path", "http://localhost:8080/baz/bar", + u.getAbsolutePath().toString()); + u = new UriInfoImpl(mockMessage("http://localhost:8080/baz/", "/bar"), + null); + assertEquals("Wrong absolute path", "http://localhost:8080/baz/bar", + u.getAbsolutePath().toString()); + + } + + @Test + public void testGetQueryParameters() { + UriInfoImpl u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar"), + null); + assertEquals("unexpected queries", 0, u.getQueryParameters().size()); + + u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar", "n=1%202"), + null); + + MultivaluedMap<String, String> qps = u.getQueryParameters(false); + assertEquals("Number of queries is wrong", 1, qps.size()); + assertEquals("Wrong query value", qps.getFirst("n"), "1%202"); + + u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar", + "n=1%202&n=3&b=2"), + null); + + qps = u.getQueryParameters(); + assertEquals("Number of queiries is wrong", 2, qps.size()); + assertEquals("Wrong query value", qps.get("n").get(0), "1 2"); + assertEquals("Wrong query value", qps.get("n").get(1), "3"); + assertEquals("Wrong query value", qps.get("b").get(0), "2"); + } + + @Test + public void testGetRequestURI() { + + UriInfo u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar", "n=1%202"), + null); + + assertEquals("Wrong request uri", "http://localhost:8080/baz/bar?n=1%202", + u.getRequestUri().toString()); + } + + @Test + public void testGetTemplateParameters() { + + UriInfoImpl u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar"), + new URITemplate("/bar")); + assertEquals("unexpected templates", 0, u.getTemplateParameters().size()); + + u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar%201"), + new URITemplate("/{id}")); + + MultivaluedMap<String, String> tps = u.getTemplateParameters(false); + assertEquals("Number of templates is wrong", 1, tps.size()); + assertEquals("Wrong template value", tps.getFirst("id"), "bar%201"); + + u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/1%202/bar"), + new URITemplate("/{id}/{baz}")); + + tps = u.getTemplateParameters(); + assertEquals("Number of templates is wrong", 2, tps.size()); + assertEquals("Wrong template value", tps.getFirst("id"), "1 2"); + assertEquals("Wrong template value", tps.getFirst("baz"), "bar"); + } + + @Test + public void testGetBaseUri() { + + UriInfoImpl u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar"), + null); + assertEquals("Wrong base path", "http://localhost:8080/baz", + u.getBaseUri().toString()); + u = new UriInfoImpl(mockMessage("http://localhost:8080/baz/", "/bar"), + null); + assertEquals("Wrong base path", "http://localhost:8080/baz/", + u.getBaseUri().toString()); + } + + @Test + public void testGetPath() { + + UriInfoImpl u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar"), + null); + assertEquals("Wrong path", "/bar", u.getPath()); + + u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar%201"), + null); + assertEquals("Wrong path", "/bar 1", u.getPath()); + + u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar%201"), + null); + assertEquals("Wrong path", "/bar%201", u.getPath(false)); + } + + private Message mockMessage(String baseAddress, String pathInfo) { + return mockMessage(baseAddress, pathInfo, null, null); + } + + private Message mockMessage(String baseAddress, String pathInfo, String query) { + return mockMessage(baseAddress, pathInfo, query, null); + } + + private Message mockMessage(String baseAddress, String pathInfo, + String query, String fragment) { + control.reset(); + Message m = control.createMock(Message.class); + Exchange e = control.createMock(Exchange.class); + m.getExchange(); + EasyMock.expectLastCall().andReturn(e); + Destination d = control.createMock(Destination.class); + e.getDestination(); + EasyMock.expectLastCall().andReturn(d); + EndpointReferenceType epr = new EndpointReferenceType(); + epr.setAddress(new AttributedURIType()); + epr.getAddress().setValue(baseAddress); + d.getAddress(); + EasyMock.expectLastCall().andReturn(epr); + m.get(Message.PATH_INFO); + EasyMock.expectLastCall().andReturn(pathInfo); + m.get(Message.QUERY_STRING); + EasyMock.expectLastCall().andReturn(query); + control.replay(); + return m; + } + +} Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriInfoImplTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriInfoImplTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java?rev=633633&r1=633632&r2=633633&view=diff ============================================================================== --- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java (original) +++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java Tue Mar 4 12:47:58 2008 @@ -32,7 +32,9 @@ import javax.ws.rs.Path; import javax.ws.rs.ProduceMime; import javax.ws.rs.UriParam; +import javax.ws.rs.core.HttpContext; import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; import javax.xml.bind.JAXBContext; import org.apache.abdera.Abdera; @@ -45,6 +47,7 @@ @Path("/bookstore/") public class AtomBookStore { + @HttpContext private UriInfo uField; private Map<Long, Book> books = new HashMap<Long, Book>(); private Map<Long, CD> cds = new HashMap<Long, CD>(); private long bookId = 123; @@ -58,9 +61,10 @@ @GET @Path("/books/feed") @ProduceMime("application/atom+xml") - public Feed getBooksAsFeed() { + public Feed getBooksAsFeed(@HttpContext UriInfo uParam) { Factory factory = Abdera.getNewFactory(); Feed f = factory.newFeed(); + f.setBaseUri(uParam.getAbsolutePath().toString()); f.setTitle("Collection of Books"); f.setId("http://www.books.com"); f.addAuthor("BookStore Management Company"); @@ -89,7 +93,10 @@ books.put(b.getId(), b); // this code is broken as Response does not - URI uri = new URI("http://localhost:9080/bookstore/books/entries/" + b.getId()); + + URI uri = + uField.getBaseUriBuilder().path("bookstore", "books", "entries", + Long.toString(b.getId())).build(); return Response.created(uri).build(); } catch (Exception ex) { return Response.serverError().build(); @@ -104,7 +111,7 @@ Book book = books.get(Long.parseLong(id)); if (book != null) { try { - return AtomUtils.createBookEntry(book); + return AtomUtils.createBookEntry(book, uField.getAbsolutePath().toString()); } catch (Exception ex) { // ignore } Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java?rev=633633&r1=633632&r2=633633&view=diff ============================================================================== --- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java (original) +++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java Tue Mar 4 12:47:58 2008 @@ -57,6 +57,7 @@ Document<Feed> doc = abdera.getParser().parse(in); Feed feed = doc.getRoot(); + assertEquals(endpointAddress, feed.getBaseUri().toString()); assertEquals("Collection of Books", feed.getTitle()); @@ -89,6 +90,7 @@ Document<Entry> entryDoc = abdera.getParser().parse(in); Entry entry = entryDoc.getRoot(); + assertEquals(location, entry.getBaseUri().toString()); assertEquals("AtomBook", entry.getTitle()); in.close(); Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomUtils.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomUtils.java?rev=633633&r1=633632&r2=633633&view=diff ============================================================================== --- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomUtils.java (original) +++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomUtils.java Tue Mar 4 12:47:58 2008 @@ -36,10 +36,17 @@ } public static Entry createBookEntry(Book b) throws Exception { + return createBookEntry(b, null); + } + + public static Entry createBookEntry(Book b, String baseUri) throws Exception { Factory factory = Abdera.getNewFactory(); JAXBContext jc = JAXBContext.newInstance(Book.class); Entry e = factory.getAbdera().newEntry(); + if (baseUri != null) { + e.setBaseUri(baseUri); + } e.setTitle(b.getName()); e.setId(Long.toString(b.getId()));
