Search in sources :

Example 1 with JsonArray

use of com.google.gson.JsonArray in project zeppelin by apache.

the class InterpreterRestApiTest method testCreatedInterpreterDependencies.

@Test
public void testCreatedInterpreterDependencies() throws IOException {
    // when: Create 2 interpreter settings `md1` and `md2` which have different dep.
    String md1Name = "md1";
    String md2Name = "md2";
    String md1Dep = "org.apache.drill.exec:drill-jdbc:jar:1.7.0";
    String md2Dep = "org.apache.drill.exec:drill-jdbc:jar:1.6.0";
    String reqBody1 = "{\"name\":\"" + md1Name + "\",\"group\":\"md\",\"properties\":{\"propname\":\"propvalue\"}," + "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," + "\"dependencies\":[ {\n" + "      \"groupArtifactVersion\": \"" + md1Dep + "\",\n" + "      \"exclusions\":[]\n" + "    }]," + "\"option\": { \"remote\": true, \"session\": false }}";
    PostMethod post = httpPost("/interpreter/setting", reqBody1);
    assertThat("test create method:", post, isAllowed());
    post.releaseConnection();
    String reqBody2 = "{\"name\":\"" + md2Name + "\",\"group\":\"md\",\"properties\":{\"propname\":\"propvalue\"}," + "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," + "\"dependencies\":[ {\n" + "      \"groupArtifactVersion\": \"" + md2Dep + "\",\n" + "      \"exclusions\":[]\n" + "    }]," + "\"option\": { \"remote\": true, \"session\": false }}";
    post = httpPost("/interpreter/setting", reqBody2);
    assertThat("test create method:", post, isAllowed());
    post.releaseConnection();
    // 1. Call settings API
    GetMethod get = httpGet("/interpreter/setting");
    String rawResponse = get.getResponseBodyAsString();
    get.releaseConnection();
    // 2. Parsing to List<InterpreterSettings>
    JsonObject responseJson = gson.fromJson(rawResponse, JsonElement.class).getAsJsonObject();
    JsonArray bodyArr = responseJson.getAsJsonArray("body");
    List<InterpreterSetting> settings = new Gson().fromJson(bodyArr, new TypeToken<ArrayList<InterpreterSetting>>() {
    }.getType());
    // 3. Filter interpreters out we have just created
    InterpreterSetting md1 = null;
    InterpreterSetting md2 = null;
    for (InterpreterSetting setting : settings) {
        if (md1Name.equals(setting.getName())) {
            md1 = setting;
        } else if (md2Name.equals(setting.getName())) {
            md2 = setting;
        }
    }
    // then: should get created interpreters which have different dependencies
    // 4. Validate each md interpreter has its own dependencies
    assertEquals(1, md1.getDependencies().size());
    assertEquals(1, md2.getDependencies().size());
    assertEquals(md1Dep, md1.getDependencies().get(0).getGroupArtifactVersion());
    assertEquals(md2Dep, md2.getDependencies().get(0).getGroupArtifactVersion());
}
Also used : JsonArray(com.google.gson.JsonArray) PostMethod(org.apache.commons.httpclient.methods.PostMethod) JsonElement(com.google.gson.JsonElement) TypeToken(com.google.gson.reflect.TypeToken) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 2 with JsonArray

use of com.google.gson.JsonArray in project weixin-java-tools by chanjarster.

the class WxCpServiceImpl method getCallbackIp.

@Override
public String[] getCallbackIp() throws WxErrorException {
    String url = "https://qyapi.weixin.qq.com/cgi-bin/getcallbackip";
    String responseContent = get(url, null);
    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
    JsonArray jsonArray = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
    String[] ips = new String[jsonArray.size()];
    for (int i = 0; i < jsonArray.size(); i++) {
        ips[i] = jsonArray.get(i).getAsString();
    }
    return ips;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader)

Example 3 with JsonArray

use of com.google.gson.JsonArray in project weixin-java-tools by chanjarster.

the class WxCpServiceImpl method userDelete.

@Override
public void userDelete(String[] userids) throws WxErrorException {
    String url = "https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete";
    JsonObject jsonObject = new JsonObject();
    JsonArray jsonArray = new JsonArray();
    for (int i = 0; i < userids.length; i++) {
        jsonArray.add(new JsonPrimitive(userids[i]));
    }
    jsonObject.add("useridlist", jsonArray);
    post(url, jsonObject.toString());
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject)

Example 4 with JsonArray

use of com.google.gson.JsonArray in project weixin-java-tools by chanjarster.

the class WxCpServiceImpl method tagAddUsers.

@Override
public void tagAddUsers(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException {
    String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers";
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("tagid", tagId);
    if (userIds != null) {
        JsonArray jsonArray = new JsonArray();
        for (String userId : userIds) {
            jsonArray.add(new JsonPrimitive(userId));
        }
        jsonObject.add("userlist", jsonArray);
    }
    if (partyIds != null) {
        JsonArray jsonArray = new JsonArray();
        for (String userId : partyIds) {
            jsonArray.add(new JsonPrimitive(userId));
        }
        jsonObject.add("partylist", jsonArray);
    }
    post(url, jsonObject.toString());
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject)

Example 5 with JsonArray

use of com.google.gson.JsonArray in project weixin-java-tools by chanjarster.

the class WxMenuGsonAdapter method deserialize.

public WxMenu deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    /*
     * 操蛋的微信
     * 创建菜单时是 { button : ... }
     * 查询菜单时是 { menu : { button : ... } }
     */
    WxMenu menu = new WxMenu();
    JsonObject menuJson = json.getAsJsonObject().get("menu").getAsJsonObject();
    JsonArray buttonsJson = menuJson.get("button").getAsJsonArray();
    for (int i = 0; i < buttonsJson.size(); i++) {
        JsonObject buttonJson = buttonsJson.get(i).getAsJsonObject();
        WxMenu.WxMenuButton button = convertFromJson(buttonJson);
        menu.getButtons().add(button);
        if (buttonJson.get("sub_button") == null || buttonJson.get("sub_button").isJsonNull()) {
            continue;
        }
        JsonArray sub_buttonsJson = buttonJson.get("sub_button").getAsJsonArray();
        for (int j = 0; j < sub_buttonsJson.size(); j++) {
            JsonObject sub_buttonJson = sub_buttonsJson.get(j).getAsJsonObject();
            button.getSubButtons().add(convertFromJson(sub_buttonJson));
        }
    }
    return menu;
}
Also used : JsonArray(com.google.gson.JsonArray) WxMenu(me.chanjar.weixin.common.bean.WxMenu) JsonObject(com.google.gson.JsonObject)

Aggregations

JsonArray (com.google.gson.JsonArray)351 JsonObject (com.google.gson.JsonObject)227 JsonElement (com.google.gson.JsonElement)122 JsonPrimitive (com.google.gson.JsonPrimitive)103 Test (org.testng.annotations.Test)59 JsonParser (com.google.gson.JsonParser)49 ArrayList (java.util.ArrayList)44 HashMap (java.util.HashMap)33 Map (java.util.Map)31 Gson (com.google.gson.Gson)17 Test (org.junit.Test)16 IOException (java.io.IOException)10 Matchers.anyString (org.mockito.Matchers.anyString)10 TextView (android.widget.TextView)9 List (java.util.List)9 Point (android.graphics.Point)8 JsonParseException (com.google.gson.JsonParseException)7 GsonUtilities.jboolean (com.ibm.streamsx.topology.internal.gson.GsonUtilities.jboolean)7 KcaUtils.getStringFromException (com.antest1.kcanotify.KcaUtils.getStringFromException)6 JsonSyntaxException (com.google.gson.JsonSyntaxException)6