FileDocCategorySizeDatePackage
TestGDataResponse.javaAPI DocApache Lucene 2.1.06889Wed Feb 14 10:46:02 GMT 2007org.apache.lucene.gdata.server

TestGDataResponse

public class TestGDataResponse extends TestCase
author
Simon Willnauer

Fields Summary
private GDataResponse
response
private HttpServletResponse
httpResponse
private org.easymock.MockControl
control
private static String
generatedFeedAtom
private static String
generatedEntryAtom
private static String
generatedFeedRSS
private static String
generatedEntryRSS
Constructors Summary
Methods Summary
private com.google.gdata.data.EntrycreateEntry()

 
        Entry e = new Entry(); 
        e.setTitle(new PlainTextConstruct("Test")); 
        return e; 
    
private com.google.gdata.data.FeedcreateFeed()

 
        Feed feed = new Feed(); 
         
        feed.getEntries().add(createEntry()); 
         
        return feed; 
    
protected voidsetUp()

 
          
        this.control = MockControl.createControl(HttpServletResponse.class); 
        this.httpResponse = (HttpServletResponse)this.control.getMock(); 
        this.response = new GDataResponse(this.httpResponse); 
         
    
protected voidtearDown()

 
        super.tearDown(); 
    
public voidtestConstructor()

 
        try{ 
        new GDataResponse(null); 
        fail("IllegalArgumentExceptin expected"); 
        }catch (IllegalArgumentException e) { 
            // TODO: handle exception 
        } 
    
public voidtestSendResponseBaseEntryExtensionProfile()

 
        try{ 
            Entry e = null; 
            this.response.sendResponse(e, new ProvidedServiceStub()); 
            fail("Exception expected"); 
        }catch (IllegalArgumentException e) { 
            // 
        } 
        try{ 
            Entry e = createEntry(); 
            this.response.sendResponse(e,null); 
            fail("Exception expected"); 
        }catch (IllegalArgumentException e) { 
            // 
        } 
//        // test Atom output 
        StringWriter stringWriter = new StringWriter(); 
        PrintWriter writer = new PrintWriter(stringWriter); 
         
        this.control.expectAndReturn(this.httpResponse.getWriter(),writer); 
        this.httpResponse.setContentType(GDataResponse.XMLMIME_ATOM);
        this.response.setOutputFormat(OutputFormat.ATOM); 
        this.control.replay(); 
         
        this.response.sendResponse(createEntry(), new ProvidedServiceStub()); 
        assertEquals("Simple XML representation ATOM",stringWriter.toString(),generatedEntryAtom); 
         
        // test rss output 
        this.control.reset(); 
        stringWriter = new StringWriter(); 
        writer = new PrintWriter(stringWriter); 
         
        this.control.expectAndReturn(this.httpResponse.getWriter(),writer); 
        this.httpResponse.setContentType(GDataResponse.XMLMIME_RSS);
        this.response.setOutputFormat(OutputFormat.RSS); 
        this.control.replay(); 
         
        this.response.sendResponse(createEntry(), new ProvidedServiceStub()); 
         
        assertEquals("Simple XML representation RSS",stringWriter.toString(),generatedEntryRSS); 
         
         
         
    
public voidtestSendResponseBaseFeedExtensionProfile()

 
        try{ 
            Feed f = null; 
            this.response.sendResponse(f, new ProvidedServiceStub()); 
            fail("Exception expected"); 
        }catch (IllegalArgumentException e) { 
            // 
        } 
         
        try{ 
            Feed f = createFeed(); 
            this.response.sendResponse(f,null); 
            fail("Exception expected"); 
        }catch (IllegalArgumentException e) { 
            // 
        } 
        StringWriter stringWriter = new StringWriter(); 
        PrintWriter writer = new PrintWriter(stringWriter); 
         
        this.control.expectAndReturn(this.httpResponse.getWriter(),writer);
        this.httpResponse.setContentType(GDataResponse.XMLMIME_ATOM);
        this.response.setOutputFormat(OutputFormat.ATOM); 
        this.control.replay(); 
         
        this.response.sendResponse(createFeed(), new ProvidedServiceStub()); 
        assertEquals("Simple XML representation",stringWriter.toString(),generatedFeedAtom); 
        this.control.reset(); 
         
        stringWriter = new StringWriter(); 
        writer = new PrintWriter(stringWriter); 
         
        this.control.expectAndReturn(this.httpResponse.getWriter(),writer); 
        this.response.setOutputFormat(OutputFormat.RSS); 
        this.httpResponse.setContentType(GDataResponse.XMLMIME_RSS);
        this.control.replay(); 
         
        this.response.sendResponse(createFeed(), new ProvidedServiceStub()); 
        assertEquals("Simple XML representation",stringWriter.toString(),generatedFeedRSS);