/*
 * (C) Janne Jalkanen 2005
 * 
 */
package com.ecyrd.jspwiki.rss;

import java.io.File;
import java.util.Date;
import java.util.List;
import java.util.Properties;

import com.ecyrd.jspwiki.TestEngine;
import com.ecyrd.jspwiki.WikiContext;
import com.ecyrd.jspwiki.WikiEngine;
import com.ecyrd.jspwiki.plugin.WeblogEntryPlugin;
import com.ecyrd.jspwiki.plugin.WeblogPlugin;
import com.ecyrd.jspwiki.providers.FileSystemProvider;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 *  @author jalkanen
 *
 *  @since 
 */
public class RSSGeneratorTest extends TestCase
{
    TestEngine m_testEngine;
    Properties props = new Properties();
    
    public RSSGeneratorTest( String arg0 )
    {
        super( arg0 );
    }

    protected void setUp() throws Exception
    {
        props.load( TestEngine.findTestProperties() );

        props.setProperty( WikiEngine.PROP_BASEURL, "http://localhost/" );
        props.setProperty( RSSGenerator.PROP_GENERATE_RSS, "true" );
        m_testEngine = new TestEngine(props);
    }

    protected void tearDown() throws Exception
    {
        TestEngine.deleteAll( new File(props.getProperty( FileSystemProvider.PROP_PAGEDIR )) );
    }

    public void testBlogRSS()
        throws Exception
    {
        WeblogEntryPlugin plugin = new WeblogEntryPlugin();
        m_testEngine.saveText( "TestBlog", "Foo1" );
        
        String newPage = plugin.getNewEntryPage( m_testEngine, "TestBlog" );
        m_testEngine.saveText( newPage, "!Title1\r\nFoo" );
                
        newPage = plugin.getNewEntryPage( m_testEngine, "TestBlog" );
        m_testEngine.saveText( newPage, "!Title2\r\n__Bar__" );
        
        RSSGenerator gen = m_testEngine.getRSSGenerator();
        
        WikiContext context = new WikiContext( m_testEngine, m_testEngine.getPage("TestBlog") );
        
        WeblogPlugin blogplugin = new WeblogPlugin();
        
        List entries = blogplugin.findBlogEntries( m_testEngine.getPageManager(),
                                                   "TestBlog",
                                                   new Date(0),
                                                   new Date(Long.MAX_VALUE) );
        
        Feed feed = new RSS10Feed( context );
        String blog = gen.generateBlogRSS( context, entries, feed );
        
        assertTrue( "has Foo", blog.indexOf("<description>Foo</description>") != -1 );
        assertTrue( "has proper Bar", blog.indexOf("&lt;b&gt;Bar&lt;/b&gt;") != -1 );
    }
    
    public void testBlogRSS2()
        throws Exception
    {
        WeblogEntryPlugin plugin = new WeblogEntryPlugin();
        m_testEngine.saveText( "TestBlog", "Foo1" );
    
        String newPage = plugin.getNewEntryPage( m_testEngine, "TestBlog" );
        m_testEngine.saveText( newPage, "!Title1\r\nFoo \"blah\"." );
            
        newPage = plugin.getNewEntryPage( m_testEngine, "TestBlog" );
        m_testEngine.saveText( newPage, "!Title2\r\n__Bar__" );
    
        RSSGenerator gen = m_testEngine.getRSSGenerator();
    
        WikiContext context = new WikiContext( m_testEngine, m_testEngine.getPage("TestBlog") );
    
        WeblogPlugin blogplugin = new WeblogPlugin();
    
        List entries = blogplugin.findBlogEntries( m_testEngine.getPageManager(),
                                                   "TestBlog",
                                                   new Date(0),
                                                   new Date(Long.MAX_VALUE) );
    
        Feed feed = new RSS20Feed( context );
        String blog = gen.generateBlogRSS( context, entries, feed );
    
        assertTrue( "has Foo", blog.indexOf("<description>Foo \"blah\".</description>") != -1 );
        assertTrue( "has proper Bar", blog.indexOf("&lt;b&gt;Bar&lt;/b&gt;") != -1 );
    }
    public static Test suite()
    {
        return new TestSuite( RSSGeneratorTest.class );
    }

}

@@ -25,18 +25,17 @@
  2005%0A *
- 
 %0A
+
  */%0Apack
@@ -559,17 +559,16 @@
   @since
- 
 %0A */%0Apub
@@ -679,29 +679,25 @@
 operties();%0A
-    
 %0A
+
     public R
@@ -1392,33 +1392,25 @@
 , %22Foo1%22 );%0A
-        
 %0A
+
         Stri
@@ -1538,25 +1538,9 @@
  );%0A
-                
 %0A
+
     
@@ -1665,33 +1665,25 @@
 __Bar__%22 );%0A
-        
 %0A
+
         RSSG
@@ -1725,33 +1725,25 @@
 enerator();%0A
-        
 %0A
+
         Wiki
@@ -1823,33 +1823,25 @@
 stBlog%22) );%0A
-        
 %0A
+
         Webl
@@ -1882,25 +1882,17 @@
 ugin();%0A
-        
 %0A
+
         
@@ -2167,33 +2167,25 @@
 X_VALUE) );%0A
-        
 %0A
+
         Feed
@@ -2287,25 +2287,17 @@
 feed );%0A
-        
 %0A
+
         
@@ -2467,21 +2467,17 @@
 ;%0A    %7D%0A
-    
 %0A
+
     publ
@@ -2639,29 +2639,25 @@
 , %22Foo1%22 );%0A
-    
 %0A
+
         Stri
@@ -2795,21 +2795,9 @@
  );%0A
-            
 %0A
+
     
@@ -2922,29 +2922,25 @@
 __Bar__%22 );%0A
-    
 %0A
+
         RSSG
@@ -2982,29 +2982,25 @@
 enerator();%0A
-    
 %0A
+
         Wiki
@@ -3080,29 +3080,25 @@
 stBlog%22) );%0A
-    
 %0A
+
         Webl
@@ -3139,21 +3139,17 @@
 ugin();%0A
-    
 %0A
+
         
@@ -3424,29 +3424,25 @@
 X_VALUE) );%0A
-    
 %0A
+
         Feed
@@ -3544,20 +3544,16 @@
 feed );%0A
-    
 %0A       
@@ -3607,24 +3607,40 @@
 ion%3EFoo 
-%5C%22blah%5C%22
+&amp;quot;blah&amp;quot;
 .%3C/descr

Removed extra whitespace