summaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-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
3 files changed, 213 insertions, 0 deletions
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);
+
+ }
}