Announcement Announcement Module
Collapse
No announcement yet.
[testing spring webflow 2.0.7 + spring security 2.0.5] Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [testing spring webflow 2.0.7 + spring security 2.0.5]

    hi,
    i'm trying to test <secured> element in flows like this:
    Code:
    <secured attributes="ROLE_ADMIN" />
    when i try to test it with my mouse and my favorite browser, it works fine.

    but i want to test it with unit tests.

    when i try the code below:
    Code:
    	
                @Test
    	public void shouldNotAccessToProtectedFlow(){
    		//given
    		AccessDeniedException accessDeniedException = null;
    		login("user1", "melbourne");//grant authority is "ROLE_USER"
    
    		//when
    		try{
    			//expected grant authority is ROLE_ADMIN
    			MutableAttributeMap input = new LocalAttributeMap();
    
    			MockExternalContext context = new MockExternalContext();
    			//setCurrentState("enterSearchCriteria");
    
    			startFlow(input, context);
    
    			assertCurrentStateEquals("enterSearchCriteria");
    		}catch(AccessDeniedException a){
    			accessDeniedException = a;
    		}
    
    		//then
    		assertNotNull("Access to protected flows is not protected, accessDeniedException should be null", accessDeniedException);
    	}
    the code compile but no exception is raised
    the test failed because i thinck the <secured> element is not readen or understood (maybe no listener available?)

    so what is the way to test it?

  • #2
    For the generations to come (and ask the same question), please, see my post


    Originally posted by kisscool View Post
    hi,
    i'm trying to test <secured> element in flows like this:
    Code:
    <secured attributes="ROLE_ADMIN" />
    when i try to test it with my mouse and my favorite browser, it works fine.

    but i want to test it with unit tests.

    when i try the code below:
    Code:
    	
                @Test
    	public void shouldNotAccessToProtectedFlow(){
    		//given
    		AccessDeniedException accessDeniedException = null;
    		login("user1", "melbourne");//grant authority is "ROLE_USER"
    
    		//when
    		try{
    			//expected grant authority is ROLE_ADMIN
    			MutableAttributeMap input = new LocalAttributeMap();
    
    			MockExternalContext context = new MockExternalContext();
    			//setCurrentState("enterSearchCriteria");
    
    			startFlow(input, context);
    
    			assertCurrentStateEquals("enterSearchCriteria");
    		}catch(AccessDeniedException a){
    			accessDeniedException = a;
    		}
    
    		//then
    		assertNotNull("Access to protected flows is not protected, accessDeniedException should be null", accessDeniedException);
    	}
    the code compile but no exception is raised
    the test failed because i thinck the <secured> element is not readen or understood (maybe no listener available?)

    so what is the way to test it?

    Comment

    Working...
    X