use of net.minidev.json.JSONObject in project scheduler by btrplace.
the class TestCase method toJSON.
public String toJSON() throws JSONConverterException {
InstanceConverter ic = new InstanceConverter();
ic.getConstraintsConverter().register(new ScheduleConverter());
ReconfigurationPlanConverter pc = new ReconfigurationPlanConverter();
JSONObject o = new JSONObject();
o.put("constraint", constraint().id());
JSONArray a = new JSONArray();
for (Constant c : args()) {
a.add(c.toJSON());
}
o.put("args", a);
o.put("continuous", continuous());
o.put("groups", groups());
o.put("plan", pc.toJSON(plan()));
o.put("instance", ic.toJSON(instance()));
return o.toJSONString();
}
use of net.minidev.json.JSONObject in project scheduler by btrplace.
the class ModelViewsConverterTest method testFromJSonWithNoConverter.
@Test(dependsOnMethods = { "testRegister" }, expectedExceptions = { JSONConverterException.class })
public void testFromJSonWithNoConverter() throws JSONConverterException {
JSONObject ob = new JSONObject();
ob.put("id", "mockView");
ob.put("value", "val");
ModelViewsConverter c = new ModelViewsConverter();
c.fromJSON(null, ob);
}
use of net.minidev.json.JSONObject in project scheduler by btrplace.
the class ModelViewsConverterTest method testWithExistingConverter.
@Test(dependsOnMethods = { "testRegister" })
public void testWithExistingConverter() throws JSONConverterException {
ModelViewsConverter c = new ModelViewsConverter();
c.register(new MockModelViewConverter());
MockModelView m = new MockModelView("bar");
JSONObject o = c.toJSON(m);
MockModelView m2 = (MockModelView) c.fromJSON(null, o);
Assert.assertEquals(m.value, m2.value);
}
use of net.minidev.json.JSONObject in project scheduler by btrplace.
the class Constant method fromJSON.
public static Constant fromJSON(JSONObject o) {
Type t = Type.decode(o.getAsString("type"));
Object r = t.fromJSON(o.get("value"));
return new Constant(r, t);
}
use of net.minidev.json.JSONObject in project scheduler by btrplace.
the class ScheduleConverter method toJSON.
@Override
public JSONObject toJSON(Schedule o) {
JSONObject c = new JSONObject();
c.put("id", getJSONId());
if (o.getNode() != null) {
c.put("node", JSONs.elementToJSON(o.getNode()));
} else {
c.put("vm", JSONs.elementToJSON(o.getVM()));
}
c.put("start", o.getStart());
c.put("END", o.getEnd());
return c;
}
Aggregations