You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2018/06/28 16:08:52 UTC
svn commit: r1834623 -
/webservices/wss4j/trunk/ws-security-common/src/test/java/org/apache/wss4j/common/cache/ReplayCacheTest.java
Author: coheigea
Date: Thu Jun 28 16:08:52 2018
New Revision: 1834623
URL: http://svn.apache.org/viewvc?rev=1834623&view=rev
Log:
Adding some unit tests for ReplayCache
Added:
webservices/wss4j/trunk/ws-security-common/src/test/java/org/apache/wss4j/common/cache/ReplayCacheTest.java
Added: webservices/wss4j/trunk/ws-security-common/src/test/java/org/apache/wss4j/common/cache/ReplayCacheTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-common/src/test/java/org/apache/wss4j/common/cache/ReplayCacheTest.java?rev=1834623&view=auto
==============================================================================
--- webservices/wss4j/trunk/ws-security-common/src/test/java/org/apache/wss4j/common/cache/ReplayCacheTest.java (added)
+++ webservices/wss4j/trunk/ws-security-common/src/test/java/org/apache/wss4j/common/cache/ReplayCacheTest.java Thu Jun 28 16:08:52 2018
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.wss4j.common.cache;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.UUID;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Some unit tests for the ReplayCache implementations
+ */
+public class ReplayCacheTest extends Assert {
+
+ @Test
+ public void testMemoryReplayCache() throws InterruptedException, IOException {
+ ReplayCache replayCache = new MemoryReplayCache();
+
+ testReplayCacheInstance(replayCache);
+
+ replayCache.close();
+ }
+
+ @Test
+ public void testEhCacheReplayCache() throws InterruptedException, IOException {
+ ReplayCache replayCache = new EHCacheReplayCache("xyz", (URL)null);
+
+ testReplayCacheInstance(replayCache);
+
+ replayCache.close();
+ }
+
+ private void testReplayCacheInstance(ReplayCache replayCache) throws InterruptedException, IOException {
+
+ // Test default TTL caches OK
+ String id = UUID.randomUUID().toString();
+ replayCache.add(id);
+ assertTrue(replayCache.contains(id));
+
+ // Test specifying TTL caches OK
+ id = UUID.randomUUID().toString();
+ replayCache.add(id, 100L);
+ assertTrue(replayCache.contains(id));
+
+ // Test expiration
+ id = UUID.randomUUID().toString();
+ replayCache.add(id, 1L);
+ Thread.sleep(1250L);
+ assertFalse(replayCache.contains(id));
+
+ }
+}