Search in sources :

Example 6 with SyndEnclosure

use of com.rometools.rome.feed.synd.SyndEnclosure in project openolat by klemens.

the class RomeFeedFetcherTest method convertEntry.

@Test
public void convertEntry() {
    // prepare the mock
    String author = "author";
    when(syndEntryMock.getAuthor()).thenReturn(author);
    String description = "description";
    when(syndEntryMock.getDescription().getValue()).thenReturn(description);
    String link = "link";
    when(syndEntryMock.getLink()).thenReturn(link);
    String title = "title";
    when(syndEntryMock.getTitle()).thenReturn(title);
    String uri = "uri";
    when(syndEntryMock.getUri()).thenReturn(uri);
    Date publishedDate = new Date();
    when(syndEntryMock.getPublishedDate()).thenReturn(publishedDate);
    Date updatedDate = new Date();
    when(syndEntryMock.getUpdatedDate()).thenReturn(updatedDate);
    List<SyndContent> contents = Arrays.asList(syndContentMock);
    when(syndEntryMock.getContents()).thenReturn(contents);
    when(syndEnclosureMock.getUrl()).thenReturn("URL");
    List<SyndEnclosure> enclosures = Arrays.asList(syndEnclosureMock);
    when(syndEntryMock.getEnclosures()).thenReturn(enclosures);
    // call the method
    Item item = sut.convertEntry(feedMock, syndEntryMock);
    // test
    assertThat(item.getFeed()).isEqualTo(feedMock);
    assertThat(item.getAuthor()).isEqualTo(author);
    assertThat(item.getContent()).isNotNull();
    assertThat(item.getDescription()).isEqualTo(description);
    assertThat(item.getEnclosure()).isNotNull();
    assertThat(item.getExternalLink()).isEqualTo(link);
    assertThat(item.getTitle()).isEqualTo(title);
    assertThat(item.getGuid()).isEqualTo(uri);
    assertThat(item.getLastModified()).isEqualTo(updatedDate);
    assertThat(item.getPublishDate()).isEqualTo(publishedDate);
}
Also used : Item(org.olat.modules.webFeed.Item) SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) Date(java.util.Date) Test(org.junit.Test)

Example 7 with SyndEnclosure

use of com.rometools.rome.feed.synd.SyndEnclosure in project openolat by klemens.

the class RomeFeedFetcherTest method convertEnclosures.

@Test
public void convertEnclosures() {
    Long length = 1l;
    when(syndEnclosureMock.getLength()).thenReturn(length);
    String type = "type";
    when(syndEnclosureMock.getType()).thenReturn(type);
    String url = "url";
    when(syndEnclosureMock.getUrl()).thenReturn(url);
    List<SyndEnclosure> enclosures = Arrays.asList(syndEnclosureMock);
    Enclosure enclosure = sut.convertEnclosures(enclosures);
    assertThat(enclosure.getExternalUrl()).isEqualTo(url);
    assertThat(enclosure.getLength()).isEqualTo(length);
    assertThat(enclosure.getType()).isEqualTo(type);
}
Also used : SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) Enclosure(org.olat.modules.webFeed.Enclosure) Test(org.junit.Test)

Example 8 with SyndEnclosure

use of com.rometools.rome.feed.synd.SyndEnclosure in project openolat by klemens.

the class RomeFeedFetcher method convertEntry.

/**
 * Converts a <code>SyndEntry</code> into an <code>Item</code>
 *
 * @param entry
 * @return
 */
protected Item convertEntry(Feed feed, SyndEntry entry) {
    Item item = new ItemImpl(feed);
    item.setAuthor(entry.getAuthor());
    item.setExternalLink(entry.getLink());
    item.setGuid(entry.getUri());
    item.setLastModified(entry.getUpdatedDate());
    item.setPublishDate(entry.getPublishedDate());
    item.setTitle(entry.getTitle());
    if (entry.getDescription() != null) {
        item.setDescription(entry.getDescription().getValue());
    }
    List<SyndContent> contents = entry.getContents();
    item.setContent(joinContents(contents));
    List<SyndEnclosure> enclosures = entry.getEnclosures();
    item.setEnclosure(convertEnclosures(enclosures));
    return item;
}
Also used : Item(org.olat.modules.webFeed.Item) SyndContent(com.rometools.rome.feed.synd.SyndContent) ItemImpl(org.olat.modules.webFeed.model.ItemImpl) SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure)

Example 9 with SyndEnclosure

use of com.rometools.rome.feed.synd.SyndEnclosure in project OpenOLAT by OpenOLAT.

the class RomeFeedFetcherTest method convertEntry.

@Test
public void convertEntry() {
    // prepare the mock
    String author = "author";
    when(syndEntryMock.getAuthor()).thenReturn(author);
    String description = "description";
    when(syndEntryMock.getDescription().getValue()).thenReturn(description);
    String link = "link";
    when(syndEntryMock.getLink()).thenReturn(link);
    String title = "title";
    when(syndEntryMock.getTitle()).thenReturn(title);
    String uri = "uri";
    when(syndEntryMock.getUri()).thenReturn(uri);
    Date publishedDate = new Date();
    when(syndEntryMock.getPublishedDate()).thenReturn(publishedDate);
    Date updatedDate = new Date();
    when(syndEntryMock.getUpdatedDate()).thenReturn(updatedDate);
    List<SyndContent> contents = Arrays.asList(syndContentMock);
    when(syndEntryMock.getContents()).thenReturn(contents);
    when(syndEnclosureMock.getUrl()).thenReturn("URL");
    List<SyndEnclosure> enclosures = Arrays.asList(syndEnclosureMock);
    when(syndEntryMock.getEnclosures()).thenReturn(enclosures);
    // call the method
    Item item = sut.convertEntry(feedMock, syndEntryMock);
    // test
    assertThat(item.getFeed()).isEqualTo(feedMock);
    assertThat(item.getAuthor()).isEqualTo(author);
    assertThat(item.getContent()).isNotNull();
    assertThat(item.getDescription()).isEqualTo(description);
    assertThat(item.getEnclosure()).isNotNull();
    assertThat(item.getExternalLink()).isEqualTo(link);
    assertThat(item.getTitle()).isEqualTo(title);
    assertThat(item.getGuid()).isEqualTo(uri);
    assertThat(item.getLastModified()).isEqualTo(updatedDate);
    assertThat(item.getPublishDate()).isEqualTo(publishedDate);
}
Also used : Item(org.olat.modules.webFeed.Item) SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) Date(java.util.Date) Test(org.junit.Test)

Example 10 with SyndEnclosure

use of com.rometools.rome.feed.synd.SyndEnclosure in project OpenOLAT by OpenOLAT.

the class RomeFeedFetcher method convertEnclosures.

/**
 * Converts a List of <code>SyndEnclosures</code> into an <code>Enclosure</code>.
 * Only one media file is supported. If the List has more than one entry, the
 * first entry is taken.
 * SyndEnclosures without an URL are not converted, because it is necessary to
 * fetch the enclosure.
 *
 * @param enclosures
 * @return the enclosure or null
 */
protected Enclosure convertEnclosures(List<SyndEnclosure> enclosures) {
    if (enclosures == null || enclosures.isEmpty())
        return null;
    SyndEnclosure syndEnclosure = enclosures.get(0);
    Enclosure enclosure = null;
    if (StringHelper.containsNonWhitespace(syndEnclosure.getUrl())) {
        enclosure = new EnclosureImpl();
        enclosure.setExternalUrl(syndEnclosure.getUrl());
        enclosure.setLength(syndEnclosure.getLength());
        enclosure.setType(syndEnclosure.getType());
    }
    return enclosure;
}
Also used : SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) Enclosure(org.olat.modules.webFeed.Enclosure) SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) EnclosureImpl(org.olat.modules.webFeed.model.EnclosureImpl)

Aggregations

SyndEnclosure (com.rometools.rome.feed.synd.SyndEnclosure)15 Test (org.junit.Test)8 Enclosure (org.olat.modules.webFeed.Enclosure)8 SyndContent (com.rometools.rome.feed.synd.SyndContent)5 Item (org.olat.modules.webFeed.Item)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 EnclosureImpl (org.olat.modules.webFeed.model.EnclosureImpl)2 ItemImpl (org.olat.modules.webFeed.model.ItemImpl)2 GeoRSSModule (com.rometools.modules.georss.GeoRSSModule)1 Position (com.rometools.modules.georss.geometries.Position)1 MediaEntryModule (com.rometools.modules.mediarss.MediaEntryModule)1 MediaContent (com.rometools.modules.mediarss.types.MediaContent)1 PlayerReference (com.rometools.modules.mediarss.types.PlayerReference)1 UrlReference (com.rometools.modules.mediarss.types.UrlReference)1 SyndCategory (com.rometools.rome.feed.synd.SyndCategory)1 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)1 SyndEnclosureImpl (com.rometools.rome.feed.synd.SyndEnclosureImpl)1 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)1 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)1