Package com.meterware.servletunit

Examples of com.meterware.servletunit.InvocationContext


   
     
        ServletRunner sr = new ServletRunner();
    ServletUnitClient sc = sr.newClient();
    WebRequest request   = new PostMethodWebRequest( "https://test.meterware.com/myServlet" );
    InvocationContext ic = sc.newInvocation( request );
   
        OAuth2ProblemException problem = new OAuth2ProblemException(OAuth2.ErrorCode.UNSUPPORTED_RESPONSE_TYPE);
        // if you do not specify status code 200 here response does not inluce anything
        problem.setParameter(OAuth2ProblemException.HTTP_STATUS_CODE,new Integer(200));
        HttpServletResponse hsr = ic.getResponse();
        OAuth2Servlet.handleException(ic.getRequest(),hsr,problem,null,true,false);
       
        WebResponse response   = ic.getServletResponse();
   
        assertEquals("ErrorJSONResponse Body chcek", "{"+toStringWithQuotation("error")+":"+toStringWithQuotation("unsupported_response_type")+"}", response.getText());
        assertEquals("ErrorJSONResponse ContentType check", "application/json", response.getContentType());

           
View Full Code Here


   
     
        ServletRunner sr = new ServletRunner();
    ServletUnitClient sc = sr.newClient();
    WebRequest request   = new PostMethodWebRequest( "https://test.meterware.com/myServlet" );
    InvocationContext ic = sc.newInvocation( request );
   
        OAuth2ProblemException problem = new OAuth2ProblemException(OAuth2.ErrorCode.UNSUPPORTED_RESPONSE_TYPE);
        problem.setParameter(OAuth2ProblemException.HTTP_STATUS_CODE,new Integer(302));
        //problem.getParameters().put(OAuth2.REDIRECT_URI,"https://client.example.com/cb");
        problem.setParameter(OAuth2.REDIRECT_URI,"https://client.example.com/cb");
        HttpServletResponse hsr = ic.getResponse();
        OAuth2Servlet.handleException(ic.getRequest(),hsr,problem,null,false,false);
       
     
        WebResponse response   = ic.getServletResponse();
           
        assertEquals("ErroeRedirectResponse Location chceck", "https://client.example.com/cb?error=unsupported_response_type", response.getHeaderField(OAuth2ProblemException.HTTP_LOCATION));  
        assertEquals("ErrorRedirectResponse Code check", "302", new Integer(response.getResponseCode()).toString());
           
       
View Full Code Here

    {

        ServletRunner sr = new ServletRunner();
        ServletUnitClient sc = sr.newClient();
        WebRequest request   = new PostMethodWebRequest( "https://test.meterware.com/myServlet" );
        InvocationContext ic = sc.newInvocation( request );

        OAuth2ProblemException problem = new OAuth2ProblemException(OAuth2.ErrorCode.UNSUPPORTED_RESPONSE_TYPE);
        problem.setParameter(OAuth2ProblemException.HTTP_STATUS_CODE,new Integer(302));
        //problem.getParameters().put(OAuth2.REDIRECT_URI,"https://client.example.com/cb");
        problem.setParameter(OAuth2.REDIRECT_URI,"https://client.example.com/cb");
        HttpServletResponse hsr = ic.getResponse();
        OAuth2Servlet.handleException(ic.getRequest(),hsr,problem,null,false,false);


        WebResponse response   = ic.getServletResponse();

        assertEquals("ErroeRedirectResponse Location chceck", "https://client.example.com/cb?error=unsupported_response_type", response.getHeaderField(OAuth2ProblemException.HTTP_LOCATION));
        assertEquals("ErrorRedirectResponse Code check", "302", new Integer(response.getResponseCode()).toString());

View Full Code Here

     
      for (String[] testCase : OAUTH_PARAMETERS) {
        ServletRunner sr = new ServletRunner();
        ServletUnitClient sc = sr.newClient();
        WebRequest request   = new PostMethodWebRequest( "https://test.meterware.com/myServlet" );      
        InvocationContext ic = sc.newInvocation( request );     
      
            String label = testCase[0];
            //String realm = testCase[1];
            List<OAuth2.Parameter> parameters = decodeForm(testCase[1]);
            OAuth2Servlet.sendFormInJson(ic.getResponse(),parameters);
            WebResponse response   = ic.getServletResponse();
            String expectedGrantType = testCase[2];
            String expectedClientId = testCase[3];
            //String expectedSecret = testCase[5];
            String expectedCode = testCase[4];
            String expectedRedirectURI = testCase[5];
View Full Code Here

        request.setParameter( "grant_type", testCase[2] );
        request.setParameter( "client_id", testCase[3] );
        //request.setParameter( "client_secret", testCase[5] );
        request.setParameter( "code", testCase[4] );
        request.setParameter( "redirect_uri", testCase[5] );       
        InvocationContext ic = sc.newInvocation( request );
        OAuth2Message message = OAuth2Servlet.getMessage(ic.getRequest(),"https://test.meterware.com/myServlet");
       
            String label = testCase[0];
            //String realm = testCase[1];
            String expectedGrantType = testCase[2];
            String expectedClientId = testCase[3];
View Full Code Here

   
      ServletRunner sr = new ServletRunner();
      ServletUnitClient sc = sr.newClient();
        WebRequest request   = new GetMethodWebRequest( "http://test.meterware.com/myServlet" );
        request.setParameter( "color", "red" );
        InvocationContext ic = sc.newInvocation( request );
        String url = OAuth2Servlet.getRequestURL(ic.getRequest());
        assertEquals("URL check", "http://test.meterware.com/myServlet?color=red", url);       
    }
View Full Code Here

        String putUrl = "http://machine.com/repository/internal/path/to/artifact.jar";
        InputStream is = getClass().getResourceAsStream( "/artifact.jar" );
        assertNotNull( "artifact.jar inputstream", is );

        WebRequest request = new PutMethodWebRequest( putUrl, is, "application/octet-stream" );
        InvocationContext ic = sc.newInvocation( request );
        servlet = (RepositoryServlet) ic.getServlet();
        servlet.setDavSessionProvider( davSessionProvider );

        AuthenticationResult result = new AuthenticationResult();
        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
        servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ),
                                           new AuthenticationException( "Authentication error" ) );

        servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD );
        servletAuthControl.setMatcher( MockControl.EQUALS_MATCHER );
        servletAuthControl.setThrowable( new UnauthorizedException( "'guest' has no write access to repository" ) );

        httpAuthControl.replay();
        servletAuthControl.replay();

        servlet.service( ic.getRequest(), ic.getResponse() );

        httpAuthControl.verify();
        servletAuthControl.verify();

        // assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getResponseCode());
View Full Code Here

        InputStream is = getClass().getResourceAsStream( "/artifact.jar" );
        assertNotNull( "artifact.jar inputstream", is );

        WebRequest request = new PutMethodWebRequest( putUrl, is, "application/octet-stream" );

        InvocationContext ic = sc.newInvocation( request );
        servlet = (RepositoryServlet) ic.getServlet();
        servlet.setDavSessionProvider( davSessionProvider );

        ArchivaDavResourceFactory archivaDavResourceFactory = (ArchivaDavResourceFactory) servlet.getResourceFactory();
        archivaDavResourceFactory.setHttpAuth( httpAuth );
        archivaDavResourceFactory.setServletAuth( servletAuth );

        servlet.setResourceFactory( archivaDavResourceFactory );

        AuthenticationResult result = new AuthenticationResult();
        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
        servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ),
                                           new AuthenticationException( "Authentication error" ) );

        servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD );
        servletAuthControl.setMatcher( MockControl.EQUALS_MATCHER );
        servletAuthControl.setReturnValue( true );

        // ArchivaDavResourceFactory#isAuthorized()
        SecuritySession session = new DefaultSecuritySession();
        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
        httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session );
        servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, result ),
                                           new AuthenticationException( "Authentication error" ) );

        httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), null );

        // check if guest has write access
        servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD );
        servletAuthControl.setMatcher( MockControl.EQUALS_MATCHER );
        servletAuthControl.setReturnValue( true );

        httpAuthControl.replay();
        servletAuthControl.replay();

        servlet.service( ic.getRequest(), ic.getResponse() );

        httpAuthControl.verify();
        servletAuthControl.verify();

        // assertEquals( HttpServletResponse.SC_CREATED, response.getResponseCode() );
View Full Code Here

        InputStream is = getClass().getResourceAsStream( "/artifact.jar" );
        assertNotNull( "artifact.jar inputstream", is );

        WebRequest request = new PutMethodWebRequest( putUrl, is, "application/octet-stream" );

        InvocationContext ic = sc.newInvocation( request );
        servlet = (RepositoryServlet) ic.getServlet();
        servlet.setDavSessionProvider( davSessionProvider );

        ArchivaDavResourceFactory archivaDavResourceFactory = (ArchivaDavResourceFactory) servlet.getResourceFactory();
        archivaDavResourceFactory.setHttpAuth( httpAuth );
        archivaDavResourceFactory.setServletAuth( servletAuth );
        servlet.setResourceFactory( archivaDavResourceFactory );

        AuthenticationResult result = new AuthenticationResult();
        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
        servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true );

        // ArchivaDavResourceFactory#isAuthorized()
        SecuritySession session = new DefaultSecuritySession();
        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
        httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session );
        httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), new SimpleUser() );
        servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true );
        servletAuthControl.expectAndThrow(
                                           servletAuth.isAuthorized( null, session, "internal",
                                                                     ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ),
                                           new UnauthorizedException( "User not authorized" ) );

        httpAuthControl.replay();
        servletAuthControl.replay();

        servlet.service( ic.getRequest(), ic.getResponse() );

        httpAuthControl.verify();
        servletAuthControl.verify();

        // assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getResponseCode());
View Full Code Here

        InputStream is = getClass().getResourceAsStream( "/artifact.jar" );
        assertNotNull( "artifact.jar inputstream", is );

        WebRequest request = new PutMethodWebRequest( putUrl, is, "application/octet-stream" );

        InvocationContext ic = sc.newInvocation( request );
        servlet = (RepositoryServlet) ic.getServlet();
        servlet.setDavSessionProvider( davSessionProvider );

        ArchivaDavResourceFactory archivaDavResourceFactory = (ArchivaDavResourceFactory) servlet.getResourceFactory();
        archivaDavResourceFactory.setHttpAuth( httpAuth );
        archivaDavResourceFactory.setServletAuth( servletAuth );

        TestAuditListener listener = new TestAuditListener();
        archivaDavResourceFactory.addAuditListener( listener );
        servlet.setResourceFactory( archivaDavResourceFactory );

        AuthenticationResult result = new AuthenticationResult();
        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
        servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true );

        User user = new SimpleUser();
        user.setUsername( "admin" );
       
        // ArchivaDavResourceFactory#isAuthorized()
        SecuritySession session = new DefaultSecuritySession();
        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
        httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session );
        httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), user );
        servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true );
        servletAuthControl.expectAndReturn(
                                            servletAuth.isAuthorized( null, session, "internal",
                                                                      ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ),
                                            true );

        httpAuthControl.replay();
        servletAuthControl.replay();

        servlet.service( ic.getRequest(), ic.getResponse() );

        httpAuthControl.verify();
        servletAuthControl.verify();

        // assertEquals(HttpServletResponse.SC_CREATED, response.getResponseCode());
View Full Code Here

TOP

Related Classes of com.meterware.servletunit.InvocationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.