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);
}
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);
}
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;
}
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);
}
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;
}
Aggregations