Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
1a11fdd3bd |
|
|
@ -2,7 +2,7 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.jasig.cas</groupId>
|
<groupId>org.jasig.cas</groupId>
|
||||||
<version>3.1.5</version>
|
<version>3.1.6</version>
|
||||||
<artifactId>cas-client</artifactId>
|
<artifactId>cas-client</artifactId>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
|
||||||
|
|
@ -166,4 +166,8 @@ public class Cas20ProxyReceivingTicketValidationFilter extends AbstractTicketVal
|
||||||
public void setTimerTask(final TimerTask timerTask) {
|
public void setTimerTask(final TimerTask timerTask) {
|
||||||
this.timerTask = timerTask;
|
this.timerTask = timerTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMillisBetweenCleanUps(final int millisBetweenCleanUps) {
|
||||||
|
this.millisBetweenCleanUps = millisBetweenCleanUps;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,125 +0,0 @@
|
||||||
package org.jasig.cas.client.proxy;
|
|
||||||
|
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
import javax.servlet.ServletContextEvent;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.jasig.cas.client.util.MethodFlag;
|
|
||||||
import org.springframework.mock.web.MockServletContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unit test for {@link CleanUpListener}
|
|
||||||
*
|
|
||||||
* @author Brad Cupit (brad [at] lsu {dot} edu)
|
|
||||||
*/
|
|
||||||
public class CleanUpListenerTest extends TestCase {
|
|
||||||
private final Timer defaultTimer = new Timer(true);
|
|
||||||
/*
|
|
||||||
private final CleanUpTimerTask defaultTimerTask = new CleanUpTimerTask();
|
|
||||||
|
|
||||||
|
|
||||||
public void testStartsThreadAtStartup() throws Exception {
|
|
||||||
final MethodFlag scheduleMethodFlag = new MethodFlag();
|
|
||||||
|
|
||||||
final Timer timer = new Timer(true) {
|
|
||||||
public void schedule(TimerTask task, long delay, long period) {
|
|
||||||
scheduleMethodFlag.setCalled();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
final CleanUpListener cleanUpListener = new CleanUpListener(timer, defaultTimerTask);
|
|
||||||
cleanUpListener.contextInitialized(new TestServletContextEvent(1));
|
|
||||||
|
|
||||||
assertTrue(scheduleMethodFlag.wasCalled());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testShutsDownTimerThread() throws Exception {
|
|
||||||
final MethodFlag cancelMethodFlag = new MethodFlag();
|
|
||||||
|
|
||||||
final Timer timer = new Timer(true) {
|
|
||||||
public void cancel() {
|
|
||||||
cancelMethodFlag.setCalled();
|
|
||||||
super.cancel();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
final CleanUpListener cleanUpListener = new CleanUpListener(timer, defaultTimerTask);
|
|
||||||
cleanUpListener.contextInitialized(new TestServletContextEvent(1));
|
|
||||||
cleanUpListener.contextDestroyed(null);
|
|
||||||
|
|
||||||
assertTrue(cancelMethodFlag.wasCalled());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testCallsCleanAllOnSchedule() throws Exception {
|
|
||||||
final MethodFlag timerTaskFlag = new MethodFlag();
|
|
||||||
|
|
||||||
final TimerTask timerTask = new TimerTask() {
|
|
||||||
public void run() {
|
|
||||||
timerTaskFlag.setCalled();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
long millisBetweenCleanUps = 250;
|
|
||||||
|
|
||||||
final CleanUpListener cleanUpListener = new CleanUpListener(defaultTimer, timerTask);
|
|
||||||
cleanUpListener.contextInitialized(new TestServletContextEvent(millisBetweenCleanUps));
|
|
||||||
|
|
||||||
// wait long enough for the clean up to occur
|
|
||||||
Thread.sleep(millisBetweenCleanUps * 2);
|
|
||||||
|
|
||||||
assertTrue(timerTaskFlag.wasCalled());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDelaysFirstCleanAll() throws Exception {
|
|
||||||
final MethodFlag timerTaskFlag = new MethodFlag();
|
|
||||||
|
|
||||||
final TimerTask timerTask = new TimerTask() {
|
|
||||||
public void run() {
|
|
||||||
timerTaskFlag.setCalled();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
long millisBetweenCleanUps = 250;
|
|
||||||
|
|
||||||
final CleanUpListener cleanUpListener = new CleanUpListener(defaultTimer, timerTask);
|
|
||||||
cleanUpListener.contextInitialized(new TestServletContextEvent(millisBetweenCleanUps));
|
|
||||||
|
|
||||||
assertFalse(timerTaskFlag.wasCalled());
|
|
||||||
|
|
||||||
// wait long enough for the clean up to occur
|
|
||||||
Thread.sleep(millisBetweenCleanUps * 2);
|
|
||||||
|
|
||||||
assertTrue(timerTaskFlag.wasCalled());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testReturnsDefaultWhenNoContextParamConfigured() throws Exception {
|
|
||||||
final ServletContext servletContext = new MockServletContext();
|
|
||||||
|
|
||||||
long millisBetweenCleanups = new CleanUpListener().getMillisBetweenCleanups(servletContext);
|
|
||||||
assertEquals(CleanUpListener.DEFAULT_MILLIS_BETWEEN_CLEANUPS, millisBetweenCleanups);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testFailsWithInvalidNumber() throws Exception {
|
|
||||||
final ServletContext servletContext = new MockServletContext() {
|
|
||||||
public String getInitParameter(String name) {
|
|
||||||
if (name.equals(CleanUpListener.MILLIS_BETWEEN_CLEANUPS_INIT_PARAM)) {
|
|
||||||
return "not a number";
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
new CleanUpListener().getMillisBetweenCleanups(servletContext);
|
|
||||||
fail("expected an exception");
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
// expected, test passes
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
@ -2,6 +2,14 @@ package org.jasig.cas.client.validation;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
import org.jasig.cas.client.proxy.CleanUpTimerTask;
|
||||||
|
import org.jasig.cas.client.proxy.ProxyGrantingTicketStorage;
|
||||||
|
import org.jasig.cas.client.proxy.ProxyGrantingTicketStorageImpl;
|
||||||
|
import org.jasig.cas.client.util.MethodFlag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for {@link Cas20ProxyReceivingTicketValidationFilter}
|
* Unit test for {@link Cas20ProxyReceivingTicketValidationFilter}
|
||||||
*
|
*
|
||||||
|
|
@ -9,6 +17,105 @@ import junit.framework.TestCase;
|
||||||
*/
|
*/
|
||||||
public class Cas20ProxyReceivingTicketValidationFilterTest extends TestCase {
|
public class Cas20ProxyReceivingTicketValidationFilterTest extends TestCase {
|
||||||
|
|
||||||
|
private final Timer defaultTimer = new Timer(true);
|
||||||
|
|
||||||
|
private final ProxyGrantingTicketStorage storage = new ProxyGrantingTicketStorageImpl();
|
||||||
|
|
||||||
|
private final CleanUpTimerTask defaultTimerTask = new CleanUpTimerTask(storage);
|
||||||
|
|
||||||
|
public void testStartsThreadAtStartup() throws Exception {
|
||||||
|
final MethodFlag scheduleMethodFlag = new MethodFlag();
|
||||||
|
final Cas20ProxyReceivingTicketValidationFilter filter = newCas20ProxyReceivingTicketValidationFilter();
|
||||||
|
|
||||||
|
final Timer timer = new Timer(true) {
|
||||||
|
public void schedule(TimerTask task, long delay, long period) {
|
||||||
|
scheduleMethodFlag.setCalled();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
filter.setMillisBetweenCleanUps(1);
|
||||||
|
filter.setProxyGrantingTicketStorage(storage);
|
||||||
|
filter.setTimer(timer);
|
||||||
|
filter.setTimerTask(defaultTimerTask);
|
||||||
|
|
||||||
|
filter.init();
|
||||||
|
assertTrue(scheduleMethodFlag.wasCalled());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testShutsDownTimerThread() throws Exception {
|
||||||
|
final MethodFlag cancelMethodFlag = new MethodFlag();
|
||||||
|
final Cas20ProxyReceivingTicketValidationFilter filter = newCas20ProxyReceivingTicketValidationFilter();
|
||||||
|
|
||||||
|
final Timer timer = new Timer(true) {
|
||||||
|
public void cancel() {
|
||||||
|
cancelMethodFlag.setCalled();
|
||||||
|
super.cancel();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
filter.setProxyGrantingTicketStorage(storage);
|
||||||
|
filter.setMillisBetweenCleanUps(1);
|
||||||
|
filter.setTimer(timer);
|
||||||
|
filter.setTimerTask(defaultTimerTask);
|
||||||
|
filter.init();
|
||||||
|
filter.destroy();
|
||||||
|
|
||||||
|
assertTrue(cancelMethodFlag.wasCalled());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCallsCleanAllOnSchedule() throws Exception {
|
||||||
|
final MethodFlag timerTaskFlag = new MethodFlag();
|
||||||
|
final Cas20ProxyReceivingTicketValidationFilter filter = newCas20ProxyReceivingTicketValidationFilter();
|
||||||
|
|
||||||
|
final TimerTask timerTask = new TimerTask() {
|
||||||
|
public void run() {
|
||||||
|
timerTaskFlag.setCalled();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
final int millisBetweenCleanUps = 250;
|
||||||
|
filter.setProxyGrantingTicketStorage(storage);
|
||||||
|
filter.setTimerTask(timerTask);
|
||||||
|
filter.setTimer(defaultTimer);
|
||||||
|
filter.setMillisBetweenCleanUps(millisBetweenCleanUps);
|
||||||
|
|
||||||
|
filter.init();
|
||||||
|
|
||||||
|
// wait long enough for the clean up to occur
|
||||||
|
Thread.sleep(millisBetweenCleanUps * 2);
|
||||||
|
|
||||||
|
assertTrue(timerTaskFlag.wasCalled());
|
||||||
|
filter.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDelaysFirstCleanAll() throws Exception {
|
||||||
|
final MethodFlag timerTaskFlag = new MethodFlag();
|
||||||
|
final Cas20ProxyReceivingTicketValidationFilter filter = newCas20ProxyReceivingTicketValidationFilter();
|
||||||
|
|
||||||
|
final TimerTask timerTask = new TimerTask() {
|
||||||
|
public void run() {
|
||||||
|
timerTaskFlag.setCalled();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
final int millisBetweenCleanUps = 250;
|
||||||
|
filter.setProxyGrantingTicketStorage(storage);
|
||||||
|
filter.setMillisBetweenCleanUps(millisBetweenCleanUps);
|
||||||
|
filter.setTimer(defaultTimer);
|
||||||
|
filter.setTimerTask(timerTask);
|
||||||
|
|
||||||
|
filter.init();
|
||||||
|
|
||||||
|
assertFalse(timerTaskFlag.wasCalled());
|
||||||
|
|
||||||
|
// wait long enough for the clean up to occur
|
||||||
|
Thread.sleep(millisBetweenCleanUps * 2);
|
||||||
|
|
||||||
|
assertTrue(timerTaskFlag.wasCalled());
|
||||||
|
|
||||||
|
filter.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
public void testThrowsForNullStorage() throws Exception {
|
public void testThrowsForNullStorage() throws Exception {
|
||||||
Cas20ProxyReceivingTicketValidationFilter filter = newCas20ProxyReceivingTicketValidationFilter();
|
Cas20ProxyReceivingTicketValidationFilter filter = newCas20ProxyReceivingTicketValidationFilter();
|
||||||
filter.setProxyGrantingTicketStorage(null);
|
filter.setProxyGrantingTicketStorage(null);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.jasig.cas</groupId>
|
<groupId>org.jasig.cas</groupId>
|
||||||
<version>3.1.5</version>
|
<version>3.1.6</version>
|
||||||
<artifactId>cas-client</artifactId>
|
<artifactId>cas-client</artifactId>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
|
||||||
2
pom.xml
2
pom.xml
|
|
@ -1,7 +1,7 @@
|
||||||
<project>
|
<project>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.jasig.cas</groupId>
|
<groupId>org.jasig.cas</groupId>
|
||||||
<version>3.1.5</version>
|
<version>3.1.6</version>
|
||||||
<artifactId>cas-client</artifactId>
|
<artifactId>cas-client</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>JA-SIG CAS Client for Java</name>
|
<name>JA-SIG CAS Client for Java</name>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue