REST-Client Library: unit tests cleanup

Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/cbf5e418
Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/cbf5e418
Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/cbf5e418

Branch: refs/heads/master
Commit: cbf5e418cc6efa38bc69251bf2f1f95606741b10
Parents: 1166673
Author: Paul Merlin <[email protected]>
Authored: Fri Feb 15 15:01:19 2013 +0100
Committer: Paul Merlin <[email protected]>
Committed: Fri Feb 15 15:01:19 2013 +0100

----------------------------------------------------------------------
 .../qi4j/library/rest/client/RssReaderTest.java | 61 +++++++-------------
 1 file changed, 21 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/cbf5e418/libraries/rest-client/src/test/java/org/qi4j/library/rest/client/RssReaderTest.java
----------------------------------------------------------------------
diff --git 
a/libraries/rest-client/src/test/java/org/qi4j/library/rest/client/RssReaderTest.java
 
b/libraries/rest-client/src/test/java/org/qi4j/library/rest/client/RssReaderTest.java
index 76eb8a2..52d7e11 100644
--- 
a/libraries/rest-client/src/test/java/org/qi4j/library/rest/client/RssReaderTest.java
+++ 
b/libraries/rest-client/src/test/java/org/qi4j/library/rest/client/RssReaderTest.java
@@ -9,7 +9,6 @@ import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
 import org.junit.Test;
-import org.qi4j.api.value.ValueBuilder;
 import org.qi4j.bootstrap.AssemblyException;
 import org.qi4j.bootstrap.ModuleAssembly;
 import org.qi4j.library.rest.client.api.ContextResourceClient;
@@ -20,7 +19,6 @@ import org.qi4j.library.rest.client.spi.ResponseHandler;
 import org.qi4j.library.rest.client.spi.ResponseReader;
 import org.qi4j.library.rest.client.spi.ResultHandler;
 import org.qi4j.library.rest.common.ValueAssembler;
-import org.qi4j.library.rest.common.link.Link;
 import org.qi4j.test.AbstractQi4jTest;
 import org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler;
 import org.restlet.Client;
@@ -35,12 +33,14 @@ import org.w3c.dom.NodeList;
 import static org.qi4j.library.rest.client.api.HandlerCommand.*;
 
 /**
- * Reads my RSS feed and prints out all comments for each entry. This is an 
example of how
- * to use the RSS client for something more generic that was not produced by 
Qi4j REST server library.
+ * Reads Qi4j Github commits on develop ATOM feed and prints out all title and 
detail url for each entry.
+ * This is an example of how to use the RSS client for something more generic 
that was not produced by Qi4j REST server
+ * library.
  */
 public class RssReaderTest
     extends AbstractQi4jTest
 {
+
     private ContextResourceClient crc;
 
     @Override
@@ -56,7 +56,7 @@ public class RssReaderTest
     @Test
     public void testReadRssFeed()
     {
-        Client client = new Client( Protocol.HTTP );
+        Client client = new Client( Protocol.HTTPS );
         Reference ref = new Reference( 
"https://github.com/Qi4j/qi4j-sdk/commits/develop.atom"; );
         ContextResourceClientFactory contextResourceClientFactory = 
module.newObject( ContextResourceClientFactory.class, client );
 
@@ -66,7 +66,7 @@ public class RssReaderTest
             public Object readResponse( Response response, Class<?> resultType 
)
                 throws ResourceException
             {
-                if (resultType.equals( Document.class ))
+                if( resultType.equals( Document.class ) )
                 {
                     try
                     {
@@ -80,7 +80,7 @@ public class RssReaderTest
                     }
                 }
 
-                return null;  //To change body of implemented methods use File 
| Settings | File Templates.
+                return null;
             }
         } );
 
@@ -89,7 +89,7 @@ public class RssReaderTest
             @Override
             public HandlerCommand handleResponse( Response response, 
ContextResourceClient client )
             {
-                // Try to restart
+                System.out.println( ">> REFRESH on recoverable error: " + 
response.getStatus() );
                 return refresh();
             }
         } ) );
@@ -107,12 +107,14 @@ public class RssReaderTest
                 {
                     final XPath xPath = XPathFactory.newInstance().newXPath();
 
-                    System.out.println( "== "+xPath.evaluate( 
"rss/channel/title", result )+" ==");
+                    System.out.println( "== " + xPath.evaluate( "feed/title", 
result ) + " ==" );
 
-                    final NodeList nodes = (NodeList)xPath.evaluate( 
"rss/channel/item", result, XPathConstants.NODESET);
+                    final NodeList nodes = (NodeList) xPath.evaluate( 
"feed/entry", result, XPathConstants.NODESET );
                     List<Node> items = new ArrayList<Node>();
-                    for (int i = 0; i < nodes.getLength(); i++)
+                    for( int i = 0; i < nodes.getLength(); i++ )
+                    {
                         items.add( nodes.item( i ) );
+                    }
 
                     itemNodes = items.iterator();
 
@@ -127,41 +129,20 @@ public class RssReaderTest
             private HandlerCommand processEntry( final XPath xPath )
                 throws XPathExpressionException
             {
-                if (!itemNodes.hasNext())
+                if( !itemNodes.hasNext() )
+                {
                     return null;
+                }
 
                 Node item = itemNodes.next();
 
-                System.out.println( "-- "+xPath.evaluate( "title", item )+" 
--" );
-                String commentUrl = xPath.evaluate( "commentRss", item );
+                String title = xPath.evaluate( "title", item );
+                String detailUrl = xPath.evaluate( "link/@href", item );
 
-                ValueBuilder<Link> link = module.newValueBuilder( Link.class );
-                link.prototype().rel().set( "item" );
-                link.prototype().id().set( "item" );
-                link.prototype().href().set( commentUrl );
+                System.out.println( "-- " + title + " --" );
+                System.out.println( "-- " + detailUrl + " --" );
 
-                return query( link.newInstance() ).onSuccess( new 
ResultHandler<Document>()
-                    {
-                        @Override
-                        public HandlerCommand handleResult( Document result, 
ContextResourceClient client )
-                        {
-                            try
-                            {
-                                final NodeList comments = 
(NodeList)xPath.evaluate( "rss/channel/item", result, XPathConstants.NODESET);
-                                for (int i = 0; i < comments.getLength(); i++)
-                                {
-                                    System.out.println( xPath.evaluate( 
"description", comments.item( i ) ));
-                                    System.out.println( "---");
-                                }
-
-                                return processEntry( xPath );
-                            }
-                            catch( XPathExpressionException e )
-                            {
-                                throw new ResourceException( e );
-                            }
-                        }
-                    } );
+                return processEntry( xPath );
             }
         } );
 

Reply via email to