From 1a768852e52fbbd9406e9741c54940e397437d4b Mon Sep 17 00:00:00 2001
From: Jianghao Lu <jianghaolu@users.noreply.github.com>
Date: Tue, 4 Oct 2016 12:19:39 -0700
Subject: [PATCH 1/3] Fix case sensitive resource group lookup

---
 .../resources/fluentcore/arm/ResourceUtils.java     |  2 +-
 .../management/resources/ResourceUtilsTests.java    | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceUtilsTests.java

diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/ResourceUtils.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/ResourceUtils.java
index 1c06f6bd41d5d..164f7346fb1cb 100644
--- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/ResourceUtils.java
+++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/ResourceUtils.java
@@ -21,7 +21,7 @@ private ResourceUtils() { }
      * @return the resource group name
      */
     public static String groupFromResourceId(String id) {
-        return extractFromResourceId(id, "resourceGroups");
+        return extractFromResourceId(id, "resource[gG]roups");
     }
 
     /**
diff --git a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceUtilsTests.java b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceUtilsTests.java
new file mode 100644
index 0000000000000..b4d58028dc122
--- /dev/null
+++ b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceUtilsTests.java
@@ -0,0 +1,13 @@
+package com.microsoft.azure.management.resources;
+
+import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ResourceUtilsTests {
+    @Test
+    public void canExtractGroupFromId() throws Exception {
+        Assert.assertEquals("foo", ResourceUtils.groupFromResourceId("subscriptions/123/resourceGroups/foo/Microsoft.Bar/bars/bar1"));
+        Assert.assertEquals("foo", ResourceUtils.groupFromResourceId("subscriptions/123/resourcegroups/foo/Microsoft.Bar/bars/bar1"));
+    }
+}

From 717c77a64e03a99665f18910f2796335b49657d2 Mon Sep 17 00:00:00 2001
From: Jianghao Lu <jianghaolu@users.noreply.github.com>
Date: Tue, 4 Oct 2016 12:20:41 -0700
Subject: [PATCH 2/3] Fix a bug in azure configure

---
 .../fluentcore/arm/implementation/AzureConfigurableImpl.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java
index 7f886dad47d0f..54bcc179472ea 100644
--- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java
+++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java
@@ -70,7 +70,7 @@ public T withConnectionTimeout(long timeout, TimeUnit unit) {
     @SuppressWarnings("unchecked")
     @Override
     public T withMaxIdleConnections(int maxIdleConnections) {
-        this.restClientBuilder = restClientBuilder.withMaxIdleConnections(5);
+        this.restClientBuilder = restClientBuilder.withMaxIdleConnections(maxIdleConnections);
         return (T) this;
     }
 

From 5f9a10629bcd3bacbb31a3dc8cdd973342be780d Mon Sep 17 00:00:00 2001
From: Jianghao Lu <jianghaolu@users.noreply.github.com>
Date: Tue, 4 Oct 2016 13:56:34 -0700
Subject: [PATCH 3/3] [#1156] Fix creation of deployment

---
 .../implementation/DeploymentImpl.java        | 28 +++++--------------
 1 file changed, 7 insertions(+), 21 deletions(-)

diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java
index 6664650aba359..bc59ae8d3df8a 100644
--- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java
+++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java
@@ -24,8 +24,6 @@
 import com.microsoft.azure.management.resources.fluentcore.model.implementation.CreatableUpdatableImpl;
 import org.joda.time.DateTime;
 import rx.Observable;
-import rx.functions.Func1;
-import rx.schedulers.Schedulers;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -184,6 +182,7 @@ public DeploymentImpl withNewResourceGroup(String resourceGroupName, Region regi
         this.creatableResourceGroup = this.resourceManager.resourceGroups()
                 .define(resourceGroupName)
                 .withRegion(region);
+        addCreatableDependency(this.creatableResourceGroup);
         this.resourceGroupName = resourceGroupName;
         return this;
     }
@@ -191,6 +190,7 @@ public DeploymentImpl withNewResourceGroup(String resourceGroupName, Region regi
     @Override
     public DeploymentImpl withNewResourceGroup(Creatable<ResourceGroup> resourceGroupDefinition) {
         this.resourceGroupName = resourceGroupDefinition.name();
+        addCreatableDependency(resourceGroupDefinition);
         this.creatableResourceGroup = resourceGroupDefinition;
         return this;
     }
@@ -268,6 +268,9 @@ public DeploymentImpl withParametersLink(String uri, String contentVersion) {
 
     @Override
     public DeploymentImpl beginCreate() {
+        if (creatableResourceGroup != null) {
+            creatableResourceGroup.create();
+        }
         DeploymentInner inner = new DeploymentInner()
                 .withProperties(new DeploymentProperties());
         inner.properties().withMode(mode());
@@ -279,24 +282,6 @@ public DeploymentImpl beginCreate() {
         return this;
     }
 
-    @Override
-    public Observable<Deployment> createAsync() {
-        Observable<Deployment> observable;
-        if (this.creatableResourceGroup != null) {
-            observable = this.creatableResourceGroup.createAsync()
-                    .subscribeOn(Schedulers.io())
-                    .flatMap(new Func1<ResourceGroup, Observable<Deployment>>() {
-                        @Override
-                        public Observable<Deployment> call(ResourceGroup resourceGroup) {
-                            return createResourceAsync();
-                        }
-                    });
-        } else {
-            observable = createResourceAsync();
-        }
-        return observable;
-    }
-
     @Override
     public Observable<Deployment> createResourceAsync() {
         DeploymentInner inner = new DeploymentInner()
@@ -332,7 +317,8 @@ public Observable<Deployment> updateResourceAsync() {
 
     @Override
     public Deployment refresh() {
-        return null;
+        setInner(client.get(resourceGroupName(), name()));
+        return this;
     }
 
     @Override