@Test public void testLoadQuestionFromText() throws Exception { JSONObject testQuestion = new JSONObject(); testQuestion.put( "instance", new JSONObject() .put("instanceName", "testQuestionName") .put("description", "test question description") .put( "variables", new JSONObject() .put( "var1", new JSONObject() .put("description", "test var1 description") .put("longDescription", "test var1 long description")))); JSONObject question = Client.loadQuestionFromText(testQuestion.toString(), "testquestion"); assertEquals( "testQuestionName", question.getJSONObject(BfConsts.PROP_INSTANCE).getString(BfConsts.PROP_INSTANCE_NAME)); assertEquals( "test question description", question.getJSONObject(BfConsts.PROP_INSTANCE).getString(BfConsts.PROP_DESCRIPTION)); assertEquals( "test var1 description", question .getJSONObject(BfConsts.PROP_INSTANCE) .getJSONObject(BfConsts.PROP_VARIABLES) .getJSONObject("var1") .getString(BfConsts.PROP_DESCRIPTION)); assertEquals( "test var1 long description", question .getJSONObject(BfConsts.PROP_INSTANCE) .getJSONObject(BfConsts.PROP_VARIABLES) .getJSONObject("var1") .getString(BfConsts.PROP_LONG_DESCRIPTION)); }
static JSONObject loadQuestionFromText(String questionText, String questionSource) { try { JSONObject questionObj = new JSONObject(questionText); if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) { JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE); String instanceDataStr = instanceDataObj.toString(); InstanceData instanceData = BatfishObjectMapper.mapper() .readValue(instanceDataStr, new TypeReference<InstanceData>() {}); validateInstanceData(instanceData); return questionObj; } else { throw new BatfishException( String.format("Question in %s has no instance data", questionSource)); } } catch (JSONException | IOException e) { throw new BatfishException("Failed to process question", e); } }
Client extends AbstractClient implements IClient { static JSONObject loadQuestionFromText(String questionText, String questionSource) { try { JSONObject questionObj = new JSONObject(questionText); if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) { JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE); String instanceDataStr = instanceDataObj.toString(); InstanceData instanceData = BatfishObjectMapper.mapper() .readValue(instanceDataStr, new TypeReference<InstanceData>() {}); validateInstanceData(instanceData); return questionObj; } else { throw new BatfishException( String.format("Question in %s has no instance data", questionSource)); } } catch (JSONException | IOException e) { throw new BatfishException("Failed to process question", e); } } }
Client extends AbstractClient implements IClient { static JSONObject loadQuestionFromText(String questionText, String questionSource) { try { JSONObject questionObj = new JSONObject(questionText); if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) { JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE); String instanceDataStr = instanceDataObj.toString(); InstanceData instanceData = BatfishObjectMapper.mapper() .readValue(instanceDataStr, new TypeReference<InstanceData>() {}); validateInstanceData(instanceData); return questionObj; } else { throw new BatfishException( String.format("Question in %s has no instance data", questionSource)); } } catch (JSONException | IOException e) { throw new BatfishException("Failed to process question", e); } } Client(Settings settings);  Client(String[] args); }
Client extends AbstractClient implements IClient { static JSONObject loadQuestionFromText(String questionText, String questionSource) { try { JSONObject questionObj = new JSONObject(questionText); if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) { JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE); String instanceDataStr = instanceDataObj.toString(); InstanceData instanceData = BatfishObjectMapper.mapper() .readValue(instanceDataStr, new TypeReference<InstanceData>() {}); validateInstanceData(instanceData); return questionObj; } else { throw new BatfishException( String.format("Question in %s has no instance data", questionSource)); } } catch (JSONException | IOException e) { throw new BatfishException("Failed to process question", e); } } Client(Settings settings);  Client(String[] args); @Override BatfishLogger getLogger(); Settings getSettings(); void run(List<String> initialCommands); }
Client extends AbstractClient implements IClient { static JSONObject loadQuestionFromText(String questionText, String questionSource) { try { JSONObject questionObj = new JSONObject(questionText); if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) { JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE); String instanceDataStr = instanceDataObj.toString(); InstanceData instanceData = BatfishObjectMapper.mapper() .readValue(instanceDataStr, new TypeReference<InstanceData>() {}); validateInstanceData(instanceData); return questionObj; } else { throw new BatfishException( String.format("Question in %s has no instance data", questionSource)); } } catch (JSONException | IOException e) { throw new BatfishException("Failed to process question", e); } } Client(Settings settings);  Client(String[] args); @Override BatfishLogger getLogger(); Settings getSettings(); void run(List<String> initialCommands);  }