Copied: 
incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/MemorySearchProviderTest.java
 (from r1234540, 
incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/WaveMapTest.java)
URL: 
http://svn.apache.org/viewvc/incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/MemorySearchProviderTest.java?p2=incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/MemorySearchProviderTest.java&p1=incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/WaveMapTest.java&r1=1234540&r2=1237143&rev=1237143&view=diff
==============================================================================
--- 
incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/WaveMapTest.java
 (original)
+++ 
incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/MemorySearchProviderTest.java
 Sat Jan 28 19:28:41 2012
@@ -1,5 +1,5 @@
 /**
- * Copyright 2010 Google Inc.
+ * Copyright 2012 Apache Wave
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,21 +17,20 @@
 
 package org.waveprotocol.box.server.waveserver;
 
-import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.HashMultimap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Ordering;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.MoreExecutors;
+import com.google.gxp.com.google.common.collect.Maps;
 import com.google.wave.api.SearchResult;
 
 import junit.framework.TestCase;
 
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.waveprotocol.box.common.ExceptionalIterator;
 import org.waveprotocol.box.server.common.CoreWaveletOperationSerializer;
 import org.waveprotocol.box.server.persistence.PersistenceException;
 import org.waveprotocol.box.server.persistence.memory.MemoryDeltaStore;
@@ -56,15 +55,13 @@ import org.waveprotocol.wave.util.escape
 
 import java.util.Arrays;
 import java.util.Comparator;
+import java.util.Map;
 import java.util.concurrent.Executor;
 
 /**
- * @author [email protected] (Joseph Gentle)
- * @author [email protected] (Soren Lassen)
+ * @author [email protected] (Yuri Zelikov)
  */
-public class WaveMapTest extends TestCase {
-  private static final HashedVersionFactory V0_HASH_FACTORY =
-      new HashedVersionZeroFactoryImpl(new IdURIEncoderDecoder(new 
JavaUrlCodec()));
+public class MemorySearchProviderTest extends TestCase {
 
   private static final String DOMAIN = "example.com";
   private static final WaveId WAVE_ID = WaveId.of(DOMAIN, "abc123");
@@ -73,10 +70,19 @@ public class WaveMapTest extends TestCas
 
   private static final ParticipantId USER1 = ParticipantId.ofUnsafe("user1@" + 
DOMAIN);
   private static final ParticipantId USER2 = ParticipantId.ofUnsafe("user2@" + 
DOMAIN);
+  private static final ParticipantId SHARED_USER = ParticipantId.ofUnsafe("@" 
+ DOMAIN);
 
   private static final WaveletOperationContext CONTEXT =
       new WaveletOperationContext(USER1, 1234567890, 1);
-  
+
+  private static final HashedVersionFactory V0_HASH_FACTORY =
+      new HashedVersionZeroFactoryImpl(new IdURIEncoderDecoder(new 
JavaUrlCodec()));
+
+  private final HashMultimap<WaveId,WaveletId> wavesViewUser1 = 
HashMultimap.create();
+  private final HashMultimap<WaveId,WaveletId> wavesViewUser2 = 
HashMultimap.create();
+  private final HashMultimap<WaveId,WaveletId> wavesViewUser3 = 
HashMultimap.create();
+
+  private final Map<ParticipantId, HashMultimap<WaveId,WaveletId>> wavesViews 
= Maps.newHashMap();
 
   /** Sorts search result in ascending order by LMT. */
   static final Comparator<SearchResult.Digest> ASCENDING_DATE_COMPARATOR =
@@ -117,7 +123,7 @@ public class WaveMapTest extends TestCas
           return -ASC_CREATED_COMPARATOR.compare(arg0, arg1);
         }
       };
-  
+
   /** Sorts search result in ascending order by author. */
   static final Comparator<SearchResult.Digest> ASC_CREATOR_COMPARATOR =
       new Comparator<SearchResult.Digest>() {
@@ -135,7 +141,7 @@ public class WaveMapTest extends TestCas
           return author;
         }
       };
-  
+
   /** Sorts search result in descending order by author. */
   static final Comparator<SearchResult.Digest> DESC_CREATOR_COMPARATOR =
       new Comparator<SearchResult.Digest>() {
@@ -145,24 +151,37 @@ public class WaveMapTest extends TestCas
         }
       };
 
-  private static WaveletOperation addParticipantToWavelet(ParticipantId user) {
+  private WaveletOperation addParticipantToWavelet(ParticipantId user, 
WaveletName name) {
+    addWaveletToUserView(name, user);
     return new AddParticipant(CONTEXT, user);
   }
 
+  @Mock private IdGenerator idGenerator;
   @Mock private WaveletNotificationDispatcher notifiee;
+  @Mock private DeltaAndSnapshotStore waveletStore;
   @Mock private RemoteWaveletContainer.Factory remoteWaveletContainerFactory;
-  
-  @Mock private IdGenerator idGenerator;
+  @Mock private PerUserWaveViewSubscriber subscriber;
 
-  private DeltaAndSnapshotStore waveletStore;
-  private WaveMap waveMap;
+  private SearchProvider searchProvider;
   private ConversationUtil conversationUtil;
   private WaveDigester digester;
-  
+  private WaveMap waveMap;
+
   @Override
   protected void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
 
+    wavesViews.put(USER1, wavesViewUser1);
+    wavesViews.put(USER2, wavesViewUser2);
+    wavesViews.put(SHARED_USER, wavesViewUser3);
+
+    when(subscriber.getPerUserWaveView(USER1)).thenReturn(wavesViewUser1);
+    when(subscriber.getPerUserWaveView(USER2)).thenReturn(wavesViewUser2);
+    
when(subscriber.getPerUserWaveView(SHARED_USER)).thenReturn(wavesViewUser3);
+
+    conversationUtil = new ConversationUtil(idGenerator);
+    digester = new WaveDigester(conversationUtil);
+
     final DeltaStore deltaStore = new MemoryDeltaStore();
     final Executor persistExecutor = MoreExecutors.sameThreadExecutor();
     LocalWaveletContainer.Factory localWaveletContainerFactory =
@@ -182,69 +201,39 @@ public class WaveMapTest extends TestCas
           }
         };
 
-    conversationUtil = new ConversationUtil(idGenerator);
-    digester = new WaveDigester(conversationUtil);
-    waveletStore = mock(DeltaAndSnapshotStore.class);
     waveMap =
         new WaveMap(waveletStore, notifiee, notifiee, 
localWaveletContainerFactory,
             remoteWaveletContainerFactory, "example.com", digester);
+    searchProvider = new MemorySearchProvider(notifiee, DOMAIN, digester, 
waveMap, subscriber);
   }
 
-  public void testWaveMapStartsEmpty() throws WaveServerException {
-    assertFalse(waveMap.getWaveIds().hasNext());
-  }
-
-  public void testWavesStartWithNoWavelets() throws WaveletStateException, 
PersistenceException {
-    
when(waveletStore.lookup(WAVE_ID)).thenReturn(ImmutableSet.<WaveletId>of());
-    assertNull(waveMap.getLocalWavelet(WAVELET_NAME));
-    assertNull(waveMap.getRemoteWavelet(WAVELET_NAME));
-  }
-
-  public void testWaveAvailableAfterLoad() throws PersistenceException, 
WaveServerException {
-    when(waveletStore.getWaveIdIterator()).thenReturn(eitr(WAVE_ID));
-    waveMap.loadAllWavelets();
-
-    ExceptionalIterator<WaveId, WaveServerException> waves = 
waveMap.getWaveIds();
-    assertTrue(waves.hasNext());
-    assertEquals(WAVE_ID, waves.next());
-  }
-
-  public void testWaveletAvailableAfterLoad() throws WaveletStateException, 
PersistenceException {
-    when(waveletStore.getWaveIdIterator()).thenReturn(eitr(WAVE_ID));
-    
when(waveletStore.lookup(WAVE_ID)).thenReturn(ImmutableSet.<WaveletId>of(WAVELET_ID));
-    waveMap.loadAllWavelets();
-
-    assertNotNull(waveMap.getLocalWavelet(WAVELET_NAME));
-  }
-
-  public void testGetOrCreateCreatesWavelets() throws WaveletStateException, 
PersistenceException {
-    
when(waveletStore.lookup(WAVE_ID)).thenReturn(ImmutableSet.<WaveletId>of());
-    LocalWaveletContainer wavelet = 
waveMap.getOrCreateLocalWavelet(WAVELET_NAME);
-    assertSame(wavelet, waveMap.getLocalWavelet(WAVELET_NAME));
+  @Override
+  protected void tearDown() throws Exception {
+    wavesViews.clear();
   }
 
   public void testSearchEmptyInboxReturnsNothing() {
-    SearchResult results = waveMap.search(USER1, "in:inbox", 0, 20);
+    SearchResult results = searchProvider.search(USER1, "in:inbox", 0, 20);
 
     assertEquals(0, results.getNumResults());
   }
 
   public void testSearchInboxReturnsWaveWithExplicitParticipant() throws 
Exception {
-    submitDeltaToNewWavelet(WAVELET_NAME, USER1, 
addParticipantToWavelet(USER2));
+    submitDeltaToNewWavelet(WAVELET_NAME, USER1, 
addParticipantToWavelet(USER2, WAVELET_NAME));
 
-    SearchResult results = waveMap.search(USER2, "in:inbox", 0, 20);
+    SearchResult results = searchProvider.search(USER2, "in:inbox", 0, 20);
 
     assertEquals(1, results.getNumResults());
     assertEquals(WAVELET_NAME.waveId.serialise(), 
results.getDigests().get(0).getWaveId());
   }
 
   public void testSearchInboxDoesNotReturnWaveWithoutUser() throws Exception {
-    submitDeltaToNewWavelet(WAVELET_NAME, USER1, 
addParticipantToWavelet(USER1));
+    submitDeltaToNewWavelet(WAVELET_NAME, USER1, 
addParticipantToWavelet(USER1, WAVELET_NAME));
 
-    SearchResult results = waveMap.search(USER2, "in:inbox", 0, 20);
+    SearchResult results = searchProvider.search(USER2, "in:inbox", 0, 20);
     assertEquals(0, results.getNumResults());
   }
-  
+
   public void testSearchWaveReturnsWaveWithImplicitParticipant() throws 
Exception {
     ParticipantId sharedDomainParticipantId =
         ParticipantIdUtil.makeUnsafeSharedDomainParticipantId(DOMAIN);
@@ -252,12 +241,12 @@ public class WaveMapTest extends TestCas
       WaveletName.of(WaveId.of(DOMAIN, String.valueOf(1)), WAVELET_ID);
     // Implicit participant in this wave.
     submitDeltaToNewWavelet(waveletName, USER1,
-        addParticipantToWavelet(sharedDomainParticipantId));
+        addParticipantToWavelet(sharedDomainParticipantId, waveletName));
     waveletName = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(2)), 
WAVELET_ID);
     // Explicit participant in this wave.
-    submitDeltaToNewWavelet(waveletName, USER1, 
addParticipantToWavelet(USER2));
+    submitDeltaToNewWavelet(waveletName, USER1, addParticipantToWavelet(USER2, 
waveletName));
 
-    SearchResult results = waveMap.search(USER2, "", 0, 20);
+    SearchResult results = searchProvider.search(USER2, "", 0, 20);
     // Should return both waves.
     assertEquals(2, results.getNumResults());
   }
@@ -265,21 +254,21 @@ public class WaveMapTest extends TestCas
   public void testSearchAllReturnsWavesOnlyWithSharedDomainUser() throws 
Exception {
     WaveletName waveletName =
       WaveletName.of(WaveId.of(DOMAIN, String.valueOf(1)), WAVELET_ID);
-    submitDeltaToNewWavelet(waveletName, USER1, 
addParticipantToWavelet(USER1));
+    submitDeltaToNewWavelet(waveletName, USER1, addParticipantToWavelet(USER1, 
waveletName));
     waveletName = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(2)), 
WAVELET_ID);
-    submitDeltaToNewWavelet(waveletName, USER1, 
addParticipantToWavelet(USER2));
-    
-    SearchResult results = waveMap.search(USER2, "", 0, 20);
+    submitDeltaToNewWavelet(waveletName, USER1, addParticipantToWavelet(USER2, 
waveletName));
+
+    SearchResult results = searchProvider.search(USER2, "", 0, 20);
     assertEquals(1, results.getNumResults());
   }
 
   public void testSearchLimitEnforced() throws Exception {
     for (int i = 0; i < 10; i++) {
       WaveletName name = WaveletName.of(WaveId.of(DOMAIN, "w" + i), 
WAVELET_ID);
-      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
+      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1, 
name));
     }
 
-    SearchResult results = waveMap.search(USER1, "in:inbox", 0, 5);
+    SearchResult results = searchProvider.search(USER1, "in:inbox", 0, 5);
 
     assertEquals(5, results.getNumResults());
   }
@@ -291,14 +280,14 @@ public class WaveMapTest extends TestCas
 
     for (int i = 0; i < 10; i++) {
       WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
-      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
+      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1, 
name));
     }
 
     // The number of times we see each wave when we search
     int[] saw_wave = new int[10];
 
     for (int i = 0; i < 10; i++) {
-      SearchResult results = waveMap.search(USER1, "in:inbox", i, 1);
+      SearchResult results = searchProvider.search(USER1, "in:inbox", i, 1);
       assertEquals(1, results.getNumResults());
       WaveId waveId = 
WaveId.deserialise(results.getDigests().get(0).getWaveId());
       int index = Integer.parseInt(waveId.getId());
@@ -310,61 +299,61 @@ public class WaveMapTest extends TestCas
       assertEquals(1, saw_wave[i]);
     }
   }
-  
+
   public void testSearchOrderByAscWorks() throws Exception {
     for (int i = 0; i < 10; i++) {
       WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
-      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
+      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1, 
name));
     }
-    SearchResult results = waveMap.search(USER1, "in:inbox orderby:dateasc", 
0, 10);
+    SearchResult results = searchProvider.search(USER1, "in:inbox 
orderby:dateasc", 0, 10);
     Ordering<SearchResult.Digest> ascOrdering = 
Ordering.from(ASCENDING_DATE_COMPARATOR);
     assertTrue(ascOrdering.isOrdered(results.getDigests()));
   }
-  
+
   public void testSearchOrderByDescWorks() throws Exception {
     for (int i = 0; i < 10; i++) {
       WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
-      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
+      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1, 
name));
     }
-    SearchResult results = waveMap.search(USER1, "in:inbox orderby:datedesc", 
0, 10);
+    SearchResult results = searchProvider.search(USER1, "in:inbox 
orderby:datedesc", 0, 10);
     Ordering<SearchResult.Digest> descOrdering = 
Ordering.from(DESCENDING_DATE_COMPARATOR);
     assertTrue(descOrdering.isOrdered(results.getDigests()));
   }
-  
+
   public void testSearchOrderByCreatedAscWorks() throws Exception {
     for (int i = 0; i < 10; i++) {
       WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
-      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
+      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1, 
name));
     }
-    SearchResult results = waveMap.search(USER1, "in:inbox 
orderby:createdasc", 0, 10);
+    SearchResult results = searchProvider.search(USER1, "in:inbox 
orderby:createdasc", 0, 10);
     Ordering<SearchResult.Digest> ascOrdering = 
Ordering.from(ASC_CREATED_COMPARATOR);
     assertTrue(ascOrdering.isOrdered(results.getDigests()));
   }
-  
+
   public void testSearchOrderByCreatedDescWorks() throws Exception {
     for (int i = 0; i < 10; i++) {
       WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
-      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
+      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1, 
name));
     }
-    SearchResult results = waveMap.search(USER1, "in:inbox 
orderby:createddesc", 0, 10);
+    SearchResult results = searchProvider.search(USER1, "in:inbox 
orderby:createddesc", 0, 10);
     Ordering<SearchResult.Digest> descOrdering = 
Ordering.from(DESC_CREATED_COMPARATOR);
     assertTrue(descOrdering.isOrdered(results.getDigests()));
   }
-  
+
   public void testSearchOrderByAuthorAscWithCompundingWorks() throws Exception 
{
     for (int i = 0; i < 10; i++) {
       WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
       // Add USER2 to two waves.
       if (i == 1 || i == 2) {
-        WaveletOperation op1 = addParticipantToWavelet(USER1);
-        WaveletOperation op2 = addParticipantToWavelet(USER2);
+        WaveletOperation op1 = addParticipantToWavelet(USER1, name);
+        WaveletOperation op2 = addParticipantToWavelet(USER2, name);
         submitDeltaToNewWavelet(name, USER1, op1, op2);
       } else {
-        submitDeltaToNewWavelet(name, USER2, addParticipantToWavelet(USER2));
+        submitDeltaToNewWavelet(name, USER2, addParticipantToWavelet(USER2, 
name));
       }
     }
     SearchResult resultsAsc =
-        waveMap.search(USER2, "in:inbox orderby:creatorasc 
orderby:createddesc", 0, 10);
+        searchProvider.search(USER2, "in:inbox orderby:creatorasc 
orderby:createddesc", 0, 10);
     assertEquals(10, resultsAsc.getNumResults());
     Ordering<SearchResult.Digest> ascAuthorOrdering = 
Ordering.from(ASC_CREATOR_COMPARATOR);
     assertTrue(ascAuthorOrdering.isOrdered(resultsAsc.getDigests()));
@@ -377,101 +366,99 @@ public class WaveMapTest extends TestCas
     
assertTrue(descCreatedOrdering.isOrdered(Lists.newArrayList(resultsAsc.getDigests()).subList(2,
         10)));
   }
-  
+
   public void testSearchOrderByAuthorDescWorks() throws Exception {
     for (int i = 0; i < 10; i++) {
       WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
       // Add USER2 to two waves.
       if (i == 1 || i == 2) {
-        WaveletOperation op1 = addParticipantToWavelet(USER1);
-        WaveletOperation op2 = addParticipantToWavelet(USER2);
+        WaveletOperation op1 = addParticipantToWavelet(USER1, name);
+        WaveletOperation op2 = addParticipantToWavelet(USER2, name);
         submitDeltaToNewWavelet(name, USER1, op1, op2);
       } else {
-        submitDeltaToNewWavelet(name, USER2, addParticipantToWavelet(USER2));
+        submitDeltaToNewWavelet(name, USER2, addParticipantToWavelet(USER2, 
name));
       }
     }
     SearchResult resultsAsc =
-        waveMap.search(USER2, "in:inbox orderby:creatordesc", 0, 10);
+        searchProvider.search(USER2, "in:inbox orderby:creatordesc", 0, 10);
     assertEquals(10, resultsAsc.getNumResults());
     Ordering<SearchResult.Digest> descAuthorOrdering = 
Ordering.from(DESC_CREATOR_COMPARATOR);
     assertTrue(descAuthorOrdering.isOrdered(resultsAsc.getDigests()));
   }
-  
+
   public void testSearchFilterByWithWorks() throws Exception {
     for (int i = 0; i < 10; i++) {
       WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
       // Add USER2 to two waves.
       if (i == 1 || i == 2) {
-        WaveletOperation op1 = addParticipantToWavelet(USER1);
-        WaveletOperation op2 = addParticipantToWavelet(USER2);
+        WaveletOperation op1 = addParticipantToWavelet(USER1, name);
+        WaveletOperation op2 = addParticipantToWavelet(USER2, name);
         submitDeltaToNewWavelet(name, USER1, op1, op2);
       } else {
-        submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
+        submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1, 
name));
       }
     }
     SearchResult results =
-        waveMap.search(USER1, "in:inbox with:" + USER2.getAddress(), 0, 10);
+        searchProvider.search(USER1, "in:inbox with:" + USER2.getAddress(), 0, 
10);
     assertEquals(2, results.getNumResults());
-    results = waveMap.search(USER1, "in:inbox with:" + USER1.getAddress(), 0, 
10);
+    results = searchProvider.search(USER1, "in:inbox with:" + 
USER1.getAddress(), 0, 10);
     assertEquals(10, results.getNumResults());
   }
-  
+
   /**
    * If query contains invalid search param - it should return empty result.
    */
   public void testInvalidWithSearchParam() throws Exception {
     WaveletName name = WaveletName.of(WAVE_ID, WAVELET_ID);
-    submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
+    submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1, name));
     SearchResult results =
-        waveMap.search(USER1, "in:inbox with@^^^@:" + USER1.getAddress(), 0, 
10);
+        searchProvider.search(USER1, "in:inbox with@^^^@:" + 
USER1.getAddress(), 0, 10);
     assertEquals(0, results.getNumResults());
   }
-  
+
   public void testInvalidOrderByParam() throws Exception {
     for (int i = 0; i < 10; i++) {
       WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
-      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
+      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1, 
name));
     }
     SearchResult results =
-        waveMap.search(USER1, "in:inbox orderby:createddescCCC", 0, 10);
+        searchProvider.search(USER1, "in:inbox orderby:createddescCCC", 0, 10);
     assertEquals(0, results.getNumResults());
   }
-  
+
   public void testSearchFilterByCreatorWorks() throws Exception {
     for (int i = 0; i < 10; i++) {
       WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
       // Add USER2 to two waves as creator.
       if (i == 1 || i == 2) {
-        WaveletOperation op1 = addParticipantToWavelet(USER1);
-        WaveletOperation op2 = addParticipantToWavelet(USER2);
+        WaveletOperation op1 = addParticipantToWavelet(USER1, name);
+        WaveletOperation op2 = addParticipantToWavelet(USER2, name);
         submitDeltaToNewWavelet(name, USER2, op1, op2);
       } else {
-        submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
+        submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1, 
name));
       }
     }
     SearchResult results =
-        waveMap.search(USER1, "in:inbox creator:" + USER2.getAddress(), 0, 10);
+        searchProvider.search(USER1, "in:inbox creator:" + USER2.getAddress(), 
0, 10);
     assertEquals(2, results.getNumResults());
-    results = waveMap.search(USER1, "in:inbox creator:" + USER1.getAddress(), 
0, 10);
+    results = searchProvider.search(USER1, "in:inbox creator:" + 
USER1.getAddress(), 0, 10);
     assertEquals(8, results.getNumResults());
     results =
-        waveMap.search(USER1,
+        searchProvider.search(USER1,
             "in:inbox creator:" + USER1.getAddress() + " creator:" + 
USER2.getAddress(), 0, 10);
     assertEquals(0, results.getNumResults());
   }
 
-
-  private ExceptionalIterator<WaveId, PersistenceException> eitr(WaveId... 
waves) {
-    return ExceptionalIterator.FromIterator.<WaveId, 
PersistenceException>create(
-        Arrays.asList(waves).iterator());
-  }
-
   // *** Helpers
 
   private void submitDeltaToNewWavelet(WaveletName name, ParticipantId user,
       WaveletOperation... ops) throws Exception {
+
     HashedVersion version = V0_HASH_FACTORY.createVersionZero(name);
     WaveletDelta delta = new WaveletDelta(user, version, Arrays.asList(ops));
+    addWaveletToUserView(name, user);
+
+
     ProtocolWaveletDelta protoDelta = 
CoreWaveletOperationSerializer.serialize(delta);
 
     // Submitting the request will require the certificate manager to sign the 
delta. We'll just
@@ -482,5 +469,11 @@ public class WaveMapTest extends TestCas
     LocalWaveletContainer wavelet = waveMap.getOrCreateLocalWavelet(name);
     wavelet.submitRequest(name, signedProtoDelta);
   }
-  
+
+  private void addWaveletToUserView(WaveletName name, ParticipantId user) {
+    HashMultimap<WaveId,WaveletId> wavesView = wavesViews.get(user);
+    if (!wavesView.containsEntry(name.waveId, name.waveletId)) {
+      wavesViews.get(user).put(name.waveId, name.waveletId);
+    }
+  }
 }

Added: 
incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/PerUserWaveViewSubscriberTest.java
URL: 
http://svn.apache.org/viewvc/incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/PerUserWaveViewSubscriberTest.java?rev=1237143&view=auto
==============================================================================
--- 
incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/PerUserWaveViewSubscriberTest.java
 (added)
+++ 
incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/PerUserWaveViewSubscriberTest.java
 Sat Jan 28 19:28:41 2012
@@ -0,0 +1,91 @@
+/**
+ * Copyright 2012 Apache Wave
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.waveprotocol.box.server.waveserver;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Multimap;
+
+import junit.framework.TestCase;
+
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.waveprotocol.box.common.DeltaSequence;
+import org.waveprotocol.box.common.ExceptionalIterator;
+import org.waveprotocol.box.server.common.CoreWaveletOperationSerializer;
+import org.waveprotocol.box.server.util.WaveletDataUtil;
+import org.waveprotocol.box.server.util.testing.TestingConstants;
+import org.waveprotocol.wave.federation.Proto.ProtocolWaveletDelta;
+import org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation;
+import org.waveprotocol.wave.model.id.WaveId;
+import org.waveprotocol.wave.model.id.WaveletId;
+import org.waveprotocol.wave.model.version.HashedVersion;
+import org.waveprotocol.wave.model.wave.data.WaveletData;
+
+import java.util.Iterator;
+
+/**
+ * @author [email protected] (Yuri Zelikov)
+ */
+public class PerUserWaveViewSubscriberTest extends TestCase implements 
TestingConstants {
+
+  private static final HashedVersion BEGIN_VERSION = 
HashedVersion.unsigned(101L);
+  private static final HashedVersion END_VERSION = 
HashedVersion.unsigned(102L);
+
+  private static final ProtocolWaveletDelta DELTA = 
ProtocolWaveletDelta.newBuilder()
+    .setAuthor(USER)
+    .setHashedVersion(CoreWaveletOperationSerializer.serialize(BEGIN_VERSION))
+    
.addOperation(ProtocolWaveletOperation.newBuilder().setNoOp(true).build()).build();
+
+  private static final DeltaSequence POJO_DELTAS =
+      DeltaSequence.of(CoreWaveletOperationSerializer.deserialize(DELTA, 
END_VERSION, 0L));
+
+  private PerUserWaveViewSubscriber perUserWaveViewSubscriber;
+
+  @Mock WaveMap waveMap;
+
+  @Override
+  protected void setUp() throws Exception {
+    MockitoAnnotations.initMocks(this);
+    perUserWaveViewSubscriber = new PerUserWaveViewSubscriber(waveMap);
+  }
+
+  public void testGetPerUserWaveView() throws WaveletStateException {
+    Iterator<WaveId> inner = ImmutableList.of(WAVELET_NAME.waveId).iterator();
+    ExceptionalIterator<WaveId, WaveServerException> iter= 
ExceptionalIterator.FromIterator.create(inner);
+    when(waveMap.getWaveIds()).thenReturn(iter);
+    ImmutableSet<WaveletId> wavelets = ImmutableSet.of(WAVELET_NAME.waveletId);
+    when(waveMap.lookupWavelets(WAVELET_NAME.waveId)).thenReturn(wavelets);
+
+    LocalWaveletContainer c = mock(LocalWaveletContainer.class);
+    when(c.hasParticipant(PARTICIPANT)).thenReturn(true);
+    when(waveMap.getLocalWavelet(WAVELET_NAME)).thenReturn(c);
+
+    long dummyCreationTime = System.currentTimeMillis();
+    WaveletData wavelet = WaveletDataUtil.createEmptyWavelet(WAVELET_NAME, 
PARTICIPANT,
+        BEGIN_VERSION, dummyCreationTime);
+    perUserWaveViewSubscriber.waveletUpdate(wavelet, POJO_DELTAS);
+    Multimap<WaveId, WaveletId> perUserWavesView = 
perUserWaveViewSubscriber.getPerUserWaveView(PARTICIPANT);
+
+    assertNotNull(perUserWavesView);
+    assertEquals(1, perUserWavesView.size());
+  }
+}

Modified: 
incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/WaveDigesterTest.java
URL: 
http://svn.apache.org/viewvc/incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/WaveDigesterTest.java?rev=1237143&r1=1237142&r2=1237143&view=diff
==============================================================================
--- 
incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/WaveDigesterTest.java
 (original)
+++ 
incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/WaveDigesterTest.java
 Sat Jan 28 19:28:41 2012
@@ -1,5 +1,5 @@
 /**
- * Copyright 2011 Google Inc.
+ * Copyright 2012 Google Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -42,15 +42,14 @@ import org.waveprotocol.wave.model.wave.
 
 /**
  * Unit tests for {@link WaveDigester}.
- * 
+ *
  * @author [email protected] (Yuri Zelikov)
  */
 public class WaveDigesterTest extends TestCase {
 
   private static final WaveletId CONVERSATION_WAVELET_ID = 
WaveletId.of("example.com", "conv+root");
 
-  @Mock
-  private IdGenerator idGenerator;
+  @Mock private IdGenerator idGenerator;
 
   private ConversationUtil conversationUtil;
 
@@ -96,6 +95,24 @@ public class WaveDigesterTest extends Te
     Digest digest = digester.generateDigest(conversation, supplement, 
observableWaveletData);
 
     assertEquals(title, digest.getTitle());
-    assertEquals(digest.getBlipCount(), 1);
+    assertEquals(1, digest.getBlipCount());
+  }
+
+  public void testUnreadCount() {
+    TestingWaveletData data =
+        new TestingWaveletData(WAVE_ID, CONVERSATION_WAVELET_ID, PARTICIPANT, 
true);
+    data.appendBlipWithText("blip number 1");
+    data.appendBlipWithText("blip number 2");
+    data.appendBlipWithText("blip number 3");
+    ObservableWaveletData observableWaveletData = 
data.copyWaveletData().get(0);
+    ObservableWavelet wavelet = 
OpBasedWavelet.createReadOnly(observableWaveletData);
+    ObservableConversationView conversation = 
conversationUtil.buildConversation(wavelet);
+
+    SupplementedWave supplement = mock(SupplementedWave.class);
+    when(supplement.isUnread(any(ConversationBlip.class))).thenReturn(true, 
true, false);
+    Digest digest = digester.generateDigest(conversation, supplement, 
observableWaveletData);
+
+    assertEquals(3, digest.getBlipCount());
+    assertEquals(2, digest.getUnreadCount());
   }
 }

Modified: 
incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/WaveMapTest.java
URL: 
http://svn.apache.org/viewvc/incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/WaveMapTest.java?rev=1237143&r1=1237142&r2=1237143&view=diff
==============================================================================
--- 
incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/WaveMapTest.java
 (original)
+++ 
incubator/wave/trunk/test/org/waveprotocol/box/server/waveserver/WaveMapTest.java
 Sat Jan 28 19:28:41 2012
@@ -21,41 +21,23 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Ordering;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.MoreExecutors;
-import com.google.wave.api.SearchResult;
 
 import junit.framework.TestCase;
 
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.waveprotocol.box.common.ExceptionalIterator;
-import org.waveprotocol.box.server.common.CoreWaveletOperationSerializer;
 import org.waveprotocol.box.server.persistence.PersistenceException;
 import org.waveprotocol.box.server.persistence.memory.MemoryDeltaStore;
 import org.waveprotocol.box.server.robots.util.ConversationUtil;
-import org.waveprotocol.wave.federation.Proto.ProtocolSignedDelta;
-import org.waveprotocol.wave.federation.Proto.ProtocolWaveletDelta;
 import org.waveprotocol.wave.model.id.IdGenerator;
-import org.waveprotocol.wave.model.id.IdURIEncoderDecoder;
 import org.waveprotocol.wave.model.id.WaveId;
 import org.waveprotocol.wave.model.id.WaveletId;
 import org.waveprotocol.wave.model.id.WaveletName;
-import org.waveprotocol.wave.model.operation.wave.AddParticipant;
-import org.waveprotocol.wave.model.operation.wave.WaveletDelta;
-import org.waveprotocol.wave.model.operation.wave.WaveletOperation;
-import org.waveprotocol.wave.model.operation.wave.WaveletOperationContext;
-import org.waveprotocol.wave.model.version.HashedVersion;
-import org.waveprotocol.wave.model.version.HashedVersionFactory;
-import org.waveprotocol.wave.model.version.HashedVersionZeroFactoryImpl;
-import org.waveprotocol.wave.model.wave.ParticipantId;
-import org.waveprotocol.wave.model.wave.ParticipantIdUtil;
-import org.waveprotocol.wave.util.escapers.jvm.JavaUrlCodec;
 
 import java.util.Arrays;
-import java.util.Comparator;
 import java.util.concurrent.Executor;
 
 /**
@@ -63,102 +45,23 @@ import java.util.concurrent.Executor;
  * @author [email protected] (Soren Lassen)
  */
 public class WaveMapTest extends TestCase {
-  private static final HashedVersionFactory V0_HASH_FACTORY =
-      new HashedVersionZeroFactoryImpl(new IdURIEncoderDecoder(new 
JavaUrlCodec()));
 
   private static final String DOMAIN = "example.com";
   private static final WaveId WAVE_ID = WaveId.of(DOMAIN, "abc123");
   private static final WaveletId WAVELET_ID = WaveletId.of(DOMAIN, 
"conv+root");
   private static final WaveletName WAVELET_NAME = WaveletName.of(WAVE_ID, 
WAVELET_ID);
 
-  private static final ParticipantId USER1 = ParticipantId.ofUnsafe("user1@" + 
DOMAIN);
-  private static final ParticipantId USER2 = ParticipantId.ofUnsafe("user2@" + 
DOMAIN);
-
-  private static final WaveletOperationContext CONTEXT =
-      new WaveletOperationContext(USER1, 1234567890, 1);
-  
-
-  /** Sorts search result in ascending order by LMT. */
-  static final Comparator<SearchResult.Digest> ASCENDING_DATE_COMPARATOR =
-      new Comparator<SearchResult.Digest>() {
-        @Override
-        public int compare(SearchResult.Digest arg0, SearchResult.Digest arg1) 
{
-          long lmt0 = arg0.getLastModified();
-          long lmt1 = arg1.getLastModified();
-          return Long.signum(lmt0 - lmt1);
-        }
-      };
-
-  /** Sorts search result in descending order by LMT. */
-  static final Comparator<SearchResult.Digest> DESCENDING_DATE_COMPARATOR =
-      new Comparator<SearchResult.Digest>() {
-        @Override
-        public int compare(SearchResult.Digest arg0, SearchResult.Digest arg1) 
{
-          return -ASCENDING_DATE_COMPARATOR.compare(arg0, arg1);
-        }
-      };
-
-  /** Sorts search result in ascending order by creation time. */
-  static final Comparator<SearchResult.Digest> ASC_CREATED_COMPARATOR =
-      new Comparator<SearchResult.Digest>() {
-        @Override
-        public int compare(SearchResult.Digest arg0, SearchResult.Digest arg1) 
{
-          long time0 = arg0.getCreated();
-          long time1 = arg1.getCreated();
-          return Long.signum(time0 - time1);
-        }
-      };
-
-  /** Sorts search result in descending order by creation time. */
-  static final Comparator<SearchResult.Digest> DESC_CREATED_COMPARATOR =
-      new Comparator<SearchResult.Digest>() {
-        @Override
-        public int compare(SearchResult.Digest arg0, SearchResult.Digest arg1) 
{
-          return -ASC_CREATED_COMPARATOR.compare(arg0, arg1);
-        }
-      };
-  
-  /** Sorts search result in ascending order by author. */
-  static final Comparator<SearchResult.Digest> ASC_CREATOR_COMPARATOR =
-      new Comparator<SearchResult.Digest>() {
-        @Override
-        public int compare(SearchResult.Digest arg0, SearchResult.Digest arg1) 
{
-          ParticipantId author0 = computeAuthor(arg0);
-          ParticipantId author1 = computeAuthor(arg1);
-          return author0.compareTo(author1);
-        }
-
-        private ParticipantId computeAuthor(SearchResult.Digest digest) {
-          ParticipantId author = null;
-          author = ParticipantId.ofUnsafe(digest.getParticipants().get(0));
-          assert author != null : "Cannot find author for the wave: " + 
digest.getWaveId();
-          return author;
-        }
-      };
-  
-  /** Sorts search result in descending order by author. */
-  static final Comparator<SearchResult.Digest> DESC_CREATOR_COMPARATOR =
-      new Comparator<SearchResult.Digest>() {
-        @Override
-        public int compare(SearchResult.Digest arg0, SearchResult.Digest arg1) 
{
-          return -ASC_CREATOR_COMPARATOR.compare(arg0, arg1);
-        }
-      };
-
-  private static WaveletOperation addParticipantToWavelet(ParticipantId user) {
-    return new AddParticipant(CONTEXT, user);
-  }
 
   @Mock private WaveletNotificationDispatcher notifiee;
   @Mock private RemoteWaveletContainer.Factory remoteWaveletContainerFactory;
-  
+
   @Mock private IdGenerator idGenerator;
 
   private DeltaAndSnapshotStore waveletStore;
   private WaveMap waveMap;
   private ConversationUtil conversationUtil;
   private WaveDigester digester;
-  
+
   @Override
   protected void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
@@ -223,264 +126,8 @@ public class WaveMapTest extends TestCas
     assertSame(wavelet, waveMap.getLocalWavelet(WAVELET_NAME));
   }
 
-  public void testSearchEmptyInboxReturnsNothing() {
-    SearchResult results = waveMap.search(USER1, "in:inbox", 0, 20);
-
-    assertEquals(0, results.getNumResults());
-  }
-
-  public void testSearchInboxReturnsWaveWithExplicitParticipant() throws 
Exception {
-    submitDeltaToNewWavelet(WAVELET_NAME, USER1, 
addParticipantToWavelet(USER2));
-
-    SearchResult results = waveMap.search(USER2, "in:inbox", 0, 20);
-
-    assertEquals(1, results.getNumResults());
-    assertEquals(WAVELET_NAME.waveId.serialise(), 
results.getDigests().get(0).getWaveId());
-  }
-
-  public void testSearchInboxDoesNotReturnWaveWithoutUser() throws Exception {
-    submitDeltaToNewWavelet(WAVELET_NAME, USER1, 
addParticipantToWavelet(USER1));
-
-    SearchResult results = waveMap.search(USER2, "in:inbox", 0, 20);
-    assertEquals(0, results.getNumResults());
-  }
-  
-  public void testSearchWaveReturnsWaveWithImplicitParticipant() throws 
Exception {
-    ParticipantId sharedDomainParticipantId =
-        ParticipantIdUtil.makeUnsafeSharedDomainParticipantId(DOMAIN);
-    WaveletName waveletName =
-      WaveletName.of(WaveId.of(DOMAIN, String.valueOf(1)), WAVELET_ID);
-    // Implicit participant in this wave.
-    submitDeltaToNewWavelet(waveletName, USER1,
-        addParticipantToWavelet(sharedDomainParticipantId));
-    waveletName = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(2)), 
WAVELET_ID);
-    // Explicit participant in this wave.
-    submitDeltaToNewWavelet(waveletName, USER1, 
addParticipantToWavelet(USER2));
-
-    SearchResult results = waveMap.search(USER2, "", 0, 20);
-    // Should return both waves.
-    assertEquals(2, results.getNumResults());
-  }
-
-  public void testSearchAllReturnsWavesOnlyWithSharedDomainUser() throws 
Exception {
-    WaveletName waveletName =
-      WaveletName.of(WaveId.of(DOMAIN, String.valueOf(1)), WAVELET_ID);
-    submitDeltaToNewWavelet(waveletName, USER1, 
addParticipantToWavelet(USER1));
-    waveletName = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(2)), 
WAVELET_ID);
-    submitDeltaToNewWavelet(waveletName, USER1, 
addParticipantToWavelet(USER2));
-    
-    SearchResult results = waveMap.search(USER2, "", 0, 20);
-    assertEquals(1, results.getNumResults());
-  }
-
-  public void testSearchLimitEnforced() throws Exception {
-    for (int i = 0; i < 10; i++) {
-      WaveletName name = WaveletName.of(WaveId.of(DOMAIN, "w" + i), 
WAVELET_ID);
-      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
-    }
-
-    SearchResult results = waveMap.search(USER1, "in:inbox", 0, 5);
-
-    assertEquals(5, results.getNumResults());
-  }
-
-  public void testSearchIndexWorks() throws Exception {
-    // For this test, we'll create 10 waves with wave ids "0", "1", ... "9" 
and then run 10
-    // searches using offsets 0..9. The waves we get back can be in any order, 
but we must get
-    // all 10 of the waves back exactly once each from the search query.
-
-    for (int i = 0; i < 10; i++) {
-      WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
-      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
-    }
-
-    // The number of times we see each wave when we search
-    int[] saw_wave = new int[10];
-
-    for (int i = 0; i < 10; i++) {
-      SearchResult results = waveMap.search(USER1, "in:inbox", i, 1);
-      assertEquals(1, results.getNumResults());
-      WaveId waveId = 
WaveId.deserialise(results.getDigests().get(0).getWaveId());
-      int index = Integer.parseInt(waveId.getId());
-      saw_wave[index]++;
-    }
-
-    for (int i = 0; i < 10; i++) {
-      // Each wave should appear exactly once in the results
-      assertEquals(1, saw_wave[i]);
-    }
-  }
-  
-  public void testSearchOrderByAscWorks() throws Exception {
-    for (int i = 0; i < 10; i++) {
-      WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
-      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
-    }
-    SearchResult results = waveMap.search(USER1, "in:inbox orderby:dateasc", 
0, 10);
-    Ordering<SearchResult.Digest> ascOrdering = 
Ordering.from(ASCENDING_DATE_COMPARATOR);
-    assertTrue(ascOrdering.isOrdered(results.getDigests()));
-  }
-  
-  public void testSearchOrderByDescWorks() throws Exception {
-    for (int i = 0; i < 10; i++) {
-      WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
-      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
-    }
-    SearchResult results = waveMap.search(USER1, "in:inbox orderby:datedesc", 
0, 10);
-    Ordering<SearchResult.Digest> descOrdering = 
Ordering.from(DESCENDING_DATE_COMPARATOR);
-    assertTrue(descOrdering.isOrdered(results.getDigests()));
-  }
-  
-  public void testSearchOrderByCreatedAscWorks() throws Exception {
-    for (int i = 0; i < 10; i++) {
-      WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
-      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
-    }
-    SearchResult results = waveMap.search(USER1, "in:inbox 
orderby:createdasc", 0, 10);
-    Ordering<SearchResult.Digest> ascOrdering = 
Ordering.from(ASC_CREATED_COMPARATOR);
-    assertTrue(ascOrdering.isOrdered(results.getDigests()));
-  }
-  
-  public void testSearchOrderByCreatedDescWorks() throws Exception {
-    for (int i = 0; i < 10; i++) {
-      WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
-      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
-    }
-    SearchResult results = waveMap.search(USER1, "in:inbox 
orderby:createddesc", 0, 10);
-    Ordering<SearchResult.Digest> descOrdering = 
Ordering.from(DESC_CREATED_COMPARATOR);
-    assertTrue(descOrdering.isOrdered(results.getDigests()));
-  }
-  
-  public void testSearchOrderByAuthorAscWithCompundingWorks() throws Exception 
{
-    for (int i = 0; i < 10; i++) {
-      WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
-      // Add USER2 to two waves.
-      if (i == 1 || i == 2) {
-        WaveletOperation op1 = addParticipantToWavelet(USER1);
-        WaveletOperation op2 = addParticipantToWavelet(USER2);
-        submitDeltaToNewWavelet(name, USER1, op1, op2);
-      } else {
-        submitDeltaToNewWavelet(name, USER2, addParticipantToWavelet(USER2));
-      }
-    }
-    SearchResult resultsAsc =
-        waveMap.search(USER2, "in:inbox orderby:creatorasc 
orderby:createddesc", 0, 10);
-    assertEquals(10, resultsAsc.getNumResults());
-    Ordering<SearchResult.Digest> ascAuthorOrdering = 
Ordering.from(ASC_CREATOR_COMPARATOR);
-    assertTrue(ascAuthorOrdering.isOrdered(resultsAsc.getDigests()));
-    Ordering<SearchResult.Digest> descCreatedOrdering = 
Ordering.from(DESC_CREATED_COMPARATOR);
-    // The whole list should not be ordered by creation time.
-    assertFalse(descCreatedOrdering.isOrdered(resultsAsc.getDigests()));
-    // Each sublist should be ordered by creation time.
-    
assertTrue(descCreatedOrdering.isOrdered(Lists.newArrayList(resultsAsc.getDigests()).subList(0,
-        2)));
-    
assertTrue(descCreatedOrdering.isOrdered(Lists.newArrayList(resultsAsc.getDigests()).subList(2,
-        10)));
-  }
-  
-  public void testSearchOrderByAuthorDescWorks() throws Exception {
-    for (int i = 0; i < 10; i++) {
-      WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
-      // Add USER2 to two waves.
-      if (i == 1 || i == 2) {
-        WaveletOperation op1 = addParticipantToWavelet(USER1);
-        WaveletOperation op2 = addParticipantToWavelet(USER2);
-        submitDeltaToNewWavelet(name, USER1, op1, op2);
-      } else {
-        submitDeltaToNewWavelet(name, USER2, addParticipantToWavelet(USER2));
-      }
-    }
-    SearchResult resultsAsc =
-        waveMap.search(USER2, "in:inbox orderby:creatordesc", 0, 10);
-    assertEquals(10, resultsAsc.getNumResults());
-    Ordering<SearchResult.Digest> descAuthorOrdering = 
Ordering.from(DESC_CREATOR_COMPARATOR);
-    assertTrue(descAuthorOrdering.isOrdered(resultsAsc.getDigests()));
-  }
-  
-  public void testSearchFilterByWithWorks() throws Exception {
-    for (int i = 0; i < 10; i++) {
-      WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
-      // Add USER2 to two waves.
-      if (i == 1 || i == 2) {
-        WaveletOperation op1 = addParticipantToWavelet(USER1);
-        WaveletOperation op2 = addParticipantToWavelet(USER2);
-        submitDeltaToNewWavelet(name, USER1, op1, op2);
-      } else {
-        submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
-      }
-    }
-    SearchResult results =
-        waveMap.search(USER1, "in:inbox with:" + USER2.getAddress(), 0, 10);
-    assertEquals(2, results.getNumResults());
-    results = waveMap.search(USER1, "in:inbox with:" + USER1.getAddress(), 0, 
10);
-    assertEquals(10, results.getNumResults());
-  }
-  
-  /**
-   * If query contains invalid search param - it should return empty result.
-   */
-  public void testInvalidWithSearchParam() throws Exception {
-    WaveletName name = WaveletName.of(WAVE_ID, WAVELET_ID);
-    submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
-    SearchResult results =
-        waveMap.search(USER1, "in:inbox with@^^^@:" + USER1.getAddress(), 0, 
10);
-    assertEquals(0, results.getNumResults());
-  }
-  
-  public void testInvalidOrderByParam() throws Exception {
-    for (int i = 0; i < 10; i++) {
-      WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
-      submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
-    }
-    SearchResult results =
-        waveMap.search(USER1, "in:inbox orderby:createddescCCC", 0, 10);
-    assertEquals(0, results.getNumResults());
-  }
-  
-  public void testSearchFilterByCreatorWorks() throws Exception {
-    for (int i = 0; i < 10; i++) {
-      WaveletName name = WaveletName.of(WaveId.of(DOMAIN, String.valueOf(i)), 
WAVELET_ID);
-      // Add USER2 to two waves as creator.
-      if (i == 1 || i == 2) {
-        WaveletOperation op1 = addParticipantToWavelet(USER1);
-        WaveletOperation op2 = addParticipantToWavelet(USER2);
-        submitDeltaToNewWavelet(name, USER2, op1, op2);
-      } else {
-        submitDeltaToNewWavelet(name, USER1, addParticipantToWavelet(USER1));
-      }
-    }
-    SearchResult results =
-        waveMap.search(USER1, "in:inbox creator:" + USER2.getAddress(), 0, 10);
-    assertEquals(2, results.getNumResults());
-    results = waveMap.search(USER1, "in:inbox creator:" + USER1.getAddress(), 
0, 10);
-    assertEquals(8, results.getNumResults());
-    results =
-        waveMap.search(USER1,
-            "in:inbox creator:" + USER1.getAddress() + " creator:" + 
USER2.getAddress(), 0, 10);
-    assertEquals(0, results.getNumResults());
-  }
-
-
   private ExceptionalIterator<WaveId, PersistenceException> eitr(WaveId... 
waves) {
     return ExceptionalIterator.FromIterator.<WaveId, 
PersistenceException>create(
         Arrays.asList(waves).iterator());
   }
-
-  // *** Helpers
-
-  private void submitDeltaToNewWavelet(WaveletName name, ParticipantId user,
-      WaveletOperation... ops) throws Exception {
-    HashedVersion version = V0_HASH_FACTORY.createVersionZero(name);
-    WaveletDelta delta = new WaveletDelta(user, version, Arrays.asList(ops));
-    ProtocolWaveletDelta protoDelta = 
CoreWaveletOperationSerializer.serialize(delta);
-
-    // Submitting the request will require the certificate manager to sign the 
delta. We'll just
-    // leave it unsigned.
-    ProtocolSignedDelta signedProtoDelta =
-        
ProtocolSignedDelta.newBuilder().setDelta(protoDelta.toByteString()).build();
-
-    LocalWaveletContainer wavelet = waveMap.getOrCreateLocalWavelet(name);
-    wavelet.submitRequest(name, signedProtoDelta);
-  }
-  
 }


Reply via email to