]> www.vanbest.org Git - tv_grab_nl_java/commitdiff
Added simple test case for horizon.tv
authorJan-Pascal van Best <janpascal@vanbest.org>
Tue, 11 Jun 2013 07:34:44 +0000 (09:34 +0200)
committerJan-Pascal van Best <janpascal@vanbest.org>
Tue, 11 Jun 2013 07:34:44 +0000 (09:34 +0200)
release.properties [deleted file]
src/test/java/org/vanbest/xmltv/HorizonTest.java [new file with mode: 0644]

diff --git a/release.properties b/release.properties
deleted file mode 100644 (file)
index d633921..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#release configuration
-#Tue Mar 05 21:21:51 CET 2013
-project.scm.org.vanbest.xmltv.tv_grab_nl_java\:tv_grab_nl_java.tag=HEAD
-scm.tag=1.2.1
-project.scm.org.vanbest.xmltv.tv_grab_nl_java\:tv_grab_nl_java.url=https\://github.com/janpascal/tv_grab_nl_java
-scm.url=scm\:git\:https\://janpascal@github.com/janpascal/tv_grab_nl_java.git
-preparationGoals=clean verify
-project.scm.org.vanbest.xmltv.tv_grab_nl_java\:tv_grab_nl_java.connection=scm\:git\:git\://github.com/janpascal/tv_grab_nl_java.git
-project.scm.org.vanbest.xmltv.tv_grab_nl_java\:tv_grab_nl_java.developerConnection=scm\:git\:https\://janpascal@github.com/janpascal/tv_grab_nl_java.git
-scm.commentPrefix=[maven-release-plugin] 
-project.dev.org.vanbest.xmltv.tv_grab_nl_java\:tv_grab_nl_java=1.2.2-SNAPSHOT
-project.rel.org.vanbest.xmltv.tv_grab_nl_java\:tv_grab_nl_java=1.2.1
-completedPhase=scm-commit-release
diff --git a/src/test/java/org/vanbest/xmltv/HorizonTest.java b/src/test/java/org/vanbest/xmltv/HorizonTest.java
new file mode 100644 (file)
index 0000000..62be493
--- /dev/null
@@ -0,0 +1,162 @@
+package org.vanbest.xmltv;
+
+import static org.junit.Assert.*;
+
+import java.util.Calendar;
+import java.util.List;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class HorizonTest {
+
+       private static Horizon horizon;
+       private final static int HORIZON_SOURCE_ID = 3;
+       private static List<Channel> channels = null;
+
+       @BeforeClass
+       public static void setUp() throws Exception {
+               Config config = Config.getDefaultConfig();
+               horizon = new Horizon(HORIZON_SOURCE_ID, config);
+               horizon.clearCache();
+       }
+
+       @AfterClass
+       public static void tearDown() throws Exception {
+               horizon.close();
+       }
+
+       @Test
+       public void testGetName() {
+               assertEquals("Horizon name should be known", "horizon.tv", horizon.getName());
+       }
+
+       @Test
+       public void testgetChannels() {
+               fetchChannels();
+
+               // there should be a least 20 channels
+               assertTrue("There should be at least 20 channels from horizon.nl",
+                               channels.size() >= 20);
+               // there should be an "RTL4" channel
+               boolean foundRTL4 = false;
+               for (Channel c : channels) {
+                       if (c.defaultName().equals("RTL 4")) {
+                               foundRTL4 = true;
+                               assertFalse("RTL 4 channel should have at least one icon",
+                                               c.icons.isEmpty());
+                       }
+                       assertEquals("All channels should have RTL.nl source id",
+                                       HORIZON_SOURCE_ID, c.source);
+               }
+               if (!foundRTL4) {
+                       fail("Channel RTL4 not found, should be there");
+               }
+       }
+
+       private void fetchChannels() {
+               if (channels == null)
+                       channels = horizon.getChannels();
+       }
+
+       @Test
+       public void testFindGTSTRerun() throws Exception {
+               fetchChannels();
+               Channel rtl4 = null;
+               for (Channel c : channels) {
+                       if (c.defaultName().equals("RTL 4")) {
+                               rtl4 = c;
+                                break;
+                       }
+               }
+               assertNotNull("Should be able to find RTL 4 channel", rtl4);
+
+               List<Programme> today = horizon.getProgrammes(rtl4, 0);
+               assertTrue("Expect at leat 10 programmes for a day", today.size() >= 10);
+
+               Calendar now = Calendar.getInstance();
+               if (now.get(Calendar.MONTH) <= Calendar.MAY
+                               || now.get(Calendar.MONTH) >= Calendar.SEPTEMBER) {
+                       int offset;
+                       switch (now.get(Calendar.DAY_OF_WEEK)) {
+                       case Calendar.SATURDAY:
+                               offset = 2;
+                               break;
+                       case Calendar.SUNDAY:
+                               offset = 1;
+                               break;
+                       default:
+                               offset = 0;
+                       }
+                       int rerun;
+                       switch (now.get(Calendar.DAY_OF_WEEK)) {
+                       case Calendar.FRIDAY:
+                               rerun = 3;
+                               break;
+                       case Calendar.SATURDAY:
+                               rerun = 3;
+                               break;
+                       case Calendar.SUNDAY:
+                               rerun = 2;
+                               break;
+                       default:
+                               rerun = 1;
+                       }
+                       List<Programme> first = horizon.getProgrammes(rtl4, offset);
+                       Programme gtstOriginal = null;
+                       for (Programme p : first) {
+                               if (p.getFirstTitle().matches("Goede Tijden.*")) {
+                                       if (p.startTime.getHours() >= 19) {
+                                               gtstOriginal = p;
+                                               break;
+                                       }
+                               }
+                       }
+                       assertNotNull(
+                                       "Should have a programme called Goede Tijden, Slechte Tijden after 19:00 on date with offset "
+                                                       + offset + " for today", gtstOriginal);
+                       assertNotNull("GTST should have a description",
+                                       gtstOriginal.descriptions);
+                       assertTrue("GTST should have at least one description",
+                                       gtstOriginal.descriptions.size() > 0);
+                       assertNotNull(
+                                       "GTST should have at least one non-empty description",
+                                       gtstOriginal.descriptions.get(0).title);
+                       assertFalse("GTST should have at least one non-empty description",
+                                       gtstOriginal.descriptions.get(0).title.isEmpty());
+
+                       assertNotNull("GTST should have kijkwijzer information",
+                                       gtstOriginal.ratings);
+                       assertTrue("GTST should have at least one kijkwijzer ratings",
+                                       gtstOriginal.ratings.size() >= 1);
+                       assertNotNull("GTST rating should have kijkwijzer system",
+                                       gtstOriginal.ratings.get(0).system);
+                       assertTrue("GTST rating should have kijkwijzer system filled in",
+                                       gtstOriginal.ratings.get(0).system.matches(".*ijkwijz.*"));
+                       assertNotNull("GTST rating should have value",
+                                       gtstOriginal.ratings.get(0).value);
+                       assertFalse("GTST rating should have value",
+                                       gtstOriginal.ratings.get(0).value.isEmpty());
+
+                       List<Programme> reruns = horizon.getProgrammes(rtl4, rerun);
+                       Programme gtstRerun = null;
+                       for (Programme p : reruns) {
+                               if (p.getFirstTitle().matches("Goede Tijden.*")) {
+                                       if (p.startTime.getHours() <= 15) {
+                                               gtstRerun = p;
+                                               break;
+                                       }
+                               }
+                       }
+                       assertNotNull(
+                                       "Should have a programme called Goede Tijden, Slechte Tijden before 15:00 on date with offset "
+                                                       + rerun, gtstRerun);
+
+                       assertEquals(
+                                       "GTST rerun should have the same description as the original",
+                                       gtstRerun.descriptions.get(0).title,
+                                       gtstOriginal.descriptions.get(0).title);
+               }
+       }
+}