Skip to content

Commit

Permalink
Fix changed date-format in FM4Stream
Browse files Browse the repository at this point in the history
Also add some more tests for verify the format of some getters
  • Loading branch information
centic9 committed Feb 23, 2024
1 parent 494c74a commit b4e35b2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 36 deletions.
41 changes: 5 additions & 36 deletions src/main/java/org/dstadler/audio/fm4/FM4Stream.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -91,6 +94,7 @@ public long getStart() {
}

public String getShortTime() {
// return time-string up to minutes
return getTime().substring(0, 16).
replace("T", " ");
}
Expand Down Expand Up @@ -150,39 +154,4 @@ public String toString() {
", duration=" + duration +
'}';
}

/*
{
"isOnDemand" : true,
"programKey" : "4GP",
"subtitle" : "<p>Die wöchentliche Radioshow von Gilles Peterson.<br/>FM4-News um 17 Uhr und 18 Uhr (englisch)</p>",
"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
},
*/
}
24 changes: 24 additions & 0 deletions src/test/java/org/dstadler/audio/fm4/FM4StreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -57,6 +76,8 @@ public void testFM4Stream() throws IOException, ParseException {
fm4Stream.getStart() > MIN_START_TIME);

assertNotNull(fm4Stream.toString());

TestHelpers.ToStringTest(fm4Stream);
}

@Test
Expand Down Expand Up @@ -101,5 +122,8 @@ public void testEquals() {

assertNotNull(fm4.toString());
assertNotNull(notEquals.toString());

TestHelpers.ToStringTest(fm4);
TestHelpers.ToStringTest(notEquals);
}
}

0 comments on commit b4e35b2

Please sign in to comment.