/resteasy-2.3.2.Final/resteasy-jaxrs/src/test/java/org/jboss/resteasy/test/regression/Regression657.java

# · Java · 365 lines · 300 code · 60 blank · 5 comment · 0 complexity · 137100124b4689b5a2d1fea183ed42d4 MD5 · raw file

  1. package org.jboss.resteasy.test.regression;
  2. import org.jboss.resteasy.client.ClientRequest;
  3. import org.jboss.resteasy.test.BaseResourceTest;
  4. import org.junit.Assert;
  5. import org.junit.BeforeClass;
  6. import org.junit.Test;
  7. import javax.ws.rs.Consumes;
  8. import javax.ws.rs.DELETE;
  9. import javax.ws.rs.GET;
  10. import javax.ws.rs.HeaderParam;
  11. import javax.ws.rs.POST;
  12. import javax.ws.rs.PUT;
  13. import javax.ws.rs.Path;
  14. import javax.ws.rs.PathParam;
  15. import javax.ws.rs.Produces;
  16. import javax.ws.rs.QueryParam;
  17. import javax.ws.rs.core.MediaType;
  18. import java.util.List;
  19. import static org.jboss.resteasy.test.TestPortProvider.*;
  20. /**
  21. * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
  22. * @version $Revision: 1 $
  23. */
  24. public class Regression657 extends BaseResourceTest
  25. {
  26. public interface Foo<T>
  27. {
  28. @GET
  29. public T getFoo(@HeaderParam("foo") String val);
  30. }
  31. @Path("blah")
  32. public static class ImpFoo implements Foo
  33. {
  34. @Override
  35. public Object getFoo(String val)
  36. {
  37. return "hello";
  38. }
  39. }
  40. public static class OhaUserModel
  41. {
  42. private String username;
  43. public OhaUserModel(String username)
  44. {
  45. this.username = username;
  46. }
  47. @Override
  48. public String toString()
  49. {
  50. return username;
  51. }
  52. }
  53. public interface BaseCrudService<T>
  54. {
  55. @GET
  56. @Path("/content/{id}")
  57. @Produces(MediaType.APPLICATION_JSON)
  58. public T getContent(
  59. @PathParam("id")
  60. String id);
  61. @POST
  62. @Path("/add")
  63. @Produces(MediaType.APPLICATION_JSON)
  64. @Consumes(MediaType.APPLICATION_JSON)
  65. public T add(T object);
  66. @GET
  67. @Path("/all")
  68. @Produces(MediaType.APPLICATION_JSON)
  69. public List<T> get();
  70. @PUT
  71. @Path("/update")
  72. @Produces(MediaType.APPLICATION_JSON)
  73. @Consumes(MediaType.APPLICATION_JSON)
  74. public T update(T object);
  75. @DELETE
  76. @Path("/delete/{id}")
  77. @Produces(MediaType.TEXT_PLAIN)
  78. public Boolean delete(
  79. @PathParam("id")
  80. String id);
  81. }
  82. @Path("/platform")
  83. public interface PlatformServiceLocator
  84. {
  85. @Path("/users/{user}")
  86. public UserRestService getUserService(
  87. @HeaderParam("entity")
  88. String entity,
  89. @HeaderParam("ticket")
  90. String ticket,
  91. @PathParam("user")
  92. String userId
  93. );
  94. }
  95. @Path("/users")
  96. public interface UserRestService extends BaseUserService
  97. {
  98. @GET
  99. @Path("/content/{id}")
  100. @Produces(MediaType.APPLICATION_JSON)
  101. public OhaUserModel getContent(
  102. @PathParam("id")
  103. String id);
  104. @POST
  105. @Path("/add")
  106. @Produces(MediaType.APPLICATION_JSON)
  107. @Consumes(MediaType.APPLICATION_JSON)
  108. public OhaUserModel add(OhaUserModel object);
  109. @GET
  110. @Path("/all")
  111. @Produces(MediaType.APPLICATION_JSON)
  112. public List<OhaUserModel> get();
  113. @PUT
  114. @Path("/update")
  115. @Produces(MediaType.APPLICATION_JSON)
  116. @Consumes(MediaType.APPLICATION_JSON)
  117. public OhaUserModel update(OhaUserModel object);
  118. @DELETE
  119. @Path("/delete/{id}")
  120. @Produces(MediaType.TEXT_PLAIN)
  121. public Boolean delete(
  122. @PathParam("id")
  123. String id);
  124. @GET
  125. @Path("/getbynamesurname/{name}/{surname}")
  126. @Produces(MediaType.APPLICATION_JSON)
  127. public List<OhaUserModel> getByNameSurname(
  128. @PathParam("name")
  129. String name,
  130. @PathParam("surname")
  131. String surname
  132. );
  133. @GET
  134. @Path("/getuserbymail/{mail}")
  135. @Produces(MediaType.APPLICATION_JSON)
  136. public OhaUserModel getUserByMail(
  137. @PathParam("mail")
  138. String mail
  139. );
  140. @POST
  141. @Path("/update/{id}")
  142. @Produces(MediaType.TEXT_PLAIN)
  143. //@Consumes(MediaType.TEXT_PLAIN)
  144. public Boolean update(
  145. @PathParam("id")
  146. String id,
  147. @QueryParam("adaId")
  148. String adaId,
  149. @QueryParam("name")
  150. String name,
  151. @QueryParam("surname")
  152. String surname,
  153. @QueryParam("address")
  154. String address,
  155. @QueryParam("city")
  156. String city,
  157. @QueryParam("country")
  158. String country,
  159. @QueryParam("zipcode")
  160. String zipcode,
  161. @QueryParam("email")
  162. String email,
  163. @QueryParam("phone")
  164. String phone,
  165. @QueryParam("phone")
  166. String timezone);
  167. @POST
  168. @Path("/updatepassword/{username}")
  169. @Produces(MediaType.TEXT_PLAIN)
  170. @Consumes(MediaType.APPLICATION_JSON)
  171. public Boolean updatePassword(
  172. @PathParam("username")
  173. String username,
  174. List<String> passwords);
  175. @POST
  176. @Path("/createuser")
  177. @Produces(MediaType.APPLICATION_JSON)
  178. public Boolean create(
  179. @QueryParam("email")
  180. String email,
  181. @QueryParam("password")
  182. String password,
  183. @QueryParam("username")
  184. String username);
  185. @GET
  186. @Path("/show-help/{user}")
  187. @Produces(MediaType.TEXT_PLAIN)
  188. public Boolean showHelp(
  189. @PathParam("user")
  190. long userId);
  191. @PUT
  192. @Path("/show-help/{user}/{show}")
  193. @Produces(MediaType.TEXT_PLAIN)
  194. public Boolean setShowHelp(
  195. @PathParam("user")
  196. long userId,
  197. @PathParam("show")
  198. boolean showHelp);
  199. @GET
  200. @Path("/create-jabber")
  201. @Produces(MediaType.TEXT_PLAIN)
  202. public void createJabberAccounts();
  203. }
  204. public interface BaseUserService extends BaseCrudService<OhaUserModel>
  205. {
  206. @GET
  207. @Produces("text/plain")
  208. @Path("data/ada/{user}")
  209. public OhaUserModel getUserDataByAdaId(
  210. @PathParam("user")
  211. String adaId);
  212. }
  213. public static class PlatformServiceLocatorImpl implements PlatformServiceLocator
  214. {
  215. @Override
  216. public UserRestService getUserService(String entity, String ticket, String userId)
  217. {
  218. return new UserRestService()
  219. {
  220. @Override
  221. public List<OhaUserModel> getByNameSurname(@PathParam("name") String name, @PathParam("surname") String surname)
  222. {
  223. return null;
  224. }
  225. @Override
  226. public OhaUserModel getUserByMail(@PathParam("mail") String mail)
  227. {
  228. return null;
  229. }
  230. @Override
  231. public Boolean update(@PathParam("id") String id, @QueryParam("adaId") String adaId, @QueryParam("name") String name, @QueryParam("surname") String surname, @QueryParam("address") String address, @QueryParam("city") String city, @QueryParam("country") String country, @QueryParam("zipcode") String zipcode, @QueryParam("email") String email, @QueryParam("phone") String phone, @QueryParam("phone") String timezone)
  232. {
  233. return null;
  234. }
  235. @Override
  236. public Boolean updatePassword(@PathParam("username") String username, List<String> passwords)
  237. {
  238. return null;
  239. }
  240. @Override
  241. public Boolean create(@QueryParam("email") String email, @QueryParam("password") String password, @QueryParam("username") String username)
  242. {
  243. return null;
  244. }
  245. @Override
  246. public Boolean showHelp(@PathParam("user") long userId)
  247. {
  248. return null;
  249. }
  250. @Override
  251. public Boolean setShowHelp(@PathParam("user") long userId, @PathParam("show") boolean showHelp)
  252. {
  253. return null;
  254. }
  255. @Override
  256. public void createJabberAccounts()
  257. {
  258. }
  259. @Override
  260. public OhaUserModel getContent(String id)
  261. {
  262. return null;
  263. }
  264. @Override
  265. public OhaUserModel add(OhaUserModel object)
  266. {
  267. return null;
  268. }
  269. @Override
  270. public List<OhaUserModel> get()
  271. {
  272. return null;
  273. }
  274. @Override
  275. public OhaUserModel update(OhaUserModel object)
  276. {
  277. return null;
  278. }
  279. @Override
  280. public Boolean delete(String id)
  281. {
  282. return null;
  283. }
  284. @Override
  285. public OhaUserModel getUserDataByAdaId(String adaId)
  286. {
  287. return new OhaUserModel("bill");
  288. }
  289. };
  290. }
  291. }
  292. @BeforeClass
  293. public static void setup() throws Exception
  294. {
  295. addPerRequestResource(ImpFoo.class); /* this is the actual reproduction of the problem */
  296. addPerRequestResource(PlatformServiceLocatorImpl.class);
  297. }
  298. @Test
  299. public void test657() throws Exception
  300. {
  301. ClientRequest request = new ClientRequest(generateBaseUrl() + "/platform/users/89080/data/ada/jsanchez110");
  302. String s = request.getTarget(String.class);
  303. Assert.assertEquals(s, "bill");
  304. }
  305. }