📄 queryparamasprimitivetest.java
字号:
/* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can obtain * a copy of the License at https://jersey.dev.java.net/CDDL+GPL.html * or jersey/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at jersey/legal/LICENSE.txt. * Sun designates this particular file as subject to the "Classpath" exception * as provided by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the License * Header, with the fields enclosed by brackets [] replaced by your own * identifying information: "Portions Copyrighted [year] * [name of copyright owner]" * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */package com.sun.jersey.impl.methodparams;import com.sun.jersey.impl.AbstractResourceTester;import javax.ws.rs.DefaultValue;import javax.ws.rs.ProduceMime;import javax.ws.rs.QueryParam;import javax.ws.rs.Path;import com.sun.jersey.impl.AbstractResourceTester;import com.sun.jersey.api.client.ClientResponse;import java.util.List;import javax.ws.rs.GET;/** * * @author Paul.Sandoz@Sun.Com */public class QueryParamAsPrimitiveTest extends AbstractResourceTester { public QueryParamAsPrimitiveTest(String testName) { super(testName); initiateWebApplication( ResourceQueryPrimitives.class, ResourceQueryPrimitivesDefaultNull.class, ResourceQueryPrimitivesDefault.class, ResourceQueryPrimitivesDefaultOverride.class, ResourceQueryPrimitiveWrappers.class, ResourceQueryPrimitiveWrappersDefaultNull.class, ResourceQueryPrimitiveWrappersDefault.class, ResourceQueryPrimitiveWrappersDefaultOverride.class, ResourceQueryPrimitiveList.class, ResourceQueryPrimitiveListDefaultNull.class, ResourceQueryPrimitiveListDefault.class, ResourceQueryPrimitiveListDefaultOverride.class ); } @Path("/") public static class ResourceQueryPrimitives { @GET @ProduceMime("application/boolean") public String doGet(@QueryParam("boolean") boolean v) { assertEquals(true, v); return "content"; } @GET @ProduceMime("application/byte") public String doGet(@QueryParam("byte") byte v) { assertEquals(127, v); return "content"; } @GET @ProduceMime("application/short") public String doGet(@QueryParam("short") short v) { assertEquals(32767, v); return "content"; } @GET @ProduceMime("application/int") public String doGet(@QueryParam("int") int v) { assertEquals(2147483647, v); return "content"; } @GET @ProduceMime("application/long") public String doGet(@QueryParam("long") long v) { assertEquals(9223372036854775807L, v); return "content"; } @GET @ProduceMime("application/float") public String doGet(@QueryParam("float") float v) { assertEquals(3.14159265f, v); return "content"; } @GET @ProduceMime("application/double") public String doGet(@QueryParam("double") double v) { assertEquals(3.14159265358979d, v); return "content"; } } @Path("/default/null") public static class ResourceQueryPrimitivesDefaultNull { @GET @ProduceMime("application/boolean") public String doGet(@QueryParam("boolean") boolean v) { assertEquals(false, v); return "content"; } @GET @ProduceMime("application/byte") public String doGet(@QueryParam("byte") byte v) { assertEquals(0, v); return "content"; } @GET @ProduceMime("application/short") public String doGet(@QueryParam("short") short v) { assertEquals(0, v); return "content"; } @GET @ProduceMime("application/int") public String doGet(@QueryParam("int") int v) { assertEquals(0, v); return "content"; } @GET @ProduceMime("application/long") public String doGet(@QueryParam("long") long v) { assertEquals(0l, v); return "content"; } @GET @ProduceMime("application/float") public String doGet(@QueryParam("float") float v) { assertEquals(0.0f, v); return "content"; } @GET @ProduceMime("application/double") public String doGet(@QueryParam("double") double v) { assertEquals(0.0d, v); return "content"; } } @Path("/default") public static class ResourceQueryPrimitivesDefault { @GET @ProduceMime("application/boolean") public String doGet(@QueryParam("boolean") @DefaultValue("true") boolean v) { assertEquals(true, v); return "content"; } @GET @ProduceMime("application/byte") public String doGet(@QueryParam("byte") @DefaultValue("127") byte v) { assertEquals(127, v); return "content"; } @GET @ProduceMime("application/short") public String doGet(@QueryParam("short") @DefaultValue("32767") short v) { assertEquals(32767, v); return "content"; } @GET @ProduceMime("application/int") public String doGet(@QueryParam("int") @DefaultValue("2147483647") int v) { assertEquals(2147483647, v); return "content"; } @GET @ProduceMime("application/long") public String doGet(@QueryParam("long") @DefaultValue("9223372036854775807") long v) { assertEquals(9223372036854775807L, v); return "content"; } @GET @ProduceMime("application/float") public String doGet(@QueryParam("float") @DefaultValue("3.14159265") float v) { assertEquals(3.14159265f, v); return "content"; } @GET @ProduceMime("application/double") public String doGet(@QueryParam("double") @DefaultValue("3.14159265358979") double v) { assertEquals(3.14159265358979d, v); return "content"; } } @Path("/default/override") public static class ResourceQueryPrimitivesDefaultOverride { @GET @ProduceMime("application/boolean") public String doGet(@QueryParam("boolean") @DefaultValue("false") boolean v) { assertEquals(true, v); return "content"; } @GET @ProduceMime("application/byte") public String doGet(@QueryParam("byte") @DefaultValue("1") byte v) { assertEquals(127, v); return "content"; } @GET @ProduceMime("application/short") public String doGet(@QueryParam("short") @DefaultValue("1") short v) { assertEquals(32767, v); return "content"; } @GET @ProduceMime("application/int") public String doGet(@QueryParam("int") @DefaultValue("1") int v) { assertEquals(2147483647, v); return "content"; } @GET @ProduceMime("application/long") public String doGet(@QueryParam("long") @DefaultValue("1") long v) { assertEquals(9223372036854775807L, v); return "content"; } @GET @ProduceMime("application/float") public String doGet(@QueryParam("float") @DefaultValue("0.0") float v) { assertEquals(3.14159265f, v); return "content"; } @GET @ProduceMime("application/double") public String doGet(@QueryParam("double") @DefaultValue("0.0") double v) { assertEquals(3.14159265358979d, v); return "content"; } } @Path("/wrappers") public static class ResourceQueryPrimitiveWrappers { @GET @ProduceMime("application/boolean") public String doGet(@QueryParam("boolean") Boolean v) { assertEquals(true, v.booleanValue()); return "content"; } @GET @ProduceMime("application/byte") public String doGet(@QueryParam("byte") Byte v) { assertEquals(127, v.byteValue()); return "content"; } @GET @ProduceMime("application/short") public String doGet(@QueryParam("short") Short v) { assertEquals(32767, v.shortValue()); return "content"; } @GET @ProduceMime("application/int") public String doGet(@QueryParam("int") Integer v) { assertEquals(2147483647, v.intValue()); return "content"; } @GET @ProduceMime("application/long") public String doGet(@QueryParam("long") Long v) { assertEquals(9223372036854775807L, v.longValue()); return "content"; } @GET @ProduceMime("application/float") public String doGet(@QueryParam("float") Float v) { assertEquals(3.14159265f, v.floatValue()); return "content"; } @GET @ProduceMime("application/double") public String doGet(@QueryParam("double") Double v) { assertEquals(3.14159265358979d, v.doubleValue()); return "content"; } } @Path("/wrappers/default/null") public static class ResourceQueryPrimitiveWrappersDefaultNull { @GET @ProduceMime("application/boolean") public String doGet(@QueryParam("boolean") Boolean v) { assertEquals(null, v); return "content"; } @GET @ProduceMime("application/byte") public String doGet(@QueryParam("byte") Byte v) { assertEquals(null, v); return "content"; } @GET @ProduceMime("application/short") public String doGet(@QueryParam("short") Short v) { assertEquals(null, v); return "content"; } @GET @ProduceMime("application/int") public String doGet(@QueryParam("int") Integer v) { assertEquals(null, v); return "content"; } @GET @ProduceMime("application/long") public String doGet(@QueryParam("long") Long v) { assertEquals(null, v); return "content"; } @GET @ProduceMime("application/float") public String doGet(@QueryParam("float") Float v) { assertEquals(null, v); return "content"; } @GET @ProduceMime("application/double") public String doGet(@QueryParam("double") Double v) { assertEquals(null, v); return "content"; } } @Path("/wrappers/default") public static class ResourceQueryPrimitiveWrappersDefault { @GET @ProduceMime("application/boolean") public String doGet(@QueryParam("boolean") @DefaultValue("true") Boolean v) { assertEquals(true, v.booleanValue()); return "content"; } @GET @ProduceMime("application/byte") public String doGet(@QueryParam("byte") @DefaultValue("127") Byte v) { assertEquals(127, v.byteValue()); return "content"; } @GET @ProduceMime("application/short") public String doGet(@QueryParam("short") @DefaultValue("32767") Short v) { assertEquals(32767, v.shortValue()); return "content"; } @GET @ProduceMime("application/int") public String doGet(@QueryParam("int") @DefaultValue("2147483647") Integer v) { assertEquals(2147483647, v.intValue()); return "content"; } @GET @ProduceMime("application/long") public String doGet(@QueryParam("long") @DefaultValue("9223372036854775807") Long v) { assertEquals(9223372036854775807L, v.longValue()); return "content"; } @GET @ProduceMime("application/float") public String doGet(@QueryParam("float") @DefaultValue("3.14159265") Float v) { assertEquals(3.14159265f, v.floatValue()); return "content"; } @GET @ProduceMime("application/double") public String doGet(@QueryParam("double") @DefaultValue("3.14159265358979") Double v) { assertEquals(3.14159265358979d, v.doubleValue()); return "content"; } } @Path("/wrappers/default/override") public static class ResourceQueryPrimitiveWrappersDefaultOverride { @GET @ProduceMime("application/boolean") public String doGet(@QueryParam("boolean") @DefaultValue("false") Boolean v) { assertEquals(true, v.booleanValue());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -