diff options
Diffstat (limited to 'plans')
6 files changed, 270 insertions, 75 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/AssetInfo.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/AssetInfo.java index 39055cf5..17bcdda8 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/AssetInfo.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/AssetInfo.java @@ -229,7 +229,9 @@ public class AssetInfo implements Serializable { @Override public String toString() { final StringBuilder sb = new StringBuilder(); - sb.append("class AssetInfo {\n"); + sb.append("class "); + sb.append(this.getClass().getName()); + sb.append(" {\n"); sb.append(" uuid: ").append(uuid).append("\n"); sb.append(" invariantUuid: ").append(invariantUuid).append("\n"); sb.append(" name: ").append(name).append("\n"); diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/AssetType.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/AssetType.java index 749a714f..a86e0630 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/AssetType.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/AssetType.java @@ -19,13 +19,96 @@ */ package org.onap.so.sdcsimulator.models; - /** +import static org.onap.so.sdcsimulator.utils.Constants.CATALOG_URL; +import static org.onap.so.sdcsimulator.utils.Constants.FORWARD_SLASH; +import java.io.File; +import java.io.IOException; +import org.springframework.core.io.Resource; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** * * @author Waqas Ikram (waqas.ikram@est.tech) * */ public enum AssetType { - RESOURCES, SERVICES; + RESOURCES { + @Override + public AssetInfo getAssetInfo(final Resource resource) throws IOException { + return OBJ_MAPPER.readValue(resource.getInputStream(), ResourceAssetInfo.class); + } + + @Override + public AssetInfo getAssetInfo(final File file) throws IOException { + return OBJ_MAPPER.readValue(file, ResourceAssetInfo.class); + } + + @Override + public Metadata getMetadata(final Resource resource) throws IOException { + return OBJ_MAPPER.readValue(resource.getInputStream(), ResourceMetadata.class); + } + + @Override + public Metadata getMetadata(final File file) throws IOException { + return OBJ_MAPPER.readValue(file, ResourceMetadata.class); + } + + }, + SERVICES { + @Override + public AssetInfo getAssetInfo(final Resource resource) throws IOException { + return OBJ_MAPPER.readValue(resource.getInputStream(), ServiceAssetInfo.class); + } + + @Override + public AssetInfo getAssetInfo(final File file) throws IOException { + return OBJ_MAPPER.readValue(file, ServiceAssetInfo.class); + } + + @Override + public Metadata getMetadata(final Resource resource) throws IOException { + return OBJ_MAPPER.readValue(resource.getInputStream(), ServiceMetadata.class); + } + + @Override + public Metadata getMetadata(final File file) throws IOException { + return OBJ_MAPPER.readValue(file, ServiceMetadata.class); + } + + }; + + private static final ObjectMapper OBJ_MAPPER = + new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + + public abstract AssetInfo getAssetInfo(final Resource resource) throws IOException; + + public abstract AssetInfo getAssetInfo(final File file) throws IOException; + + public abstract Metadata getMetadata(final Resource resource) throws IOException; + + public abstract Metadata getMetadata(final File file) throws IOException; + + public String getToscaModelUrl(final String filename) { + return CATALOG_URL + FORWARD_SLASH + this.toString().toLowerCase() + FORWARD_SLASH + filename + "/toscaModel"; + } + + public AssetInfo getDefaultAssetInfo(final String filename) { + AssetInfo defaultValue = null; + + if (this.equals(RESOURCES)) { + defaultValue = new ResourceAssetInfo().subCategory("Network Service"); + } else if (this.equals(SERVICES)) { + defaultValue = new ServiceAssetInfo().distributionStatus("DISTRIBUTED"); + } else { + defaultValue = new AssetInfo(); + } + + return defaultValue.uuid(filename).invariantUuid(filename).name(filename).version("1.0") + .toscaModelUrl(getToscaModelUrl(filename)).category("Generic").lifecycleState("CERTIFIED") + .lastUpdaterUserId("SDC_SIMULATOR"); + } } diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ResourceMetadata.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ResourceMetadata.java new file mode 100644 index 00000000..9ff02c43 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ResourceMetadata.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.sdcsimulator.models; + +import java.io.Serializable; +import org.springframework.util.ObjectUtils; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class ResourceMetadata extends Metadata implements Serializable { + + private static final long serialVersionUID = -6812049917047990700L; + + @JsonProperty("subCategory") + private String subCategory; + + public String getSubCategory() { + return subCategory; + } + + public void setSubCategory(final String subCategory) { + this.subCategory = subCategory; + } + + public ResourceMetadata subCategory(final String subCategory) { + this.subCategory = subCategory; + return this; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + super.hashCode(); + result = prime * result + ((subCategory == null) ? 0 : subCategory.hashCode()); + + return result; + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof ResourceMetadata) { + final ResourceMetadata other = (ResourceMetadata) obj; + return super.equals(obj) && ObjectUtils.nullSafeEquals(subCategory, other.subCategory); + + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append(super.toString()); + sb.deleteCharAt(sb.length() - 1); + sb.append(" subCategory: ").append(subCategory).append("\n"); + + sb.append("}"); + return sb.toString(); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ServiceMetadata.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ServiceMetadata.java new file mode 100644 index 00000000..5a2a8ade --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ServiceMetadata.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.sdcsimulator.models; + +import java.io.Serializable; +import org.springframework.util.ObjectUtils; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class ServiceMetadata extends Metadata implements Serializable { + + private static final long serialVersionUID = -5677805295913361365L; + @JsonProperty("distributionStatus") + private String distributionStatus; + + public String getDistributionStatus() { + return distributionStatus; + } + + public void setDistributionStatus(final String distributionStatus) { + this.distributionStatus = distributionStatus; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + super.hashCode(); + result = prime * result + ((distributionStatus == null) ? 0 : distributionStatus.hashCode()); + + return result; + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof ServiceMetadata) { + final ServiceMetadata other = (ServiceMetadata) obj; + return super.equals(obj) && ObjectUtils.nullSafeEquals(distributionStatus, other.distributionStatus); + + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append(super.toString()); + sb.deleteCharAt(sb.length() - 1); + sb.append(" distributionStatus: ").append(distributionStatus).append("\n"); + + sb.append("}"); + return sb.toString(); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/AssetProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/AssetProviderImpl.java index d2614029..28800b51 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/AssetProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/AssetProviderImpl.java @@ -20,14 +20,12 @@ package org.onap.so.sdcsimulator.providers; -import static org.onap.so.sdcsimulator.utils.Constants.CATALOG_URL; import static org.onap.so.sdcsimulator.utils.Constants.DOT_CSAR; import static org.onap.so.sdcsimulator.utils.Constants.DOT_JSON; import static org.onap.so.sdcsimulator.utils.Constants.FORWARD_SLASH; import static org.onap.so.sdcsimulator.utils.Constants.MAIN_RESOURCE_FOLDER; import static org.onap.so.sdcsimulator.utils.Constants.WILD_CARD_REGEX; import static org.springframework.core.io.support.ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.DirectoryStream; @@ -40,8 +38,6 @@ import java.util.Set; import org.onap.so.sdcsimulator.models.AssetInfo; import org.onap.so.sdcsimulator.models.AssetType; import org.onap.so.sdcsimulator.models.Metadata; -import org.onap.so.sdcsimulator.models.ResourceAssetInfo; -import org.onap.so.sdcsimulator.models.ServiceAssetInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -51,8 +47,6 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.stereotype.Service; import org.springframework.util.StreamUtils; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; /** * @author Waqas Ikram (waqas.ikram@est.tech) @@ -62,9 +56,6 @@ public class AssetProviderImpl implements AssetProvider { private static final Logger LOGGER = LoggerFactory.getLogger(AssetProvider.class); - private final ObjectMapper mapper = - new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);; - private final String resourceLocation; private final ResourcePatternResolver resourcePatternResolver; @@ -133,7 +124,7 @@ public class AssetProviderImpl implements AssetProvider { if (Files.exists(metadataFilePath)) { LOGGER.info("Found metadata file on file system using path: {}", metadataFilePath); - return Optional.of(mapper.readValue(metadataFilePath.toFile(), Metadata.class)); + return Optional.of(assetType.getMetadata(metadataFilePath.toFile())); } } catch (final IOException ioException) { @@ -147,7 +138,7 @@ public class AssetProviderImpl implements AssetProvider { final ClassPathResource classPathResource = getClassPathResource(path); if (classPathResource.exists()) { LOGGER.info("Found metadata file in classpath using path: {}", path); - return Optional.of(mapper.readValue(classPathResource.getInputStream(), Metadata.class)); + return Optional.of(assetType.getMetadata(classPathResource)); } } catch (final IOException ioException) { LOGGER.error("Unable to find metadata file in classpath", ioException); @@ -161,15 +152,15 @@ public class AssetProviderImpl implements AssetProvider { final Resource jsonResource = resource.createRelative(filename + DOT_JSON); if (jsonResource != null && jsonResource.exists()) { - final AssetInfo assetInfo = getJsonAssetInfo(assetType, jsonResource); + final AssetInfo assetInfo = assetType.getAssetInfo(jsonResource); assetInfo.setUuid(filename); - assetInfo.setToscaModelUrl(getToscaModelUrl(filename, assetType)); + assetInfo.setToscaModelUrl(assetType.getToscaModelUrl(filename)); LOGGER.info("Found AssetInfo file in classpath: {}", assetInfo); return assetInfo; } - final AssetInfo assetInfo = getAssetInfo(filename, assetType); + final AssetInfo assetInfo = assetType.getDefaultAssetInfo(filename); LOGGER.info("Returning AssetInfo: {}", assetInfo); return assetInfo; @@ -179,67 +170,18 @@ public class AssetProviderImpl implements AssetProvider { throws IOException { final Path assetJsonFilePath = entry.getParent().resolve(filename + DOT_JSON); if (Files.exists(assetJsonFilePath)) { - final AssetInfo assetInfo = getJsonAssetInfo(assetType, assetJsonFilePath.toFile()); + final AssetInfo assetInfo = assetType.getAssetInfo(assetJsonFilePath.toFile()); assetInfo.setUuid(filename); - assetInfo.setToscaModelUrl(getToscaModelUrl(filename, assetType)); + assetInfo.setToscaModelUrl(assetType.getToscaModelUrl(filename)); LOGGER.info("Found AssetInfo file on file system: {}", assetInfo); return assetInfo; } - final AssetInfo assetInfo = getAssetInfo(filename, assetType); + final AssetInfo assetInfo = assetType.getDefaultAssetInfo(filename); LOGGER.info("Returning AssetInfo: {}", assetInfo); return assetInfo; } - - private AssetInfo getJsonAssetInfo(final AssetType assetType, final Resource jsonResource) throws IOException { - if (AssetType.RESOURCES.equals(assetType)) { - return mapper.readValue(jsonResource.getInputStream(), ResourceAssetInfo.class); - } - - if (AssetType.SERVICES.equals(assetType)) { - return mapper.readValue(jsonResource.getInputStream(), ServiceAssetInfo.class); - } - - return mapper.readValue(jsonResource.getInputStream(), AssetInfo.class); - } - - - private AssetInfo getJsonAssetInfo(final AssetType assetType, final File file) throws IOException { - if (AssetType.RESOURCES.equals(assetType)) { - return mapper.readValue(file, ResourceAssetInfo.class); - } - - if (AssetType.SERVICES.equals(assetType)) { - return mapper.readValue(file, ServiceAssetInfo.class); - } - - return mapper.readValue(file, AssetInfo.class); - } - - private AssetInfo getAssetInfo(final String filename, final AssetType assetType) { - return getAssetInfoObject(assetType).uuid(filename).invariantUuid(filename).name(filename).version("1.0") - .toscaModelUrl(getToscaModelUrl(filename, assetType)).category("Generic").lifecycleState("CERTIFIED") - .lastUpdaterUserId("SDC_SIMULATOR"); - } - - private AssetInfo getAssetInfoObject(final AssetType assetType) { - if (AssetType.RESOURCES.equals(assetType)) { - return new ResourceAssetInfo().subCategory("Network Service"); - } - - if (AssetType.SERVICES.equals(assetType)) { - return new ServiceAssetInfo().distributionStatus("DISTRIBUTED"); - } - - return new AssetInfo(); - } - - private String getToscaModelUrl(final String filename, final AssetType assetType) { - return CATALOG_URL + FORWARD_SLASH + assetType.toString().toLowerCase() + FORWARD_SLASH + filename - + "/toscaModel"; - } - private String getFilenameWithoutExtension(final String filename) { return filename.substring(0, filename.lastIndexOf('.')); } diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java index d7ae74bb..57db74c3 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java @@ -29,7 +29,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.onap.so.sdcsimulator.models.Metadata; import org.onap.so.sdcsimulator.models.ResourceAssetInfo; +import org.onap.so.sdcsimulator.models.ResourceMetadata; import org.onap.so.sdcsimulator.models.ServiceAssetInfo; +import org.onap.so.sdcsimulator.models.ServiceMetadata; import org.onap.so.sdcsimulator.utils.Constants; import org.onap.so.simulator.model.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; @@ -58,6 +60,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @Configuration public class CatalogControllerTest { + private static final String SUB_CATEGORY = "Network Service"; + + private static final String DISTRIBUTION_STATUS = "DISTRIBUTED"; + private static final String SERVICE_ID = "9bb8c882-44a1-4b67-a12c-5a998e18d6ba"; private static final String RESOURCE_ID = "73522444-e8e9-49c1-be29-d355800aa349"; @@ -97,6 +103,7 @@ public class CatalogControllerTest { assertEquals(HttpStatus.OK, response.getStatusCode()); assertTrue(response.hasBody()); assertEquals(1, response.getBody().size()); + assertEquals(SUB_CATEGORY, response.getBody().iterator().next().getSubCategory()); } @@ -110,6 +117,7 @@ public class CatalogControllerTest { assertEquals(HttpStatus.OK, response.getStatusCode()); assertTrue(response.hasBody()); assertEquals(1, response.getBody().size()); + assertEquals(DISTRIBUTION_STATUS, response.getBody().iterator().next().getDistributionStatus()); } @@ -130,15 +138,16 @@ public class CatalogControllerTest { final String url = getBaseUrl() + "/resources/" + RESOURCE_ID + "/metadata"; - final ResponseEntity<Metadata> response = - restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), Metadata.class); + final ResponseEntity<ResourceMetadata> response = + restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), ResourceMetadata.class); assertEquals(HttpStatus.OK, response.getStatusCode()); assertTrue(response.hasBody()); - final Metadata actual = response.getBody(); + final ResourceMetadata actual = response.getBody(); assertEquals(8, actual.getResources().size()); assertEquals(3, actual.getArtifacts().size()); + assertEquals(SUB_CATEGORY, actual.getSubCategory()); } @@ -147,15 +156,16 @@ public class CatalogControllerTest { final String url = getBaseUrl() + "/services/" + SERVICE_ID + "/metadata"; - final ResponseEntity<Metadata> response = - restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), Metadata.class); + final ResponseEntity<ServiceMetadata> response = + restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), ServiceMetadata.class); assertEquals(HttpStatus.OK, response.getStatusCode()); assertTrue(response.hasBody()); - final Metadata actual = response.getBody(); + final ServiceMetadata actual = response.getBody(); assertEquals(1, actual.getResources().size()); assertEquals(1, actual.getArtifacts().size()); + assertEquals(DISTRIBUTION_STATUS, actual.getDistributionStatus()); } |