@Test public void testLoadProductWithAttributes() throws Exception { String productReleaseJson = "{\"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\"}" + "]" + "}}}"; Response response = mock(Response.class); com.telefonica.euro_iaas.sdc.model.ProductRelease productRelease = new com.telefonica.euro_iaas.sdc.model.ProductRelease(); productRelease.setProduct(new com.telefonica.euro_iaas.sdc.model.Product("orion", "descr")); productRelease.setVersion("0.6.0"); when(builder.get()).thenReturn(response); when(pIService.load(anyString(), anyString(), anyString(), anyString())).thenReturn(productRelease); when(sdcClient.getProductReleaseService(anyString(), anyString())).thenReturn(pIService); when(response.readEntity(String.class)).thenReturn(productReleaseJson); ClaudiaData claudiaData = new ClaudiaData("org", "tenantId", "service"); PaasManagerUser user = new PaasManagerUser("user", "pass"); user.setToken("token"); claudiaData.setUser(user); ProductRelease product = productReleaseSdcDaoImpl.load("orion", "0.6.0", claudiaData); assertNotNull(product); }
public ProductRelease load(String product, String version, ClaudiaData data) throws EntityNotFoundException, SdcException { log.debug("Load by name " + product + " " + version); ProductRelease p = null; try { String url = sDCUtil.getSdcUtil(); log.info("Loading from SDC in url: " + url); com.telefonica.euro_iaas.sdc.client.services.ProductReleaseService pIService = sDCClient .getProductReleaseService(url, SDC_SERVER_MEDIATYPE); com.telefonica.euro_iaas.sdc.model.ProductRelease prod = pIService.load(product, version, data.getUser() .getToken(), data.getUser().getTenantId()); p = new ProductRelease(prod.getProduct().getName(), prod.getVersion()); for (com.telefonica.euro_iaas.sdc.model.Metadata sdcMetadata : prod.getProduct().getMetadatas()) { Metadata metadata = new Metadata(); metadata.setKey(sdcMetadata.getKey()); metadata.setValue(sdcMetadata.getValue()); metadata.setDescription(sdcMetadata.getDescription()); p.addMetadata(metadata); } for (com.telefonica.euro_iaas.sdc.model.Attribute att : prod.getProduct().getAttributes()) { Attribute attribute = new Attribute(); attribute.setKey(att.getKey()); attribute.setValue(att.getValue()); attribute.setType(att.getType()); attribute.setDescription(att.getDescription()); p.addAttribute(attribute); } } catch (OpenStackException e) { String message = "Error calling SDC to obtain the product: " + e.getMessage(); log.error(message); throw new SdcException(message); } catch (ResourceNotFoundException e) { String message = "The Product Release " + product + "-" + version + " is not present in SDC DataBase "; log.error(message); throw new EntityNotFoundException(ProductRelease.class, "name", "product" + "-" + "version"); } return p; }
ProductReleaseSdcDaoImpl implements ProductReleaseSdcDao { public ProductRelease load(String product, String version, ClaudiaData data) throws EntityNotFoundException, SdcException { log.debug("Load by name " + product + " " + version); ProductRelease p = null; try { String url = sDCUtil.getSdcUtil(); log.info("Loading from SDC in url: " + url); com.telefonica.euro_iaas.sdc.client.services.ProductReleaseService pIService = sDCClient .getProductReleaseService(url, SDC_SERVER_MEDIATYPE); com.telefonica.euro_iaas.sdc.model.ProductRelease prod = pIService.load(product, version, data.getUser() .getToken(), data.getUser().getTenantId()); p = new ProductRelease(prod.getProduct().getName(), prod.getVersion()); for (com.telefonica.euro_iaas.sdc.model.Metadata sdcMetadata : prod.getProduct().getMetadatas()) { Metadata metadata = new Metadata(); metadata.setKey(sdcMetadata.getKey()); metadata.setValue(sdcMetadata.getValue()); metadata.setDescription(sdcMetadata.getDescription()); p.addMetadata(metadata); } for (com.telefonica.euro_iaas.sdc.model.Attribute att : prod.getProduct().getAttributes()) { Attribute attribute = new Attribute(); attribute.setKey(att.getKey()); attribute.setValue(att.getValue()); attribute.setType(att.getType()); attribute.setDescription(att.getDescription()); p.addAttribute(attribute); } } catch (OpenStackException e) { String message = "Error calling SDC to obtain the product: " + e.getMessage(); log.error(message); throw new SdcException(message); } catch (ResourceNotFoundException e) { String message = "The Product Release " + product + "-" + version + " is not present in SDC DataBase "; log.error(message); throw new EntityNotFoundException(ProductRelease.class, "name", "product" + "-" + "version"); } return p; } }
ProductReleaseSdcDaoImpl implements ProductReleaseSdcDao { public ProductRelease load(String product, String version, ClaudiaData data) throws EntityNotFoundException, SdcException { log.debug("Load by name " + product + " " + version); ProductRelease p = null; try { String url = sDCUtil.getSdcUtil(); log.info("Loading from SDC in url: " + url); com.telefonica.euro_iaas.sdc.client.services.ProductReleaseService pIService = sDCClient .getProductReleaseService(url, SDC_SERVER_MEDIATYPE); com.telefonica.euro_iaas.sdc.model.ProductRelease prod = pIService.load(product, version, data.getUser() .getToken(), data.getUser().getTenantId()); p = new ProductRelease(prod.getProduct().getName(), prod.getVersion()); for (com.telefonica.euro_iaas.sdc.model.Metadata sdcMetadata : prod.getProduct().getMetadatas()) { Metadata metadata = new Metadata(); metadata.setKey(sdcMetadata.getKey()); metadata.setValue(sdcMetadata.getValue()); metadata.setDescription(sdcMetadata.getDescription()); p.addMetadata(metadata); } for (com.telefonica.euro_iaas.sdc.model.Attribute att : prod.getProduct().getAttributes()) { Attribute attribute = new Attribute(); attribute.setKey(att.getKey()); attribute.setValue(att.getValue()); attribute.setType(att.getType()); attribute.setDescription(att.getDescription()); p.addAttribute(attribute); } } catch (OpenStackException e) { String message = "Error calling SDC to obtain the product: " + e.getMessage(); log.error(message); throw new SdcException(message); } catch (ResourceNotFoundException e) { String message = "The Product Release " + product + "-" + version + " is not present in SDC DataBase "; log.error(message); throw new EntityNotFoundException(ProductRelease.class, "name", "product" + "-" + "version"); } return p; } ProductReleaseSdcDaoImpl(); }
ProductReleaseSdcDaoImpl implements ProductReleaseSdcDao { public ProductRelease load(String product, String version, ClaudiaData data) throws EntityNotFoundException, SdcException { log.debug("Load by name " + product + " " + version); ProductRelease p = null; try { String url = sDCUtil.getSdcUtil(); log.info("Loading from SDC in url: " + url); com.telefonica.euro_iaas.sdc.client.services.ProductReleaseService pIService = sDCClient .getProductReleaseService(url, SDC_SERVER_MEDIATYPE); com.telefonica.euro_iaas.sdc.model.ProductRelease prod = pIService.load(product, version, data.getUser() .getToken(), data.getUser().getTenantId()); p = new ProductRelease(prod.getProduct().getName(), prod.getVersion()); for (com.telefonica.euro_iaas.sdc.model.Metadata sdcMetadata : prod.getProduct().getMetadatas()) { Metadata metadata = new Metadata(); metadata.setKey(sdcMetadata.getKey()); metadata.setValue(sdcMetadata.getValue()); metadata.setDescription(sdcMetadata.getDescription()); p.addMetadata(metadata); } for (com.telefonica.euro_iaas.sdc.model.Attribute att : prod.getProduct().getAttributes()) { Attribute attribute = new Attribute(); attribute.setKey(att.getKey()); attribute.setValue(att.getValue()); attribute.setType(att.getType()); attribute.setDescription(att.getDescription()); p.addAttribute(attribute); } } catch (OpenStackException e) { String message = "Error calling SDC to obtain the product: " + e.getMessage(); log.error(message); throw new SdcException(message); } catch (ResourceNotFoundException e) { String message = "The Product Release " + product + "-" + version + " is not present in SDC DataBase "; log.error(message); throw new EntityNotFoundException(ProductRelease.class, "name", "product" + "-" + "version"); } return p; } 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); }
ProductReleaseSdcDaoImpl implements ProductReleaseSdcDao { public ProductRelease load(String product, String version, ClaudiaData data) throws EntityNotFoundException, SdcException { log.debug("Load by name " + product + " " + version); ProductRelease p = null; try { String url = sDCUtil.getSdcUtil(); log.info("Loading from SDC in url: " + url); com.telefonica.euro_iaas.sdc.client.services.ProductReleaseService pIService = sDCClient .getProductReleaseService(url, SDC_SERVER_MEDIATYPE); com.telefonica.euro_iaas.sdc.model.ProductRelease prod = pIService.load(product, version, data.getUser() .getToken(), data.getUser().getTenantId()); p = new ProductRelease(prod.getProduct().getName(), prod.getVersion()); for (com.telefonica.euro_iaas.sdc.model.Metadata sdcMetadata : prod.getProduct().getMetadatas()) { Metadata metadata = new Metadata(); metadata.setKey(sdcMetadata.getKey()); metadata.setValue(sdcMetadata.getValue()); metadata.setDescription(sdcMetadata.getDescription()); p.addMetadata(metadata); } for (com.telefonica.euro_iaas.sdc.model.Attribute att : prod.getProduct().getAttributes()) { Attribute attribute = new Attribute(); attribute.setKey(att.getKey()); attribute.setValue(att.getValue()); attribute.setType(att.getType()); attribute.setDescription(att.getDescription()); p.addAttribute(attribute); } } catch (OpenStackException e) { String message = "Error calling SDC to obtain the product: " + e.getMessage(); log.error(message); throw new SdcException(message); } catch (ResourceNotFoundException e) { String message = "The Product Release " + product + "-" + version + " is not present in SDC DataBase "; log.error(message); throw new EntityNotFoundException(ProductRelease.class, "name", "product" + "-" + "version"); } return p; } 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);  }