/** * Licensed to The Apereo Foundation under one or more contributor license * agreements. See the NOTICE file distributed with this work for additional * information regarding copyright ownership. * * * The Apereo Foundation licenses this file to you under the Educational * Community License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License * at: * * http://opensource.org/licenses/ecl2.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. * */ package org.opencastproject.feed.impl; import org.opencastproject.feed.api.Category; import org.opencastproject.feed.api.Content; import org.opencastproject.feed.api.Content.Mode; import org.opencastproject.feed.api.Feed.Type; import org.opencastproject.feed.api.FeedEntry; import org.opencastproject.feed.api.FeedExtension; import org.opencastproject.feed.api.Image; import org.opencastproject.feed.api.Link; import org.opencastproject.feed.api.Person; import org.easymock.EasyMock; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Date; import java.util.LinkedList; import java.util.List; import junit.framework.Assert; public class FeedImplTest { private static final Logger logger = LoggerFactory.getLogger(FeedImplTest.class); private static FeedImpl instance; @BeforeClass public static void setupClass() { Content title = new PlainTextContent("Test Feed"); Content description = new HtmlContent("generated by <b>unit test</b>", Mode.Escaped); instance = new FeedImpl(Type.RSS, "http://localhost:8080/feeds/rss/2.0/test", title, description, "http://localhost:8080/feeds/rss/2.0/test"); } @AfterClass public static void tearDownClass() throws Exception { instance = null; } @Test public void testFeedImpl() { try { Content title = new PlainTextContent("Test Feed"); Content description = new HtmlContent("generated by <b>unit test</b>", Mode.Escaped); FeedImpl feed = new FeedImpl(Type.RSS, "http://localhost:8080/feeds/rss/2.0/test", title, description, "http://localhost:8080/feeds/rss/2.0/test"); feed.addAuthor(new PersonImpl("Test User", "testuser@example.com", "http://www.example.com/testuser")); feed.addContributor(new PersonImpl("test university")); FeedEntry entry = new FeedEntryImpl(feed, "test entry", new LinkImpl( "http://localhost:8080/feeds/rss/2.0/test/testentry"), "http://localhost:8080/feeds/rss/2.0/test/testentry"); entry.addEnclosure(new EnclosureImpl("http://www.example.com/video.mp4", "video/mp4", "presenter/delivery", 12)); feed.addEntry(entry); ITunesFeedExtension itunesmodule = new ITunesFeedExtension(); itunesmodule.addKeyword("test"); List<String> categories = new LinkedList<String>(); categories.add("Higher Education"); itunesmodule.setCategories(categories); feed.addModule(itunesmodule); DublinCoreExtension dcModule = new DublinCoreExtension(); feed.addModule(dcModule); Assert.assertEquals(feed.getAuthors().get(0).getName(), "Test User"); Assert.assertEquals(feed.getAuthors().get(0).getEmail(), "testuser@example.com"); Assert.assertEquals(feed.getContributors().get(0).getName(), "test university"); Assert.assertEquals(feed.getTitle().getValue(), "Test Feed"); Assert.assertEquals(feed.getDescription().getType(), "text/html"); Assert.assertEquals(feed.getType(), Type.RSS); Assert.assertEquals(feed.getLink(), "http://localhost:8080/feeds/rss/2.0/test"); } catch (Exception e) { Assert.fail(); } // Todo test Services... but this cannot be done outside OSGI and the servlet Container, so this has to be done by // an integration test. } @Test public void setterGetterTest() { instance.setTitle("text"); logger.info(instance.getTitle().getValue()); Assert.assertEquals(instance.getTitle().getValue(), "text"); instance.setLink("http://localhost:8080/feeds/rss/2.0/test"); Assert.assertEquals(instance.getLink(), "http://localhost:8080/feeds/rss/2.0/test"); instance.setCopyright("text"); Assert.assertEquals(instance.getCopyright(), "text"); List<Person> person = new ArrayList<Person>(); instance.setAuthors(person); Assert.assertEquals(instance.getAuthors(), person); instance.setContributors(person); Assert.assertEquals(instance.getContributors(), person); instance.setUri("http://testuri/"); Assert.assertEquals(instance.getUri(), "http://testuri/"); List<Category> category = new ArrayList<Category>(); instance.setCategories(category); Assert.assertEquals(instance.getCategories(), category); instance.setDescription("description"); Assert.assertEquals(instance.getDescription().getValue(), "description"); Content content = new ContentImpl("desciption"); instance.setDescription(content); Assert.assertEquals(instance.getDescription(), content); instance.setEncoding("encode"); Assert.assertEquals(instance.getEncoding(), "encode"); List<FeedEntry> feed = new ArrayList<FeedEntry>(); instance.setEntries(feed); Assert.assertEquals(instance.getEntries(), feed); Image image = new ImageImpl("http://picture/"); instance.setImage(image); Assert.assertEquals(instance.getImage(), image); instance.setLanguage("English"); Assert.assertEquals(instance.getLanguage(), "English"); List<Link> link = new ArrayList<Link>(); instance.setLinks(link); Assert.assertEquals(instance.getLinks(), link); List<FeedExtension> feedExtension = new ArrayList<FeedExtension>(); instance.setModules(feedExtension); Assert.assertEquals(instance.getModules(), feedExtension); Date date = new Date(21091981); instance.setPublishedDate(date); Assert.assertEquals(instance.getPublishedDate(), date); instance.setUpdatedDate(date); Assert.assertEquals(instance.getUpdatedDate(), date); instance.setTitle(content); Assert.assertEquals(instance.getTitle(), content); } @Test public void addLink() { //Link link = new LinkImpl("http://link/"); instance.addLink(null); Assert.assertNotNull(instance.getLink()); } @Test public void addEntry() { instance.addEntry(null); Assert.assertNotNull(instance.getEntries()); } @Test public void getModuleByString() { instance.setModules(null); FeedExtension feedext = EasyMock.createNiceMock(FeedExtension.class); EasyMock.expect(feedext.getUri()).andReturn("module"); EasyMock.replay(feedext); instance.addModule(feedext); Assert.assertEquals(instance.getModule("module"), feedext); Assert.assertNotSame(instance.getModule("false"), feedext); } }