summaryrefslogtreecommitdiffstats
path: root/auth
diff options
context:
space:
mode:
authorJonathan Gathman <jonathan.gathman@att.com>2018-04-12 12:52:05 +0000
committerGerrit Code Review <gerrit@onap.org>2018-04-12 12:52:05 +0000
commitdcfee329193f2324196f5a1bda18a2d30f1277a4 (patch)
tree5597286fb87c8230ef5d36f4d2c5fb867b8e6721 /auth
parent23a1c2ebc86885d2b62dc5b8afc842a3e730fdae (diff)
parent9b0ed8da9474c99c13fbdff62894c09311cf9036 (diff)
Merge "Improve JUnit test coverage"
Diffstat (limited to 'auth')
-rw-r--r--auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_Cached.java42
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java85
-rw-r--r--auth/auth-core/test/keyfile27
3 files changed, 103 insertions, 51 deletions
diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_Cached.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_Cached.java
index 22f9a6f7..e942f3f1 100644
--- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_Cached.java
+++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_Cached.java
@@ -22,57 +22,68 @@
package org.onap.aaf.auth.dao;
import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
+import static org.mockito.Mockito.*;
+import org.junit.*;
+import org.mockito.*;
+// import org.junit.runner.RunWith;
+// import org.powermock.modules.junit4.PowerMockRunner;
import java.util.Date;
import java.util.List;
+import java.util.ArrayList;
import java.util.Map;
import java.util.Timer;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
import org.onap.aaf.auth.cache.Cache;
import org.onap.aaf.auth.cache.Cache.Dated;
import org.onap.aaf.auth.dao.CIDAO;
import org.onap.aaf.auth.dao.Cached;
import org.onap.aaf.auth.dao.Cached.Getter;
+import org.onap.aaf.auth.dao.JU_Cached.DataStub;
+import org.onap.aaf.auth.dao.cass.CacheableData;
import org.onap.aaf.auth.env.AuthzEnv;
import org.onap.aaf.auth.env.AuthzTrans;
import org.onap.aaf.auth.layer.Result;
import org.onap.aaf.misc.env.Trans;
-import org.powermock.modules.junit4.PowerMockRunner;
-@RunWith(PowerMockRunner.class)
+// @RunWith(PowerMockRunner.class)
public class JU_Cached {
- Cached cached;
+
@Mock
CIDAO<Trans> ciDaoMock;
+
@Mock
AuthzEnv authzEnvMock;
+
@Mock
CIDAO<AuthzTrans> cidaoATMock;
String name = "nameString";
-
+
@Before
public void setUp(){
- cached = new Cached(ciDaoMock, name, (int)0, 30000L);
+ MockitoAnnotations.initMocks(this);
}
- @Test(expected=ArithmeticException.class)
+ @Test
public void testCachedIdx(){
- int Result = cached.cacheIdx("1234567890");
+ Cached<Trans, DataStub> cached = new Cached<Trans, DataStub>(ciDaoMock, name, 1, 30000L);
+ assertThat(cached.cacheIdx("1234567890"), is(0));
}
- @Test(expected=ArithmeticException.class)
+ @Test
public void testInvalidate(){
- int Res = cached.invalidate(name);
+ Cached<Trans, DataStub> cached = new Cached<Trans, DataStub>(ciDaoMock, name, 5, 30000L);
+ cached.add("test", new ArrayList<DataStub>());
+ cached.invalidate("test");
+ cached.invalidate("test1");
}
@SuppressWarnings("static-access")
@Test
public void testStopTimer(){
+ Cached<Trans, DataStub> cached = new Cached<Trans, DataStub>(ciDaoMock, name, 1, 30000L);
cached.stopTimer();
assertTrue(true);
}
@@ -80,6 +91,7 @@ public class JU_Cached {
@SuppressWarnings("static-access")
@Test
public void testStartRefresh(){
+ Cached<Trans, DataStub> cached = new Cached<Trans, DataStub>(ciDaoMock, name, 1, 30000L);
cached.startRefresh(authzEnvMock, cidaoATMock);
assertTrue(true);
}
@@ -121,4 +133,8 @@ public class JU_Cached {
// }
// return rld;
// }
+
+ class DataStub extends CacheableData {
+ @Override public int[] invalidate(Cached<?, ?> cache) { return null; }
+ }
}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java
index 6413b099..8630aadf 100644
--- a/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java
@@ -21,87 +21,97 @@
******************************************************************************/
package org.onap.aaf.auth.env.test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
+import org.junit.*;
import java.io.IOException;
import java.io.InputStream;
+import java.io.PrintStream;
+import java.io.ByteArrayOutputStream;
import java.util.Properties;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
import org.onap.aaf.auth.env.AuthzEnv;
import org.onap.aaf.cadi.Access;
import org.onap.aaf.cadi.PropAccess;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.onap.aaf.cadi.config.Config;
-import junit.framework.Assert;
-
-@RunWith(PowerMockRunner.class)
public class JU_AuthzEnv {
- private static final org.onap.aaf.cadi.Access.Level DEBUG = null;
+
AuthzEnv authzEnv;
- enum Level {DEBUG, INFO, AUDIT, INIT, WARN, ERROR};
+
+ ByteArrayOutputStream outStream;
+ ByteArrayOutputStream errStream;
@Before
- public void setUp(){
- PropAccess access = null;
- Properties props = null;
+ public void setUp() {
+ outStream = new ByteArrayOutputStream();
+ errStream = new ByteArrayOutputStream();
+
+ System.setOut(new PrintStream(outStream));
+ System.setErr(new PrintStream(errStream));
+
authzEnv = new AuthzEnv();
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(System.out);
+ System.setErr(System.err);
+ }
+
+ @Test
+ @SuppressWarnings("unused")
+ public void testConstructors() {
AuthzEnv authzEnv1 = new AuthzEnv("Test");
- AuthzEnv authzEnv2 = new AuthzEnv(props);
- AuthzEnv authzEnv3 = new AuthzEnv(access);
+ AuthzEnv authzEnv2 = new AuthzEnv((PropAccess)null);
+ AuthzEnv authzEnv3 = new AuthzEnv((Properties)null);
}
@Test
public void testTransRate() {
- Long Result = authzEnv.transRate();
- assertNotNull(Result);
+ Long Result = authzEnv.transRate();
+ assertNotNull(Result);
}
@Test
public void checkNewTransNoAvg() {
-
- Assert.assertNotNull(authzEnv.newTransNoAvg());
+ assertNotNull(authzEnv.newTransNoAvg());
}
@Test
public void checkNewTrans() {
- Assert.assertNotNull(authzEnv.newTrans());
+ assertNotNull(authzEnv.newTrans());
}
@Test
public void checkPropAccess() {
- Assert.assertNotNull(authzEnv.access());
+ assertNotNull(authzEnv.access());
}
@Test
public void checkgetProperties() { //TODO:[GABE]No setter for this, add?
- Assert.assertNotNull(authzEnv.getProperties());
- Assert.assertNotNull(authzEnv.getProperties("test"));
+ assertNotNull(authzEnv.getProperties());
+ assertNotNull(authzEnv.getProperties("test"));
}
@Test
public void checkPropertyGetters(){
authzEnv.setProperty("key","value");
- Assert.assertEquals(authzEnv.getProperty("key"), "value");
- Assert.assertEquals(authzEnv.getProperty("key","value"), "value");
+ assertEquals(authzEnv.getProperty("key"), "value");
+ assertEquals(authzEnv.getProperty("key","value"), "value");
}
@Test
public void checkPropertySetters(){
- Assert.assertEquals(authzEnv.getProperty("key","value"), authzEnv.setProperty("key","value"));
+ assertEquals(authzEnv.getProperty("key","value"), authzEnv.setProperty("key","value"));
}
-// @Test(expected = IOException.class) //TODO: AAF-111 make fail not happen
-// public void testDecryptException() throws IOException{
-// String encrypted = "enc:";
-// authzEnv.setProperty(Config.CADI_KEYFILE, "test");//TODO: Figure out setter for this
-// authzEnv.decrypt(encrypted, true);
-// authzEnv.decrypt("", false); //TODO: AAF-111 fail without logging a fail
-// }
+ @Test(expected = IOException.class)
+ public void testDecryptException() throws IOException{
+ authzEnv.setProperty(Config.CADI_KEYFILE, "test/keyfile");
+ authzEnv.decrypt(null, false);
+ }
@Test
public void testDecrypt() throws IOException{
@@ -114,7 +124,7 @@ public class JU_AuthzEnv {
public void testClassLoader() {
ClassLoader cLoad = mock(ClassLoader.class);
cLoad = authzEnv.classLoader();
- Assert.assertNotNull(cLoad);
+ assertNotNull(cLoad);
}
@Test
@@ -149,10 +159,9 @@ public class JU_AuthzEnv {
Access.Level lvl = Access.Level.DEBUG;
Access.Level lvl1 = Access.Level.AUDIT;
boolean test = authzEnv.willLog(lvl);
- Assert.assertFalse(test);
+ assertFalse(test);
test = authzEnv.willLog(lvl1);
- Assert.assertTrue(test);
-
+ assertTrue(test);
}
@Test
diff --git a/auth/auth-core/test/keyfile b/auth/auth-core/test/keyfile
new file mode 100644
index 00000000..e84bd616
--- /dev/null
+++ b/auth/auth-core/test/keyfile
@@ -0,0 +1,27 @@
+9zgJxUXT1CrzC_A2Z0PdKi3n9l6zmErB26ZlSXCCyloxi3bGqD3lNHC3aFHfgC8-ZwNMuLBM93WY
+JV4sEacNodHGjgmAqSVyMHiPTEP4XRrydfjXAvaBIERcU1Yvu4pa4Mq25RXLHt8tIAnToFVbq82n
+bjkfdcv2-shgwkEvRiNIdK5TITO8JTvTRWND5MqXc9gnCKkR6Rl5dU5QGIB2SxWOPCvKBBWeUGRO
+bSinrjkI-iXabuLOYUaGo6FI_XAU5S9WxvfrDVpBijUAGJW8QZe1oBIo5QmQlx6ONB4ohjEu89ZZ
+gTee22MvSNUvaT8IGbj_Zt_TyuCqcdmkVahWp5ffeK2J3bmHActAC2IxXD4yV-sFLB7PW7I8KMA7
+tML3Lcy9ozmYa2E8N8B9uQ0zMHz_TVpPvj5xkVF4_FEKOTD1mkf-JYC1CyzwJS2YWWxO6fqsxIjD
+1qB4OJudv4RK6hSxdVrNxc_wchVAGXVD6ulm8UPBGP_wpfItP8BGYwCHlOjUrZofewKB2Aa9Uk9m
+oyk309WmPVBeRzZ0vRlXUp8jhKlAPISvv8CBbG-6SuXAszY2qedgd3huYKNreVN-xMZM2hnYbEUW
+0sdcqpFqIV039Awfwjn5sZPFW4iT3yWhxib1PwFzwfaXnrwgwbLAda68mRDAWCrsDRu11IiQJqb7
+cjNLYB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