@Test public void createEntityTest() { HttpServletRequest servletRequest = mock(HttpServletRequest.class); when(servletRequest.getParameterNames()).thenReturn(Collections.enumeration(Collections.singletonList("name"))); when(servletRequest.getParameterValues("name")).thenReturn(new String[] { "métier" }); Application application = new Application(); Request request = new Request(servletRequest, application); User user = request.createEntityFromParameters(User.class); assertNotNull(user); String name = user.getName(); assertEquals(name, "métier"); }
public <T> T createEntityFromParameters(Class<T> entityClass) { T entity; try { entity = entityClass.newInstance(); } catch (Exception e) { log.error("Cannot create new instance of class '{}'", entityClass.getName(), e); return null; } updateEntityFromParameters(entity); return entity; }
Request { public <T> T createEntityFromParameters(Class<T> entityClass) { T entity; try { entity = entityClass.newInstance(); } catch (Exception e) { log.error("Cannot create new instance of class '{}'", entityClass.getName(), e); return null; } updateEntityFromParameters(entity); return entity; } }
Request { public <T> T createEntityFromParameters(Class<T> entityClass) { T entity; try { entity = entityClass.newInstance(); } catch (Exception e) { log.error("Cannot create new instance of class '{}'", entityClass.getName(), e); return null; } updateEntityFromParameters(entity); return entity; } Request(HttpServletRequest servletRequest, Application application); }
Request { public <T> T createEntityFromParameters(Class<T> entityClass) { T entity; try { entity = entityClass.newInstance(); } catch (Exception e) { log.error("Cannot create new instance of class '{}'", entityClass.getName(), e); return null; } updateEntityFromParameters(entity); return entity; } Request(HttpServletRequest servletRequest, Application application); Map<String, ParameterValue> getParameters(); ParameterValue getParameter(String name); Map<String, ParameterValue> getQueryParameters(); ParameterValue getQueryParameter(String name); Map<String, ParameterValue> getPathParameters(); ParameterValue getPathParameter(String name); void internalSetPathParameters(Map<String, String> pathParameters); T createEntityFromParameters(Class<T> entityClass); @SuppressWarnings("unchecked") T updateEntityFromParameters(T entity); T createEntityFromBody(Class<T> entityClass); String getHost(); String getUserAgent(); int getPort(); String getClientIp(); int getContentLength(); String getScheme(); String getAcceptType(); String getContentType(); Locale getLocale(); String getBody(); String getHeader(String name); Enumeration<String> getHeaders(String name); Enumeration<String> getHeaderNames(); boolean isSecure(); String getUrl(); String getUri(); String getQuery(); String getApplicationUri(); String getApplicationUriWithQuery(); String getContextPath(); String getApplicationPath(); String getPath(); String getMethod(); HttpServletRequest getHttpServletRequest(); Session getSession(); Session getSession(boolean create); void resetSession(); void recreateSession(); Map<String, FileItem> getFiles(); FileItem getFile(String name); List<Cookie> getCookies(); Cookie getCookie(String name); static Request get(); @Override String toString(); }
Request { public <T> T createEntityFromParameters(Class<T> entityClass) { T entity; try { entity = entityClass.newInstance(); } catch (Exception e) { log.error("Cannot create new instance of class '{}'", entityClass.getName(), e); return null; } updateEntityFromParameters(entity); return entity; } Request(HttpServletRequest servletRequest, Application application); Map<String, ParameterValue> getParameters(); ParameterValue getParameter(String name); Map<String, ParameterValue> getQueryParameters(); ParameterValue getQueryParameter(String name); Map<String, ParameterValue> getPathParameters(); ParameterValue getPathParameter(String name); void internalSetPathParameters(Map<String, String> pathParameters); T createEntityFromParameters(Class<T> entityClass); @SuppressWarnings("unchecked") T updateEntityFromParameters(T entity); T createEntityFromBody(Class<T> entityClass); String getHost(); String getUserAgent(); int getPort(); String getClientIp(); int getContentLength(); String getScheme(); String getAcceptType(); String getContentType(); Locale getLocale(); String getBody(); String getHeader(String name); Enumeration<String> getHeaders(String name); Enumeration<String> getHeaderNames(); boolean isSecure(); String getUrl(); String getUri(); String getQuery(); String getApplicationUri(); String getApplicationUriWithQuery(); String getContextPath(); String getApplicationPath(); String getPath(); String getMethod(); HttpServletRequest getHttpServletRequest(); Session getSession(); Session getSession(boolean create); void resetSession(); void recreateSession(); Map<String, FileItem> getFiles(); FileItem getFile(String name); List<Cookie> getCookies(); Cookie getCookie(String name); static Request get(); @Override String toString();  }