@Test public void testConversion() throws JSONConverterException { Model mo = new DefaultModel(); Mapping ma = mo.getMapping(); Node n1 = mo.newNode(); VM vm1 = mo.newVM(); VM vm2 = mo.newVM(); ma.addOnlineNode(n1); ma.addOfflineNode(n1); ma.addReadyVM(vm1); ma.addReadyVM(vm2); List<SatConstraint> cstrs = new ArrayList<>(); cstrs.addAll(Online.newOnline(ma.getAllNodes())); cstrs.add(new Running(vm2)); Instance i = new Instance(mo, cstrs, new MinMTTR()); InstanceConverter conv = new InstanceConverter(); String o = conv.toJSONString(i); System.out.println(o); Instance res = conv.fromJSON(o); Assert.assertEquals(i, res); }
@Override public Instance fromJSON(JSONObject in) throws JSONConverterException { checkKeys(in, MODEL_LABEL, CONSTRAINTS_LABEL, OBJ_LABEL); Model mo = moc.fromJSON((JSONObject) in.get(MODEL_LABEL)); return new Instance(mo, cc.listFromJSON(mo, (JSONArray) in.get(CONSTRAINTS_LABEL)), (OptConstraint) cc.fromJSON(mo, (JSONObject) in.get(OBJ_LABEL))); }
InstanceConverter implements JSONObjectConverter<Instance> { @Override public Instance fromJSON(JSONObject in) throws JSONConverterException { checkKeys(in, MODEL_LABEL, CONSTRAINTS_LABEL, OBJ_LABEL); Model mo = moc.fromJSON((JSONObject) in.get(MODEL_LABEL)); return new Instance(mo, cc.listFromJSON(mo, (JSONArray) in.get(CONSTRAINTS_LABEL)), (OptConstraint) cc.fromJSON(mo, (JSONObject) in.get(OBJ_LABEL))); } }
InstanceConverter implements JSONObjectConverter<Instance> { @Override public Instance fromJSON(JSONObject in) throws JSONConverterException { checkKeys(in, MODEL_LABEL, CONSTRAINTS_LABEL, OBJ_LABEL); Model mo = moc.fromJSON((JSONObject) in.get(MODEL_LABEL)); return new Instance(mo, cc.listFromJSON(mo, (JSONArray) in.get(CONSTRAINTS_LABEL)), (OptConstraint) cc.fromJSON(mo, (JSONObject) in.get(OBJ_LABEL))); } InstanceConverter(); }
InstanceConverter implements JSONObjectConverter<Instance> { @Override public Instance fromJSON(JSONObject in) throws JSONConverterException { checkKeys(in, MODEL_LABEL, CONSTRAINTS_LABEL, OBJ_LABEL); Model mo = moc.fromJSON((JSONObject) in.get(MODEL_LABEL)); return new Instance(mo, cc.listFromJSON(mo, (JSONArray) in.get(CONSTRAINTS_LABEL)), (OptConstraint) cc.fromJSON(mo, (JSONObject) in.get(OBJ_LABEL))); } InstanceConverter(); @Override Instance fromJSON(JSONObject in); ModelConverter getModelConverter(); ConstraintsConverter getConstraintsConverter(); @Override JSONObject toJSON(Instance instance); }
InstanceConverter implements JSONObjectConverter<Instance> { @Override public Instance fromJSON(JSONObject in) throws JSONConverterException { checkKeys(in, MODEL_LABEL, CONSTRAINTS_LABEL, OBJ_LABEL); Model mo = moc.fromJSON((JSONObject) in.get(MODEL_LABEL)); return new Instance(mo, cc.listFromJSON(mo, (JSONArray) in.get(CONSTRAINTS_LABEL)), (OptConstraint) cc.fromJSON(mo, (JSONObject) in.get(OBJ_LABEL))); } InstanceConverter(); @Override Instance fromJSON(JSONObject in); ModelConverter getModelConverter(); ConstraintsConverter getConstraintsConverter(); @Override JSONObject toJSON(Instance instance);  }