This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch CXF-7594
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/CXF-7594 by this push:
     new d79cc7b  Refactoring TokenStore tests into a single parameterized test
d79cc7b is described below

commit d79cc7bed044d4f48ef64d12a9013078197ceb03
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Fri Apr 10 17:38:58 2020 +0100

    Refactoring TokenStore tests into a single parameterized test
---
 .../security/tokenstore/MemoryTokenStoreTest.java  | 91 ----------------------
 .../ws/security/tokenstore/SecurityTokenTest.java  | 14 ++++
 ...acheTokenStoreTest.java => TokenStoreTest.java} | 32 +++++---
 3 files changed, 36 insertions(+), 101 deletions(-)

diff --git 
a/rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/MemoryTokenStoreTest.java
 
b/rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/MemoryTokenStoreTest.java
deleted file mode 100644
index 0c2766f..0000000
--- 
a/rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/MemoryTokenStoreTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * 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.cxf.ws.security.tokenstore;
-
-import java.time.Instant;
-
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageImpl;
-import org.apache.cxf.ws.security.SecurityConstants;
-
-import org.junit.BeforeClass;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-public class MemoryTokenStoreTest {
-
-    private static TokenStore store;
-
-    @BeforeClass
-    public static void init() throws TokenStoreException {
-        TokenStoreFactory tokenStoreFactory = new MemoryTokenStoreFactory();
-        Message message = new MessageImpl();
-        store = 
tokenStoreFactory.newTokenStore(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, 
message);
-    }
-
-    // tests TokenStore apis for storing in the cache.
-    @org.junit.Test
-    public void testTokenAdd() throws Exception {
-        String key = "key";
-        SecurityToken token = new SecurityToken(key);
-        store.add(token);
-        assertEquals(token, store.getToken(key));
-        store.remove(token.getId());
-        assertNull(store.getToken(key));
-
-        String newKey = "xyz";
-        store.add(newKey, token);
-        assertNull(store.getToken(key));
-        assertEquals(token, store.getToken(newKey));
-        store.remove(newKey);
-        assertNull(store.getToken(newKey));
-    }
-
-    // tests TokenStore apis for removing from the cache.
-    @org.junit.Test
-    public void testTokenRemove() {
-        SecurityToken token1 = new SecurityToken("token1");
-        SecurityToken token2 = new SecurityToken("token2");
-        SecurityToken token3 = new SecurityToken("token3");
-        store.add(token1);
-        store.add(token2);
-        store.add(token3);
-        assertTrue(store.getTokenIdentifiers().size() == 3);
-        store.remove(token3.getId());
-        assertNull(store.getToken("test3"));
-        store.remove(token1.getId());
-        store.remove(token2.getId());
-        assertTrue(store.getTokenIdentifiers().isEmpty());
-    }
-
-    @org.junit.Test
-    public void testTokenExpiry() {
-        SecurityToken token = new SecurityToken();
-
-        Instant expires = Instant.now().plusSeconds(5L * 60L);
-        token.setExpires(expires);
-
-        assertFalse(token.isExpired());
-        assertFalse(token.isAboutToExpire(100L));
-        assertTrue(token.isAboutToExpire((5L * 60L * 1000L) + 1L));
-    }
-}
diff --git 
a/rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/SecurityTokenTest.java
 
b/rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/SecurityTokenTest.java
index a4c08e9..df343cd 100644
--- 
a/rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/SecurityTokenTest.java
+++ 
b/rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/SecurityTokenTest.java
@@ -31,8 +31,10 @@ import org.apache.wss4j.common.util.DateUtil;
 import static org.apache.wss4j.common.WSS4JConstants.WST_NS_05_12;
 import static org.apache.wss4j.common.WSS4JConstants.WSU_NS;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
 public class SecurityTokenTest {
 
@@ -119,4 +121,16 @@ public class SecurityTokenTest {
         assertEquals(created, token.getCreated());
         assertNull(token.getExpires());
     }
+
+    @org.junit.Test
+    public void testTokenExpiry() {
+        SecurityToken token = new SecurityToken();
+
+        Instant expires = Instant.now().plusSeconds(5L * 60L);
+        token.setExpires(expires);
+
+        assertFalse(token.isExpired());
+        assertFalse(token.isAboutToExpire(100L));
+        assertTrue(token.isAboutToExpire((5L * 60L * 1000L) + 1L));
+    }
 }
diff --git 
a/rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreTest.java
 
b/rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/TokenStoreTest.java
similarity index 73%
rename from 
rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreTest.java
rename to 
rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/TokenStoreTest.java
index 5e7e009..506bb78 100644
--- 
a/rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreTest.java
+++ 
b/rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/TokenStoreTest.java
@@ -18,32 +18,43 @@
  */
 package org.apache.cxf.ws.security.tokenstore;
 
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import java.util.Arrays;
+import java.util.Collection;
+
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.ws.security.SecurityConstants;
+import org.apache.xml.security.utils.ClassLoaderUtils;
 
-import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-public class EHCacheTokenStoreTest {
+@RunWith(value = org.junit.runners.Parameterized.class)
+public class TokenStoreTest {
+
+    private TokenStore store;
 
-    private static TokenStore store;
+    public TokenStoreTest(TokenStore store) {
+        this.store = store;
+    }
 
-    @BeforeClass
-    public static void init() throws TokenStoreException {
-        TokenStoreFactory tokenStoreFactory = new EHCacheTokenStoreFactory();
+    @Parameterized.Parameters(name = "{0}")
+    public static Collection<TokenStore> data() throws TokenStoreException {
         Message message = new MessageImpl();
         message.put(
-            SecurityConstants.CACHE_CONFIG_FILE,
-            ClassLoaderUtils.getResource("cxf-ehcache.xml", 
EHCacheTokenStoreTest.class)
+                SecurityConstants.CACHE_CONFIG_FILE,
+                ClassLoaderUtils.getResource("cxf-ehcache.xml", 
TokenStoreTest.class)
         );
         message.setExchange(new ExchangeImpl());
-        store = 
tokenStoreFactory.newTokenStore(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, 
message);
+        return Arrays.asList(
+                new 
MemoryTokenStoreFactory().newTokenStore(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE,
 message),
+                new 
EHCacheTokenStoreFactory().newTokenStore(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE,
 message)
+        );
     }
 
     // tests TokenStore apis for storing in the cache.
@@ -80,4 +91,5 @@ public class EHCacheTokenStoreTest {
         store.remove(token2.getId());
         assertTrue(store.getTokenIdentifiers().isEmpty());
     }
+
 }

Reply via email to