@Test public void testVanillaWhereExistingResourceGroup() throws Exception { //Setup config bag ConfigBag configBag = ConfigBag.newInstance(); configBag.put(CLOUD_REGION_ID, TEST_LOCATION); //Setup mocks when(subnetApi.get(TEST_SUBNET_NAME)).thenReturn(null).thenReturn(subnet); //null first time, subnet next when(resourceGroupApi.get(TEST_RESOURCE_GROUP)).thenReturn(resourceGroup); when(subnet.properties().provisioningState()).thenReturn("Updating").thenReturn("Succeeded"); //Test DefaultAzureArmNetworkCreator.createDefaultNetworkAndAddToTemplateOptionsIfRequired(computeService, configBag); //verify verify(subnetApi, atLeast(2)).get(TEST_SUBNET_NAME); verify(subnet).id(); verify(resourceGroupApi).get(TEST_RESOURCE_GROUP); verify(resourceGroupApi, never()).create(any(), any(), any()); verify(virtualNetworkApi).createOrUpdate(eq(TEST_NETWORK_NAME), eq(TEST_LOCATION), any()); //verify templateOptions updated to include defaults Map<String, Object> templateOptions = configBag.get(TEMPLATE_OPTIONS); Map<String, Object> ipOptions = (Map<String, Object>) ((List)templateOptions.get("ipOptions")).iterator().next(); assertEquals(ipOptions.get("subnet"), TEST_SUBNET_ID); assertEquals(ipOptions.get("allocateNewPublicIp"), true); }
@Test public void testVanillaWhereExistingNetworkButNoSubnet() throws Exception { //Setup config bag ConfigBag configBag = ConfigBag.newInstance(); configBag.put(CLOUD_REGION_ID, TEST_LOCATION); //Setup mocks when(subnetApi.get(TEST_SUBNET_NAME)).thenReturn(null).thenReturn(subnet); //null first time, subnet next when(virtualNetworkApi.get(TEST_NETWORK_NAME)).thenReturn(virtualNetwork); when(resourceGroupApi.get(TEST_RESOURCE_GROUP)).thenReturn(resourceGroup); when(subnet.properties().provisioningState()).thenReturn("Updating").thenReturn("Succeeded"); //Test DefaultAzureArmNetworkCreator.createDefaultNetworkAndAddToTemplateOptionsIfRequired(computeService, configBag); //verify verify(subnetApi).createOrUpdate(eq(TEST_SUBNET_NAME), any()); verify(subnetApi, atLeast(2)).get(TEST_SUBNET_NAME); verify(subnet).id(); verify(resourceGroupApi).get(TEST_RESOURCE_GROUP); verify(resourceGroupApi, never()).create(any(), any(), any()); verify(virtualNetworkApi, never()).createOrUpdate(any(), any(), any()); //verify templateOptions updated to include defaults Map<String, Object> templateOptions = configBag.get(TEMPLATE_OPTIONS); Map<String, Object> ipOptions = (Map<String, Object>) ((List)templateOptions.get("ipOptions")).iterator().next(); assertEquals(ipOptions.get("subnet"), TEST_SUBNET_ID); assertEquals(ipOptions.get("allocateNewPublicIp"), true); }
protected ConfigBag runVanilla(Map<?, ?> additionalConfig) throws Exception { //Setup config bag ConfigBag configBag = ConfigBag.newInstance(); configBag.putAll(additionalConfig); configBag.put(CLOUD_REGION_ID, TEST_LOCATION); //Setup mocks when(subnetApi.get(TEST_SUBNET_NAME)).thenReturn(null).thenReturn(subnet); //null first time, subnet next when(resourceGroupApi.get(TEST_RESOURCE_GROUP)).thenReturn(null); when(subnet.properties().provisioningState()).thenReturn("Updating").thenReturn("Succeeded"); //Test DefaultAzureArmNetworkCreator.createDefaultNetworkAndAddToTemplateOptionsIfRequired(computeService, configBag); //verify calls made verify(subnet).id(); verify(subnetApi, atLeast(2)).get(TEST_SUBNET_NAME); verify(resourceGroupApi).get(TEST_RESOURCE_GROUP); verify(resourceGroupApi).create(eq(TEST_RESOURCE_GROUP), eq(TEST_LOCATION), any()); verify(virtualNetworkApi).createOrUpdate(eq(TEST_NETWORK_NAME), eq(TEST_LOCATION), any()); //verify templateOptions updated to include defaults Map<String, Object> templateOptions = configBag.get(TEMPLATE_OPTIONS); Map<String, Object> ipOptions = (Map<String, Object>) ((List)templateOptions.get("ipOptions")).iterator().next(); assertEquals(ipOptions.get("subnet"), TEST_SUBNET_ID); assertEquals(ipOptions.get("allocateNewPublicIp"), true); return configBag; }
@Override public boolean apply(final String name) { Subnet subnet = api.getSubnetApi(resourceGroupName, virtualNetworkName).get(name); return subnet.properties().provisioningState().equals("Succeeded"); } }, 60 * 4 * 1000).apply(subnet.name());