Search in sources :

Example 1 with GfJsonObject

use of org.apache.geode.management.internal.cli.json.GfJsonObject in project geode by apache.

the class TypedJsonJUnitTest method checkResult.

public void checkResult(TypedJson tjson) {
    GfJsonObject gfJsonObj;
    try {
        gfJsonObj = new GfJsonObject(tjson.toString());
        System.out.println(gfJsonObj);
        assertNotNull(gfJsonObj.get(RESULT));
    } catch (GfJsonException e) {
        fail("Result could not be found");
    }
}
Also used : GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException)

Example 2 with GfJsonObject

use of org.apache.geode.management.internal.cli.json.GfJsonObject in project geode by apache.

the class DataCommandFunctionWithPDXJUnitTest method testTableIsRectangular.

// GEODE-2662: building a table where early values are missing keys causes the data to shift
// upward during reporting.
@Test
public void testTableIsRectangular() throws GfJsonException {
    TabularResultData rawTable = getTableFromQuery("select * from /" + PARTITIONED_REGION);
    // Verify any table built
    assertThat(rawTable.getGfJsonObject()).isNotNull();
    assertThat(rawTable.getGfJsonObject().getJSONObject("content")).isNotNull();
    GfJsonObject tableJson = rawTable.getGfJsonObject().getJSONObject("content");
    // Verify table is rectangular
    SoftAssertions softly = new SoftAssertions();
    for (String k : new String[] { "id", "phone", "firstName", "lastName" }) {
        softly.assertThat(tableJson.getJSONArray(k).size()).isEqualTo(4);
    }
    softly.assertAll();
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) SoftAssertions(org.assertj.core.api.SoftAssertions) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with GfJsonObject

use of org.apache.geode.management.internal.cli.json.GfJsonObject in project geode by apache.

the class DataCommandFunctionWithPDXJUnitTest method testFilteredQueryWithPhone.

@Test
public void testFilteredQueryWithPhone() throws Exception {
    TabularResultData rawTable = getTableFromQuery("select * from /" + PARTITIONED_REGION + " c where IS_DEFINED ( c.phone ) order by id");
    assertThat(rawTable.getGfJsonObject()).isNotNull();
    assertThat(rawTable.getGfJsonObject().getJSONObject("content")).isNotNull();
    GfJsonObject tableJson = rawTable.getGfJsonObject().getJSONObject("content");
    for (String k : new String[] { "id", "phone", "firstName", "lastName" }) {
        assertThat(tableJson.getJSONArray(k).size()).isEqualTo(2);
    }
    assertThatRowIsBuiltCorrectly(tableJson, 0, charlie);
    assertThatRowIsBuiltCorrectly(tableJson, 1, dan);
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with GfJsonObject

use of org.apache.geode.management.internal.cli.json.GfJsonObject in project geode by apache.

the class LocatorStateTest method createStatusJson.

private String createStatusJson() {
    final Map<String, Object> map = new HashMap<String, Object>();
    map.put(ServiceState.JSON_CLASSPATH, getClasspath());
    map.put(ServiceState.JSON_GEMFIREVERSION, getGemFireVersion());
    map.put(ServiceState.JSON_HOST, getHost());
    map.put(ServiceState.JSON_JAVAVERSION, getJavaVersion());
    map.put(ServiceState.JSON_JVMARGUMENTS, getJvmArguments());
    map.put(ServiceState.JSON_LOCATION, getServiceLocation());
    map.put(ServiceState.JSON_LOGFILE, getLogFile());
    map.put(ServiceState.JSON_MEMBERNAME, getMemberName());
    map.put(ServiceState.JSON_PID, getPid());
    map.put(ServiceState.JSON_PORT, getPort());
    map.put(ServiceState.JSON_STATUS, getStatusDescription());
    map.put(ServiceState.JSON_STATUSMESSAGE, getStatusMessage());
    map.put(ServiceState.JSON_TIMESTAMP, getTimestampTime());
    map.put(ServiceState.JSON_UPTIME, getUptime());
    map.put(ServiceState.JSON_WORKINGDIRECTORY, getWorkingDirectory());
    return new GfJsonObject(map).toString();
}
Also used : GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) HashMap(java.util.HashMap) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject)

Example 5 with GfJsonObject

use of org.apache.geode.management.internal.cli.json.GfJsonObject in project geode by apache.

the class DataCommandResult method addJSONObjectToTable.

private void addJSONObjectToTable(TabularResultData table, GfJsonObject object) {
    Iterator<String> keys;
    keys = object.keys();
    while (keys.hasNext()) {
        String k = keys.next();
        // filter out meta-field type-class used to identify java class of json object
        if (!"type-class".equals(k)) {
            Object value = object.get(k);
            if (value != null) {
                table.accumulate(k, getDomainValue(value));
            }
        }
    }
}
Also used : JSONObject(org.json.JSONObject) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject)

Aggregations

GfJsonObject (org.apache.geode.management.internal.cli.json.GfJsonObject)34 GfJsonException (org.apache.geode.management.internal.cli.json.GfJsonException)23 GfJsonArray (org.apache.geode.management.internal.cli.json.GfJsonArray)9 JSONObject (org.json.JSONObject)5 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 Row (org.apache.geode.management.internal.cli.result.TableBuilder.Row)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 SelectResultRow (org.apache.geode.management.internal.cli.domain.DataCommandResult.SelectResultRow)2 CliJsonSerializable (org.apache.geode.management.internal.cli.result.CliJsonSerializable)2 ResultDataException (org.apache.geode.management.internal.cli.result.ResultDataException)2 RowGroup (org.apache.geode.management.internal.cli.result.TableBuilder.RowGroup)2 Table (org.apache.geode.management.internal.cli.result.TableBuilder.Table)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1