String channelId1 = "Ch1";
String channelId2 = "Ch2";
String channelId3 = "Ch3";
// Create a test file
SummaryFile summary1 = new SummaryFile();
summary1.setDayProgramVersion(date3, country, channelId1, 0, 1);
summary1.setDayProgramVersion(date3, country, channelId1, 1, 2);
summary1.setDayProgramVersion(date3, country, channelId1, 2, 3);
summary1.setDayProgramVersion(date2, country, channelId1, 0, 4);
summary1.setDayProgramVersion(date2, country, channelId1, 2, 5);
summary1.setDayProgramVersion(date4, country, channelId1, 0, 6);
summary1.setDayProgramVersion(date4, country, channelId1, 1, 7);
summary1.setDayProgramVersion(date5, country, channelId1, 0, 8);
summary1.setDayProgramVersion(date4, country, channelId2, 1, 9);
summary1.setDayProgramVersion(date4, country, channelId2, 2, 10);
// Save and load the file
File file = null;
SummaryFile summary2;
try {
file = File.createTempFile("tvbrowser", ".test_summary.gz");
summary1.writeToFile(file);
// System.out.println("Test file saved: " + file.getAbsolutePath());
summary2 = new SummaryFile();
summary2.readFromFile(file);
}
finally {
if (file != null) {
// file.delete();
}
}
// Check the set fields
assertEquals(summary2.getDayProgramVersion(date3, country, channelId1, 0), 1);
assertEquals(summary2.getDayProgramVersion(date3, country, channelId1, 1), 2);
assertEquals(summary2.getDayProgramVersion(date3, country, channelId1, 2), 3);
assertEquals(summary2.getDayProgramVersion(date2, country, channelId1, 0), 4);
assertEquals(summary2.getDayProgramVersion(date2, country, channelId1, 2), 5);
assertEquals(summary2.getDayProgramVersion(date4, country, channelId1, 0), 6);
assertEquals(summary2.getDayProgramVersion(date4, country, channelId1, 1), 7);
assertEquals(summary2.getDayProgramVersion(date5, country, channelId1, 0), 8);
assertEquals(summary2.getDayProgramVersion(date4, country, channelId2, 1), 9);
assertEquals(summary2.getDayProgramVersion(date4, country, channelId2, 2), 10);
// Check unset version
assertEquals(summary2.getDayProgramVersion(date2, country, channelId1, 1), -1);
// Check unset days
assertEquals(summary2.getDayProgramVersion(date1, country, channelId1, 0), -1);
assertEquals(summary2.getDayProgramVersion(date6, country, channelId1, 2), -1);
// Check unset channel
assertEquals(summary2.getDayProgramVersion(date3, country, channelId3, 1), -1);
}