forked from Archives/Athou_commafeed
unit tests for opml importer (#636)
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
11
src/test/resources/opml/opml_noversion.xml
Normal file
11
src/test/resources/opml/opml_noversion.xml
Normal 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>
|
||||
11
src/test/resources/opml/opml_v1.0.xml
Normal file
11
src/test/resources/opml/opml_v1.0.xml
Normal 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>
|
||||
11
src/test/resources/opml/opml_v1.1.xml
Normal file
11
src/test/resources/opml/opml_v1.1.xml
Normal 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>
|
||||
11
src/test/resources/opml/opml_v2.0.xml
Normal file
11
src/test/resources/opml/opml_v2.0.xml
Normal 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>
|
||||
Reference in New Issue
Block a user