@Test public void objectApplicationToJSONTest() throws JDOMException, IOException, ParseException { Application application = new Application(); application.setHref("/applications/101"); application.setId(101); application.setName("SaaS Application"); Deployment deployment1 = new Deployment(); deployment1.setId(1); deployment1.setHref("/applications/101/deployments/1"); deployment1.setPrice("222"); deployment1.setStatus("DELETED"); Link linkSelf = new Link(); linkSelf.setRel("self"); linkSelf.setType("application/xml"); linkSelf.setHref("/applications/101/deployments/1"); deployment1.addLink(linkSelf); Link linkApplication = new Link(); linkApplication.setRel("application"); linkApplication.setType("application/xml"); linkApplication.setHref("/applications/101"); deployment1.addLink(linkApplication); application.addDeployment(deployment1); Link link = new Link(); link.setRel("self"); link.setType("application/xml"); link.setHref("/applications/101"); application.addLink(link); Link linkParent = new Link(); linkParent.setRel("parent"); linkParent.setType("application/xml"); linkParent.setHref("/applications"); application.addLink(linkParent); VM vm1 = new VM(); vm1.setId(33); vm1.setHref("/applications/101/deployments/1/vms/33"); vm1.setOvfId("vm ovf id"); vm1.setProviderId("IaaS vm Id"); vm1.setProviderVmId("IaaS provider Id"); vm1.setStatus("IaaS status of the VM"); vm1.setIp("172.0.0.1"); Image image1 = new Image(); image1.setHref("hrefImage1"); image1.setId(111); image1.setOvfId("333"); image1.setProviderImageId("444"); image1.setOvfHref("dfs image1.setProviderId("provider-id"); vm1.addImage(image1); vm1.setSlaAgreement("sla agreement reference"); Link linkVm1Self = new Link(); linkVm1Self.setRel("self"); linkVm1Self.setType("application/xml"); linkVm1Self.setHref("/applications/101/deployments/1/vms/33"); vm1.addLink(linkVm1Self); Link linkVm1Parent = new Link(); linkVm1Parent.setRel("deployment"); linkVm1Parent.setType("application/xml"); linkVm1Parent.setHref("/applications/101/deployments/1"); vm1.addLink(linkVm1Parent); deployment1.addVM(vm1); VM vm2 = new VM(); vm2.setId(44); vm2.setHref("/applications/101/deployments/1/vms/44"); vm2.setOvfId("vm ovf id"); vm2.setProviderId("IaaS vm Id"); vm2.setProviderVmId("IaaS provider Id"); vm2.setStatus("IaaS status of the VM"); vm2.setIp("172.0.0.2"); vm2.setSlaAgreement("sla agreement reference"); Image image2 = new Image(); image2.setHref("hrefImage2"); image2.setId(111); image2.setOvfId("333"); image2.setProviderImageId("444"); vm2.addImage(image2); Link linkVm2Self = new Link(); linkVm2Self.setRel("self"); linkVm2Self.setType("application/xml"); linkVm2Self.setHref("/applications/101/deployments/1/vms/44"); vm2.addLink(linkVm2Self); Link linkVm2Parent = new Link(); linkVm2Parent.setRel("deployment"); linkVm2Parent.setType("application/xml"); linkVm2Parent.setHref("/applications/101/deployments/1"); vm2.addLink(linkVm2Parent); deployment1.addVM(vm2); String json = ModelConverter.objectApplicationToJSON(application); JSONParser parser = new JSONParser(); Object obj = parser.parse(json); JSONObject jsonObject = (JSONObject) obj; assertEquals("/applications/101", (String) jsonObject.get("href")); assertEquals(101l, jsonObject.get("id")); assertEquals("SaaS Application", (String) jsonObject.get("name")); jsonObject = (JSONObject) jsonObject.get("deployments"); JSONArray deployments = (JSONArray) jsonObject.get("deployment"); jsonObject = (JSONObject) deployments.get(0); assertEquals("/applications/101/deployments/1", (String) jsonObject.get("href")); }
public static String objectApplicationToJSON(Application application) { return toJSON(Application.class, application); }
ModelConverter { public static String objectApplicationToJSON(Application application) { return toJSON(Application.class, application); } }
ModelConverter { public static String objectApplicationToJSON(Application application) { return toJSON(Application.class, application); }  }
ModelConverter { public static String objectApplicationToJSON(Application application) { return toJSON(Application.class, application); }  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 objectApplicationToJSON(Application application) { return toJSON(Application.class, application); }  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);  }