Package com.meterware.servletunit

Examples of com.meterware.servletunit.InvocationContext


        artifactFile.getParentFile().mkdirs();

        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );

        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
        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.expectAndReturn(
                                            servletAuth.isAuthorized( null, session, "internal",
                                                                      ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ),
                                            true );
View Full Code Here


        artifactFile.getParentFile().mkdirs();

        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );

        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
        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 to read repository." ) );
View Full Code Here

    protected static void initServlet() throws Exception {
        ServletRunner servletRunner = new ServletRunner(new File(srcdir, "WEB-INF/web.xml"), "");
        client = servletRunner.newClient();

        InvocationContext ic = client.newInvocation("http://www.taobao.com/app1");
        servletContext = createServletContextWrapper(ic.getServlet().getServletConfig().getServletContext());

        assertNotNull(servletContext);
    }
View Full Code Here

    @Before
    public final void prepareRequest() throws Exception {
        ServletRunner servletRunner = new ServletRunner(new File(srcdir, "WEB-INF/web.xml"), "/myapp");
        ServletUnitClient client = servletRunner.newClient();
        InvocationContext invocationContext = client.newInvocation("http://localhost/myapp/myservlet");

        HttpServletRequest request = invocationContext.getRequest();
        HttpServletResponse response = invocationContext.getResponse();
        ServletConfig config = invocationContext.getServlet().getServletConfig();

        this.requestContexts = (RequestContextChainingService) factory.getBean("requestContexts");
        this.request = this.requestContexts.getRequestContext(config.getServletContext(), request, response)
                                           .getRequest();
View Full Code Here

            uri = URI.create(uri).normalize().toString(); // full uri
        } else {
            uri = URI.create("http://www.taobao.com/" + trimToEmpty(uri)).normalize().toString(); // partial uri
        }

        InvocationContext ic = client.newInvocation(uri);
        ic.getFilter().doFilter(new MyHttpRequest(ic.getRequest(), uri), ic.getResponse(), ic.getFilterChain());

        clientResponse = client.getResponse(ic);
        clientResponseCode = clientResponse.getResponseCode();
        clientResponseContent = clientResponse.getText();
    }
View Full Code Here

        assertEquals("Unknown Version", WebxUtil.getWebxVersion());
    }

    @Test
    public void getServletAPIVersion() throws Exception {
        InvocationContext ic = client.newInvocation("http://localhost/myapps/test");
        ServletContext servletContext = ic.getRequest().getSession().getServletContext();
        assertEquals("2.4", WebxUtil.getServletApiVersion(servletContext)); // http unit version
    }
View Full Code Here

    public AbstractLogConfiguratorListenerTests() throws Exception {
        listener = new LogConfiguratorListener();

        ServletRunner runner = new ServletRunner(new File(webxml()), "");
        ServletUnitClient client = runner.newClient();
        InvocationContext ic = client.newInvocation("http://localhost/servlet");
        servletContext = ic.getServlet().getServletConfig().getServletContext();
        event = new ServletContextEvent(servletContext);
    }
View Full Code Here

        requestContexts = (RequestContextChainingService) factory.getBean("requestContexts");

        ServletRunner servletRunner = new ServletRunner();
        servletRunner.registerServlet("/app1/*", MyServlet.class.getName());
        ServletUnitClient client = servletRunner.newClient();
        InvocationContext ic = client.newInvocation(url);
        MyServlet servlet = (MyServlet) ic.getServlet();

        rc = requestContexts.getRequestContext(servlet.getServletContext(), ic.getRequest(), ic.getResponse());
    }
View Full Code Here

        } else {
            fail("Could not find non-ascii filename: " + nonAsciiFile.getAbsolutePath()
                 + ".  Please make sure the OS charset is correctly set.");
        }

        InvocationContext invocationContext = client.newInvocation(request);

        this.request = invocationContext.getRequest();

        // 因为页面的content type是text/html; charset=UTF-8,
        // 所以应该以UTF-8方式解析request。
        this.request.setCharacterEncoding("UTF-8");
    }
View Full Code Here

    public void isMultipartContent() throws Exception {
        assertTrue(upload.isMultipartContent(request));

        // 初始页面的请求是一个普通的“application/x-www-form-urlencoded”请求。
        WebRequest request = new GetMethodWebRequest("http://localhost/myservlet");
        InvocationContext invocationContext = client.newInvocation(request);

        assertFalse(upload.isMultipartContent(invocationContext.getRequest()));
    }
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.