PageRenderTime 695ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/OrphanedGroupsByRegionIdTest.java

http://github.com/jclouds/jclouds
Java | 91 lines | 57 code | 18 blank | 16 comment | 0 complexity | 88d17cd34870ddea1d4b518a60d24494 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.openstack.nova.v2_0.compute.functions;
  18. import static org.testng.Assert.assertEquals;
  19. import java.util.Map;
  20. import java.util.Set;
  21. import org.jclouds.compute.domain.Hardware;
  22. import org.jclouds.compute.domain.Image;
  23. import org.jclouds.compute.domain.NodeMetadata;
  24. import org.jclouds.compute.functions.GroupNamingConvention;
  25. import org.jclouds.domain.Location;
  26. import org.jclouds.domain.LocationBuilder;
  27. import org.jclouds.domain.LocationScope;
  28. import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule;
  29. import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
  30. import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ServerInRegion;
  31. import org.jclouds.openstack.nova.v2_0.parse.ParseServerTest;
  32. import org.testng.annotations.Test;
  33. import com.google.common.base.Predicates;
  34. import com.google.common.base.Supplier;
  35. import com.google.common.base.Suppliers;
  36. import com.google.common.collect.ImmutableMap;
  37. import com.google.common.collect.ImmutableMultimap;
  38. import com.google.common.collect.ImmutableSet;
  39. import com.google.inject.Guice;
  40. @Test(testName = "OrphanedGroupsByRegionIdTest")
  41. public class OrphanedGroupsByRegionIdTest {
  42. Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova").description(
  43. "openstack-nova").build();
  44. Location region = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
  45. LocationScope.REGION).parent(provider).build();
  46. Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
  47. .<String, Location> of("az-1.region-a.geo-1", region));
  48. GroupNamingConvention.Factory namingConvention = Guice.createInjector().getInstance(GroupNamingConvention.Factory.class);
  49. @Test
  50. public void testWhenComputeServiceSaysAllNodesAreDeadBothGroupsAreReturned() {
  51. ServerInRegion withoutHost = new ServerInRegion(new ServerInRegionToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1");
  52. ServerInRegion withHost = new ServerInRegion(new ParseServerTest().expected(), "az-1.region-a.geo-1");
  53. ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata(
  54. NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
  55. .<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers
  56. .<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention);
  57. Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost));
  58. assertEquals(new OrphanedGroupsByRegionId(Predicates.<RegionAndName> alwaysTrue()).apply(set), ImmutableMultimap
  59. .<String, String> builder().putAll("az-1.region-a.geo-1", "sample", "test").build());
  60. }
  61. @Test
  62. public void testWhenComputeServiceSaysAllNodesAreDeadNoGroupsAreReturned() {
  63. ServerInRegion withoutHost = new ServerInRegion(new ServerInRegionToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1");
  64. ServerInRegion withHost = new ServerInRegion(new ParseServerTest().expected(), "az-1.region-a.geo-1");
  65. ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata(
  66. NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
  67. .<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers
  68. .<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention);
  69. Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost));
  70. assertEquals(new OrphanedGroupsByRegionId(Predicates.<RegionAndName> alwaysFalse()).apply(set), ImmutableMultimap
  71. .<String, String> of());
  72. }
  73. }