ProductReleaseSdcDaoImpl implements ProductReleaseSdcDao { public List<ProductRelease> fromStringToProductReleases(String sdcproductReleases) { List<ProductRelease> productReleases = new ArrayList<ProductRelease>(); JSONObject json = (JSONObject) JSONSerializer.toJSON(sdcproductReleases); Object obj = json.get("productRelease"); if (obj instanceof JSONObject) { JSONObject jsonProductRelease = (JSONObject) obj; ProductRelease productRelease = new ProductRelease(); productRelease.fromSdcJson(jsonProductRelease); productReleases.add(productRelease); } else { JSONArray ja = (JSONArray) obj; JSONArray jsonproductReleasesList = ja; for (Object o : jsonproductReleasesList) { ProductRelease productRelease = new ProductRelease(); JSONObject jsonProductRelease = (JSONObject) o; productRelease.fromSdcJson(jsonProductRelease); productReleases.add(productRelease); } } return productReleases; } ProductReleaseSdcDaoImpl(); HttpClientConnectionManager getHttpConnectionManager(); void setHttpConnectionManager(HttpClientConnectionManager httpConnectionManager); ProductRelease load(String product, String version, ClaudiaData data); List<String> findAllProducts(String token, String tenant); List<ProductRelease> fromStringToProductReleases(String sdcproductReleases); void setClient(Client client); Client getClient(); void setSDCUtil(SDCUtil sDCUtil); void setSDCClient(SDCClient sDCClient);  }
@Test public void testFromStringToProductReleasesTwoProductReleases() throws Exception { String twoProductReleaseString = "{\"productRelease\":[{" + "\"version\":\"0.8.1\"," + "\"product\":{" + "\"name\":\"orion\"," + "\"description\":\"\"," + "\"attributes\":[" + "{\"key\":\"openports\",\"value\":\"1026 27017 27018 27019 28017\"}," + "{\"key\":\"dd\",\"value\":\"dd\",\"description\":\"dd\"}" + "]," + "\"metadatas\":[" + "{\"key\":\"image\",\"value\":\"df44f62d-9d66-4dc5-b084-2d6c7bc4cfe4\"}," + "{\"key\":\"cookbook_url\",\"value\":\"\"}," + "{\"key\":\"cloud\",\"value\":\"yes\"}," + "{\"key\":\"installator\",\"value\":\"chef\"}," + "{\"key\":\"open_ports\",\"value\":\"80 22\"}" + "]" + "}}," + "{\"version\":\"0.6.0\"," + "\"product\":{" + "\"name\":\"orion\"," + "\"description\":\"\"," + "\"attributes\":[" + "{\"key\":\"openports\",\"value\":\"1026 27017 27018 27019 28017\"}," + "{\"key\":\"dd\",\"value\":\"dd\",\"description\":\"dd\"}" + "]," + "\"metadatas\":[" + "{\"key\":\"image\",\"value\":\"df44f62d-9d66-4dc5-b084-2d6c7bc4cfe4\"}," + "{\"key\":\"cookbook_url\",\"value\":\"\"}," + "{\"key\":\"cloud\",\"value\":\"yes\"}," + "{\"key\":\"installator\",\"value\":\"chef\"}," + "{\"key\":\"open_ports\",\"value\":\"80 22\"}" + "]" + "}}]}"; List<ProductRelease> productReleases = productReleaseSdcDaoImpl .fromStringToProductReleases(twoProductReleaseString); assertEquals(productReleases.size(), 2); }
@Test public void testFromStringToProductReleasesOneProductRelease() throws Exception { String twoProductReleaseString = "{\"productRelease\":{" + "\"version\":\"0.6.0\"," + "\"product\":{" + "\"name\":\"orion\"," + "\"description\":\"\"," + "\"attributes\":[" + "{\"key\":\"openports\",\"value\":\"1026 27017 27018 27019 28017\"}," + "{\"key\":\"dd\",\"value\":\"dd\",\"description\":\"dd\"}" + "]," + "\"metadatas\":[" + "{\"key\":\"image\",\"value\":\"df44f62d-9d66-4dc5-b084-2d6c7bc4cfe4\"}," + "{\"key\":\"cookbook_url\",\"value\":\"\"}," + "{\"key\":\"cloud\",\"value\":\"yes\"}," + "{\"key\":\"installator\",\"value\":\"chef\"}," + "{\"key\":\"open_ports\",\"value\":\"80 22\"}" + "]" + "}}}"; List<ProductRelease> productReleases = productReleaseSdcDaoImpl .fromStringToProductReleases(twoProductReleaseString); assertEquals(productReleases.size(), 1); }