@Test(dataProvider = "journal") public void testBrowseLatestIssueFromLatestVolume(Journal journal) { // set journal to have a null currentIssue Issue originalIssue = journal.getCurrentIssue(); journal.setCurrentIssue(null); dummyDataStore.update(journal); try { assertEquals(action.execute(), BaseActionSupport.SUCCESS, "Action didn't return success"); IssueInfo issueInfo = action.getIssueInfo(); assertNotNull(issueInfo, "action had null issue info"); // Load up latest volume w/ dummy datastore to defeat lazy-loaded issues Long volumeId = journal.getVolumes().get(journal.getVolumes().size() - 1).getID(); Volume latestVolume = dummyDataStore.get(Volume.class, volumeId); Issue latestIssue = latestVolume.getIssues().get(latestVolume.getIssues().size() - 1); assertEquals( issueInfo.getIssueURI(), latestIssue.getIssueUri(), "action had incorrect issue uri"); assertEquals( issueInfo.getDescription(), latestIssue.getDescription(), "action had incorrect issue description"); assertEquals( action.getVolumeInfo().getVolumeUri(), latestVolume.getVolumeUri(), "action had incorrect volume"); } finally { // reset state journal.setCurrentIssue(originalIssue); dummyDataStore.update(journal); } }
@DataProvider(name = "journal") public Object[][] getJournal() { Journal journal = new Journal(journalKey); journal.setVolumes(new ArrayList<Volume>(3)); for (String volumeName : new String[] {"OldVolume", "NewVolume"}) { Volume volume = new Volume("id:BrowseIssueAction" + volumeName); volume.setTitle(volumeName); volume.setDescription( "A plane crash causes the firm to go after the account for the airline involved " + "and drop the smaller airline they have an account with. Peggy pays a visit to her mother and sister, " + "who are now guardians of a child."); volume.setIssues(new ArrayList<Issue>(4)); for (int i = 1; i <= 3; i++) { List<String> articleDOIs = Arrays.asList( volumeName + "Issue" + i + "Article1", volumeName + "Issue" + i + "Article2", volumeName + "Issue" + i + "Article3"); for (String doi : articleDOIs) { Article art = new Article(); art.setDoi(doi); art.setState(0); art.setTitle(doi); dummyDataStore.store(art); } Issue issue = new Issue("id:" + volumeName + "Issue" + i); issue.setTitle(volumeName + " Issue " + i); issue.setDescription(volumeName + " Issue " + i); issue.setArticleDois(articleDOIs); volume.getIssues().add(issue); } journal.getVolumes().add(volume); } journal.setCurrentIssue(journal.getVolumes().get(1).getIssues().get(0)); Long id = Long.valueOf(dummyDataStore.store(journal)); return new Object[][] {{dummyDataStore.get(Journal.class, id)}}; }