/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.jclouds.ec2.options;

import static org.jclouds.ec2.options.BundleInstanceS3StorageOptions.Builder.bucketOwnedBy;
import static org.testng.Assert.assertEquals;

import org.jclouds.domain.Credentials;
import org.jclouds.http.options.HttpRequestOptions;
import org.testng.annotations.Test;

import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;

/**
 * Tests possible uses of BundleInstanceS3StorageOptions and
 * BundleInstanceS3StorageOptions.Builder.*
 */
public class BundleInstanceS3StorageOptionsTest {

   @Test
   public void testAssignability() {
      assert HttpRequestOptions.class.isAssignableFrom(BundleInstanceS3StorageOptions.class);
      assert !String.class.isAssignableFrom(BundleInstanceS3StorageOptions.class);
   }

   @Test
   public void testBucketOwnedBy() {
      BundleInstanceS3StorageOptions options = new BundleInstanceS3StorageOptions();
      options.bucketOwnedBy("test");
      assertEquals(options.buildFormParameters().get("Storage.S3.AWSAccessKeyId"), ImmutableList.of("test"));
   }

   @Test(expectedExceptions = IllegalStateException.class)
   public void testNullBucketOwnedByNotInjected() {
      BundleInstanceS3StorageOptions options = new BundleInstanceS3StorageOptions();
      assertEquals(options.buildFormParameters().get("Storage.S3.AWSAccessKeyId"), ImmutableList.of());
   }

   @Test
   public void testNullBucketOwnedBy() {
      BundleInstanceS3StorageOptions options = new BundleInstanceS3StorageOptions();
      options.creds = Suppliers.ofInstance(new Credentials("foo", null));
      assertEquals(options.buildFormParameters().get("Storage.S3.AWSAccessKeyId"), ImmutableList.of("foo"));
   }

   @Test
   public void testBucketOwnedByStatic() {
      BundleInstanceS3StorageOptions options = bucketOwnedBy("test");
      assertEquals(options.buildFormParameters().get("Storage.S3.AWSAccessKeyId"), ImmutableList.of("test"));
   }

   @Test(expectedExceptions = NullPointerException.class)
   public void testBucketOwnedByNPE() {
      bucketOwnedBy(null);
   }

}
