Package com.mockrunner.mock.web

Examples of com.mockrunner.mock.web.MockHttpServletRequest


    {
        MockServletConfig config = new MockServletConfig();
        MockServletContext context = new MockServletContext();
        MockHttpSession session = new MockHttpSession();
        session.setupServletContext(context);
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setupAddParameter("action", "constraints");
        request.setupAddParameter("method", method);
        request.setupAddParameter("xml", xml);
        request.setupAddParameter("name", defName);
        request.setSession(session);
        MockHttpServletResponse response = new MockHttpServletResponse();

        final RequestContext rc =
            new JetspeedRequestContext(request, response, config, null);
       
View Full Code Here


        segments.add("windowid");
        ContentCacheKeyGenerator generator = new JetspeedCacheKeyGenerator(segments);
        JetspeedCache contentCache = new EhPortletContentCacheImpl(ehContentCache, generator);
       
        // create the mock request context
        MockHttpServletRequest request = new MockHttpServletRequest();      
        MockHttpServletResponse response = new MockHttpServletResponse();
        request.setUserPrincipal(new MockPrincipal("david"));
        MockRequestContext context = new MockRequestContext(request, response);
       
        // create a simple key
        String window1 = "555-01";
        ContentCacheKey cckey1 = contentCache.createCacheKey(context, window1);
        assertEquals(cckey1.getKey(), "david/portal/555-01");

        // create a another key for desktop
        String window2 = "555-02";
        context.getParameterMap().put("encoder", "desktop");
        ContentCacheKey cckey2 = contentCache.createCacheKey(context, window2);
        assertEquals(cckey2.getKey(), "david/desktop/555-02");
       
        // create some PortletContent mock objects
        PortletContent content1 = new MockPortletContent(cckey1, 100, "ContentOne", "content1content1content1content1");
        PortletContent content2 = new MockPortletContent(cckey2, 200, "ContentTwo", "content2content2content2content2");
       
        // put it in the cache
        CacheElement element1 = contentCache.createElement(cckey1, content1);
        contentCache.put(element1);
        CacheElement element2 = contentCache.createElement(cckey2, content2);
        contentCache.put(element2);
       
        // assert the gets
        Object result1 = contentCache.get(cckey1);
        assertNotNull(result1);
        System.out.println("result 1 = " + result1);
        Object result2 = contentCache.get(cckey2);
        assertNotNull(result2);
        System.out.println("result 2 = " + result2);
       
        // assert isKey Apis       
        assertTrue(contentCache.isKeyInCache(cckey1));
               
       
        // test removes
        contentCache.remove(cckey1);
        assertFalse(contentCache.isKeyInCache(cckey1));       
        assertTrue(contentCache.isKeyInCache(cckey2));
       
        // test user stuff
        request.setUserPrincipal(new MockPrincipal("sean"));       
        // create a simple key
        String window3 = "555-03";
        ContentCacheKey cckey3 = contentCache.createCacheKey(context, window3);
        assertEquals(cckey3.getKey(), "sean/desktop/555-03");
View Full Code Here

        segments.add("windowid");
        ContentCacheKeyGenerator generator = new JetspeedCacheKeyGenerator(segments);
        JetspeedCache contentCache = new EhPortletContentCacheImpl(ehContentCache, generator);
       
        // create the mock request context
        MockHttpServletRequest request = new MockHttpServletRequest();      
        MockHttpServletResponse response = new MockHttpServletResponse();
        request.setUserPrincipal(new MockPrincipal("david"));
        MockHttpSession session = new MockHttpSession();
        request.setSession(session);
        String sessionId = session.getId();

        MockRequestContext context = new MockRequestContext(request, response);
       
        // create a simple key
        String window1 = "555-01";
        ContentCacheKey cckey1 = contentCache.createCacheKey(context, window1);
        assertEquals(cckey1.getKey(), sessionId + "/portal/555-01");

        // create a another key for desktop
        String window2 = "555-02";
        context.getParameterMap().put("encoder", "desktop");
        ContentCacheKey cckey2 = contentCache.createCacheKey(context, window2);
        assertEquals(cckey2.getKey(), sessionId + "/desktop/555-02");
       
        // create some PortletContent mock objects
        PortletContent content1 = new MockPortletContent(cckey1, 100, "ContentOne", "content1content1content1content1");
        PortletContent content2 = new MockPortletContent(cckey2, 200, "ContentTwo", "content2content2content2content2");
       
        // put it in the cache
        CacheElement element1 = contentCache.createElement(cckey1, content1);
        contentCache.put(element1);
        CacheElement element2 = contentCache.createElement(cckey2, content2);
        contentCache.put(element2);
       
        // assert the gets
        Object result1 = contentCache.get(cckey1);
        assertNotNull(result1);
        System.out.println("result 1 = " + result1);
        Object result2 = contentCache.get(cckey2);
        assertNotNull(result2);
        System.out.println("result 2 = " + result2);
       
        // assert isKey Apis       
        assertTrue(contentCache.isKeyInCache(cckey1));
               
       
        // test removes
        contentCache.remove(cckey1);
        assertFalse(contentCache.isKeyInCache(cckey1));       
        assertTrue(contentCache.isKeyInCache(cckey2));
       
        // test user stuff
        session = new MockHttpSession();
        request.setSession(session);       
        sessionId = session.getId();       
        request.setUserPrincipal(new MockPrincipal("sean"));       
        // create a simple key
        String window3 = "555-03";
        ContentCacheKey cckey3 = contentCache.createCacheKey(context, window3);
        assertEquals(cckey3.getKey(), sessionId + "/desktop/555-03");
View Full Code Here

        segments.add("windowid");
        ContentCacheKeyGenerator generator = new JetspeedCacheKeyGenerator(segments);
        JetspeedCache contentCache = new EhDecorationContentCacheImpl(ehContentCache, generator);
       
        // create the mock request context
        MockHttpServletRequest request = new MockHttpServletRequest();      
        MockHttpServletResponse response = new MockHttpServletResponse();
        request.setUserPrincipal(new MockPrincipal("david"));
        MockRequestContext context = new MockRequestContext(request, response);
       
        // create a simple key
        String window1 = "/default-page.psml";
        ContentCacheKey cckey1 = contentCache.createCacheKey(context, window1);
        assertEquals(cckey1.getKey(), "david/portal//default-page.psml");

        // create a another key for desktop
        String window2 = "/about.psml";
        context.getParameterMap().put("encoder", "desktop");
        ContentCacheKey cckey2 = contentCache.createCacheKey(context, window2);
        assertEquals(cckey2.getKey(), "david/desktop//about.psml");
       
        // create some PortletContent mock objects
        MockTheme theme1 = new MockTheme("/default-page.psml");
        MockTheme theme2 = new MockTheme("/about.psml");
       
        // put it in the cache
        CacheElement element1 = contentCache.createElement(cckey1, theme1);
        contentCache.put(element1);
        CacheElement element2 = contentCache.createElement(cckey2, theme2);
        contentCache.put(element2);
       
        // assert the gets
        Object result1 = contentCache.get(cckey1);
        assertNotNull(result1);
        System.out.println("result 1 = " + result1);
        Object result2 = contentCache.get(cckey2);
        assertNotNull(result2);
        System.out.println("result 2 = " + result2);
       
        // assert isKey Apis       
        assertTrue(contentCache.isKeyInCache(cckey1));

       
        // test removes
        contentCache.remove(cckey1);
        assertFalse(contentCache.isKeyInCache(cckey1));       
        assertTrue(contentCache.isKeyInCache(cckey2));
       
        // test user stuff
        request.setUserPrincipal(new MockPrincipal("sean"));       
        // create a simple key
        String window3 = "/default-page.psml";
        ContentCacheKey cckey3 = contentCache.createCacheKey(context, window3);
        assertEquals(cckey3.getKey(), "sean/desktop//default-page.psml");
View Full Code Here

        segments.add("windowid");
        ContentCacheKeyGenerator generator = new JetspeedCacheKeyGenerator(segments);
        JetspeedCache contentCache = new EhDecorationContentCacheImpl(ehContentCache, generator);
       
        // create the mock request context
        MockHttpServletRequest request = new MockHttpServletRequest();      
        MockHttpServletResponse response = new MockHttpServletResponse();
        request.setUserPrincipal(new MockPrincipal("david"));
        MockHttpSession session = new MockHttpSession();
        request.setSession(session);
        String sessionId = session.getId();

        MockRequestContext context = new MockRequestContext(request, response);
       
        // create a simple key
        String window1 = "/default-page.psml";
        ContentCacheKey cckey1 = contentCache.createCacheKey(context, window1);
        assertEquals(cckey1.getKey(), sessionId + "/portal//default-page.psml");

        // create a another key for desktop
        String window2 = "/about.psml";
        context.getParameterMap().put("encoder", "desktop");
        ContentCacheKey cckey2 = contentCache.createCacheKey(context, window2);
        assertEquals(cckey2.getKey(), sessionId + "/desktop//about.psml");
       
        // create some MockTheme objects
        MockTheme theme1 = new MockTheme("/default-page.psml");
        MockTheme theme2 = new MockTheme("/about.psml");
       
        // put it in the cache
        CacheElement element1 = contentCache.createElement(cckey1, theme1);
        contentCache.put(element1);
        CacheElement element2 = contentCache.createElement(cckey2, theme2);
        contentCache.put(element2);
       
        // assert the gets
        Object result1 = contentCache.get(cckey1);
        assertNotNull(result1);
        System.out.println("result 1 = " + result1);
        Object result2 = contentCache.get(cckey2);
        assertNotNull(result2);
        System.out.println("result 2 = " + result2);
       
        // assert isKey Apis       
        assertTrue(contentCache.isKeyInCache(cckey1));
               
       
        // test removes
        contentCache.remove(cckey1);
        assertFalse(contentCache.isKeyInCache(cckey1));       
        assertTrue(contentCache.isKeyInCache(cckey2));
       
        // test user stuff
        session = new MockHttpSession();
        request.setSession(session);       
        sessionId = session.getId();       
        request.setUserPrincipal(new MockPrincipal("sean"));       
        // create a simple key
        String window3 = "/default-page.psml";
        ContentCacheKey cckey3 = contentCache.createCacheKey(context, window3);
        assertEquals(cckey3.getKey(), sessionId + "/desktop//default-page.psml");
View Full Code Here

    }

    private RequestContext initRequestContext()
    {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockHttpSession session = new MockHttpSession();

//        Principal p = new UserPrincipalImpl("anotherFaker");
        Principal p = new UserPrincipalImpl(USERNAME);

        request.setUserPrincipal(p);

        request.setRemoteAddr("123.234.145.156");
        request.setSession(session);
        request.setServerName("www.sporteportal.com");
        request.setScheme("http");
        request.setContextPath("/jetspeed");
        request.setServletPath("/portal");
        request.setPathInfo("/news/default-page.psml");
        request.setRequestURI("/jetspeed/portal/news/default-page.psml");
        request.setMethod("GET");
        RequestContext rc = new MockRequestContext(request, response);
        return rc;
    }
View Full Code Here

    assertEquals( null, req
        .getAttribute( UsernameSubstringPreAuthenticatedProcessingFilter.PENTAHO_ORIG_USER_PRINCIPAL ) );
  }

  private final HttpServletRequest getRequest( final String aUserName ) {
    MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteUser( aUserName );
    req.setUserPrincipal( new Principal() {
      public String getName() {
        return aUserName;
      }
    } );
    return req;
View Full Code Here

  }

  public void testPentahoHttpSession() {
    startTest();
    // @TOTO Not sure how to test PentahoHttpSession. In a request object to be present
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpSession session = new MockHttpSession();
    request.setSession( session );
    request.setupAddParameter( "solution", "samples" ); //$NON-NLS-1$//$NON-NLS-2$
    request.setupAddParameter( "path", "steel-wheels/reports" ); //$NON-NLS-1$ //$NON-NLS-2$
    request.setupAddParameter( "action", "Inventory List.xaction" ); //$NON-NLS-1$ //$NON-NLS-2$
    request.setupAddParameter( "details", "all" ); //$NON-NLS-1$ //$NON-NLS-2$
    HttpSession httpSession = session;

    Enumeration attrNames = httpSession.getAttributeNames();
    while ( attrNames.hasMoreElements() ) {
      System.out.println( "Attribute Name " + attrNames.nextElement() ); //$NON-NLS-1$
View Full Code Here

    listeners.put( "globalObjects", "globalObjects" ); //$NON-NLS-1$ //$NON-NLS-2$
    return listeners;
  }

  public void testService() throws ServletException, IOException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpSession session = new MockHttpSession();
    request.setSession( session );
    request.setupAddParameter( "ProxyURL", "http://www.pentaho.org" ); //$NON-NLS-1$//$NON-NLS-2$

    MockHttpServletResponse response = new MockHttpServletResponse();
    ProxyServlet servlet = new ProxyServlet();
    servlet.service( request, response );
  }
View Full Code Here

    listeners.put( "globalObjects", "globalObjects" ); //$NON-NLS-1$ //$NON-NLS-2$
    return listeners;
  }

  public void testGetResouce() throws ServletException, IOException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpSession session = new MockHttpSession();
    request.setSession( session );
    request.setupAddParameter( "resource", "adhoc/picklist.xsl" ); //$NON-NLS-1$ //$NON-NLS-2$
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockServletContext context = new MockServletContext();
    context.setServletContextName( "pentaho" );
    MockServletConfig config = new MockServletConfig();
    config.setServletContext( context );
    config.setServletName( "getResource" );
    request.setContextPath( "pentaho" );
    GetResource servlet = new GetResource();
    servlet.init( config );
    // servlet.service(request, response);
  }
View Full Code Here

TOP

Related Classes of com.mockrunner.mock.web.MockHttpServletRequest

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.