/*
 * Copyright 2016, TeamDev Ltd. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.spine3.server.storage;

import com.google.protobuf.FieldMask;
import org.junit.Test;

import java.util.Map;

import static org.junit.Assert.assertNotNull;
import static org.spine3.test.Verify.assertEmpty;

/**
 * @author Dmytro Dashenkov
 */
public abstract class RecordStorageShould {

    @Test
    public void retrieve_empty_map_if_storage_is_empty() {
        final RecordStorage<String> storage = createStorage();

        final FieldMask nonEmptyFieldMask = FieldMask.newBuilder()
                                                     .addPaths("invalid-path")
                                                     .build();

        final Map empty = storage.readAll(nonEmptyFieldMask);
        assertNotNull(empty);
        assertEmpty(empty);
    }

    protected abstract <T> RecordStorage<T> createStorage();
}

@@ -1046,16 +1046,56 @@
 orage;%0A%0A
+import com.google.common.base.Supplier;%0A
 import c
@@ -1151,29 +1151,338 @@
 st;%0A
-%0Aimport java.util.Map
+import org.spine3.protobuf.AnyPacker;%0Aimport org.spine3.protobuf.Timestamps;%0Aimport org.spine3.test.projection.Project;%0Aimport org.spine3.test.projection.ProjectId;%0Aimport org.spine3.test.projection.Task;%0A%0Aimport java.util.Collection;%0Aimport java.util.LinkedList;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.UUID
 ;%0A%0Ai
@@ -1575,16 +1575,65 @@
 rtEmpty;
+%0Aimport static org.spine3.test.Verify.assertSize;
 %0A%0A/**%0A *
@@ -2177,16 +2177,1904 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void retrieve_all_records() %7B%0A        final RecordStorage%3CString%3E storage = createStorage();%0A        final Collection%3CString%3E ids = fill(storage, 10, new Supplier%3CString%3E() %7B%0A            @Override%0A            public String get() %7B%0A                return UUID.randomUUID()%0A                           .toString();%0A            %7D%0A        %7D);%0A%0A        final Map%3CString, EntityStorageRecord%3E allRecords = storage.readAll();%0A        assertSize(ids.size(), allRecords);%0A%0A    %7D%0A%0A    protected static %3CT%3E List%3CT%3E fill(RecordStorage%3CT%3E storage, int count, Supplier%3CT%3E idSupplier) %7B%0A        final List%3CT%3E ids = new LinkedList%3C%3E();%0A%0A        for (int i = 0; i %3C count; i++) %7B%0A            final T genericId = idSupplier.get();%0A            final ProjectId id = ProjectId.newBuilder()%0A                                          .setId(genericId.toString())%0A                                          .build();%0A            final Project project = Project.newBuilder()%0A                                           .setId(id)%0A                                           .setStatus(Project.Status.CREATED)%0A                                           .setName(String.format(%22test-project-%25s%22, i))%0A                                           .addTask(Task.getDefaultInstance())%0A                                           .build();%0A            final EntityStorageRecord record = EntityStorageRecord.newBuilder()%0A                                                                  .setState(AnyPacker.pack(project))%0A                                                                  .setWhenModified(Timestamps.getCurrentTime())%0A                                                                  .setVersion(1)%0A                                                                  .build();%0A            storage.write(genericId, record);%0A            ids.add(genericId);%0A        %7D%0A%0A        return ids;%0A    %7D%0A%0A
     prot

Add read-all tests for record storage.