Skip to content

Commit

Permalink
Add JQ testing for disk-store controller
Browse files Browse the repository at this point in the history
  • Loading branch information
jmelchio committed Jun 25, 2020
1 parent 5f98828 commit c68479d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
Expand All @@ -37,6 +38,8 @@

import org.apache.geode.management.api.ClusterManagementService;
import org.apache.geode.management.client.ClusterManagementServiceBuilder;
import org.apache.geode.management.configuration.DiskDir;
import org.apache.geode.management.configuration.DiskStore;
import org.apache.geode.management.configuration.Index;
import org.apache.geode.management.configuration.IndexType;
import org.apache.geode.management.configuration.Region;
Expand All @@ -60,7 +63,7 @@ public class JQFilterVerificationDUnitTest {
public static RequiresGeodeHome requiresGeodeHome = new RequiresGeodeHome();

private static GeodeDevRestClient client;
private static Map<String, JsonNode> apiWithJQFilters = new HashMap<>();
private static final Map<String, JsonNode> apiWithJQFilters = new HashMap<>();
private static JqLibrary library;

@BeforeClass
Expand All @@ -81,6 +84,12 @@ public static void beforeClass() throws IOException {
index1.setIndexType(IndexType.RANGE);
cms.create(index1);

DiskStore diskStore = new DiskStore();
diskStore.setName("diskstore1");
DiskDir diskDir = new DiskDir("./diskDir", null);
diskStore.setDirectories(Collections.singletonList(diskDir));
cms.create(diskStore);

client = new GeodeDevRestClient("/management", "localhost", locator.getHttpPort(), false);
JsonNode jsonObject =
client.doGetAndAssert("/v1/api-docs").getJsonObject().get("paths");
Expand Down Expand Up @@ -182,4 +191,27 @@ public void getIndex() throws Exception {
System.out.println("JQ output: " + response.getOutput());
Assertions.assertThat(response.getOutput()).contains("\"name\": \"index1\"");
}

@Test
public void listDiskStores() throws Exception {
String uri = "/v1/diskstores";
JqResponse response =
getJqResponse(uri, apiWithJQFilters.remove(uri).get("jqFilter").textValue());
Assertions.assertThat(response.hasErrors()).isFalse();
System.out.println("JQ output: " + response.getOutput());
Assertions.assertThat(response.getOutput()).contains("\"Member\": \"server-1\"");
Assertions.assertThat(response.getOutput()).contains("\"Disk Store Name\": \"diskstore1\"");
}

@Test
public void getDiskStore() throws Exception {
String uri = "/v1/diskstores/diskstore1";
JqResponse response =
getJqResponse(uri, apiWithJQFilters.remove("/v1/diskstores/{id}").get("jqFilter").textValue());
response.getErrors().forEach(System.out::println);
Assertions.assertThat(response.hasErrors()).isFalse();
System.out.println("JQ output: " + response.getOutput());
Assertions.assertThat(response.getOutput()).contains("\"Member\": \"server-1\"");
Assertions.assertThat(response.getOutput()).contains("\"Disk Store Name\": \"diskstore1\"");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public ClusterManagementListResult<DiskStore, DiskStoreInfo> listDiskStores(
@ApiOperation(value = "get disk-store",
extensions = {@Extension(properties = {
@ExtensionProperty(name = "jqFilter",
value = ".result[] | .groups[] | .runtimeInfo[] + .configuration | {Member:.memberName,\"Disk Store Name\":.name}")})})
value = ".result | .groups[] | .runtimeInfo[] + .configuration | {Member:.memberName,\"Disk Store Name\":.name}")})})
@GetMapping(DISK_STORE_CONFIG_ENDPOINT + "/{id}")
public ClusterManagementGetResult<DiskStore, DiskStoreInfo> getDiskStore(
@PathVariable(name = "id") String id) {
Expand Down

0 comments on commit c68479d

Please sign in to comment.