-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jorge Bescos Gascon <[email protected]>
- Loading branch information
Showing
3 changed files
with
218 additions
and
109 deletions.
There are no files selected for viewing
108 changes: 0 additions & 108 deletions
108
...or/src/test/java/org/glassfish/jersey/jdk/connector/internal/ArrayParamConverterTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 217 additions & 0 deletions
217
...e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/ArrayParamConverterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
/* | ||
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.jersey.tests.e2e.server; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.SortedSet; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.Application; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.glassfish.jersey.server.ResourceConfig; | ||
import org.glassfish.jersey.test.JerseyTest; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class ArrayParamConverterTest extends JerseyTest { | ||
|
||
private static final String PARAM_NAME = "paramName"; | ||
|
||
@Path("/test") | ||
public static class ArraysResource { | ||
|
||
@Path("/queryStrArray") | ||
@GET | ||
public Response queryStrArray(@QueryParam(PARAM_NAME) String[] data) { | ||
return Response.ok(String.join("", data)).build(); | ||
} | ||
|
||
@Path("/queryStrList") | ||
@GET | ||
public Response queryStrList(@QueryParam(PARAM_NAME) List<String> data) { | ||
return Response.ok(String.join("", data)).build(); | ||
} | ||
|
||
@Path("/queryIntArray") | ||
@GET | ||
public Response queryIntArray(@QueryParam(PARAM_NAME) Integer[] data) { | ||
StringBuilder sb = new StringBuilder(data.length); | ||
for (int d : data) { | ||
sb.append(d); | ||
} | ||
return Response.ok(sb.toString()).build(); | ||
} | ||
|
||
@Path("/queryIntList") | ||
@GET | ||
public Response queryIntList(@QueryParam(PARAM_NAME) List<Integer> data) { | ||
StringBuilder sb = new StringBuilder(data.size()); | ||
for (int d : data) { | ||
sb.append(d); | ||
} | ||
return Response.ok(sb.toString()).build(); | ||
} | ||
|
||
@Path("/queryStrSortedSet") | ||
@GET | ||
public Response queryStrSortedSet(@QueryParam(PARAM_NAME) SortedSet<String> data) { | ||
return Response.ok(String.join("", data)).build(); | ||
} | ||
|
||
@Path("/queryStrSet") | ||
@GET | ||
public Response queryStrSet(@QueryParam(PARAM_NAME) Set<String> data) { | ||
return Response.ok(String.join("", data)).build(); | ||
} | ||
|
||
@Path("/querySingleStrConstructor") | ||
@GET | ||
public Response querySingleStrConstructor(@QueryParam(PARAM_NAME) SingleStringConstructor[] data) { | ||
StringBuilder sb = new StringBuilder(data.length); | ||
for (SingleStringConstructor d : data) { | ||
sb.append(d.value); | ||
} | ||
return Response.ok(sb.toString()).build(); | ||
} | ||
|
||
@Path("/querySingleStringFromString") | ||
@GET | ||
public Response querySingleStringFromString(@QueryParam(PARAM_NAME) SingleStringFromString[] data) { | ||
StringBuilder sb = new StringBuilder(data.length); | ||
for (SingleStringFromString d : data) { | ||
sb.append(d.value); | ||
} | ||
return Response.ok(sb.toString()).build(); | ||
} | ||
|
||
@Path("/querySingleStringFromStringList") | ||
@GET | ||
public Response querySingleStringFromStringList(@QueryParam(PARAM_NAME) List<SingleStringFromString> data) { | ||
StringBuilder sb = new StringBuilder(data.size()); | ||
for (SingleStringFromString d : data) { | ||
sb.append(d.value); | ||
} | ||
return Response.ok(sb.toString()).build(); | ||
} | ||
|
||
@Path("/querySingleStringValueOf") | ||
@GET | ||
public Response querySingleStringValueOf(@QueryParam(PARAM_NAME) SingleStringValueOf[] data) { | ||
StringBuilder sb = new StringBuilder(data.length); | ||
for (SingleStringValueOf d : data) { | ||
sb.append(d.value); | ||
} | ||
return Response.ok(sb.toString()).build(); | ||
} | ||
} | ||
|
||
public static class SingleStringConstructor { | ||
private final String value; | ||
public SingleStringConstructor(String value) { | ||
this.value = value; | ||
} | ||
} | ||
|
||
public static class SingleStringFromString { | ||
private final String value; | ||
private SingleStringFromString(String value) { | ||
this.value = value; | ||
} | ||
public static SingleStringFromString fromString(String value) { | ||
return new SingleStringFromString(value); | ||
} | ||
} | ||
|
||
public static class SingleStringValueOf { | ||
private final String value; | ||
private SingleStringValueOf(String value) { | ||
this.value = value; | ||
} | ||
public static SingleStringValueOf valueOf(String value) { | ||
return new SingleStringValueOf(value); | ||
} | ||
} | ||
|
||
@Override | ||
protected Application configure() { | ||
return new ResourceConfig(ArraysResource.class); | ||
} | ||
|
||
@Test | ||
public void queryStr() { | ||
Response expected = target("/test/queryStrList").queryParam(PARAM_NAME, "1", "2").request().get(); | ||
Response arrayResponse = target("/test/queryIntArray").queryParam(PARAM_NAME, "1", "2").request().get(); | ||
verifyStr(expected, arrayResponse); | ||
} | ||
|
||
@Test | ||
public void queryInt() { | ||
Response expected = target("/test/queryIntList").queryParam(PARAM_NAME, 1, 2).request().get(); | ||
Response arrayResponse = target("/test/queryIntArray").queryParam(PARAM_NAME, 1, 2).request().get(); | ||
verifyStr(expected, arrayResponse); | ||
} | ||
|
||
@Test | ||
public void queryStrSortedSet() { | ||
Response response = target("/test/queryStrSortedSet").queryParam(PARAM_NAME, 1, 2).request().get(); | ||
assertEquals(200, response.getStatus()); | ||
assertEquals("12", response.readEntity(String.class)); | ||
} | ||
|
||
@Test | ||
public void queryStrSet() { | ||
Response response = target("/test/queryStrSet").queryParam(PARAM_NAME, 1, 2).request().get(); | ||
assertEquals(200, response.getStatus()); | ||
assertEquals("12", response.readEntity(String.class)); | ||
} | ||
|
||
@Test | ||
public void querySingleStrConstructor() { | ||
Response response = target("/test/querySingleStrConstructor").queryParam(PARAM_NAME, 1, 2).request().get(); | ||
assertEquals(200, response.getStatus()); | ||
assertEquals("12", response.readEntity(String.class)); | ||
} | ||
|
||
@Test | ||
public void querySingleStringFromString() { | ||
Response expected = target("/test/querySingleStringFromStringList").queryParam(PARAM_NAME, "1", "2").request().get(); | ||
Response arrayResponse = target("/test/querySingleStringFromString").queryParam(PARAM_NAME, "1", "2").request().get(); | ||
verifyStr(expected, arrayResponse); | ||
} | ||
|
||
@Test | ||
public void querySingleStringValueOf() { | ||
Response response = target("/test/querySingleStringValueOf").queryParam(PARAM_NAME, 1, 2).request().get(); | ||
assertEquals(200, response.getStatus()); | ||
assertEquals("12", response.readEntity(String.class)); | ||
} | ||
|
||
private void verifyStr(Response expected, Response arrayResponse) { | ||
assertEquals(200, expected.getStatus()); | ||
assertEquals(200, arrayResponse.getStatus()); | ||
String expectedStr = expected.readEntity(String.class); | ||
String arrayStr = arrayResponse.readEntity(String.class); | ||
// Check the result is the same | ||
assertEquals(expectedStr, arrayStr); | ||
assertEquals("12", arrayStr); | ||
} | ||
} |