* @throws Exception if any errors are hit
*/
@Test
public void parse() throws Exception {
// Setup
PackageSyncReport report = new PackageSyncReport();
assert rssDocument1 != null : "Rss Document was not read properly in set up";
// Test #1 - Initial call with no prior server knowledge
parser.parseResults(rssDocument1, report, null);
// Verify
Set<ContentProviderPackageDetails> newPackages = report.getNewPackages();
assert newPackages.size() == 59 : "Incorrect number of cumulative patches found. Expected: 59, Found: "
+ newPackages.size();
assert report.getDeletedPackages().size() == 0 : "Incorrect number of deleted packages. Expected: 0, Found: "
+ report.getDeletedPackages().size();
assert report.getUpdatedPackages().size() == 0 : "Incorrect number of updated packages. Expected: 0, Found: "
+ report.getUpdatedPackages().size();
int totalNumVersions = 0;
for (ContentProviderPackageDetails pkg : newPackages) {
totalNumVersions += pkg.getResourceVersions().size();
Assert.assertEquals("[sha256=" + pkg.getSHA256() + "]", pkg.getKey().getVersion());
}
assert totalNumVersions == 282 : "Incorrect number of total versions represented. Expected: 282, Found: "
+ totalNumVersions;
// Test #2 - Call again using the previous results as the existing package list, simulating the server passing in
// its knowledge of the package list
report = new PackageSyncReport();
parser.parseResults(rssDocument1, report, newPackages);
// Verify
assert report.getNewPackages().size() == 0 : "New packages incorrectly reported. Expected: 0, Found: "
+ report.getNewPackages().size();
assert report.getDeletedPackages().size() == 0 : "Incorrect number of deleted packages. Expected: 0, Found: "
+ report.getDeletedPackages().size();
assert report.getUpdatedPackages().size() == 0 : "Incorrect number of updated packages. Expected: 0, Found: "
+ report.getUpdatedPackages().size();
// Test #3 - Use second example set to trigger a deleted package
report = new PackageSyncReport();
parser.parseResults(rssDocument2, report, newPackages);
assert report.getNewPackages().size() == 1 : "New packages incorrectly reported. Expected: 1, Found: "
+ report.getNewPackages().size();
assert report.getDeletedPackages().size() == 1 : "Incorrect number of deleted packages. Expected: 0, Found: "
+ report.getDeletedPackages().size();
assert report.getUpdatedPackages().size() == 0 : "Incorrect number of updated packages. Expected: 0, Found: "
+ report.getUpdatedPackages().size();
for (ContentProviderPackageDetails pkg : report.getNewPackages()) {
Assert.assertEquals("[sha256=" + pkg.getSHA256() + "]", pkg.getKey().getVersion());
}
}