You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2019/04/12 14:49:24 UTC

[geode] branch develop updated: GEODE-6612: create ClusterManagementResultAssert for assert chaining (#3446)

This is an automated email from the ASF dual-hosted git repository.

jinmeiliao pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new c29ba38  GEODE-6612: create ClusterManagementResultAssert for assert chaining (#3446)
c29ba38 is described below

commit c29ba3874bab00990400ae34320b253d9710e382
Author: jinmeiliao <ji...@pivotal.io>
AuthorDate: Fri Apr 12 07:49:08 2019 -0700

    GEODE-6612: create ClusterManagementResultAssert for assert chaining (#3446)
---
 .../assertions/ClusterManagementResultAssert.java  | 61 ++++++++++++++++++++++
 .../rest/RegionManagementIntegrationTest.java      | 36 ++++++-------
 2 files changed, 76 insertions(+), 21 deletions(-)

diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/assertions/ClusterManagementResultAssert.java b/geode-junit/src/main/java/org/apache/geode/test/junit/assertions/ClusterManagementResultAssert.java
new file mode 100644
index 0000000..f66acbe
--- /dev/null
+++ b/geode-junit/src/main/java/org/apache/geode/test/junit/assertions/ClusterManagementResultAssert.java
@@ -0,0 +1,61 @@
+/*
+ * 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.apache.geode.test.junit.assertions;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.assertj.core.api.AbstractAssert;
+import org.assertj.core.api.ListAssert;
+
+import org.apache.geode.cache.configuration.CacheElement;
+import org.apache.geode.management.api.ClusterManagementResult;
+
+public class ClusterManagementResultAssert
+    extends AbstractAssert<ClusterManagementResultAssert, ClusterManagementResult> {
+  public ClusterManagementResultAssert(
+      ClusterManagementResult clusterManagementResult, Class<?> selfType) {
+    super(clusterManagementResult, selfType);
+  }
+
+  public ClusterManagementResultAssert isSuccessful() {
+    assertThat(actual.isSuccessful()).isTrue();
+    return this;
+  }
+
+  public ClusterManagementResultAssert failed() {
+    assertThat(actual.isSuccessful()).isFalse();
+    return this;
+  }
+
+  public ClusterManagementResultAssert hasStatusCode(ClusterManagementResult.StatusCode... codes) {
+    assertThat(actual.getStatusCode()).isIn(codes);
+    return this;
+  }
+
+  public ClusterManagementResultAssert containsStatusMessage(String statusMessage) {
+    assertThat(actual.getStatusMessage()).contains(statusMessage);
+    return this;
+  }
+
+  public ListAssert<CacheElement> hasListResult() {
+    return assertThat(actual.getResult());
+  }
+
+  public static ClusterManagementResultAssert assertManagementResult(
+      ClusterManagementResult result) {
+    return new ClusterManagementResultAssert(result, ClusterManagementResultAssert.class);
+  }
+}
diff --git a/geode-web-management/src/integrationTest/java/org/apache/geode/management/internal/rest/RegionManagementIntegrationTest.java b/geode-web-management/src/integrationTest/java/org/apache/geode/management/internal/rest/RegionManagementIntegrationTest.java
index e9891e9..b61016b 100644
--- a/geode-web-management/src/integrationTest/java/org/apache/geode/management/internal/rest/RegionManagementIntegrationTest.java
+++ b/geode-web-management/src/integrationTest/java/org/apache/geode/management/internal/rest/RegionManagementIntegrationTest.java
@@ -15,14 +15,10 @@
 
 package org.apache.geode.management.internal.rest;
 
-import static org.hamcrest.Matchers.is;
+import static org.apache.geode.test.junit.assertions.ClusterManagementResultAssert.assertManagementResult;
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -35,6 +31,9 @@ import org.springframework.web.context.WebApplicationContext;
 
 import org.apache.geode.cache.configuration.BasicRegionConfig;
 import org.apache.geode.cache.configuration.RegionType;
+import org.apache.geode.management.api.ClusterManagementResult;
+import org.apache.geode.management.api.ClusterManagementService;
+import org.apache.geode.management.client.ClusterManagementServiceProvider;
 
 @RunWith(SpringRunner.class)
 @ContextConfiguration(locations = {"classpath*:WEB-INF/geode-management-servlet.xml"},
@@ -48,9 +47,12 @@ public class RegionManagementIntegrationTest {
   // needs to be used together with any BaseLocatorContextLoader
   private LocatorWebContext context;
 
+  private ClusterManagementService client;
+
   @Before
   public void before() {
     context = new LocatorWebContext(webApplicationContext);
+    client = ClusterManagementServiceProvider.getService(context.getRequestFactory());
   }
 
   @Test
@@ -60,14 +62,10 @@ public class RegionManagementIntegrationTest {
     regionConfig.setName("customers");
     regionConfig.setType(RegionType.REPLICATE);
 
-    ObjectMapper mapper = new ObjectMapper();
-    String json = mapper.writeValueAsString(regionConfig);
-
-    context.perform(post("/v2/regions").content(json))
-        .andExpect(status().isInternalServerError())
-        .andExpect(jsonPath("$.statusCode", is("ERROR")))
-        .andExpect(jsonPath("$.statusMessage",
-            is("no members found in cluster to create cache element")));
+    assertManagementResult(client.create(regionConfig))
+        .failed()
+        .hasStatusCode(ClusterManagementResult.StatusCode.ERROR)
+        .containsStatusMessage("no members found in cluster to create cache element");
   }
 
   @Test
@@ -77,14 +75,10 @@ public class RegionManagementIntegrationTest {
     regionConfig.setName("customers");
     regionConfig.setType("LOCAL");
 
-    ObjectMapper mapper = new ObjectMapper();
-    String json = mapper.writeValueAsString(regionConfig);
-
-    context.perform(post("/v2/regions").content(json))
-        .andExpect(status().isBadRequest())
-        .andExpect(jsonPath("$.statusCode", is("ILLEGAL_ARGUMENT")))
-        .andExpect(jsonPath("$.statusMessage",
-            is("Type LOCAL is not supported in Management V2 API.")));
+    assertManagementResult(client.create(regionConfig))
+        .failed()
+        .hasStatusCode(ClusterManagementResult.StatusCode.ILLEGAL_ARGUMENT)
+        .containsStatusMessage("Type LOCAL is not supported in Management V2 API.");
   }
 
   @Test