summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_List.java78
-rw-r--r--auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/role/JU_List.java39
-rw-r--r--cadi/oauth-enduser/pom.xml2
-rw-r--r--cadi/shiro/pom.xml2
-rw-r--r--misc/env/propfile.properties3
-rw-r--r--misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_BasicEnvTest.java40
-rw-r--r--misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_ChronoTest.java170
7 files changed, 321 insertions, 13 deletions
diff --git a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_List.java b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_List.java
index f62a8182..cf8539ab 100644
--- a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_List.java
+++ b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_List.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.*;
import java.io.Writer;
import java.net.URI;
+import java.util.ArrayList;
import org.onap.aaf.auth.cmd.ns.List;
import org.onap.aaf.auth.cmd.ns.NS;
@@ -38,6 +39,9 @@ import org.onap.aaf.cadi.http.HMangr;
import org.onap.aaf.misc.env.APIException;
import aaf.v2_0.Nss;
+import aaf.v2_0.Roles;
+import aaf.v2_0.Users.User;
+import junit.framework.Assert;
import org.onap.aaf.auth.cmd.AAFcli;
import org.junit.After;
@@ -52,6 +56,45 @@ import org.junit.Test;
public class JU_List {
List list;
+ AAFcli aafcli;
+ User user;
+
+ private class NssStub extends Nss {
+ public void addNs(Nss.Ns ns) {
+ if (this.ns == null) {
+ this.ns = new ArrayList<Nss.Ns>();
+ }
+ this.ns.add(ns);
+ }
+
+ private class NsStub extends Ns{
+ public void addAttrib(Nss.Ns.Attrib attrib) {
+ if ( this.attrib == null) {
+ this.attrib = new ArrayList<Nss.Ns.Attrib>();
+ }
+ this.attrib.add(attrib);
+ }
+
+ public void addResponsible(String str) {
+ if (this.responsible == null) {
+ this.responsible = new ArrayList<String>();
+ }
+ this.responsible.add(str);
+ }
+
+ public void addAdmin(String str) {
+ if (this.admin == null) {
+ this.admin = new ArrayList<String>();
+ }
+ this.admin.add(str);
+ }
+ }
+
+
+
+
+ }
+
@Before
public void setUp() throws APIException, LocatorException {
@@ -60,23 +103,42 @@ public class JU_List {
Writer wtr = mock(Writer.class);
Locator loc = mock(Locator.class);
HMangr hman = new HMangr(aEnv, loc);
- AAFcli aafcli = new AAFcli(prop, aEnv, wtr, hman, null, null);
+ aafcli = new AAFcli(prop, aEnv, wtr, hman, null, null);
+ user = new User();
NS ns = new NS(aafcli);
list = new List(ns);
}
@Test
- public void testReport() {
+ public void testReport() throws Exception {
Future<Nss> fu = mock(Future.class);
- Nss.Ns nss = new Nss.Ns();
- Nss ns = new Nss();
- fu.value = ns;
- fu.value.getNs();
- System.out.print(fu.value.getNs());
+ NssStub nssStub = new NssStub();
+ NssStub.NsStub nsStub = nssStub.new NsStub();
+ Nss.Ns.Attrib attrib = mock(Nss.Ns.Attrib.class);
+ when(attrib.getKey()).thenReturn("key");
+ when(attrib.getValue()).thenReturn("value");
+ nsStub.addAttrib(attrib);
+ nsStub.addResponsible("test");
+ nsStub.addAdmin("admin");
+ nssStub.addNs(nsStub);
+ fu.value = nssStub;
+ aafcli.eval("DETAILS @[ 123");
- list.report(null, "test");
list.report(fu, "test");
}
+ @Test
+ public void testGetType() {
+ Assert.assertEquals("n/a", list.getType(user));
+ user.setType(1);
+ Assert.assertEquals("U/P", list.getType(user));
+ user.setType(2);
+ Assert.assertEquals("U/P2", list.getType(user));
+ user.setType(10);
+ Assert.assertEquals("Cert", list.getType(user));
+ user.setType(200);
+ Assert.assertEquals("x509", list.getType(user));
+ }
+
}
diff --git a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/role/JU_List.java b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/role/JU_List.java
index 7767e054..9eb4b75b 100644
--- a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/role/JU_List.java
+++ b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/role/JU_List.java
@@ -35,6 +35,7 @@ import org.onap.aaf.auth.cmd.Cmd;
import org.onap.aaf.auth.cmd.Param;
import org.onap.aaf.auth.env.AuthzEnv;
import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.cadi.Access;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.Locator;
import org.onap.aaf.cadi.LocatorException;
@@ -42,10 +43,12 @@ import org.onap.aaf.cadi.PropAccess;
import org.onap.aaf.cadi.SecuritySetter;
import org.onap.aaf.cadi.client.Future;
import org.onap.aaf.cadi.client.Rcli;
+import org.onap.aaf.cadi.config.SecurityInfoC;
import org.onap.aaf.cadi.http.HMangr;
import org.onap.aaf.misc.env.APIException;
import aaf.v2_0.Perms;
+import aaf.v2_0.Pkey;
import aaf.v2_0.Roles;
import aaf.v2_0.UserRoles;
@@ -59,6 +62,7 @@ import java.net.HttpURLConnection;
import java.net.URI;
import java.security.GeneralSecurityException;
import java.security.Principal;
+import java.util.ArrayList;
import org.junit.Test;
@@ -80,8 +84,25 @@ public class JU_List {
super(parent);
// TODO Auto-generated constructor stub
}
-
-
+ }
+
+ private class RolesStub extends Roles {
+ public void addRole(aaf.v2_0.Role role) {
+ if (this.role == null) {
+ this.role = new ArrayList<aaf.v2_0.Role>();
+ }
+ this.role.add(role);
+ }
+ }
+
+ private class RoleStub extends aaf.v2_0.Role {
+
+ public void addPerms(Pkey perms) {
+ if (this.perms == null) {
+ this.perms = new ArrayList<Pkey>();
+ }
+ this.perms.add(perms);
+ }
}
@Before
@@ -119,10 +140,22 @@ public class JU_List {
public void testReport() throws Exception {
UserRoles urs = new UserRoles();
Perms perms = new Perms();
- Roles roles = mock(Roles.class);
+ RolesStub roles = new RolesStub();
list.report(roles, perms , urs , "test");
AAFcli cli = JU_AAFCli.getAAfCli();
+ RoleStub role = new RoleStub();
+ roles.addRole(role);
+ Pkey pkey = new Pkey();
+ pkey.setInstance("test");
+ pkey.setAction("test");
+ pkey.setInstance("test");
+ pkey.setType("test");
+
+ list.report(roles, perms , urs , "test");
+ list.report(roles, perms , null , "test");
cli.eval("DETAILS @[ 123");
+ role.setName("test");
+ role.addPerms(pkey);
list.report(roles, perms , urs , "test");
}
diff --git a/cadi/oauth-enduser/pom.xml b/cadi/oauth-enduser/pom.xml
index 0f9bacab..83ea803a 100644
--- a/cadi/oauth-enduser/pom.xml
+++ b/cadi/oauth-enduser/pom.xml
@@ -37,7 +37,7 @@
<properties>
<!-- SONAR -->
- <!-- <sonar.skip>true</sonar.skip> -->
+ <sonar.skip>true</sonar.skip>
<jacoco.version>0.7.7.201606060606</jacoco.version>
<sonar-jacoco-listeners.version>3.2</sonar-jacoco-listeners.version>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
diff --git a/cadi/shiro/pom.xml b/cadi/shiro/pom.xml
index 0346dbe7..4e7790cf 100644
--- a/cadi/shiro/pom.xml
+++ b/cadi/shiro/pom.xml
@@ -35,7 +35,7 @@
<properties>
<!-- SONAR -->
- <!-- <sonar.skip>true</sonar.skip> -->
+ <sonar.skip>true</sonar.skip>
<jacoco.version>0.7.7.201606060606</jacoco.version>
<sonar-jacoco-listeners.version>3.2</sonar-jacoco-listeners.version>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
diff --git a/misc/env/propfile.properties b/misc/env/propfile.properties
new file mode 100644
index 00000000..c5965ff6
--- /dev/null
+++ b/misc/env/propfile.properties
@@ -0,0 +1,3 @@
+# Property file to test property loading
+prop1 = New Property
+single prop \ No newline at end of file
diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_BasicEnvTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_BasicEnvTest.java
index 5eab5dd8..65dc7c50 100644
--- a/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_BasicEnvTest.java
+++ b/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_BasicEnvTest.java
@@ -22,11 +22,14 @@ package org.onap.aaf.misc.env.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import java.applet.Applet;
+import java.io.IOException;
import java.util.Properties;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
@@ -129,12 +132,49 @@ public class JU_BasicEnvTest {
assertEquals(tt.toString(), "New Name " + (end - tt.start) / 1000000f + "ms 10");
assertEquals(sb.toString(), "JSON New Name " + (end - tt.start) / 1000000f + "ms size: 10");
+ env.staticSlot("tag", "prop");
+
if (System.getProperties().keySet().iterator().hasNext()) {
String key = (String) System.getProperties().keySet().iterator().next();
env.loadFromSystemPropsStartsWith(key);
assertEquals(env.getProperty(key), System.getProperties().get(key));
}
+
+ BasicTrans trans = env.newTrans();
+ assertEquals(trans.delegate, env);
+
+ }
+
+ @Test
+ public void testLoadProperties() throws IOException {
+ Properties prop = new Properties();
+
+ BasicEnv env = new BasicEnv("tag1", prop);
+
+ env.loadPropFiles("tag1", null);
+ env.setProperty("tag1", "propfile.properties");
+ env.loadPropFiles("tag1", null);
+
+ assertEquals(env.getProperty("prop1"), "New Property");
+
+ env.loadToSystemPropsStartsWith("prop1");
+
+ assertTrue(System.getProperties().keySet().contains("prop1"));
+ assertEquals(System.getProperties().get("prop1"), "New Property");
}
+ @After
+ public void tearDown() throws IOException {
+ /*
+ * File file = new File("./log-Append" + ending + "_0.log"); if (file.exists())
+ * { Files.delete(Paths.get(file.getAbsolutePath())); } file = new
+ * File("./log-Append" + ending + "_1.log"); if (file.exists()) {
+ * Files.delete(Paths.get(file.getAbsolutePath())); } file = new File("./Append"
+ * + ending + "_0.log"); if (file.exists()) {
+ * Files.delete(Paths.get(file.getAbsolutePath())); } file = new File("./Append"
+ * + ending + "_1.log"); if (file.exists()) {
+ * Files.delete(Paths.get(file.getAbsolutePath())); }
+ */
+ }
}
diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_ChronoTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_ChronoTest.java
index 389e7f75..05fd6fbf 100644
--- a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_ChronoTest.java
+++ b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_ChronoTest.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertEquals;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
+import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.LogRecord;
@@ -66,4 +67,173 @@ public class JU_ChronoTest {
assertEquals(expectedCalendar, timeStamp);
}
+
+ @Test
+ public void testUTCStamp() {
+ final Date date = Calendar.getInstance().getTime();
+ String expectedUTCTime = Chrono.utcFmt.format(date);
+
+ String stamp = Chrono.utcStamp(date);
+
+ assertEquals(stamp, expectedUTCTime);
+
+ Date date1 = null;
+ assertEquals("", Chrono.utcStamp(date1));
+
+ GregorianCalendar gc = null;
+ assertEquals(Chrono.utcStamp(gc), "");
+ gc = new GregorianCalendar();
+ gc.setTime(date);
+ assertEquals(Chrono.utcStamp(gc), expectedUTCTime);
+
+ XMLGregorianCalendar xgc = null;
+ assertEquals(Chrono.utcStamp(xgc), "");
+ xgc = Chrono.timeStamp(gc);
+ assertEquals(Chrono.utcStamp(xgc), expectedUTCTime);
+
+ }
+
+ @Test
+ public void testDateStamp() {
+ final Date date = Calendar.getInstance().getTime();
+ String expectedUTCTime = Chrono.dateFmt.format(date);
+
+ String stamp = Chrono.dateStamp(date);
+
+ assertEquals(stamp, expectedUTCTime);
+
+ Date date1 = null;
+ assertEquals("", Chrono.dateStamp(date1));
+
+ GregorianCalendar gc = null;
+ assertEquals(Chrono.dateStamp(gc), "");
+ gc = new GregorianCalendar();
+ gc.setTime(date);
+ assertEquals(Chrono.dateStamp(gc), expectedUTCTime);
+
+ XMLGregorianCalendar xgc = null;
+ assertEquals(Chrono.dateStamp(xgc), "");
+ xgc = Chrono.timeStamp(gc);
+ assertEquals(Chrono.dateStamp(xgc), expectedUTCTime);
+ }
+
+ @Test
+ public void testDateTime() {
+ final Date date = Calendar.getInstance().getTime();
+ date.setTime(1525023883297L);
+
+ GregorianCalendar gc = null;
+ assertEquals(Chrono.dateTime(gc), "");
+ gc = new GregorianCalendar();
+ gc.setTime(date);
+
+ // String expectedDateTime = "2018-04-29T11:14:43.297" + sign + hourOffSet + ":"
+ // + minOffSet;
+
+ TimeZone tz = gc.getTimeZone();
+ int tz1 = (tz.getRawOffset() + tz.getDSTSavings()) / 0x8CA0;
+ int tz1abs = Math.abs(tz1);
+ String expectedDateTime = String.format("%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d:%02d",
+ gc.get(GregorianCalendar.YEAR), gc.get(GregorianCalendar.MONTH) + 1,
+ gc.get(GregorianCalendar.DAY_OF_MONTH), gc.get(GregorianCalendar.HOUR),
+ gc.get(GregorianCalendar.MINUTE), gc.get(GregorianCalendar.SECOND),
+ gc.get(GregorianCalendar.MILLISECOND), tz1 == tz1abs ? '+' : '-', tz1abs / 100,
+ ((tz1abs - (tz1abs / 100) * 100) * 6) / 10 // Get the "10s", then convert to mins (without losing int
+ // place)
+ );
+
+ String stamp = Chrono.dateTime(date);
+
+ assertEquals(stamp, expectedDateTime);
+
+ assertEquals(Chrono.dateTime(gc), expectedDateTime);
+
+ XMLGregorianCalendar xgc = null;
+ assertEquals(Chrono.dateTime(xgc), "");
+ xgc = Chrono.timeStamp(gc);
+ assertEquals(Chrono.dateTime(xgc), expectedDateTime);
+ }
+
+ @Test
+ public void testDateOnlyStamp() {
+ final Date date = Calendar.getInstance().getTime();
+ date.setTime(1525023883297L);
+
+ String expectedDateTime = Chrono.dateOnlyFmt.format(date);
+
+ String stamp = Chrono.dateOnlyStamp(date);
+
+ assertEquals(stamp, expectedDateTime);
+
+ Date date1 = null;
+ assertEquals("", Chrono.dateOnlyStamp(date1));
+
+ GregorianCalendar gc = null;
+ assertEquals(Chrono.dateOnlyStamp(gc), "");
+ gc = new GregorianCalendar();
+ gc.setTime(date);
+ assertEquals(Chrono.dateOnlyStamp(gc), expectedDateTime);
+
+ XMLGregorianCalendar xgc = null;
+ assertEquals(Chrono.dateOnlyStamp(xgc), "");
+ xgc = Chrono.timeStamp(gc);
+ assertEquals(Chrono.dateOnlyStamp(xgc), expectedDateTime);
+ }
+
+ @Test
+ public void testNiceDateStamp() {
+ final Date date = Calendar.getInstance().getTime();
+ date.setTime(1525023883297L);
+
+ String expectedDateTime = Chrono.niceDateFmt.format(date);
+
+ String stamp = Chrono.niceDateStamp(date);
+
+ assertEquals(stamp, expectedDateTime);
+
+ Date date1 = null;
+ assertEquals("", Chrono.niceDateStamp(date1));
+
+ GregorianCalendar gc = null;
+ assertEquals(Chrono.niceDateStamp(gc), "");
+ gc = new GregorianCalendar();
+ gc.setTime(date);
+ assertEquals(Chrono.niceDateStamp(gc), expectedDateTime);
+
+ XMLGregorianCalendar xgc = null;
+ assertEquals(Chrono.niceDateStamp(xgc), "");
+ xgc = Chrono.timeStamp(gc);
+ assertEquals(Chrono.niceDateStamp(xgc), expectedDateTime);
+ }
+
+ @Test
+ public void testMoment() {
+ final Date date = Calendar.getInstance().getTime();
+ date.setTime(1525023883297L);
+
+ GregorianCalendar begin = new GregorianCalendar();
+ begin.setTimeInMillis(date.getTime());
+ begin.set(GregorianCalendar.HOUR, 0);
+ begin.set(GregorianCalendar.AM_PM, GregorianCalendar.AM);
+ begin.set(GregorianCalendar.MINUTE, 0);
+ begin.set(GregorianCalendar.SECOND, 0);
+ begin.set(GregorianCalendar.MILLISECOND, 0);
+
+ long firstMoment = begin.getTimeInMillis();
+
+ begin.set(GregorianCalendar.HOUR, 11);
+ begin.set(GregorianCalendar.MINUTE, 59);
+ begin.set(GregorianCalendar.SECOND, 59);
+ begin.set(GregorianCalendar.MILLISECOND, 999);
+ begin.set(GregorianCalendar.AM_PM, GregorianCalendar.PM);
+
+ long lastMoment = begin.getTimeInMillis();
+
+ assertEquals(firstMoment, Chrono.firstMomentOfDay(date.getTime()));
+ assertEquals(lastMoment, Chrono.lastMomentOfDay(date.getTime()));
+
+ float timeInMillis = (lastMoment - firstMoment) / 1000000f;
+ assertEquals(timeInMillis, Chrono.millisFromNanos(firstMoment, lastMoment), 0);
+
+ }
}