@Test public void applicationManagerMessageToJSON() throws ParseException { ApplicationManagerMessage amMessage = new ApplicationManagerMessage(); amMessage.setApplicationId("app-id"); amMessage.setDeploymentId("deplo-id"); amMessage.setStatus("status"); eu.ascetic.paas.applicationmanager.amqp.model.VM vm1 = new eu.ascetic.paas.applicationmanager.amqp.model.VM(); vm1.setIaasMonitoringVmId("aaa"); vm1.setIaasVmId("bbb"); vm1.setOvfId("ccc"); vm1.setStatus("ddd"); vm1.setVmId("eee"); vm1.setProviderId("provider-id"); eu.ascetic.paas.applicationmanager.amqp.model.VM vm2 = new eu.ascetic.paas.applicationmanager.amqp.model.VM(); vm2.setIaasMonitoringVmId("zzz"); vm2.setIaasVmId("yyy"); vm2.setOvfId("xxx"); vm2.setStatus("ttt"); vm2.setVmId("www"); vm2.setMetricName("power"); vm2.setValue(2.0); vm2.setUnits("W"); vm2.setTimestamp(111l); vm2.setProviderId("1122"); amMessage.addVM(vm1); amMessage.addVM(vm2); String output = ModelConverter.applicationManagerMessageToJSON(amMessage); JSONParser parser = new JSONParser(); Object obj = parser.parse(output); JSONObject jsonObject = (JSONObject) obj; assertEquals("app-id", (String) jsonObject.get("applicationId")); assertEquals("deplo-id", (String) jsonObject.get("deploymentId")); assertEquals("status", (String) jsonObject.get("status")); JSONArray vms = (JSONArray) jsonObject.get("vms"); jsonObject = (JSONObject) vms.get(0); assertEquals("eee", (String) jsonObject.get("vmId")); assertEquals("bbb", (String) jsonObject.get("iaasVmId")); assertEquals("aaa", (String) jsonObject.get("iaasMonitoringVmId")); assertEquals("ccc", (String) jsonObject.get("ovfId")); assertEquals("ddd", (String) jsonObject.get("status")); assertEquals("provider-id", (String) jsonObject.get("providerId")); jsonObject = (JSONObject) vms.get(1); assertEquals("www", (String) jsonObject.get("vmId")); assertEquals("yyy", (String) jsonObject.get("iaasVmId")); assertEquals("zzz", (String) jsonObject.get("iaasMonitoringVmId")); assertEquals("xxx", (String) jsonObject.get("ovfId")); assertEquals("ttt", (String) jsonObject.get("status")); assertEquals("1122", (String) jsonObject.get("providerId")); assertEquals("power", (String) jsonObject.get("metricName")); assertEquals(2.0, (double) jsonObject.get("value"), 0.00001); assertEquals(111l, (long) jsonObject.get("timestamp")); assertEquals("W", (String) jsonObject.get("units")); }
public static String applicationManagerMessageToJSON(ApplicationManagerMessage amMessage) { return toJSON(ApplicationManagerMessage.class, amMessage); }
ModelConverter { public static String applicationManagerMessageToJSON(ApplicationManagerMessage amMessage) { return toJSON(ApplicationManagerMessage.class, amMessage); } }
ModelConverter { public static String applicationManagerMessageToJSON(ApplicationManagerMessage amMessage) { return toJSON(ApplicationManagerMessage.class, amMessage); }  }
ModelConverter { public static String applicationManagerMessageToJSON(ApplicationManagerMessage amMessage) { return toJSON(ApplicationManagerMessage.class, amMessage); }  static String objectCollectionToXML(Collection collection); static String objectCollectionToJSON(Collection collection); static Collection xmlCollectionToObject(String xml); static Collection jsonCollectionToObject(String xml); static String objectSLAApplicationTermToXML(SLAApplicationTerms slaAppTerms); static String objectSLAApplicationTermToJSON(SLAApplicationTerms slaAppTerms); static SLAApplicationTerms xmlSLAApplicationTermsToObject(String xml); static SLAApplicationTerms jsonSLAApplicationTermsToObject(String jsonString); static String objectApplicationToXML(Application application); static String objectApplicationToJSON(Application application); static Application xmlApplicationToObject(String xml); static Application jsonApplicationToObject(String jsonString); static String slaLitmitsToXML(SLALimits slaLimits); static SLALimits xmlSLALimitsToObject(String xml); static String objectRootToXML(Root root); static String applicationManagerMessageToJSON(ApplicationManagerMessage amMessage); static ApplicationManagerMessage jsonToApplicationManagerMessage(String json); static Deployment xmlDeploymentToObject(String xml); static Deployment jsonDeploymentToObject(String json); static String objectDeploymentToJSON(Deployment deployment); static String objectDeploymentToXML(Deployment deployment); static VM xmlVMToObject(String xml); static String objectVMToXML(VM vm); static Agreement xmlAgreementToObject(String xml); static String objectAgreementToXML(Agreement agreement); static String objectEnergyMeasurementToXML(EnergyMeasurement energyMeasurement); static String objectEnergyMeasurementToJSON(EnergyMeasurement energyMeasurement); static EnergyMeasurement xmlEnergyMeasurementToObject(String xml); static String objectPowerMeasurementToXML(PowerMeasurement powerMeasurement); static String objectPowerMeasurementToJSON(PowerMeasurement powerMeasurement); static PowerMeasurement xmlPowerMeasurementToObject(String xml); static String objectCostToXML(Cost cost); static String objectCostToJSON(Cost cost); static Cost xmlCostToObject(String xml); }
ModelConverter { public static String applicationManagerMessageToJSON(ApplicationManagerMessage amMessage) { return toJSON(ApplicationManagerMessage.class, amMessage); }  static String objectCollectionToXML(Collection collection); static String objectCollectionToJSON(Collection collection); static Collection xmlCollectionToObject(String xml); static Collection jsonCollectionToObject(String xml); static String objectSLAApplicationTermToXML(SLAApplicationTerms slaAppTerms); static String objectSLAApplicationTermToJSON(SLAApplicationTerms slaAppTerms); static SLAApplicationTerms xmlSLAApplicationTermsToObject(String xml); static SLAApplicationTerms jsonSLAApplicationTermsToObject(String jsonString); static String objectApplicationToXML(Application application); static String objectApplicationToJSON(Application application); static Application xmlApplicationToObject(String xml); static Application jsonApplicationToObject(String jsonString); static String slaLitmitsToXML(SLALimits slaLimits); static SLALimits xmlSLALimitsToObject(String xml); static String objectRootToXML(Root root); static String applicationManagerMessageToJSON(ApplicationManagerMessage amMessage); static ApplicationManagerMessage jsonToApplicationManagerMessage(String json); static Deployment xmlDeploymentToObject(String xml); static Deployment jsonDeploymentToObject(String json); static String objectDeploymentToJSON(Deployment deployment); static String objectDeploymentToXML(Deployment deployment); static VM xmlVMToObject(String xml); static String objectVMToXML(VM vm); static Agreement xmlAgreementToObject(String xml); static String objectAgreementToXML(Agreement agreement); static String objectEnergyMeasurementToXML(EnergyMeasurement energyMeasurement); static String objectEnergyMeasurementToJSON(EnergyMeasurement energyMeasurement); static EnergyMeasurement xmlEnergyMeasurementToObject(String xml); static String objectPowerMeasurementToXML(PowerMeasurement powerMeasurement); static String objectPowerMeasurementToJSON(PowerMeasurement powerMeasurement); static PowerMeasurement xmlPowerMeasurementToObject(String xml); static String objectCostToXML(Cost cost); static String objectCostToJSON(Cost cost); static Cost xmlCostToObject(String xml);  }