nacx commented on a change in pull request #133: URL: https://github.com/apache/jclouds/pull/133#discussion_r809781331
########## File path: providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/ActivityLogAlertApiMockTest.java ########## @@ -0,0 +1,201 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import static com.google.common.collect.Iterables.isEmpty; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.testng.Assert.assertEquals; + +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.jclouds.azurecompute.arm.domain.ActionGroup; +import org.jclouds.azurecompute.arm.domain.Actions; +import org.jclouds.azurecompute.arm.domain.ActivityLogAlert; +import org.jclouds.azurecompute.arm.domain.ActivityLogAlertProperties; +import org.jclouds.azurecompute.arm.domain.AlertRuleAllOfCondition; +import org.jclouds.azurecompute.arm.domain.AlertRuleAnyOfOrLeafCondition; +import org.jclouds.azurecompute.arm.domain.AlertRuleLeafCondition; +import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; +import org.testng.annotations.Test; + +import okhttp3.mockwebserver.MockResponse; + +@Test(groups = "unit", testName = "ActivityLogAlertApiMockTest", singleThreaded = true) +public class ActivityLogAlertApiMockTest extends BaseAzureComputeApiMockTest { + + public void testList() throws InterruptedException { + server.enqueue(jsonResponse("/activitylogalertresourcegroup.json")); + final ActivityLogAlertApi activityLogAlertApi = api.getActivityLogAlertApi("myResourceGroup"); + assertEquals(activityLogAlertApi.list(), getActivityLogRuleList()); + assertSent(server, "GET", + "/subscriptions/SUBSCRIPTIONID/resourcegroups/myResourceGroup/providers/Microsoft.Insights/activityLogAlerts?api-version=2020-10-01"); + } + + private List<ActivityLogAlert> getActivityLogRuleList() { + List<ActivityLogAlert> activityLogAlertRules = new ArrayList<ActivityLogAlert>(); + activityLogAlertRules.add(ActivityLogAlert.create( + "/subscriptions/SUBSCRIPTIONID/resourceGroups/myResourceGroup/providers/microsoft.insights/activityLogAlerts/myActivityLog", + "myActivityLog", "Global", "Microsoft.Insights/ActivityLogAlerts", tags(), + myActivityLogAlertProperties())); + activityLogAlertRules.add(ActivityLogAlert.create( + "/subscriptions/SUBSCRIPTIONID/resourceGroups/myResourceGroup/providers/microsoft.insights/activityLogAlerts/simpleActivityLog", + "simpleActivityLog", "Global", "Microsoft.Insights/ActivityLogAlerts", null, + sampleActivityLogAlertProperties())); + return activityLogAlertRules; + } + + public ActivityLogAlertProperties myActivityLogAlertProperties() { + return ActivityLogAlertProperties.create("", false, scope0(), condition0(), actions()); + } + + public ActivityLogAlertProperties sampleActivityLogAlertProperties() { + return ActivityLogAlertProperties.create("", true, scope1(), condition1(), actions()); + + } + + public void testListEmpty() throws Exception { + server.enqueue(new MockResponse().setResponseCode(404)); + final ActivityLogAlertApi activityApi = api.getActivityLogAlertApi("groupname"); + List<ActivityLogAlert> list = activityApi.list(); + assertTrue(isEmpty(list)); + assertSent(server, "GET", + "/subscriptions/SUBSCRIPTIONID/resourcegroups/groupname/providers/Microsoft.Insights/activityLogAlerts?api-version=2020-10-01"); + } + + public void testGet() throws InterruptedException { + server.enqueue(jsonResponse("/activitylogalertget.json")); + final ActivityLogAlertApi activityApi = api.getActivityLogAlertApi("myResourceGroup"); + ActivityLogAlert alert = activityApi.get("myActivityLogAlert"); + assertEquals(alert.location(), "Global"); + assertSent(server, "GET", + "/subscriptions/SUBSCRIPTIONID/resourcegroups/myResourceGroup/providers/Microsoft.Insights/activityLogAlerts/myActivityLogAlert?api-version=2020-10-01"); + } Review comment: Can you also add a test to verify the fallback when get returns a 404? ########## File path: providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/ActivityLogAlertApiLiveTest.java ########## @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.checkerframework.checker.nullness.qual.Nullable; +import org.jclouds.azurecompute.arm.domain.ActivityLogAlert; +import org.jclouds.azurecompute.arm.domain.ActivityLogAlertProperties; +import org.jclouds.azurecompute.arm.domain.AlertRuleAllOfCondition; +import org.jclouds.azurecompute.arm.domain.AlertRuleAnyOfOrLeafCondition; +import org.jclouds.azurecompute.arm.domain.ResourceGroup; +import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; + +@Test(groups = "live", testName = "ActivityLogAlertApiLiveTest", singleThreaded = true) +public class ActivityLogAlertApiLiveTest extends BaseAzureComputeApiLiveTest { + + private String alertRuleName; + private String subscriptionid; + private final String GLOBAL = "Global"; + + @BeforeClass + @Override + public void setup() { + super.setup(); + subscriptionid = getSubscriptionId(); + createTestResourceGroup(); + alertRuleName = String.format("vn-%s-%s", this.getClass().getSimpleName().toLowerCase(), + System.getProperty("user.name")); + + } + + protected void createTestResourceGroup() { Review comment: Why do you need to override this? can't you just rely on the one int he parent class? ########## File path: providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AlertApiMockTest.java ########## @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.testng.Assert.assertEquals; + +import java.util.List; + +import org.jclouds.azurecompute.arm.domain.Alert; +import org.jclouds.azurecompute.arm.domain.AlertModification; +import org.jclouds.azurecompute.arm.domain.AlertSummary; +import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; +import org.jclouds.azurecompute.arm.options.AlertRequestOptions; +import org.testng.annotations.Test; + +import static com.google.common.collect.Iterables.isEmpty; +import okhttp3.mockwebserver.MockResponse; + +@Test(groups = "unit", testName = "AlertApiMockTest", singleThreaded = true) +public class AlertApiMockTest extends BaseAzureComputeApiMockTest { + + public void testGetById() throws InterruptedException { + server.enqueue(jsonResponse("/alertsgetbyid.json")); + final AlertApi alertApi = api.getAlertApi("resourceGroups/myResourceGroup"); Review comment: From what I see in this test, the alertAPi is configured with a `resourceId` in the Path (unlike others where you pass a resource group). Is this because this APi can apply to _any resource_, not only to resource groups? ########## File path: providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AlertApiMockTest.java ########## @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.testng.Assert.assertEquals; + +import java.util.List; + +import org.jclouds.azurecompute.arm.domain.Alert; +import org.jclouds.azurecompute.arm.domain.AlertModification; +import org.jclouds.azurecompute.arm.domain.AlertSummary; +import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; +import org.jclouds.azurecompute.arm.options.AlertRequestOptions; +import org.testng.annotations.Test; + +import static com.google.common.collect.Iterables.isEmpty; +import okhttp3.mockwebserver.MockResponse; + +@Test(groups = "unit", testName = "AlertApiMockTest", singleThreaded = true) +public class AlertApiMockTest extends BaseAzureComputeApiMockTest { + + public void testGetById() throws InterruptedException { + server.enqueue(jsonResponse("/alertsgetbyid.json")); + final AlertApi alertApi = api.getAlertApi("resourceGroups/myResourceGroup"); + Alert alert = alertApi.getById("60c4d62b-xxxx-46d8-0000-b6dd8c4a769e"); + final String alertName = alert.name(); + assertEquals(alertName, "SampleAlert"); + assertSent(server, "GET", + "/subscriptions/SUBSCRIPTIONID/resourceGroups/myResourceGroup/providers/Microsoft.AlertsManagement/alerts/60c4d62b-xxxx-46d8-0000-b6dd8c4a769e?api-version=2019-03-01"); + } + + public void testGetByIdEmpty() throws Exception { + server.enqueue(new MockResponse().setResponseCode(404)); + final AlertApi alertApi = api.getAlertApi("resourceGroups/myResourceGroup"); + Alert alert = alertApi.getById("60c4d62b-xxxx-46d8-0000-b6dd8c4a769e"); + assertNull(alert); + assertSent(server, "GET", + "/subscriptions/SUBSCRIPTIONID/resourceGroups/myResourceGroup/providers/Microsoft.AlertsManagement/alerts/60c4d62b-xxxx-46d8-0000-b6dd8c4a769e?api-version=2019-03-01"); + } + + public void testGetHistory() throws InterruptedException { + server.enqueue(jsonResponse("/alertgethistory.json")); + final AlertApi alertApi = api.getAlertApi("resourceGroups/myResourceGroup"); + AlertModification history = alertApi.getHistory("d9db1f27-ce08-4c6d-8ab6-c0a8fbd8bf64"); + final String type = history.type(); + assertEquals(type, "Microsoft.AlertsManagement/alerts"); + assertSent(server, "GET", + "/subscriptions/SUBSCRIPTIONID/resourceGroups/myResourceGroup/providers/Microsoft.AlertsManagement/alerts/d9db1f27-ce08-4c6d-8ab6-c0a8fbd8bf64/history?api-version=2019-03-01"); + } + + public void testGetHistoryEmpty() throws Exception { + server.enqueue(new MockResponse().setResponseCode(404)); + final AlertApi alertApi = api.getAlertApi("resourceGroups/myResourceGroup"); + AlertModification history = alertApi.getHistory("d9db1f27-ce08-4c6d-8ab6-c0a8fbd8bf64"); + assertNull(history); + assertSent(server, "GET", + "/subscriptions/SUBSCRIPTIONID/resourceGroups/myResourceGroup/providers/Microsoft.AlertsManagement/alerts/d9db1f27-ce08-4c6d-8ab6-c0a8fbd8bf64/history?api-version=2019-03-01"); + } + + public void testGetSummary() throws InterruptedException { + server.enqueue(jsonResponse("/alertgetsummary.json")); + final AlertApi alertApi = api.getAlertApi("resourceGroups/myResourceGroup"); + AlertRequestOptions groupByOption = AlertRequestOptions.Builder.groupBy("severity"); + AlertSummary summary = alertApi.getSummary(groupByOption); + final String alertName = summary.name(); + assertEquals(alertName, "current"); + assertSent(server, "GET", + "/subscriptions/SUBSCRIPTIONID/resourceGroups/myResourceGroup/providers/Microsoft.AlertsManagement/alertsSummary?groupby=severity&api-version=2019-03-01"); + } + + public void testGetSummaryEmpty() throws Exception { + server.enqueue(new MockResponse().setResponseCode(404)); + final AlertApi alertApi = api.getAlertApi("resourceGroups/myResourceGroup"); + AlertRequestOptions groupByOption = AlertRequestOptions.Builder.groupBy("severity"); + AlertSummary summary = alertApi.getSummary(groupByOption); + assertNull(summary); + assertSent(server, "GET", + "/subscriptions/SUBSCRIPTIONID/resourceGroups/myResourceGroup/providers/Microsoft.AlertsManagement/alertsSummary?groupby=severity&api-version=2019-03-01"); + } + + public void testGetAll() throws InterruptedException { + server.enqueue(jsonResponse("/alertgetall.json")); + final AlertApi alertApi = api.getAlertApi("resourceGroups/myResourceGroup"); + List<Alert> list = alertApi.getAll(); + assertEquals(list.get(0).name(), "HostPoolAlert"); + assertSent(server, "GET", + "/subscriptions/SUBSCRIPTIONID/resourceGroups/myResourceGroup/providers/Microsoft.AlertsManagement/alerts?api-version=2019-03-01"); + } + + public void testGetAllEmpty() throws Exception { + server.enqueue(new MockResponse().setResponseCode(404)); + final AlertApi alertApi = api.getAlertApi("resourceGroups/myResourceGroup"); + List<Alert> list = alertApi.getAll(); + assertTrue(isEmpty(list)); + assertSent(server, "GET", + "/subscriptions/SUBSCRIPTIONID/resourceGroups/myResourceGroup/providers/Microsoft.AlertsManagement/alerts?api-version=2019-03-01"); + } + + public void testAlertChangeState() throws InterruptedException { + server.enqueue(jsonResponse("/alertchangestate.json")); + final AlertApi alertApi = api.getAlertApi("resourceGroups/myResourceGroup"); + alertApi.changeState("650d5726-xxxx-4e8c-0000-504d577da210", "Closed"); + assertSent(server, "POST", + "/subscriptions/SUBSCRIPTIONID/resourceGroups/myResourceGroup/providers/Microsoft.AlertsManagement/alerts/650d5726-xxxx-4e8c-0000-504d577da210/changestate?newState=Closed&api-version=2019-03-01"); + } Review comment: Add a test for the change state when the API returns a 404 to verify the fallback is properly configured. ########## File path: providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AlertApiLiveTest.java ########## @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.util.List; + +import org.jclouds.azurecompute.arm.domain.Alert; +import org.jclouds.azurecompute.arm.domain.AlertModification; +import org.jclouds.azurecompute.arm.domain.AlertSummary; +import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest; +import org.jclouds.azurecompute.arm.options.AlertRequestOptions; +import org.testng.annotations.Test; + +@Test(groups = "live", testName = "AlertApiLiveTest", singleThreaded = true) +public class AlertApiLiveTest extends BaseAzureComputeApiLiveTest { + + private String alertId; + + private AlertApi alertApi() { + return api.getAlertApi(""); Review comment: Is this expected? The `resourceId` is used to build the request path. What does it mean to pass an empty resource id here? ########## File path: providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/AlertApi.java ########## @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import java.util.List; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404; +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.azurecompute.arm.domain.Alert; +import org.jclouds.azurecompute.arm.domain.AlertModification; +import org.jclouds.azurecompute.arm.domain.AlertSummary; +import org.jclouds.azurecompute.arm.filters.ApiVersionFilter; +import org.jclouds.azurecompute.arm.options.AlertRequestOptions; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.oauth.v2.filters.OAuthFilter; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SelectJson; + +/** + * This Azure Resource Manager API provides all the alerts available for a given + * resource + * <p/> + * + * @see <a href= + * "https://docs.microsoft.com/en-us/rest/api/monitor/alertsmanagement/alerts">docs</a> + */ +@Path("/{resourceid}") +@RequestFilters({ OAuthFilter.class, ApiVersionFilter.class }) +@Consumes(MediaType.APPLICATION_JSON) +public interface AlertApi { + @Named("alerts:getAll") + @Path("/providers/Microsoft.AlertsManagement/alerts") + @GET + @SelectJson("value") + @Fallback(EmptyListOnNotFoundOr404.class) + List<Alert> getAll(@Nullable AlertRequestOptions... getAllOptions); Review comment: I've just seen this. To align with the naming in other apis, probably change the method name to: ```suggestion List<Alert> list(@Nullable AlertRequestOptions... getAllOptions); ``` ########## File path: providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/AlertApi.java ########## @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import java.util.List; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404; +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.azurecompute.arm.domain.Alert; +import org.jclouds.azurecompute.arm.domain.AlertModification; +import org.jclouds.azurecompute.arm.domain.AlertSummary; +import org.jclouds.azurecompute.arm.filters.ApiVersionFilter; +import org.jclouds.azurecompute.arm.options.AlertRequestOptions; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.oauth.v2.filters.OAuthFilter; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SelectJson; + +/** + * This Azure Resource Manager API provides all the alerts available for a given + * resource + * <p/> + * + * @see <a href= + * "https://docs.microsoft.com/en-us/rest/api/monitor/alertsmanagement/alerts">docs</a> + */ +@Path("/{resourceid}") +@RequestFilters({ OAuthFilter.class, ApiVersionFilter.class }) +@Consumes(MediaType.APPLICATION_JSON) +public interface AlertApi { + @Named("alerts:getAll") + @Path("/providers/Microsoft.AlertsManagement/alerts") + @GET + @SelectJson("value") + @Fallback(EmptyListOnNotFoundOr404.class) + List<Alert> getAll(@Nullable AlertRequestOptions... getAllOptions); + + @Named("alerts:getbyid") + @Path("/providers/Microsoft.AlertsManagement/alerts/{alertId}") + @GET + @Fallback(NullOnNotFoundOr404.class) + Alert getById(@PathParam("alertId") String alertId); Review comment: like in the previous comment? ```suggestion Alert get(@PathParam("alertId") String alertId); ``` ########## File path: providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AlertApiLiveTest.java ########## @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.util.List; + +import org.jclouds.azurecompute.arm.domain.Alert; +import org.jclouds.azurecompute.arm.domain.AlertModification; +import org.jclouds.azurecompute.arm.domain.AlertSummary; +import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest; +import org.jclouds.azurecompute.arm.options.AlertRequestOptions; +import org.testng.annotations.Test; + +@Test(groups = "live", testName = "AlertApiLiveTest", singleThreaded = true) +public class AlertApiLiveTest extends BaseAzureComputeApiLiveTest { + + private String alertId; + + private AlertApi alertApi() { + return api.getAlertApi(""); + } + + @Test + public void testGetAll() { + AlertRequestOptions pageCount = AlertRequestOptions.Builder.pageCount(1); + List<Alert> result = alertApi().getAll(pageCount); + System.out.println(result.size()); + assertNotNull(result); + assertTrue(result.size() > 0); Review comment: Is this always true, for any environment? Will alerts always exist? Or is there something the live test should do to make sure there is at least one? ########## File path: providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/ActivityLogAlertApiLiveTest.java ########## @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.checkerframework.checker.nullness.qual.Nullable; +import org.jclouds.azurecompute.arm.domain.ActivityLogAlert; +import org.jclouds.azurecompute.arm.domain.ActivityLogAlertProperties; +import org.jclouds.azurecompute.arm.domain.AlertRuleAllOfCondition; +import org.jclouds.azurecompute.arm.domain.AlertRuleAnyOfOrLeafCondition; +import org.jclouds.azurecompute.arm.domain.ResourceGroup; +import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; + +@Test(groups = "live", testName = "ActivityLogAlertApiLiveTest", singleThreaded = true) +public class ActivityLogAlertApiLiveTest extends BaseAzureComputeApiLiveTest { + + private String alertRuleName; + private String subscriptionid; + private final String GLOBAL = "Global"; + + @BeforeClass + @Override + public void setup() { + super.setup(); + subscriptionid = getSubscriptionId(); + createTestResourceGroup(); + alertRuleName = String.format("vn-%s-%s", this.getClass().getSimpleName().toLowerCase(), + System.getProperty("user.name")); + + } + + protected void createTestResourceGroup() { + String name = String.format("rg-%s-%s", this.getClass().getSimpleName().toLowerCase(), + System.getProperty("user.name")); + ResourceGroup rg = api.getResourceGroupApi().create(name, LOCATION, ImmutableMap.<String, String>of()); + assertNotNull(rg); + resourceGroupName = rg.name(); + } + + private ActivityLogAlertApi api() { + return api.getActivityLogAlertApi(resourceGroupName); + } + + @Test + public void testCreate() { + ActivityLogAlert activityAlert = api().createOrUpdate(alertRuleName, properties(), + ImmutableMap.of("createdBy", "jcloud"), GLOBAL); Review comment: :) ```suggestion ImmutableMap.of("createdBy", "jclouds"), GLOBAL); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@jclouds.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org