Java Code Examples for org.springframework.mock.web.mockhttpservletrequest#setParameter()
The following examples show how to use
org.springframework.mock.web.mockhttpservletrequest#setParameter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestControllerTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testMissingAttribute() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI("/rest/beans"); request.setMethod("GET"); request.setParameter("queryable", "noSuchAttr"); request.setParameter("noSuchAttr_eq", "200"); MockHttpServletResponse response = new MockHttpServletResponse(); try { adapter.handle(request, response, restController); Assert.fail("attribute noSuchAttr should not exist"); } catch (Exception e) { Assert.assertTrue(e instanceof RestException); Assert.assertEquals(RestException.PROBLEM_READING_LAYERSERVICE, ((RestException) e).getExceptionCode()); } }
Example 2
Source File: RightJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void testDoUnAssignUserInvalidToken( ) throws AccessDeniedException { AdminUser user = AdminUserHome.findUserByLogin( "admin" ); AdminUserHome.createRightForUser( user.getUserId( ), right.getId( ) ); MockHttpServletRequest request = new MockHttpServletRequest( ); request.setParameter( "id_right", right.getId( ) ); request.setParameter( "id_user", Integer.toString( user.getUserId( ) ) ); request.setParameter( "anchor", "anchor" ); request.setParameter( SecurityTokenService.PARAMETER_TOKEN, SecurityTokenService.getInstance( ).getToken( request, "admin/features/assign_users_right.html" ) + "b" ); assertTrue( AdminUserHome.getRightsListForUser( user.getUserId( ) ).keySet( ).contains( right.getId( ) ) ); try { bean.doUnAssignUser( request ); fail( "Should have thrown" ); } catch( AccessDeniedException e ) { assertTrue( AdminUserHome.getRightsListForUser( user.getUserId( ) ).keySet( ).contains( right.getId( ) ) ); } finally { AdminUserHome.removeRightForUser( user.getUserId( ), right.getId( ) ); } }
Example 3
Source File: AdminWorkgroupJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void testDoCreateWorkgroupNoToken( ) throws AccessDeniedException { final String key = getRandomName( ); MockHttpServletRequest request = new MockHttpServletRequest( ); AdminUser user = new AdminUser( ); Utils.registerAdminUserWithRigth( request, user, "CORE_WORKGROUPS_MANAGEMENT" ); request.setParameter( "workgroup_key", key ); request.setParameter( "workgroup_description", key ); assertFalse( AdminWorkgroupHome.checkExistWorkgroup( key ) ); bean.init( request, "CORE_WORKGROUPS_MANAGEMENT" ); try { bean.doCreateWorkgroup( request ); fail( "Should have thrown" ); } catch( AccessDeniedException e ) { assertFalse( AdminWorkgroupHome.checkExistWorkgroup( key ) ); } AdminWorkgroupHome.remove( key ); }
Example 4
Source File: LogoutActionTest.java From web-sso with Apache License 2.0 | 6 votes |
@Test public void testLogoutWithCredentialAndService() throws IOException { String servce = "http://app.com/logoutSucess.do"; MockHttpServletRequest request = new MockHttpServletRequest(); request.setParameter(WebConstants.SERVICE_PARAM_NAME, servce); MockHttpServletResponse response = new MockHttpServletResponse(); HttpSession session = request.getSession(); CredentialResolver credentialResolver = Mockito.mock(CredentialResolver.class); logoutAction.setCredentialResolver(credentialResolver); Ki4soService ki4soService = Mockito.mock(Ki4soService.class); logoutAction.setKi4soService(ki4soService); //测试存在cookie,登出后要清除cookie值,但是service参数的值是null的情况。 request.setCookies(new Cookie(WebConstants.KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY, "dddsd")); ModelAndView mv = logoutAction.logout(request, response,session); Assert.assertEquals(1, response.getCookies().length); Assert.assertEquals(0, response.getCookies()[0].getMaxAge()); RedirectView view = (RedirectView) mv.getView(); Assert.assertEquals(servce, view.getUrl()); }
Example 5
Source File: AdminLoginJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void testDoResetPasswordGET( ) { AdminLoginJspBean bean = new AdminLoginJspBean( ); MockHttpServletRequest request = new MockHttpServletRequest( ); request.setMethod( "GET" ); request.setParameter( Parameters.USER_ID, Integer.toString( user.getUserId( ) ) ); Date timestamp = new Date( ); String token = AdminUserService.getUserPasswordResetToken( user, timestamp, request ); request.setParameter( "ts", Long.toString( timestamp.getTime( ) ) ); request.setParameter( "token", token ); request.setParameter( Parameters.NEW_PASSWORD, NEW_PASSWORD ); request.setParameter( Parameters.CONFIRM_NEW_PASSWORD, NEW_PASSWORD ); try { bean.doResetPassword( request ); fail( "should have thrown" ); } catch( AppException e ) { } LuteceDefaultAdminUser storedUser = getAdminUserDAO( ).loadDefaultAdminUser( user.getUserId( ) ); assertNotNull( storedUser ); assertTrue( storedUser.getPassword( ).check( PASSWORD ) ); }
Example 6
Source File: AdminMenuJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void testDoModifyAccessibilityMode( ) throws AccessDeniedException { MockHttpServletRequest request = new MockHttpServletRequest( ); request.setParameter( SecurityTokenService.PARAMETER_TOKEN, SecurityTokenService.getInstance( ).getToken( request, AccessibilityModeAdminUserMenuItemProvider.TEMPLATE ) ); getUser( request ); Utils.registerAdminUser( request, _user ); boolean bAccessibilityMode = _user.getAccessibilityMode( ); try { AdminMenuJspBean instance = new AdminMenuJspBean( ); instance.doModifyAccessibilityMode( request ); assertEquals( !bAccessibilityMode, _user.getAccessibilityMode( ) ); } finally { _user.setAccessibilityMode( bAccessibilityMode ); AdminUserHome.update( _user ); } }
Example 7
Source File: MailingListJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void testDoModifyMailingList( ) throws AccessDeniedException { MockHttpServletRequest request = new MockHttpServletRequest( ); request.setParameter( "id_mailinglist", Integer.toString( mailingList.getId( ) ) ); request.setParameter( "name", mailingList.getName( ) + "_mod" ); request.setParameter( "description", mailingList.getDescription( ) + "_mod" ); request.setParameter( "workgroup", AdminWorkgroupService.ALL_GROUPS ); request.setParameter( SecurityTokenService.PARAMETER_TOKEN, SecurityTokenService.getInstance( ).getToken( request, "admin/mailinglist/modify_mailinglist.html" ) ); MailingList storedMailling = MailingListHome.findByPrimaryKey( mailingList.getId( ) ); assertEquals( mailingList.getName( ), storedMailling.getName( ) ); assertEquals( mailingList.getDescription( ), storedMailling.getDescription( ) ); bean.doModifyMailingList( request ); storedMailling = MailingListHome.findByPrimaryKey( mailingList.getId( ) ); assertEquals( mailingList.getName( ) + "_mod", storedMailling.getName( ) ); assertEquals( mailingList.getDescription( ) + "_mod", storedMailling.getDescription( ) ); }
Example 8
Source File: DashboardJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void testDoReorderColumn( ) throws AccessDeniedException { IDashboardComponent stored = DashboardHome.findByPrimaryKey( _dashboard.getName( ) ); assertNotNull( stored ); assertEquals( 0, stored.getOrder( ) ); assertEquals( _nZone, stored.getZone( ) ); int nZone = DashboardHome.findColumns( ).stream( ).max( Integer::compare ).orElse( 1 ) + 1; stored.setZone( nZone ); stored.setOrder( -1 ); DashboardHome.update( stored ); stored = DashboardHome.findByPrimaryKey( _dashboard.getName( ) ); assertEquals( -1, stored.getOrder( ) ); assertEquals( nZone, stored.getZone( ) ); MockHttpServletRequest request = new MockHttpServletRequest( ); request.setParameter( "column", Integer.toString( nZone ) ); request.setParameter( SecurityTokenService.PARAMETER_TOKEN, SecurityTokenService.getInstance( ).getToken( request, "/admin/dashboard/manage_dashboards.html" ) ); _instance.doReorderColumn( request ); stored = DashboardHome.findByPrimaryKey( _dashboard.getName( ) ); assertEquals( 1, stored.getOrder( ) ); assertEquals( nZone, stored.getZone( ) ); }
Example 9
Source File: AdminUserJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void testDoModifyAdminUserPasswordNoFirst( ) throws AccessDeniedException, UserNotSignedException { AdminUserJspBean bean = new AdminUserJspBean( ); MockHttpServletRequest request = new MockHttpServletRequest( ); AdminUser user = getUserToModify( ); try { AdminAuthenticationService.getInstance( ).registerUser( request, user ); request.setParameter( "id_user", Integer.toString( user.getUserId( ) ) ); String password = "CHANGEDCHANGED"; assertFalse( AdminUserHome.findLuteceDefaultAdminUserByPrimaryKey( user.getUserId( ) ).getPassword( ).check( password ) ); request.setParameter( "second_password", password ); request.setParameter( "token", SecurityTokenService.getInstance( ).getToken( request, "portal.users.modify_user_password.pageTitle" ) ); bean.init( request, "CORE_USERS_MANAGEMENT" ); bean.doModifyAdminUserPassword( request ); AdminMessage message = AdminMessageService.getMessage( request ); assertNotNull( message ); assertEquals( AdminMessage.TYPE_STOP, message.getType( ) ); assertFalse( AdminUserHome.findLuteceDefaultAdminUserByPrimaryKey( user.getUserId( ) ).getPassword( ).check( password ) ); } finally { disposeOfUser( user ); } }
Example 10
Source File: XslExportJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void testGetConfirmRemoveXslExport( ) throws AccessDeniedException { MockHttpServletRequest request = new MockHttpServletRequest( ); AdminUser user = new AdminUser( ); user.setRoles(RBACRoleHome.findAll( ).stream( ).collect(Collectors.toMap(RBACRole::getKey, Function.identity( ) ) ) ); Utils.registerAdminUserWithRigth( request, user, XslExportJspBean.RIGHT_MANAGE_XSL_EXPORT ); request.setParameter( "id_xsl_export", Integer.toString( _xslExport.getIdXslExport( ) ) ); _instance.init( request, XslExportJspBean.RIGHT_MANAGE_XSL_EXPORT ); _instance.getConfirmRemoveXslExport( request ); AdminMessage message = AdminMessageService.getMessage( request ); assertNotNull( message ); assertTrue( message.getRequestParameters( ).containsKey( SecurityTokenService.PARAMETER_TOKEN ) ); }
Example 11
Source File: SwaggerBasePathRewritingFilterTest.java From cubeai with Apache License 2.0 | 5 votes |
/** * Zuul DebugFilter can be triggered by "deug" parameter. */ @Test public void shouldFilter_on_default_swagger_url_with_param() { MockHttpServletRequest request = new MockHttpServletRequest("GET", DEFAULT_URL); request.setParameter("debug", "true"); RequestContext.getCurrentContext().setRequest(request); assertTrue(filter.shouldFilter()); }
Example 12
Source File: TestValueExtractors.java From proctor with Apache License 2.0 | 5 votes |
@Test public void testQueryExtractor() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final ValueExtractor countryExtractor = ValueExtractors.fromQueryParameter("country"); Assert.assertNull("Request missing parameter should return null", countryExtractor.extract(request)); request.setParameter("country", "US"); Assert.assertEquals("US", countryExtractor.extract(request)); }
Example 13
Source File: AttributeJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void testDoMoveDownAttributeNoToken( ) throws PasswordResetException, AccessDeniedException { List<IAttribute> listAttributes = AttributeService.getInstance( ).getAllAttributesWithoutFields( Locale.FRANCE ); assertTrue( listAttributes.size( ) >= 2 ); int nIdAttribute = listAttributes.get( 0 ).getIdAttribute( ); int nPosition = listAttributes.get( 0 ).getPosition( ); MockHttpServletRequest request = new MockHttpServletRequest( ); Utils.registerAdminUserWithRigth( request, new AdminUser( ), "CORE_USERS_MANAGEMENT" ); AttributeJspBean instance = new AttributeJspBean( ); instance.init( request, "CORE_USERS_MANAGEMENT" ); request.setParameter( "id_attribute", Integer.toString( nIdAttribute ) ); try { instance.doMoveDownAttribute( request ); fail( "Should have thrown" ); } catch( AccessDeniedException e ) { IAttribute stored = AttributeService.getInstance( ).getAttributeWithoutFields( nIdAttribute, Locale.FRANCE ); assertNotNull( stored ); assertEquals( nPosition, stored.getPosition( ) ); } }
Example 14
Source File: AdminUserJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void testDoModifyEmailPatternInvalidToken( ) throws PasswordResetException, AccessDeniedException, UserNotSignedException { String origEmailPattern = getEmailPattern( ); assertTrue( "plugin-regularexpression is not there", isEmailPatternSetManually( ) ); AdminUserJspBean bean = new AdminUserJspBean( ); MockHttpServletRequest request = new MockHttpServletRequest( ); AdminUser user = getUserToModify( ); AdminAuthenticationService.getInstance( ).registerUser( request, user ); bean.init( request, "CORE_USERS_MANAGEMENT" ); request.addParameter( SecurityTokenService.PARAMETER_TOKEN, SecurityTokenService.getInstance( ).getToken( request, "ManageAdvancedParameters.jsp" ) + "b" ); request.setParameter( "is_email_pattern_set_manually", Boolean.FALSE.toString( ) ); request.setParameter( "email_pattern", origEmailPattern + "b" ); try { bean.doModifyEmailPattern( request ); fail( "Should have thrown" ); } catch( AccessDeniedException e ) { assertEquals( origEmailPattern, getEmailPattern( ) ); assertTrue( isEmailPatternSetManually( ) ); } finally { AdminUserService.doModifyEmailPattern( origEmailPattern, isEmailPatternSetManually( ) ); disposeOfUser( user ); } }
Example 15
Source File: ClientActionTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testFinishAuthentication() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, "FacebookClient"); final MockHttpSession mockSession = new MockHttpSession(); mockSession.setAttribute(ClientAction.THEME, MY_THEME); mockSession.setAttribute(ClientAction.LOCALE, MY_LOCALE); mockSession.setAttribute(ClientAction.METHOD, MY_METHOD); final Service service = new SimpleWebApplicationServiceImpl(MY_SERVICE); mockSession.setAttribute(ClientAction.SERVICE, service); mockRequest.setSession(mockSession); final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class); when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest); final MockRequestContext mockRequestContext = new MockRequestContext(); mockRequestContext.setExternalContext(servletExternalContext); final FacebookClient facebookClient = new MockFacebookClient(); final Clients clients = new Clients(MY_LOGIN_URL, facebookClient); final ClientAction action = new ClientAction(mock(CentralAuthenticationService.class), clients); final Event event = action.execute(mockRequestContext); assertEquals("success", event.getId()); assertEquals(MY_THEME, mockRequest.getAttribute(ClientAction.THEME)); assertEquals(MY_LOCALE, mockRequest.getAttribute(ClientAction.LOCALE)); assertEquals(MY_METHOD, mockRequest.getAttribute(ClientAction.METHOD)); final MutableAttributeMap flowScope = mockRequestContext.getFlowScope(); assertEquals(service, flowScope.get(ClientAction.SERVICE)); }
Example 16
Source File: ExternalFeaturesJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test of doModifyExternalFeature method, of class ExternalFeaturesJspBean. * * @throws AccessDeniedException */ @Test public void testDoModifyExternalFeature( ) throws AccessDeniedException { MockHttpServletRequest request = new MockHttpServletRequest( ); request.addParameter( PARAMETER_ID_EXTERNAL_FEAUTRE, TEST_EXTERNAL_FEATURE_ID ); Utils.registerAdminUserWithRigth( request, new AdminUser( ), ExternalFeaturesJspBean.RIGHT_EXTERNAL_FEATURES_MANAGEMENT ); ExternalFeaturesJspBean instance = new ExternalFeaturesJspBean( ); instance.init( request, ExternalFeaturesJspBean.RIGHT_EXTERNAL_FEATURES_MANAGEMENT ); String strRandom = getRandomName( ); request.setParameter( "id", _right.getId( ) ); request.setParameter( "nameKey", strRandom ); request.setParameter( "descriptionKey", strRandom ); request.setParameter( "level_id", "0" ); request.setParameter( "url", strRandom ); request.setParameter( "pluginName", strRandom ); request.setParameter( "feature_group_id", FeatureGroupHome.getFeatureGroupsList( ).get( 0 ).getId( ) ); request.setParameter( "iconUrl", strRandom ); request.setParameter( "externalFeature", "false" ); request.setParameter( "documentationUrl", strRandom ); instance.getModifyExternalFeature( request ); request.setParameter( SecurityTokenService.PARAMETER_TOKEN, SecurityTokenService.getInstance( ).getToken( request, "admin/features/modify_external_feature.html" ) ); instance.doModifyExternalFeature( request ); Right right = RightHome.findByPrimaryKey( _right.getId( ) ); assertNotNull( right ); assertEquals( strRandom, right.getNameKey( ) ); assertEquals( strRandom, right.getDescriptionKey( ) ); assertEquals( 0, right.getLevel( ) ); assertEquals( strRandom, right.getUrl( ) ); assertEquals( strRandom, right.getPluginName( ) ); assertEquals( FeatureGroupHome.getFeatureGroupsList( ).get( 0 ).getId( ), right.getFeatureGroup( ) ); assertEquals( strRandom, right.getIconUrl( ) ); assertTrue( right.isExternalFeature( ) ); assertEquals( strRandom, right.getDocumentationUrl( ) ); }
Example 17
Source File: AttributeJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void testDoCreateAttributeNoToken( AttributeType type ) throws PasswordResetException, AccessDeniedException, InstantiationException, IllegalAccessException, ClassNotFoundException { MockHttpServletRequest request = new MockHttpServletRequest( ); request.setParameter( "attribute_type_class_name", type.getClassName( ) ); String strTitle = getRandomName( ); request.setParameter( "title", strTitle ); request.setParameter( "width", "5" ); Utils.registerAdminUserWithRigth( request, new AdminUser( ), "CORE_USERS_MANAGEMENT" ); AttributeJspBean instance = new AttributeJspBean( ); instance.init( request, "CORE_USERS_MANAGEMENT" ); try { instance.doCreateAttribute( request ); fail( "Should have thrown" ); } catch( AccessDeniedException e ) { assertFalse( "Did find attribute of type " + type.getClassName( ), AttributeService.getInstance( ).getAllAttributesWithoutFields( Locale.FRANCE ) .stream( ).anyMatch( a -> a.getTitle( ).equals( strTitle ) ) ); } finally { AttributeService.getInstance( ).getAllAttributesWithoutFields( Locale.FRANCE ).stream( ).filter( a -> a.getTitle( ).equals( strTitle ) ) .forEach( a -> AttributeService.getInstance( ).removeAttribute( a.getIdAttribute( ) ) ); } }
Example 18
Source File: LuceneSearchEngineTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void testSearchTypeNoMatch( ) throws Exception { MockHttpServletRequest request = new MockHttpServletRequest( ); request.setParameter( "type_filter", "lutecebadtype" ); List<SearchResult> listResults = _engine.getSearchResults( "lutecefoo", request ); assertTrue( "The search results list should have no elements. Got : " + listResults, listResults != null && listResults.size( ) == 0 ); }
Example 19
Source File: SimpleWebApplicationServiceImplTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testResponse() { final MockHttpServletRequest request = new MockHttpServletRequest(); request.setParameter("service", "service"); final SimpleWebApplicationServiceImpl impl = SimpleWebApplicationServiceImpl.createServiceFrom(request); final Response response = impl.getResponse("ticketId"); assertNotNull(response); assertEquals(ResponseType.REDIRECT, response.getResponseType()); }
Example 20
Source File: AttributeFieldJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void testGetModifyAttributeField( IAttribute attribute ) throws PasswordResetException, AccessDeniedException { MockHttpServletRequest request = new MockHttpServletRequest( ); request.setParameter( "id_attribute", Integer.toString( attribute.getIdAttribute( ) ) ); request.setParameter( "id_field", Integer.toString( attribute.getListAttributeFields( ).get( 0 ).getIdField( ) ) ); Utils.registerAdminUserWithRigth( request, new AdminUser( ), "CORE_USERS_MANAGEMENT" ); instance.init( request, "CORE_USERS_MANAGEMENT" ); assertNotNull( instance.getModifyAttributeField( request ) ); }