Skip to content

Commit

Permalink
fix bug that filter not applied to webapp/functionapp during list (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored Nov 30, 2020
1 parent c310548 commit 62e60e5
Show file tree
Hide file tree
Showing 4 changed files with 580 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.azure.resourcemanager.resources.fluentcore.arm.collection.SupportsBatchDeletion;
import com.azure.resourcemanager.resources.fluentcore.arm.collection.implementation.BatchDeletionImpl;
import com.azure.resourcemanager.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl;
import com.azure.resourcemanager.resources.fluentcore.utils.PagedConverter;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

Expand Down Expand Up @@ -140,8 +141,8 @@ public PagedIterable<FunctionAppBasic> listByResourceGroup(String resourceGroupN

@Override
public PagedFlux<FunctionAppBasic> listByResourceGroupAsync(String resourceGroupName) {
return inner().listByResourceGroupAsync(resourceGroupName)
.mapPage(inner -> new FunctionAppBasicImpl(inner, this.manager()));
return PagedConverter.flatMapPage(inner().listByResourceGroupAsync(resourceGroupName),
inner -> isFunctionApp(inner) ? Mono.just(new FunctionAppBasicImpl(inner, this.manager())) : Mono.empty());
}

@Override
Expand All @@ -151,7 +152,11 @@ public PagedIterable<FunctionAppBasic> list() {

@Override
public PagedFlux<FunctionAppBasic> listAsync() {
return inner().listAsync()
.mapPage(inner -> new FunctionAppBasicImpl(inner, this.manager()));
return PagedConverter.flatMapPage(inner().listAsync(),
inner -> isFunctionApp(inner) ? Mono.just(new FunctionAppBasicImpl(inner, this.manager())) : Mono.empty());
}

private static boolean isFunctionApp(SiteInner inner) {
return inner.kind() != null && Arrays.asList(inner.kind().split(",")).contains("functionapp");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
import com.azure.resourcemanager.resources.fluentcore.arm.collection.SupportsBatchDeletion;
import com.azure.resourcemanager.resources.fluentcore.arm.collection.implementation.BatchDeletionImpl;
import com.azure.resourcemanager.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl;
import com.azure.resourcemanager.resources.fluentcore.utils.PagedConverter;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/** The implementation for WebApps. */
public class WebAppsImpl
Expand Down Expand Up @@ -108,8 +110,8 @@ public PagedIterable<WebAppBasic> listByResourceGroup(String resourceGroupName)

@Override
public PagedFlux<WebAppBasic> listByResourceGroupAsync(String resourceGroupName) {
return inner().listByResourceGroupAsync(resourceGroupName)
.mapPage(inner -> new WebAppBasicImpl(inner, this.manager()));
return PagedConverter.flatMapPage(inner().listByResourceGroupAsync(resourceGroupName),
inner -> isWebApp(inner) ? Mono.just(new WebAppBasicImpl(inner, this.manager())) : Mono.empty());
}

@Override
Expand All @@ -119,7 +121,20 @@ public PagedIterable<WebAppBasic> list() {

@Override
public PagedFlux<WebAppBasic> listAsync() {
return inner().listAsync()
.mapPage(inner -> new WebAppBasicImpl(inner, this.manager()));
return PagedConverter.flatMapPage(inner().listAsync(),
inner -> isWebApp(inner) ? Mono.just(new WebAppBasicImpl(inner, this.manager())) : Mono.empty());
}

private static boolean isWebApp(SiteInner inner) {
boolean ret = false;
if (inner.kind() == null) {
ret = true;
} else {
List<String> kinds = Arrays.asList(inner.kind().split(","));
if (kinds.contains("app") || kinds.contains("api")) {
ret = true;
}
}
return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.rest.PagedIterable;
import com.azure.resourcemanager.appservice.models.AppServicePlan;
import com.azure.resourcemanager.appservice.models.FunctionApp;
import com.azure.resourcemanager.appservice.models.FunctionAppBasic;
import com.azure.resourcemanager.appservice.models.LogLevel;
import com.azure.resourcemanager.appservice.models.NetFrameworkVersion;
import com.azure.resourcemanager.appservice.models.OperatingSystem;
Expand Down Expand Up @@ -193,4 +195,35 @@ public void canCRUDWebAppWithContainer() {
Assertions.assertNotNull(webApp1.windowsFxVersion());
Assertions.assertTrue(webApp1.windowsFxVersion().contains(imageAndTag));
}

@Test
public void canListWebAppAndFunctionApp() {
rgName2 = null;

WebApp webApp1 = appServiceManager.webApps()
.define(webappName1)
.withRegion(Region.US_WEST)
.withNewResourceGroup(rgName1)
.withNewWindowsPlan(appServicePlanName1, PricingTier.BASIC_B1)
.create();

FunctionApp functionApp1 = appServiceManager.functionApps()
.define(webappName2)
.withRegion(Region.US_WEST)
.withExistingResourceGroup(rgName1)
.withNewFreeAppServicePlan()
.create();

PagedIterable<WebAppBasic> webApps = appServiceManager.webApps().listByResourceGroup(rgName1);

PagedIterable<FunctionAppBasic> functionApps = appServiceManager.functionApps().listByResourceGroup(rgName1);

Assertions.assertEquals(1, TestUtilities.getSize(webApps));

Assertions.assertEquals(1, TestUtilities.getSize(functionApps));

Assertions.assertEquals(webappName1, webApps.iterator().next().name());

Assertions.assertEquals(webappName2, functionApps.iterator().next().name());
}
}
Loading

0 comments on commit 62e60e5

Please sign in to comment.