forked from hazelcast/hazelcast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unit test for hazelcast#3049 and spring test infrastructure for hazel…
…cast-vm
- Loading branch information
serkanozal
committed
Aug 6, 2014
1 parent
3c7916e
commit ef31223
Showing
8 changed files
with
382 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...lcast-wm/src/test/java/com/hazelcast/wm/test/spring/SpringApplicationContextProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.hazelcast.wm.test.spring; | ||
|
||
import org.eclipse.jetty.util.ConcurrentHashSet; | ||
import org.springframework.beans.BeansException; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public class SpringApplicationContextProvider implements ApplicationContextAware { | ||
|
||
private static Set<ApplicationContext> applicationContextSet = | ||
new ConcurrentHashSet<ApplicationContext>(); | ||
|
||
public static Set<ApplicationContext> getApplicationContextSet() { | ||
return Collections.unmodifiableSet(applicationContextSet); | ||
} | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
applicationContextSet.add(applicationContext); | ||
} | ||
|
||
} |
122 changes: 122 additions & 0 deletions
122
hazelcast-wm/src/test/java/com/hazelcast/wm/test/spring/SpringAwareWebFilterTestSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright (c) 2008-2014, Hazelcast, Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hazelcast.wm.test.spring; | ||
|
||
import com.hazelcast.wm.test.AbstractWebFilterTest; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.CookieStore; | ||
import org.apache.http.cookie.Cookie; | ||
import org.apache.http.impl.client.BasicCookieStore; | ||
import org.springframework.web.context.support.WebApplicationContextUtils; | ||
|
||
public abstract class SpringAwareWebFilterTestSupport extends AbstractWebFilterTest { | ||
|
||
protected static final String DEFAULT_SPRING_CONTEXT_FILE_PATH = "spring/hazelcast-spring.xml"; | ||
|
||
protected static final String SPRING_SECURITY_LOGIN_URL = "j_spring_security_check"; | ||
protected static final String SPRING_SECURITY_LOGOUT_URL = "j_spring_security_logout"; | ||
protected static final String SPRING_SECURITY_LOGIN_USERNAME_PARAM = "j_username"; | ||
protected static final String SPRING_SECURITY_LOGIN_PASSWORD_PARAM = "j_password"; | ||
protected static final String SPRING_SECURITY_REMEMBER_ME_PARAM = "_spring_security_remember_me"; | ||
|
||
protected static final String SPRING_SECURITY_DEFAULT_USERNAME = "user"; | ||
protected static final String SPRING_SECURITY_DEFAULT_PASSWORD = "password"; | ||
|
||
protected static final String SESSION_ID_COOKIE_NAME = "JSESSIONID"; | ||
protected static final String HZ_SESSION_ID_COOKIE_NAME = "hazelcast.sessionId"; | ||
protected static final String SPRING_SECURITY_COOKIE_NAME = "SPRING_SECURITY_REMEMBER_ME_COOKIE"; | ||
|
||
public SpringAwareWebFilterTestSupport() { | ||
this(DEFAULT_SPRING_CONTEXT_FILE_PATH, DEFAULT_SPRING_CONTEXT_FILE_PATH); | ||
} | ||
|
||
protected SpringAwareWebFilterTestSupport(String serverXml1, String serverXml2) { | ||
super(serverXml1, serverXml2); | ||
} | ||
|
||
protected static class SpringSecuritySession { | ||
|
||
protected CookieStore cookieStore; | ||
protected HttpResponse lastResponse; | ||
|
||
protected SpringSecuritySession() { | ||
this.cookieStore = new BasicCookieStore(); | ||
} | ||
|
||
protected SpringSecuritySession(CookieStore cookieStore) { | ||
this.cookieStore = cookieStore; | ||
} | ||
|
||
protected String getCookie(String cookieName) { | ||
for (Cookie cookie : cookieStore.getCookies()) { | ||
if (cookie.getName().equals(cookieName)) { | ||
return cookie.getValue(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
protected String getSessionId() { | ||
return getCookie(SESSION_ID_COOKIE_NAME); | ||
} | ||
|
||
protected String getHazelcastSessionId() { | ||
return getCookie(HZ_SESSION_ID_COOKIE_NAME); | ||
} | ||
|
||
protected String getSpringSecurityCookie() { | ||
return getCookie(SPRING_SECURITY_COOKIE_NAME); | ||
} | ||
|
||
} | ||
|
||
protected SpringSecuritySession login(SpringSecuritySession springSecuritySession) throws Exception { | ||
return login(springSecuritySession, SPRING_SECURITY_DEFAULT_USERNAME, SPRING_SECURITY_DEFAULT_PASSWORD); | ||
} | ||
|
||
protected SpringSecuritySession login(SpringSecuritySession springSecuritySession, | ||
String username, | ||
String password) throws Exception { | ||
if (springSecuritySession== null) { | ||
springSecuritySession = new SpringSecuritySession(); | ||
} | ||
HttpResponse response = | ||
request( | ||
RequestType.POST_REQUEST, | ||
SPRING_SECURITY_LOGIN_URL + "?" + | ||
SPRING_SECURITY_LOGIN_USERNAME_PARAM + "=" + username + "&" + | ||
SPRING_SECURITY_LOGIN_PASSWORD_PARAM + "=" + password + "&" + | ||
SPRING_SECURITY_REMEMBER_ME_PARAM + "=" + "true", | ||
serverPort1, springSecuritySession.cookieStore); | ||
springSecuritySession.lastResponse = response; | ||
return springSecuritySession; | ||
} | ||
|
||
protected SpringSecuritySession logout(SpringSecuritySession springSecuritySession) throws Exception { | ||
if (springSecuritySession == null) { | ||
throw new IllegalArgumentException("SpringSecuritySession cannot be null !"); | ||
} | ||
HttpResponse response = | ||
request( | ||
RequestType.POST_REQUEST, | ||
SPRING_SECURITY_LOGOUT_URL, | ||
serverPort1, springSecuritySession.cookieStore); | ||
springSecuritySession.lastResponse = response; | ||
return springSecuritySession; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
hazelcast-wm/src/test/webapp/WEB-INF/spring/application-context.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans | ||
xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation=" | ||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> | ||
|
||
<!-- Root Context: defines shared resources visible to all other web components --> | ||
|
||
<context:annotation-config/> | ||
|
||
<context:component-scan base-package="com.hazelcast.wm.test.spring" /> | ||
|
||
<bean id="springApplicationContextProvider" | ||
class="com.hazelcast.wm.test.spring.SpringApplicationContextProvider" /> | ||
|
||
</beans> |
Oops, something went wrong.