abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r619583 - in /incubator/abdera/java/trunk/server/src: main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java
Date Thu, 07 Feb 2008 19:23:58 GMT
Author: dandiep
Date: Thu Feb  7 11:23:50 2008
New Revision: 619583

URL: http://svn.apache.org/viewvc?rev=619583&view=rev
Log:
ABDERA-101: make non-root context paths work for real now.

Modified:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java?rev=619583&r1=619582&r2=619583&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
Thu Feb  7 11:23:50 2008
@@ -210,16 +210,16 @@
               sw.startWorkspace()
                 .writeTitle(wi.getTitle(request));
               for (CollectionInfo ci : wi.getCollections(request)) {
-                sw.startCollection(request.getTargetBasePath() + ci.getHref(request))
+                sw.startCollection(ci.getHref(request))
                   .writeTitle(ci.getTitle(request))
                   .writeAccepts(ci.getAccepts(request));
                 CategoriesInfo[] catinfos = ci.getCategoriesInfo(request);
                 if (catinfos != null) {
                   for (CategoriesInfo catinfo : catinfos) {
-                    String href = catinfo.getHref(request);
-                    if (href != null) {
+                    String cathref = catinfo.getHref(request);
+                    if (cathref != null) {
                       sw.startCategories()
-                        .writeAttribute("href", request.getTargetBasePath() + href)
+                        .writeAttribute("href", request.getTargetBasePath() + cathref)
                         .endCategories();
                     } else {
                       sw.startCategories(

Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java?rev=619583&r1=619582&r2=619583&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java
(original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java
Thu Feb  7 11:23:50 2008
@@ -11,8 +11,13 @@
 import org.apache.abdera.factory.Factory;
 import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.model.Base;
+import org.apache.abdera.model.Collection;
+import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Element;
 import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Service;
+import org.apache.abdera.model.Workspace;
+import org.apache.abdera.protocol.Response.ResponseType;
 import org.apache.abdera.protocol.client.AbderaClient;
 import org.apache.abdera.protocol.client.ClientResponse;
 import org.apache.abdera.protocol.client.RequestOptions;
@@ -20,6 +25,8 @@
 import org.apache.abdera.protocol.server.impl.DefaultProvider;
 import org.apache.abdera.protocol.server.impl.SimpleWorkspaceInfo;
 import org.apache.abdera.protocol.server.servlet.AbderaServlet;
+import org.apache.abdera.util.Constants;
+import org.apache.abdera.util.MimeTypeHelper;
 import org.junit.After;
 import org.junit.Test;
 import org.mortbay.jetty.Server;
@@ -33,14 +40,14 @@
 
   private void setupAbdera(String base) throws Exception {
     customerProvider = new DefaultProvider(base);
-    
+
     CustomerAdapter ca = new CustomerAdapter();
     ca.setHref("customers");
-    
+
     SimpleWorkspaceInfo wi = new SimpleWorkspaceInfo();
     wi.setTitle("Customer Workspace");
     wi.addCollection(ca);
-    
+
     customerProvider.addWorkspace(wi);
   }
 
@@ -48,26 +55,34 @@
   public void testCustomerProvider() throws Exception {
     setupAbdera("/");
     initializeJetty("/");
-    
+
     runTests("/");
-  }  
-  
+  }
+
   @Test
-  public void testCustomerProviderWithDifferentContextPath() throws Exception {
+  public void testCustomerProviderWithNonRootContextPath() throws Exception {
     setupAbdera("/");
     initializeJetty("/foo");
-    
+
     runTests("/foo/");
   }
-  
+
   @Test
-  public void testCustomerProviderWithDifferentBase() throws Exception {
+  public void testCustomerProviderWithNonRootBase() throws Exception {
     setupAbdera("/:base/");
     initializeJetty("/");
-    
+
     runTests("/base/");
   }
 
+  @Test
+  public void testCustomerProviderWithNonRootContextBaseAndBase() throws Exception {
+    setupAbdera("/:base/");
+    initializeJetty("/foo");
+
+    runTests("/foo/base/");
+  }
+
   private void runTests(String base) throws IOException {
     Abdera abdera = new Abdera();
     Factory factory = abdera.getFactory();
@@ -75,31 +90,59 @@
     AbderaClient client = new AbderaClient(abdera);
 
     String uri = "http://localhost:9002" + base;
-    
+
+    // Service document test.
+
+    ClientResponse res = client.get(uri);
+    assertNotNull(res);
+    try {
+      assertEquals(200, res.getStatus());
+      assertEquals(ResponseType.SUCCESS, res.getType());
+      assertTrue(MimeTypeHelper.isMatch(res.getContentType().toString(), Constants.APP_MEDIA_TYPE));
+
+      Document<Service> doc = res.getDocument();
+      Service service = doc.getRoot();
+      assertEquals(1, service.getWorkspaces().size());
+
+      Workspace workspace = service.getWorkspaces().get(0);
+      assertEquals(1, workspace.getCollections().size());
+
+      // Keep the loop in case we add other collections to the test.
+
+      for (Collection collection : workspace.getCollections()) {
+        if (collection.getTitle().equals("Acme Customer Database")) {
+          String expected = uri + "customers";
+          String actual = collection.getResolvedHref().toString();
+          assertEquals(expected, actual);
+        }
+      }
+    } finally {
+      res.release();
+    }
+
     // Testing of entry creation
-    IRI colUri = new IRI(uri).resolve("customers"); 
-                                                          
+    IRI colUri = new IRI(uri).resolve("customers");
+
     Entry entry = factory.newEntry();
     entry.setTitle("This is ignored right now");
     entry.setUpdated(new Date());
     entry.addAuthor("Acme Industries");
     entry.setId(factory.newUuidUri());
     entry.setSummary("Customer document");
-    
+
     Element customerEl = factory.newElement(new QName("customer"));
     customerEl.setAttributeValue(new QName("name"), "Dan Diephouse");
     entry.setContent(customerEl);
 
     RequestOptions opts = new RequestOptions();
     opts.setContentType("application/atom+xml;type=entry");
-    ClientResponse res = client.post(colUri.toString() + "?test=foo", entry, opts);
+    res = client.post(colUri.toString() + "?test=foo", entry, opts);
     assertEquals(201, res.getStatus());
 
     prettyPrint(abdera, res.getDocument());
 
     IRI location = res.getLocation();
-    assertEquals(base + "customers/1001-Dan_Diephouse", 
-                 location.toString());
+    assertEquals(base + "customers/1001-Dan_Diephouse", location.toString());
 
     // GET the entry
     res = client.get(colUri.resolve(location.toString()).toString());
@@ -111,13 +154,13 @@
     prettyPrint(abdera, entry_doc);
     entry = entry_doc.getRoot();
     assertEquals(uri + "customers/1001-Dan_Diephouse", entry_doc.getRoot().getEditLinkResolvedHref().toString());
-    
+
     // HEAD
     res = client.head(colUri.resolve(location.toString()).toString());
     assertEquals(200, res.getStatus());
     assertEquals(0, res.getContentLength());
     res.release();
-    
+
     // Try invalid resources
     res = client.get(colUri + "/foobar");
     assertEquals(404, res.getStatus());
@@ -130,13 +173,13 @@
   }
 
   protected void prettyPrint(Abdera abdera, Base doc) throws IOException {
-//    WriterFactory factory = abdera.getWriterFactory();
-//    Writer writer = factory.getWriter("prettyxml");
-//    writer.writeTo(doc, System.out);
-//    System.out.println();
+    // WriterFactory factory = abdera.getWriterFactory();
+    // Writer writer = factory.getWriter("prettyxml");
+    // writer.writeTo(doc, System.out);
+    // System.out.println();
   }
 
-  @SuppressWarnings("serial") 
+  @SuppressWarnings("serial")
   private void initializeJetty(String contextPath) throws Exception {
 
     server = new Server(9002);
@@ -154,7 +197,8 @@
 
   @After
   public void tearDown() throws Exception {
-    if (server != null) server.stop();
+    if (server != null)
+      server.stop();
   }
 
 }



Mime
View raw message