Package de.javakaffee.web.msm.integration.TestUtils

Examples of de.javakaffee.web.msm.integration.TestUtils.Response


        _tomcat1.setChangeSessionIdOnAuth( false );
        _tomcat2.setChangeSessionIdOnAuth( false );

        LOG.info("START foo1234");
        final Response response1 = get( _httpClient, TC_PORT_1, null );
        LOG.info("END foo1234");
        final String sessionId = response1.getSessionId();
        assertNotNull( sessionId );
        assertTrue(response1.getContent().contains("j_security_check"), "IllegalState: /j_security_check not found, app is not properly initialized");

        // failed sometimes, randomly (timing issue?)?!
        Thread.sleep(200);
        // 2 sets for session and validity
        assertEquals( _daemon1.getCache().getSetCmds(), 2 );

        final Map<String, String> params = new HashMap<String, String>();
        params.put( LoginServlet.J_USERNAME, TestUtils.USER_NAME );
        params.put( LoginServlet.J_PASSWORD, TestUtils.PASSWORD );
        final Response response2 = post( _httpClient, TC_PORT_2, "/j_security_check", sessionId, params, null, false );
        assertNull(response2.getResponseSessionId());
        assertTrue(isRedirect(response2.getStatusCode()), "IllegalState: 'POST /j_security_check' did not issue a redirect,"
                + " but status " + response2.getStatusCode() +". Page content: " + response2.getContent());

        // 2 gets for session and validity
        assertEquals( _daemon1.getCache().getGetHits(), 2 );
        // 2 new sets for session and validity
        assertEquals( _daemon1.getCache().getSetCmds(), 4 );
View Full Code Here


        _tomcat2.setChangeSessionIdOnAuth( false );

        waitForReconnect(_tomcat1.getService().getMemcached(), 1, 1000);
        waitForReconnect(_tomcat2.getService().getMemcached(), 1, 1000);

        final Response response1 = get( _httpClient, TC_PORT_1, null );
        final String sessionId = response1.getSessionId();
        assertNotNull( sessionId );
        assertTrue(response1.getContent().contains("j_security_check"), "IllegalState: /j_security_check not found, app is not properly initialized");

        // Wait some time so that the GET is finished
        Thread.sleep(200);

        final Map<String, String> params = new HashMap<String, String>();
        params.put( LoginServlet.J_USERNAME, TestUtils.USER_NAME );
        params.put( LoginServlet.J_PASSWORD, TestUtils.PASSWORD );

        final Response response2 = post( _httpClient, TC_PORT_2, "/j_security_check", sessionId, params, null, true );
        assertNull(response2.getResponseSessionId());
        assertEquals(response2.getStatusCode(), 200, response2.getContent());
        assertEquals(response2.get( TestServlet.ID ), sessionId);

        final Response response3 = post( _httpClient, TC_PORT_2, "/", sessionId, asMap( "foo", "bar" ));
        assertEquals(response3.getSessionId(), sessionId);

        final Response response4 = get(_httpClient, TC_PORT_1, sessionId);
        assertEquals(response4.getSessionId(), sessionId);
        assertEquals(response4.get( TestServlet.ID ), sessionId);
        assertEquals(response4.get( "foo" ), "bar");

    }
View Full Code Here

        _tomcat1.getManager().setLockingMode(LockingMode.AUTO.name());

        final String sessionId1 = get( _httpClient, TC_PORT_1, null ).getSessionId();
        assertNotNull( sessionId1, "No session created." );

        final Response response = get( _httpClient, TC_PORT_1, PATH_INVALIDATE, sessionId1 );
        assertNull( response.getResponseSessionId() );
        assertNull(_client.get( sessionId1 ), "Invalidated session should be removed from memcached");
        assertNull(_client.get(new SessionIdFormat().createLockName(sessionId1)), "Lock should be released.");
    }
View Full Code Here

        assertEquals( format.extractJvmRoute( sessionId1 ), JVM_ROUTE_1 );

        final Object session = _client.get( sessionId1 );
        assertNotNull( session, "Session not found in memcached: " + sessionId1 );

        final Response response = get( _httpClient, TC_PORT_2, sessionId1 );
        final String sessionId2 = response.getSessionId();
        assertNull( _client.get( sessionId1 ) );
        assertNotNull( _client.get( sessionId2 ) );

        assertEquals( format.stripJvmRoute( sessionId1 ), format.stripJvmRoute( sessionId2 ) );
        assertEquals( format.extractJvmRoute( sessionId2 ), JVM_ROUTE_2 );

        /* check session attributes could be read
         */
        final String actualValue = response.get( key );
        assertEquals( value, actualValue );

        Thread.sleep( 10 );

    }
View Full Code Here

        final SessionIdFormat format = new SessionIdFormat();

        /* request the session on tomcat2
         */
        final Response response = get( _httpClient, TC_PORT_2, sessionId1 );
        assertEquals( format.stripJvmRoute( sessionId1 ), format.stripJvmRoute( response.getSessionId() ) );
        assertEquals( 2, _daemon.getCache().getSetCmds() );

        /* post key/value already stored in the session again (on tomcat2)
         */
        post( _httpClient, TC_PORT_2, sessionId1, key, value );
View Full Code Here

        /* tomcat1 failover "simulation":
         * on tomcat2, we now be able to access the secured resource directly
         * with the first request
         */
        final Response tc2Response1 = get( _httpClient, TC_PORT_2, sessionId );
        if ( stickyness.isSticky() ) {
            assertEquals( tc2Response1.getResponseSessionId(), new SessionIdFormat().changeJvmRoute( sessionId, JVM_ROUTE_2 ) );
        }
        else {
            assertEquals( tc2Response1.getSessionId(), sessionId );
        }

    }
View Full Code Here

        _tomcat1.setChangeSessionIdOnAuth( false );
        _tomcat2.setChangeSessionIdOnAuth( false );

        /* tomcat1: request secured resource, login and check that secured resource is accessable
         */
        final Response tc1Response1 = get( _httpClient, TC_PORT_1, null,
                new UsernamePasswordCredentials( TestUtils.USER_NAME, TestUtils.PASSWORD ) );
        final String sessionId = tc1Response1.getSessionId();

        assertEquals( sessionId, tc1Response1.get( TestServlet.ID ) );

        /* tomcat1 failover "simulation":
         * on tomcat2, we now should be able to access the secured resource directly
         * with the first request
         */
        final Response tc2Response1 = get( _httpClient, TC_PORT_2, sessionId );
        if ( stickyness.isSticky() ) {
            assertEquals( tc2Response1.getResponseSessionId(), new SessionIdFormat().changeJvmRoute( sessionId, JVM_ROUTE_2 ) );
        }
        else {
            assertEquals( tc2Response1.getSessionId(), sessionId );
        }

    }
View Full Code Here

        _tomcat1.setChangeSessionIdOnAuth( false );
        _tomcat2.setChangeSessionIdOnAuth( false );

        /* tomcat1: request secured resource, login and check that secured resource is accessable
         */
        final Response tc1Response1 = get( _httpClient, TC_PORT_1, null,
                new UsernamePasswordCredentials( TestUtils.USER_NAME, TestUtils.PASSWORD ) );
        final String sessionId = tc1Response1.getSessionId();

        assertEquals( sessionId, tc1Response1.get( TestServlet.ID ) );
        assertEquals( _daemon.getCache().getGetHits(), 0 );

        /* on tomcat1 failover and session takeover by tomcat2, msm in tomcat2 should
         * load the session only once.
         */
        final Response tc2Response1 = get( _httpClient, TC_PORT_2, sessionId );
        assertEquals( tc2Response1.getResponseSessionId(), new SessionIdFormat().changeJvmRoute( sessionId, JVM_ROUTE_2 ) );
        assertEquals( _daemon.getCache().getGetHits(), 1 );

    }
View Full Code Here

        _tomcat2 = startTomcat( TC_PORT_2, stickyness, stickyness.isSticky() ? JVM_ROUTE_2 : null, LoginType.BASIC );

        _tomcat1.setChangeSessionIdOnAuth( false );
        _tomcat2.setChangeSessionIdOnAuth( false );

        final Response tc1Response1 = get( _httpClient, TC_PORT_1, null, new UsernamePasswordCredentials( TestUtils.USER_NAME, TestUtils.PASSWORD ) );
        final String sessionId = tc1Response1.getSessionId();
        assertEquals( sessionId, tc1Response1.get( TestServlet.ID ) );

        /* on tomcat1 failover and session takeover by tomcat2, the changes made to the
         * session during this request must be available in the following request(s)
         */
        final Response tc2Response1 = post( _httpClient, TC_PORT_2, "/", sessionId, asMap( "foo", "bar" ) );
        if ( stickyness.isSticky() ) {
            assertEquals( tc2Response1.getResponseSessionId(), new SessionIdFormat().changeJvmRoute( sessionId, JVM_ROUTE_2 ) );
        }
        else {
            assertEquals( tc2Response1.getSessionId(), sessionId );
        }

        final Response tc2Response2 = get( _httpClient, TC_PORT_2, tc2Response1.getResponseSessionId() );
        assertEquals( tc2Response2.get( "foo" ), "bar" );

    }
View Full Code Here

        assertEquals( format.extractMemcachedId( sessionId1 ), "n2" );
        assertEquals(_daemon.getCache().getCurrentItems(), 0);
        assertEquals(daemon2.getCache().getCurrentItems(), 1);

        // failover simulation, just request the session from tomcat2
        final Response response = get( _httpClient, TC_PORT_2, sessionId1 );
        final String sessionId2 = response.getSessionId();
        assertEquals( format.extractMemcachedId( sessionId2 ), "n1" );
        assertEquals(_daemon.getCache().getCurrentItems(), 1);

        assertEquals( format.stripJvmRoute( sessionId1 ).replaceAll("n2", "n1"), format.stripJvmRoute( sessionId2 ) );

        /* check session attributes could be read
         */
        final String actualValue = response.get( key );
        assertEquals( value, actualValue );

        Thread.sleep( 10 );

    }
View Full Code Here

TOP

Related Classes of de.javakaffee.web.msm.integration.TestUtils.Response

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.