ZeppelinhubClient { boolean runAllParagraph(String noteId, String hubMsg) { LOG.info("Running paragraph with noteId {}", noteId); try { JSONObject data = new JSONObject(hubMsg); if (data.equals(JSONObject.NULL) || !(data.get("data") instanceof JSONArray)) { LOG.error("Wrong \"data\" format for RUN_NOTEBOOK"); return false; } Client client = Client.getInstance(); if (client == null) { LOG.warn("Base client isn't initialized, returning"); return false; } Message zeppelinMsg = new Message(OP.RUN_PARAGRAPH); JSONArray paragraphs = data.getJSONArray("data"); for (int i = 0; i < paragraphs.length(); i++) { if (!(paragraphs.get(i) instanceof JSONObject)) { LOG.warn("Wrong \"paragraph\" format for RUN_NOTEBOOK"); continue; } zeppelinMsg.data = gson.fromJson(paragraphs.getString(i), new TypeToken<Map<String, Object>>(){}.getType()); client.relayToZeppelin(zeppelinMsg, noteId); LOG.info("\nSending RUN_PARAGRAPH message to Zeppelin "); } } catch (JSONException e) { LOG.error("Failed to parse RUN_NOTEBOOK message from ZeppelinHub ", e); return false; } return true; } private  ZeppelinhubClient(String url, String token); static ZeppelinhubClient initialize(String zeppelinhubUrl, String token); static ZeppelinhubClient getInstance(); void start(); void stop(); String getToken(); void send(String msg); void handleMsgFromZeppelinHub(String message);  }
@Test public void runAllParagraphTest() throws Exception { Client.initialize(validWebsocketUrl, validWebsocketUrl, "TOKEN", null); Client.getInstance().start(); ZeppelinhubClient zeppelinhubClient = ZeppelinhubClient.getInstance(); boolean runStatus = zeppelinhubClient.runAllParagraph("2AB7SY361", runNotebookMsg); assertTrue(runStatus); runStatus = zeppelinhubClient.runAllParagraph("2AB7SY361", invalidRunNotebookMsg); assertFalse(runStatus); Client.getInstance().stop(); }