PageRenderTime 700ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/functions/ServerToNodeMetadataTest.java

http://github.com/jclouds/jclouds
Java | 166 lines | 128 code | 19 blank | 19 comment | 0 complexity | ead0a6822e904624eb04cd0ac175691d MD5 | raw file
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.jclouds.cloudservers.compute.functions;
  18. import static org.testng.Assert.assertEquals;
  19. import java.util.Map;
  20. import java.util.Set;
  21. import org.jclouds.cloudservers.compute.config.CloudServersComputeServiceContextModule;
  22. import org.jclouds.cloudservers.domain.Server;
  23. import org.jclouds.cloudservers.domain.ServerStatus;
  24. import org.jclouds.cloudservers.functions.ParseServerFromJsonResponseTest;
  25. import org.jclouds.compute.domain.Hardware;
  26. import org.jclouds.compute.domain.HardwareBuilder;
  27. import org.jclouds.compute.domain.Image;
  28. import org.jclouds.compute.domain.NodeMetadata;
  29. import org.jclouds.compute.domain.NodeMetadataBuilder;
  30. import org.jclouds.compute.domain.OperatingSystem;
  31. import org.jclouds.compute.domain.OsFamily;
  32. import org.jclouds.compute.domain.Processor;
  33. import org.jclouds.compute.domain.Volume;
  34. import org.jclouds.compute.domain.VolumeBuilder;
  35. import org.jclouds.compute.domain.NodeMetadata.Status;
  36. import org.jclouds.compute.functions.GroupNamingConvention;
  37. import org.jclouds.domain.Location;
  38. import org.jclouds.domain.LocationBuilder;
  39. import org.jclouds.domain.LocationScope;
  40. import org.testng.annotations.Test;
  41. import com.google.common.base.Suppliers;
  42. import com.google.common.collect.ImmutableList;
  43. import com.google.common.collect.ImmutableMap;
  44. import com.google.common.collect.ImmutableSet;
  45. import com.google.inject.Guice;
  46. /**
  47. * @author Adrian Cole
  48. */
  49. @Test(groups = "unit", testName = "ServerToNodeMetadataTest")
  50. public class ServerToNodeMetadataTest {
  51. Location provider = new LocationBuilder().scope(LocationScope.ZONE).id("dallas").description("description").build();
  52. GroupNamingConvention.Factory namingConvention = Guice.createInjector().getInstance(GroupNamingConvention.Factory.class);
  53. @Test
  54. public void testApplyWhereImageAndHardwareNotFound() {
  55. Map<ServerStatus, Status> serverStateToNodeStatus = CloudServersComputeServiceContextModule.toPortableNodeStatus;
  56. Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
  57. Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
  58. Server server = ParseServerFromJsonResponseTest.parseServer();
  59. ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeStatus, Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
  60. .ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
  61. NodeMetadata metadata = parser.apply(server);
  62. assertEquals(
  63. metadata,
  64. new NodeMetadataBuilder()
  65. .status(Status.PENDING)
  66. .publicAddresses(ImmutableSet.of("67.23.10.132", "67.23.10.131"))
  67. .privateAddresses(ImmutableSet.of("10.176.42.16"))
  68. .imageId("2")
  69. .id("1234")
  70. .providerId("1234")
  71. .name("sample-server")
  72. .group("sample")
  73. .hostname("sample-server")
  74. .location(
  75. new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0")
  76. .description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build())
  77. .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
  78. }
  79. @Test
  80. public void testApplyWhereImageFoundAndHardwareNotFound() {
  81. Map<ServerStatus, Status> serverStateToNodeStatus = CloudServersComputeServiceContextModule.toPortableNodeStatus;
  82. org.jclouds.compute.domain.Image jcImage = CloudServersImageToImageTest.convertImage();
  83. Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage);
  84. Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
  85. Server server = ParseServerFromJsonResponseTest.parseServer();
  86. ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeStatus, Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
  87. .ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
  88. NodeMetadata metadata = parser.apply(server);
  89. assertEquals(
  90. metadata,
  91. new NodeMetadataBuilder()
  92. .status(Status.PENDING)
  93. .publicAddresses(ImmutableSet.of("67.23.10.132", "67.23.10.131"))
  94. .privateAddresses(ImmutableSet.of("10.176.42.16"))
  95. .imageId("2")
  96. .operatingSystem(
  97. new OperatingSystem.Builder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2")
  98. .is64Bit(true).build())
  99. .id("1234")
  100. .providerId("1234")
  101. .name("sample-server")
  102. .hostname("sample-server")
  103. .group("sample")
  104. .location(
  105. new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0")
  106. .description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build())
  107. .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
  108. }
  109. @Test
  110. public void testApplyWhereImageAndHardwareFound() {
  111. Map<ServerStatus, Status> serverStateToNodeStatus = CloudServersComputeServiceContextModule.toPortableNodeStatus;
  112. Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(CloudServersImageToImageTest.convertImage());
  113. Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of(FlavorToHardwareTest.convertFlavor());
  114. Server server = ParseServerFromJsonResponseTest.parseServer();
  115. ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeStatus, Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
  116. .ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
  117. NodeMetadata metadata = parser.apply(server);
  118. assertEquals(
  119. metadata,
  120. new NodeMetadataBuilder()
  121. .status(Status.PENDING)
  122. .publicAddresses(ImmutableSet.of("67.23.10.132", "67.23.10.131"))
  123. .privateAddresses(ImmutableSet.of("10.176.42.16"))
  124. .imageId("2")
  125. .hardware(
  126. new HardwareBuilder()
  127. .ids("1")
  128. .name("256 MB Server")
  129. .processors(ImmutableList.of(new Processor(1.0, 1.0)))
  130. .ram(256)
  131. .volumes(
  132. ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(10.0f)
  133. .durable(true).bootDevice(true).build())).build())
  134. .operatingSystem(
  135. new OperatingSystem.Builder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2")
  136. .is64Bit(true).build())
  137. .id("1234")
  138. .providerId("1234")
  139. .name("sample-server")
  140. .group("sample")
  141. .hostname("sample-server")
  142. .location(
  143. new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0")
  144. .description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build())
  145. .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
  146. }
  147. }