/*
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * 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 com.google.cloud.storage.contrib.nio.testing;

import com.google.cloud.spi.ServiceRpcFactory;
import com.google.cloud.storage.spi.v1.StorageRpc;
import com.google.cloud.storage.StorageOptions;

/**
 * Utility to create an in-memory storage configuration for testing. Storage options can be
 * obtained via the {@link #getOptions()} method. Returned options will point to FakeStorageRpc.
 */
public final class LocalStorageHelper {

  // used for testing. Will throw if you pass it an option.
  private static final FakeStorageRpc instance = new FakeStorageRpc(true);

  private LocalStorageHelper() {}

  /**
   * Returns a {@link StorageOptions} that use the static FakeStorageRpc instance, and resets it
   * first so you start from a clean slate. That instance will throw if you pass it any option.
   */
  public static StorageOptions getOptions() {
    instance.reset();
    return StorageOptions.newBuilder()
      .setProjectId("dummy-project-for-testing")
      .setServiceRpcFactory(
        new ServiceRpcFactory<StorageOptions>() {
          @Override
          public StorageRpc create(StorageOptions options) {
            return instance;
          }
        })
      .build();
  }

  /**
   * Returns a {@link StorageOptions} that creates a new FakeStorageRpc instance with the given
   * option.
   */
  public static StorageOptions customOptions(final boolean throwIfOptions) {
    return StorageOptions.newBuilder()
      .setProjectId("dummy-project-for-testing")
      .setServiceRpcFactory(
         new ServiceRpcFactory<StorageOptions>() {
           @Override
           public StorageRpc create(StorageOptions options) {
             return new FakeStorageRpc(throwIfOptions);
           }
         })
      .build();
  }
}

@@ -1007,16 +1007,617 @@
 ageRpc.%0A
+ *%0A * %3Cp%3ENote, the created in-memory storage configuration supports limited set of operations and is %3Cb%3Enot%3C/b%3E thread-safe:%0A * %3Cul%3E%0A * %3Cli%3ESupported operations%0A *   %3Cul%3E%0A *   %3Cli%3Eobject create%0A *   %3Cli%3Eobject get%0A *   %3Cli%3Eobject delete%0A *   %3Cli%3Elist the contents of a bucket%0A *   %3C/ul%3E%0A * %3Cli%3EUnsupported operations%0A *   %3Cul%3E%0A *   %3Cli%3Ebucket create%0A *   %3Cli%3Ebucket get%0A *   %3Cli%3Ebucket delete%0A *   %3Cli%3Elist all buckets%0A *   %3Cli%3Egenerations%0A *   %3Cli%3Efile attributes%0A *   %3Cli%3Epatch%0A *   %3Cli%3EcontinueRewrite%0A *   %3Cli%3EcreateBatch%0A *   %3Cli%3Echecksums, etags%0A *   %3Cli%3EIAM operations%3C/li%3E%0A *   %3C/ul%3E%0A * %3C/ul%3E%0A
  */%0Apubl

Clarify usage of LocalStorageHelper, explicitly specify which operations are supported and which are not (#2334)