incubator-wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ngalla...@apache.org
Subject svn commit: r787553 [34/34] - in /incubator/wink/contrib/ibm-jaxrs/tests: ./ fvt/ fvt/demo/ fvt/demo/jaxrs/ fvt/demo/jaxrs/cache/ fvt/demo/jaxrs/cache/server/ fvt/demo/jaxrs/cache/test/ fvt/demo/jaxrs/datasource/ fvt/demo/jaxrs/datasource/server/ fvt/d...
Date Tue, 23 Jun 2009 05:38:19 GMT
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/org/apache/cxf/jaxrs/impl/UriBuilderTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/org/apache/cxf/jaxrs/impl/UriBuilderTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/org/apache/cxf/jaxrs/impl/UriBuilderTests.java
(added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/org/apache/cxf/jaxrs/impl/UriBuilderTests.java
Tue Jun 23 05:37:57 2009
@@ -0,0 +1,78 @@
+/*
+ * 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.impl;
+
+import java.net.URI;
+
+import javax.ws.rs.core.UriBuilder;
+
+import junit.framework.TestCase;
+
+public class UriBuilderTests extends TestCase {
+
+    public void testFromURI() throws Exception {
+        URI uri = new URI("http://www.jaxrs.com");
+        UriBuilder builder = UriBuilder.fromUri(uri);
+        assertNotNull(builder);
+        URI builtURI = builder.build(null);
+        assertEquals(uri, builtURI);
+
+        IllegalArgumentException iae = null;
+        try {
+            uri = null;
+            builder = UriBuilder.fromUri(uri);
+        } catch (IllegalArgumentException e) {
+            iae = e;
+        }
+        assertNotNull(iae);
+    }
+
+    public void testFromStringWith() throws Exception {
+        String uriStr = "ldap://[2001:db8::7]/c=GB?objectClass?one";
+        UriBuilder builder = UriBuilder.fromUri(uriStr);
+        assertNotNull(builder);
+        URI builtURI = builder.build(null);
+        assertEquals(new URI(uriStr), builtURI);
+
+        IllegalArgumentException iae = null;
+        try {
+            uriStr = null;
+            builder = UriBuilder.fromUri(uriStr);
+        } catch (IllegalArgumentException e) {
+            iae = e;
+        }
+        assertNotNull(iae);
+
+        uriStr = "telnet://192.0.2.16:80/";
+        builder = UriBuilder.fromUri(uriStr);
+        assertNotNull(builder);
+        builtURI = builder.build(null);
+        assertEquals(new URI(uriStr), builtURI);
+
+    }
+
+    public void testBuildOpaqueURI() throws Exception {
+        String uriStr = "mailto:java-net@java.sun.com";
+        UriBuilder builder = UriBuilder.fromUri(uriStr);
+        URI builtURI = builder.build(null);
+        assertEquals(new URI(uriStr), builtURI);
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/org/apache/cxf/jaxrs/utils/JAXRSUtilsTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/org/apache/cxf/jaxrs/utils/JAXRSUtilsTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/org/apache/cxf/jaxrs/utils/JAXRSUtilsTests.java
(added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/org/apache/cxf/jaxrs/utils/JAXRSUtilsTests.java
Tue Jun 23 05:37:57 2009
@@ -0,0 +1,111 @@
+/*
+ * 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.utils;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.Path;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+
+import com.ibm.rest.test.utils.TestUtils;
+import com.ibm.ws.jaxrs.metadata.MetadataRegistry;
+import com.ibm.ws.jaxrs.model.JAXRSInfoBuilder;
+import com.ibm.ws.jaxrs.model.JAXRSInfoBuilderFactory;
+import com.ibm.ws.jaxrs.model.JAXRSInfoInput;
+import com.ibm.ws.jaxrs.model.JAXRSInfoOutput;
+
+/**
+ * Verify functionality in the JAXRSUtils class.
+ *
+ */
+public class JAXRSUtilsTests extends TestCase {
+
+    static Boolean initialized = false;
+
+    ClassResourceInfo info = null;
+
+    List<ClassResourceInfo> resources = null;
+
+    public void setUp() throws Exception {
+        synchronized (initialized) {
+            if (!initialized) {
+                Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
+                classes.put(TestResource.class.getName(), TestResource.class);
+                JAXRSInfoInput source = new JAXRSInfoInput(
+                        JAXRSInfoInput.Type.REFLECTION);
+                source.setClasses(classes);
+                JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry
+                        .getImplementation(JAXRSInfoBuilderFactory.class);
+                JAXRSInfoBuilder builder = factory.getInfoBuilder(source
+                        .getInputType());
+                JAXRSInfoOutput output = builder.buildRESTInfo(source);
+                assertNotNull(output);
+                resources = output.getClassInfoList();
+                info = TestUtils.getClassResourceInfo(resources,
+                        TestResource.class.getName());
+                initialized = true;
+            }
+        }
+    }
+
+    /**
+     * This will verify that we can match a current path to a path
+     * declared for a method on a resource class.
+     *
+     */
+    public void testGetPathForOperation() throws Exception {
+
+        // first let's try the simple case when the path matches exactly to a
+        // method's uri template
+        String opPath = JAXRSUtils.getPathForOperation("/",
+                "/resource/something/1");
+        assertNotNull(opPath);
+        assertEquals("resource/something/1", opPath);
+
+        // now let's try the case when there is extra information after the
+        // part that matches the method's uri template
+        opPath = JAXRSUtils.getPathForOperation("2/3/4",
+                "/resource/something/1/2/3/4");
+        assertNotNull(opPath);
+        assertEquals("resource/something/1", opPath);
+
+        // another case of the path matching the method's uri template exactly
+        opPath = JAXRSUtils.getPathForOperation("",
+                "/resource/something/1/2/3/4");
+        assertNotNull(opPath);
+        assertEquals("resource/something/1/2/3/4", opPath);
+    }
+
+    @Path(value = "/resource")
+    public static class TestResource {
+
+        @Path(value = "/something/{id}")
+        public void getSomething() {
+
+        }
+
+    }
+
+}



Mime
View raw message