PageRenderTime 63ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/apis/vcloudexpress/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java

https://github.com/bmabey/jclouds
Java | 123 lines | 83 code | 17 blank | 23 comment | 0 complexity | a8062213c9b15c2138ed2d8a719eacef MD5 | raw file
  1. /**
  2. *
  3. * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
  4. *
  5. * ====================================================================
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.jclouds.vcloud.options;
  20. import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig;
  21. import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.customizeOnInstantiate;
  22. import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.disk;
  23. import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.memory;
  24. import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
  25. import static org.testng.Assert.assertEquals;
  26. import java.net.URI;
  27. import org.jclouds.http.functions.config.SaxParserModule;
  28. import org.jclouds.vcloud.domain.network.FenceMode;
  29. import org.jclouds.vcloud.domain.network.NetworkConfig;
  30. import org.testng.annotations.Test;
  31. import com.google.common.collect.Iterables;
  32. import com.google.inject.Guice;
  33. import com.google.inject.Injector;
  34. /**
  35. * Tests behavior of {@code InstantiateVAppTemplateOptions}
  36. *
  37. * @author Adrian Cole
  38. */
  39. @Test(groups = "unit")
  40. public class InstantiateVAppTemplateOptionsTest {
  41. Injector injector = Guice.createInjector(new SaxParserModule());
  42. @Test
  43. public void testAddNetworkConfig() {
  44. InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
  45. options.addNetworkConfig(new NetworkConfig("default", URI.create("http://localhost"), FenceMode.BRIDGED));
  46. assertEquals(Iterables.get(options.getNetworkConfig(), 0).getNetworkName(), "default");
  47. assertEquals(Iterables.get(options.getNetworkConfig(), 0).getParentNetwork(), URI.create("http://localhost"));
  48. assertEquals(Iterables.get(options.getNetworkConfig(), 0).getFenceMode(), FenceMode.BRIDGED);
  49. }
  50. @Test
  51. public void testAddNetworkConfigStatic() {
  52. InstantiateVAppTemplateOptions options = addNetworkConfig(new NetworkConfig("default", URI
  53. .create("http://localhost"), FenceMode.BRIDGED));
  54. assertEquals(Iterables.get(options.getNetworkConfig(), 0).getNetworkName(), "default");
  55. assertEquals(Iterables.get(options.getNetworkConfig(), 0).getParentNetwork(), URI.create("http://localhost"));
  56. assertEquals(Iterables.get(options.getNetworkConfig(), 0).getFenceMode(), FenceMode.BRIDGED);
  57. }
  58. @Test
  59. public void testCpuCount() {
  60. InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
  61. options.processorCount(3);
  62. assertEquals(options.getCpuCount(), "3");
  63. }
  64. @Test
  65. public void testCpuCountStatic() {
  66. InstantiateVAppTemplateOptions options = processorCount(3);
  67. assertEquals(options.getCpuCount(), "3");
  68. }
  69. @Test
  70. public void testCustomizeOnInstantiate() {
  71. InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
  72. options.customizeOnInstantiate(true);
  73. assertEquals(options.shouldCustomizeOnInstantiate(), new Boolean(true));
  74. }
  75. @Test
  76. public void testCustomizeOnInstantiateStatic() {
  77. InstantiateVAppTemplateOptions options = customizeOnInstantiate(true);
  78. assertEquals(options.shouldCustomizeOnInstantiate(), new Boolean(true));
  79. }
  80. @Test
  81. public void testRam() {
  82. InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
  83. options.memory(512);
  84. assertEquals(options.getMemorySizeMegabytes(), "512");
  85. }
  86. @Test
  87. public void testRamStatic() {
  88. InstantiateVAppTemplateOptions options = memory(512);
  89. assertEquals(options.getMemorySizeMegabytes(), "512");
  90. }
  91. @Test
  92. public void testDisk() {
  93. InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
  94. options.disk(512);
  95. assertEquals(options.getDiskSizeKilobytes(), "512");
  96. }
  97. @Test
  98. public void testDiskStatic() {
  99. InstantiateVAppTemplateOptions options = disk(512);
  100. assertEquals(options.getDiskSizeKilobytes(), "512");
  101. }
  102. @Test(expectedExceptions = IllegalArgumentException.class)
  103. public void testDiskStaticWrong() {
  104. disk(0);
  105. }
  106. }