diff --git a/src/main/java/org/dstadler/audio/fm4/FM4Stream.java b/src/main/java/org/dstadler/audio/fm4/FM4Stream.java
index e80cb95..607766b 100644
--- a/src/main/java/org/dstadler/audio/fm4/FM4Stream.java
+++ b/src/main/java/org/dstadler/audio/fm4/FM4Stream.java
@@ -2,6 +2,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.FastDateFormat;
import org.dstadler.commons.http.HttpClientWrapper;
import org.dstadler.commons.logging.jdk.LoggerFactory;
@@ -69,7 +70,9 @@ public String getTime() {
}
public String getTimeForREST() throws ParseException {
- return DATETIME_FORMAT.format(DATETIME_FORMAT.parse(time));
+ // return the date-part
+ return DateFormatUtils.ISO_8601_EXTENDED_DATE_FORMAT.format(
+ DATETIME_FORMAT.parse(time));
}
/**
@@ -91,6 +94,7 @@ public long getStart() {
}
public String getShortTime() {
+ // return time-string up to minutes
return getTime().substring(0, 16).
replace("T", " ");
}
@@ -150,39 +154,4 @@ public String toString() {
", duration=" + duration +
'}';
}
-
- /*
- {
- "isOnDemand" : true,
- "programKey" : "4GP",
- "subtitle" : "
Die wöchentliche Radioshow von Gilles Peterson.
FM4-News um 17 Uhr und 18 Uhr (englisch)
",
- "id" : 15652,
- "niceTime" : 1575820800000,
- "endISO" : "2019-12-08T19:00:40+01:00",
- "broadcastDay" : 20191208,
- "scheduledStartOffset" : -3600000,
- "niceTimeISO" : "2019-12-08T17:00:00+01:00",
- "scheduledStart" : 1575820800000,
- "niceTimeOffset" : -3600000,
- "program" : "4GP",
- "scheduledEnd" : 1575828000000,
- "title" : "Worldwide Show",
- "endOffset" : -3600000,
- "scheduledStartISO" : "2019-12-08T17:00:00+01:00",
- "scheduledEndISO" : "2019-12-08T19:00:00+01:00",
- "href" : "https://audioapi.orf.at/fm4/api/json/4.0/broadcast/4GP/20191208",
- "station" : "fm4",
- "startOffset" : -3600000,
- "start" : 1575820794000,
- "scheduledEndOffset" : -3600000,
- "ressort" : null,
- "end" : 1575828040000,
- "state" : "C",
- "startISO" : "2019-12-08T16:59:54+01:00",
- "isAdFree" : false,
- "entity" : "Broadcast",
- "isGeoProtected" : false
- },
-
- */
}
diff --git a/src/test/java/org/dstadler/audio/fm4/FM4StreamTest.java b/src/test/java/org/dstadler/audio/fm4/FM4StreamTest.java
index d223dec..dcf18f1 100644
--- a/src/test/java/org/dstadler/audio/fm4/FM4StreamTest.java
+++ b/src/test/java/org/dstadler/audio/fm4/FM4StreamTest.java
@@ -14,6 +14,7 @@
import static org.dstadler.audio.fm4.FM4Stream.DATETIME_FORMAT;
import static org.dstadler.audio.fm4.FM4Stream.FM4_STREAM_URL_BASE;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -41,11 +42,29 @@ public void testFM4Stream() throws IOException, ParseException {
assertNotNull(fm4Stream.getTime());
assertNotNull(DATETIME_FORMAT.parse(fm4Stream.getTime()));
assertNotNull(fm4Stream.getTimeForREST());
+
+ assertTrue("Failed for " + fm4Stream.getTimeForREST(),
+ fm4Stream.getTimeForREST().matches("\\d{4}-\\d{2}-\\d{2}"));
+
+ String time = DateFormatUtils.ISO_8601_EXTENDED_DATE_FORMAT.format(
+ FM4Stream.DATETIME_FORMAT.parse(fm4Stream.getTime()));
+ assertEquals(time, fm4Stream.getTimeForREST());
+
assertNotNull(fm4Stream.getProgramKey());
assertNotNull(fm4Stream.getSubtitle());
+
assertNotNull(fm4Stream.getShortSummary());
+ assertTrue(fm4Stream.getShortSummary().contains(fm4Stream.getProgramKey()));
+ assertTrue(fm4Stream.getShortSummary().contains(fm4Stream.getTitle()));
+
assertNotNull(fm4Stream.getSummary());
+ assertTrue(fm4Stream.getSummary().contains(fm4Stream.getProgramKey()));
+ assertTrue(fm4Stream.getSummary().contains(fm4Stream.getShortTime()));
+ assertTrue(fm4Stream.getSummary().contains(fm4Stream.getTitle()));
+
assertNotNull(fm4Stream.getShortTime());
+ assertTrue("Failed for " + fm4Stream.getShortTime(),
+ fm4Stream.getShortTime().matches("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}"));
assertNotNull(DateFormatUtils.ISO_8601_EXTENDED_DATE_FORMAT.parse(fm4Stream.getShortTime()));
assertTrue("Duration should be set, but had: " + fm4Stream.getDuration(),
fm4Stream.getDuration() > 0);
@@ -57,6 +76,8 @@ public void testFM4Stream() throws IOException, ParseException {
fm4Stream.getStart() > MIN_START_TIME);
assertNotNull(fm4Stream.toString());
+
+ TestHelpers.ToStringTest(fm4Stream);
}
@Test
@@ -101,5 +122,8 @@ public void testEquals() {
assertNotNull(fm4.toString());
assertNotNull(notEquals.toString());
+
+ TestHelpers.ToStringTest(fm4);
+ TestHelpers.ToStringTest(notEquals);
}
}