Skip to content
Snippets Groups Projects
Commit 902d2c6e authored by uhensler's avatar uhensler
Browse files

OO-2898: Testing and hardening

parent 8602d3e0
No related branches found
No related tags found
No related merge requests found
......@@ -107,12 +107,22 @@ public abstract class FeedManager {
public abstract boolean copy(OLATResource source, OLATResource target);
/**
* Update the feed with the properties in the repository entry.
* Enrich the feed with the properties in the RepositoryEntry.
*
* @param feed
* @param entry
* @return the same Feed object with actualized attributes
*/
public abstract Feed enrichFeedByRepositoryEntry(Feed feed, RepositoryEntry entry);
/**
* Update the feed with the properties in the RepositoryEntry and save it
* in the database.
*
* @param entry
* @return a new updated Feed object
*/
public abstract Feed updateFeedWithRepositoryEntry(RepositoryEntry entry);
/**
* Create the given Item and saves the appropriate file (podcast, video etc.)
......
......@@ -515,8 +515,19 @@ public class FeedManagerImpl extends FeedManager {
}
}
@Override
public Feed updateFeedWithRepositoryEntry(RepositoryEntry entry) {
Feed feed = loadFeed(entry.getOlatResource());
feed = enrichFeedByRepositoryEntry(feed, entry);
feed = updateFeed(feed);
return feed;
}
@Override
public Feed enrichFeedByRepositoryEntry(Feed feed, RepositoryEntry entry) {
if (feed == null) return null;
if (entry == null) return feed;
// copy the metadata
feed.setTitle(entry.getDisplayname());
feed.setDescription(entry.getDescription());
......
......@@ -242,10 +242,7 @@ public class BlogHandler implements RepositoryHandler {
@Override
public void onDescriptionChanged(RepositoryEntry entry) {
FeedManager feedManager = FeedManager.getInstance();
Feed feed = feedManager.loadFeed(entry.getOlatResource());
feed = feedManager.enrichFeedByRepositoryEntry(feed, entry);
feedManager.updateFeed(feed);
Feed feed = FeedManager.getInstance().updateFeedWithRepositoryEntry(entry);
DBFactory.getInstance().commitAndCloseSession();
CoordinatorManager.getInstance().getCoordinator().getEventBus()
......
......@@ -236,10 +236,7 @@ public class PodcastHandler implements RepositoryHandler {
@Override
public void onDescriptionChanged(RepositoryEntry entry) {
FeedManager feedManager = FeedManager.getInstance();
Feed feed = feedManager.loadFeed(entry.getOlatResource());
feed = feedManager.enrichFeedByRepositoryEntry(feed, entry);
feedManager.updateFeed(feed);
Feed feed = FeedManager.getInstance().updateFeedWithRepositoryEntry(entry);
DBFactory.getInstance().commitAndCloseSession();
CoordinatorManager.getInstance().getCoordinator().getEventBus()
......
......@@ -79,7 +79,7 @@ public class FeedManagerImplTest {
@Mock
private Coordinator coordinaterMock;
@Mock
private RepositoryManager repostoryManager;
private RepositoryManager repositoryManager;
@Mock
OLATResource resourceDummy;
@Mock
......@@ -102,7 +102,7 @@ public class FeedManagerImplTest {
ReflectionTestUtils.setField(sut, "itemDAO", itemDAOMock);
ReflectionTestUtils.setField(sut, "feedFileStorage", feedFileStorageMock);
ReflectionTestUtils.setField(sut, "externalFeedFetcher", feedFetcherMock);
ReflectionTestUtils.setField(sut, "repositoryManager", repostoryManager);
ReflectionTestUtils.setField(sut, "repositoryManager", repositoryManager);
}
@Test
......@@ -260,8 +260,9 @@ public class FeedManagerImplTest {
verify(feedFileStorageMock, times(3)).deleteItemXML(itemDummy);
}
@Test
public void enrichFeedFromrepositoryEntryShouldTransferAtributes() {
public void enrichFeedFromRepositoryEntryShouldTransferAtributes() {
Feed feed = new FeedImpl(resourceDummy);
RepositoryEntry entry = new RepositoryEntry();
String title = "Title";
......@@ -277,4 +278,32 @@ public class FeedManagerImplTest {
assertThat(enrichedFeed.getDescription()).isEqualTo(description);
assertThat(enrichedFeed.getAuthor()).isEqualTo(authors);
}
@Test
public void enrichFeedFromRepositoryEntryShouldReturnUnchangedFeedIfRepositoryIsNull() {
Feed feed = new FeedImpl(resourceDummy);
String title = "Title";
feed.setTitle(title);
String description = "Description";
feed.setDescription(description);
String authors = "Author";
feed.setAuthor(authors);
Feed enrichedFeed = sut.enrichFeedByRepositoryEntry(feed, null);
assertThat(enrichedFeed).isEqualTo(feed);
assertThat(enrichedFeed.getTitle()).isEqualTo(title);
assertThat(enrichedFeed.getDescription()).isEqualTo(description);
assertThat(enrichedFeed.getAuthor()).isEqualTo(authors);
}
@Test
public void enrichFeedFromRepositoryEntryShouldReturnNullIfFeedIsNull() {
RepositoryEntry entry = new RepositoryEntry();
Feed enrichedFeed = sut.enrichFeedByRepositoryEntry(null, entry);
assertThat(enrichedFeed).isNull();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment