From 0e93cb3b54e7868cfe5b8a85902adc100391da9c Mon Sep 17 00:00:00 2001 From: "Polavarapu, Chaitanya (cp8128)" Date: Tue, 9 Apr 2019 17:02:50 -0400 Subject: Updated to use dublin schema version Using 1.0.2 schema-service version Fixed the junit test failure for default service version Issue-ID: AAI-2338 Change-Id: Ie0ddda41f6895ff0ce8e97ad065fb935462e643a Signed-off-by: Polavarapu, Chaitanya (cp8128) --- pom.xml | 2 +- .../aai/babel/xml/generator/ModelGenerator.java | 12 +----- .../service/TestGenerateArtifactsServiceImpl.java | 50 ++++++++++++++++++++++ .../java/org/onap/aai/babel/testdata/CsarTest.java | 25 ++++++++++- .../response/responseWithVersionLessThan1.json | 1 + 5 files changed, 77 insertions(+), 13 deletions(-) create mode 100644 src/test/resources/response/responseWithVersionLessThan1.json diff --git a/pom.xml b/pom.xml index 5a5167d..1b7e91a 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,7 @@ 2.1 0.13.2 org.onap.aai.schema-service - 1.0.1 + 1.0.2 3.7 1.2.1 1.3.0 diff --git a/src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java index c5ea37a..6695241 100644 --- a/src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java +++ b/src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java @@ -45,8 +45,6 @@ public class ModelGenerator implements ArtifactGenerator { private static final Logger logger = LogHelper.INSTANCE; - private static final String VERSION_DELIMITER = "."; - private static final String VERSION_DELIMITER_REGEXP = "\\" + VERSION_DELIMITER; private static final String DEFAULT_SERVICE_VERSION = "1.0"; /** @@ -115,12 +113,9 @@ public class ModelGenerator implements ArtifactGenerator { } private static String getServiceVersion(String artifactVersion) { - logger.debug("Artifact version=" + artifactVersion ); - - // As of 1902, AAI-16260, we no longer edit the passed in artifact/service version. + logger.debug("Artifact version=" + artifactVersion); try { - // just make sure it's an integer - Integer.parseInt(artifactVersion.split(VERSION_DELIMITER_REGEXP)[0]); + return String.valueOf(Float.parseFloat(artifactVersion)); } catch (Exception e) { logger.warn(ApplicationMsgs.DISTRIBUTION_EVENT, "Error generating service version from artifact version: " + artifactVersion @@ -128,8 +123,5 @@ public class ModelGenerator implements ArtifactGenerator { + e); return DEFAULT_SERVICE_VERSION; } - - logger.debug("Use Artifact version as the serviceVersion=" + artifactVersion ); - return artifactVersion; } } diff --git a/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java b/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java index d011ba6..45eadb0 100644 --- a/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java +++ b/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java @@ -103,6 +103,56 @@ public class TestGenerateArtifactsServiceImpl { assertThat(response.toString(), response.getStatus(), is(Response.Status.OK.getStatusCode())); assertThat(response.getEntity(), is(getResponseJson("response.json"))); } + + /** + * Test with a valid request without Minor Artifact version. + * + * @throws URISyntaxException + * if the URI cannot be created + * @throws IOException + * if the resource cannot be loaded + */ + @Test + public void testGenerateArtifactsWithoutMinorArtifactVersion() throws URISyntaxException, IOException { + Response response = invokeService(CsarTest.VNF_VENDOR_CSAR.getJsonRequestWithArtifactVersion("1"), + Optional.of("transaction-id"), auth); + assertThat(response.toString(), response.getStatus(), is(Response.Status.OK.getStatusCode())); + assertThat(response.getEntity(), is(getResponseJson("response.json"))); + } + + /** + * Test with a valid request without Minor Artifact version. + * + * @throws URISyntaxException + * if the URI cannot be created + * @throws IOException + * if the resource cannot be loaded + */ + @Test + public void testGenerateArtifactsWithInvalidArtifactVersion() throws URISyntaxException, IOException { + Response response = invokeService(CsarTest.VNF_VENDOR_CSAR.getJsonRequestWithArtifactVersion("a"), + Optional.of("transaction-id"), auth); + assertThat(response.toString(), response.getStatus(), is(Response.Status.OK.getStatusCode())); + assertThat(response.getEntity(), is(getResponseJson("response.json"))); + } + + + /** + * Test with a valid request with Artifact version less than 1. + * + * @throws URISyntaxException + * if the URI cannot be created + * @throws IOException + * if the resource cannot be loaded + */ + @Test + public void testGenerateArtifactsWithArtifactVerLessThan1() throws URISyntaxException, IOException { + Response response = invokeService(CsarTest.VNF_VENDOR_CSAR.getJsonRequestWithArtifactVersion("0.1"), + Optional.of("transaction-id"), auth); + assertThat(response.toString(), response.getStatus(), is(Response.Status.OK.getStatusCode())); + assertThat(response.getEntity(), is(getResponseJson("responseWithVersionLessThan1.json"))); + } + /** * Test with a valid request, using a CSAR file that has no VNF configuration present. diff --git a/src/test/java/org/onap/aai/babel/testdata/CsarTest.java b/src/test/java/org/onap/aai/babel/testdata/CsarTest.java index 8b28551..1885555 100644 --- a/src/test/java/org/onap/aai/babel/testdata/CsarTest.java +++ b/src/test/java/org/onap/aai/babel/testdata/CsarTest.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2019 European Software Marketing Ltd. + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 European Software Marketing Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,12 +39,18 @@ public enum CsarTest { VNF_VENDOR_CSAR("catalog_csar.csar"), NO_VNF_CONFIG_CSAR("noVnfConfiguration.csar"), SD_WAN_CSAR_FILE("service-SdWanServiceTest-csar.csar"), + COS_AVPN_CSAR_FILE("service_CosAvpn_csar.csar"), MISSING_METADATA_CSAR("service-MissingMetadataTest.csar"), NO_YAML_FILES("noYmlFilesArchive.zip"), PORT_MIRROR_CSAR("service_PortMirror.csar"), MULTIPLE_VNF_CSAR("catalog_csar_too_many_vnfConfigurations.csar"), NETWORK_COLLECTION_CSAR_FILE("service_NetworkCollection.csar"), + RG_COLLECTOR_615_CSAR_FILE("service-RgCollector615-csar.csar"), + VDBE_SERVICE_CSAR_FILE("service-VdbeSrv-csar.csar"), + VNFOD_SERVICE("service-Dev2devnfodservice17July-csar.csar"), + CHILD_RESOURCE_CSAR_FILE("service-NetworkCloudVnfServiceMock-csar.csar"), SERVICE_PROXY_CSAR_FILE("service-S1-csar.csar"); + // @formatter:on private String filename; @@ -102,4 +108,19 @@ public enum CsarTest { request.setCsar(new String(GeneratorUtil.encode(getContent()))); return new Gson().toJson(request); } + + /** + * Create a BabelRequest containing the encoded CSAR content by passing in the artifact version. + * + * @return a new Babel request for this CSAR + * @throws IOException + * if an I/O exception occurs + */ + public String getJsonRequestWithArtifactVersion(String artifactVersion) throws IOException { + BabelRequest request = new BabelRequest(); + request.setArtifactName(getName()); + request.setArtifactVersion(artifactVersion); + request.setCsar(new String(GeneratorUtil.encode(getContent()))); + return new Gson().toJson(request); + } } diff --git a/src/test/resources/response/responseWithVersionLessThan1.json b/src/test/resources/response/responseWithVersionLessThan1.json new file mode 100644 index 0000000..2ffeff6 --- /dev/null +++ b/src/test/resources/response/responseWithVersionLessThan1.json @@ -0,0 +1 @@ +[{"name":"AAI-29NFOD_S-service-0.1.xml","type":"MODEL","payload":"\n 29NFOD_S-invariant-id\n service\n \n \n 29NFOD_S-version-id\n 29NFOD_S\n 0.1\n 29NFOD\n \n \n T\n unbounded\n \n \n T\n unbounded\n \n \n \n model-ver\n \n model-ver.model-version-id\n 29NFOD 0-version-id\n \n \n model.model-invariant-id\n 29NFOD 0-invariant-id\n \n \n \n \n \n \n \n model-ver\n \n model-ver.model-version-id\n service-instance-version-id\n \n \n model.model-invariant-id\n service-instance-invariant-id\n \n \n \n \n \n \n \n"},{"name":"AAI-29NFOD-resource-1.0.xml","type":"MODEL","payload":"\n 29NFOD 0-invariant-id\n resource\n \n \n 29NFOD 0-version-id\n 29NFOD\n 1.0\n 29NFOD\n \n \n T\n unbounded\n \n \n \n model-ver\n \n model-ver.model-version-id\n generic-vnf-version-id\n \n \n model.model-invariant-id\n generic-vnf-invariant-id\n \n \n \n \n \n \n \n"},{"name":"vnfVendorImageConfigurations","type":"VNFCATALOG","payload":"[{\"application\":\"VM00\",\"application-vendor\":\"29NFOD\",\"application-version\":\"3.16.1\"},{\"application\":\"VM00\",\"application-vendor\":\"29NFOD\",\"application-version\":\"3.16.9\"},{\"application\":\"VM01\",\"application-vendor\":\"29NFOD\",\"application-version\":\"3.16.1\"},{\"application\":\"VM01\",\"application-vendor\":\"29NFOD\",\"application-version\":\"3.16.9\"}]"}] -- cgit 1.2.3-korg