Use root folder for display URL when list default view is empty

Code Review : https://codereview.appspot.com/77110043/
diff --git a/src/com/google/enterprise/adaptor/sharepoint/RareModificationCache.java b/src/com/google/enterprise/adaptor/sharepoint/RareModificationCache.java
index 1dc17f4..6fc5805 100644
--- a/src/com/google/enterprise/adaptor/sharepoint/RareModificationCache.java
+++ b/src/com/google/enterprise/adaptor/sharepoint/RareModificationCache.java
@@ -238,7 +238,9 @@
       this.anonymousPermMask
           = l.getMetadata().getAnonymousPermMask().longValue();
       this.rootFolder = l.getMetadata().getRootFolder();
-      this.defaultViewUrl = l.getMetadata().getDefaultViewUrl();
+      this.defaultViewUrl = "/".equals(l.getMetadata().getDefaultViewUrl()) 
+          ? l.getMetadata().getRootFolder() 
+          : l.getMetadata().getDefaultViewUrl();
       this.defaultViewItemUrl = l.getMetadata().getDefaultViewItemUrl();
       this.scopeId = l.getMetadata().getScopeID();
     }
diff --git a/src/com/google/enterprise/adaptor/sharepoint/SharePointAdaptor.java b/src/com/google/enterprise/adaptor/sharepoint/SharePointAdaptor.java
index 3ee29fd..4500ef4 100644
--- a/src/com/google/enterprise/adaptor/sharepoint/SharePointAdaptor.java
+++ b/src/com/google/enterprise/adaptor/sharepoint/SharePointAdaptor.java
@@ -1512,7 +1512,9 @@
       response.addMetadata(METADATA_LIST_GUID, l.getMetadata().getID());
 
       response.setDisplayUrl(sharePointUrlToUri(
-          l.getMetadata().getDefaultViewUrl()));
+            "/".equals(l.getMetadata().getDefaultViewUrl()) 
+            ? l.getMetadata().getRootFolder() 
+            : l.getMetadata().getDefaultViewUrl()));
       String lastModified = l.getMetadata().getLastModified();
       try {
         response.setLastModified(
diff --git a/test/com/google/enterprise/adaptor/sharepoint/SharePointAdaptorTest.java b/test/com/google/enterprise/adaptor/sharepoint/SharePointAdaptorTest.java
index 95b1be8..10b5b0e 100644
--- a/test/com/google/enterprise/adaptor/sharepoint/SharePointAdaptorTest.java
+++ b/test/com/google/enterprise/adaptor/sharepoint/SharePointAdaptorTest.java
@@ -892,6 +892,39 @@
         .getDocContent(request, response);
     assertTrue(response.isNotFound());
   }
+  
+  @Test
+  public void testGetDocContentListEmptyDefaultView() throws Exception {
+    SiteDataSoap siteData = MockSiteData.blank()
+        .register(SITES_SITECOLLECTION_LISTS_CUSTOMLIST_URLSEG_EXCHANGE)
+        .register(SITES_SITECOLLECTION_LISTS_CUSTOMLIST_L_CONTENT_EXCHANGE
+            .replaceInContent("DefaultViewUrl=\"/sites/SiteCollection/Lists/"
+            + "Custom List/AllItems.aspx\"", "DefaultViewUrl=\"/\""))        
+        .register(SITES_SITECOLLECTION_LISTS_CUSTOMLIST_F_CONTENT_EXCHANGE)
+        .register(SITES_SITECOLLECTION_S_CONTENT_EXCHANGE)
+        .register(new URLSegmentsExchange(
+              "http://localhost:1/sites/SiteCollection/Lists/Custom List",
+               true, null, null, "{6F33949A-B3FF-4B0C-BA99-93CB518AC2C0}",
+               null));
+    adaptor = new SharePointAdaptor(initableSoapFactory,
+        new UnsupportedHttpClient(), executorFactory);
+    AccumulatingDocIdPusher pusher = new AccumulatingDocIdPusher();
+    adaptor.init(new MockAdaptorContext(config, pusher));
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    GetContentsRequest request = new GetContentsRequest(
+        new DocId("http://localhost:1/sites/SiteCollection/Lists/Custom List"));
+    GetContentsResponse response = new GetContentsResponse(baos);
+    adaptor.new SiteAdaptor("http://localhost:1/sites/SiteCollection",
+          "http://localhost:1/sites/SiteCollection", siteData,
+          new UnsupportedUserGroupSoap(), new UnsupportedPeopleSoap(),
+          Callables.returning(SITES_SITECOLLECTION_MEMBER_MAPPING),
+          new UnsupportedCallable<MemberIdMapping>())
+        .getDocContent(request, response);
+    // Verify display URL for List document
+    assertEquals(URI.create("http://localhost:1/sites/SiteCollection/Lists/"
+          + "Custom%20List"), response.getDisplayUrl());    
+  }
+  
 
   @Test
   public void testGetDocContentAttachment() throws Exception {
@@ -1514,7 +1547,37 @@
           + "Lists/Custom%20List/Test%20Folder"),
         response.getDisplayUrl());
   }
+  
+  @Test
+  public void testGetDocContentFolderEmptyDefaultView() throws Exception {
+    SiteDataSoap siteData = MockSiteData.blank()
+        .register(SITES_SITECOLLECTION_S_CONTENT_EXCHANGE)
+        .register(SITES_SITECOLLECTION_LISTS_CUSTOMLIST_1_URLSEG_EXCHANGE)
+        .register(SITES_SITECOLLECTION_LISTS_CUSTOMLIST_L_CONTENT_EXCHANGE
+            .replaceInContent("DefaultViewUrl=\"/sites/SiteCollection/Lists/"
+            + "Custom List/AllItems.aspx\"", "DefaultViewUrl=\"/\""))
+        .register(SITES_SITECOLLECTION_LISTS_CUSTOMLIST_1_LI_CONTENT_EXCHANGE)
+        .register(SITES_SITECOLLECTION_LISTS_CUSTOMLIST_1_F_CONTENT_EXCHANGE);
 
+    adaptor = new SharePointAdaptor(initableSoapFactory,
+        new UnsupportedHttpClient(), executorFactory);
+    adaptor.init(new MockAdaptorContext(config, pusher));
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    GetContentsRequest request = new GetContentsRequest(
+        new DocId("http://localhost:1/sites/SiteCollection/Lists/Custom List/"
+          + "Test Folder"));
+    GetContentsResponse response = new GetContentsResponse(baos);
+    adaptor.new SiteAdaptor("http://localhost:1/sites/SiteCollection",
+          "http://localhost:1/sites/SiteCollection",
+          siteData, new UnsupportedUserGroupSoap(), new UnsupportedPeopleSoap(),
+          Callables.returning(SITES_SITECOLLECTION_MEMBER_MAPPING),
+          new UnsupportedCallable<MemberIdMapping>())
+        .getDocContent(request, response);    
+    assertEquals(URI.create("http://localhost:1/sites/SiteCollection/Lists/"
+          + "Custom%20List?RootFolder=/sites/SiteCollection/"
+          + "Lists/Custom%20List/Test%20Folder"),response.getDisplayUrl());
+  }
+  
   @Test
   public void testGetDocIds() throws Exception {
     final Map<GroupPrincipal, Collection<Principal>> goldenGroups;