unit tests for opml importer (#636)

This commit is contained in:
Athou
2014-11-07 09:00:53 +01:00
parent 7151db0909
commit 97c2cc3d15
5 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
package com.commafeed.backend.opml;
import java.io.IOException;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.mockito.Mockito;
import com.commafeed.backend.cache.CacheService;
import com.commafeed.backend.dao.FeedCategoryDAO;
import com.commafeed.backend.model.FeedCategory;
import com.commafeed.backend.model.User;
import com.commafeed.backend.service.FeedSubscriptionService;
public class OPMLImporterTest {
@Test
public void testOpmlV10() throws IOException {
testOpmlVersion("/opml/opml_v1.0.xml");
}
@Test
public void testOpmlV11() throws IOException {
testOpmlVersion("/opml/opml_v1.1.xml");
}
@Test
public void testOpmlV20() throws IOException {
testOpmlVersion("/opml/opml_v2.0.xml");
}
@Test
public void testOpmlNoVersion() throws IOException {
testOpmlVersion("/opml/opml_noversion.xml");
}
private void testOpmlVersion(String fileName) throws IOException {
FeedCategoryDAO feedCategoryDAO = Mockito.mock(FeedCategoryDAO.class);
FeedSubscriptionService feedSubscriptionService = Mockito.mock(FeedSubscriptionService.class);
CacheService cacheService = Mockito.mock(CacheService.class);
User user = Mockito.mock(User.class);
String xml = IOUtils.toString(getClass().getResourceAsStream(fileName));
OPMLImporter importer = new OPMLImporter(feedCategoryDAO, feedSubscriptionService, cacheService);
importer.importOpml(user, xml);
Mockito.verify(feedSubscriptionService).subscribe(Mockito.eq(user), Mockito.anyString(), Mockito.anyString(),
Mockito.any(FeedCategory.class));
}
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<opml>
<head>
<title>subscriptions</title>
</head>
<body>
<outline text="out1" title="out1">
<outline type="rss" text="feed1" title="feed1" xmlUrl="http://www.feed.com/feed1.xml" htmlUrl="http://www.feed.com" />
</outline>
</body>
</opml>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>subscriptions</title>
</head>
<body>
<outline text="out1" title="out1">
<outline type="rss" text="feed1" title="feed1" xmlUrl="http://www.feed.com/feed1.xml" htmlUrl="http://www.feed.com" />
</outline>
</body>
</opml>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.1">
<head>
<title>subscriptions</title>
</head>
<body>
<outline text="out1" title="out1">
<outline type="rss" text="feed1" title="feed1" xmlUrl="http://www.feed.com/feed1.xml" htmlUrl="http://www.feed.com" />
</outline>
</body>
</opml>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0">
<head>
<title>subscriptions</title>
</head>
<body>
<outline text="out1" title="out1">
<outline type="rss" text="feed1" title="feed1" xmlUrl="http://www.feed.com/feed1.xml" htmlUrl="http://www.feed.com" />
</outline>
</body>
</opml>