Package org.jclouds.cloudsigma.functions

Source Code of org.jclouds.cloudsigma.functions.DriveDataToMapTest

/*
* 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.cloudsigma.functions;

import static org.testng.Assert.assertEquals;

import java.io.IOException;
import java.util.Map;

import org.jclouds.cloudsigma.domain.ClaimType;
import org.jclouds.cloudsigma.domain.DriveData;
import org.testng.annotations.Test;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;

/**
*
* @author Adrian Cole
*/
@Test(groups = { "unit" })
public class DriveDataToMapTest {
  
   public void testRenameKeyWhenNotFound() {
      Map<String, String> nothing = ImmutableMap.of();
      assertEquals(DriveDataToMap.renameKey(nothing, "foo", "bar"), nothing);
   }

   public void testRenameKeyWhenFound() {
      Map<String, String> nothing = ImmutableMap.of("foo", "bar");
      assertEquals(DriveDataToMap.renameKey(nothing, "foo", "bar"), ImmutableMap.of("bar", "bar"));
   }

   private static final DriveDataToMap BASEDRIVE_TO_MAP = Guice.createInjector().getInstance(DriveDataToMap.class);

   public void testBasics() {
      assertEquals(BASEDRIVE_TO_MAP.apply(new DriveData.Builder().name("foo").size(100l).build()),
            ImmutableMap.of("name", "foo", "size", "100"));
   }

   public void testComplete() throws IOException {
      DriveData one = new DriveData.Builder().name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
      //
            .size(8589934592l)//
            .claimType(ClaimType.SHARED)//
            .tags(ImmutableSet.of("foo", "bar", "baz"))//
            .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
            .use(ImmutableSet.of("tag1", "tag2"))//
            .build();
      assertEquals(
            BASEDRIVE_TO_MAP.apply(one),
            ImmutableMap.builder()
                  .put("name", "Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
                  .put("size", "8589934592")
                  .put("claim:type", "shared")
                  .put("tags", "foo bar baz")
                  .put("readers", "ffffffff-ffff-ffff-ffff-ffffffffffff")
                  .put("use", "tag1 tag2").build()

      );

   }
}
TOP

Related Classes of org.jclouds.cloudsigma.functions.DriveDataToMapTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.