diff options
Diffstat (limited to 'plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator')
8 files changed, 227 insertions, 46 deletions
diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/pom.xml b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/pom.xml index 30d25215..99768146 100755 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/pom.xml +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/pom.xml @@ -55,6 +55,11 @@ <groupId>javax.activation</groupId> <artifactId>activation</artifactId> </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.8.5</version> + </dependency> </dependencies> <build> <plugins> diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/controller/ServiceDesignAndCreationController.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/controller/ServiceDesignAndCreationController.java index ddc2b624..13753871 100644 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/controller/ServiceDesignAndCreationController.java +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/controller/ServiceDesignAndCreationController.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,14 @@ */ package org.onap.aaisimulator.controller; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import javax.ws.rs.core.MediaType; +import org.onap.aaisimulator.models.ServiceModelVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -50,25 +53,27 @@ public class ServiceDesignAndCreationController { @Value("${SERVICE_DESIGN_AND_CREATION_RESPONSES_LOCATION:./}") private String responsesLocation; - @GetMapping(path = "/models/model/{model-invariant-id}/model-vers", - produces = MediaType.APPLICATION_XML_VALUE) + @GetMapping(path = "/models/model/{model-invariant-id}/model-vers", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseEntity<String> getModelVers(@PathVariable("model-invariant-id") String modelInvariantId) { Path responsesPath = Paths.get(responsesLocation).toAbsolutePath(); LOGGER.info("Will get ModelVer for 'model-invariant-id': {}, looking under {}", modelInvariantId, responsesPath.toString()); - Path responsePath = responsesPath.resolve(modelInvariantId + ".xml"); + Path responsePath = responsesPath.resolve(modelInvariantId + ".json"); if (!responsePath.toFile().exists()) { LOGGER.error("{} not found", responsePath.toString()); return ResponseEntity.notFound().build(); } try { String content = new String(Files.readAllBytes(responsePath), StandardCharsets.UTF_8); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + ServiceModelVersion json = gson.fromJson(content, ServiceModelVersion.class); + String jsonInString = gson.toJson(json); LOGGER.info("{} found with {} characters", responsePath.toString(), content.length()); - return ResponseEntity.ok().body(content); + return ResponseEntity.ok().body(jsonInString); } catch (IOException e) { LOGGER.error("Failed to read response from {}: {}}", responsePath.toString(), e.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } } -} +}
\ No newline at end of file diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/models/ModelVersion.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/models/ModelVersion.java new file mode 100644 index 00000000..d6825089 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/models/ModelVersion.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 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.aaisimulator.models; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class ModelVersion { + + @SerializedName("model-version-id") + @Expose + private String modelVersionId; + + @SerializedName("model-name") + @Expose + private String modelName; + + @SerializedName("model-version") + @Expose + private String modelVersion; + + @SerializedName("model-description") + @Expose + private String modelDescription; + + @SerializedName("resource-version") + @Expose + private String resourceVersion; + + public String getModelVersionId() { + return modelVersionId; + } + + public void setModelVersionId(String modelVersionId) { + this.modelVersionId = modelVersionId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getModelVersion() { + return modelVersion; + } + + public void setModelVersion(String modelVersion) { + this.modelVersion = modelVersion; + } + + public String getModelDescription() { + return modelDescription; + } + + public void setModelDescription(String modelDescription) { + this.modelDescription = modelDescription; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/models/ModelVersions.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/models/ModelVersions.java new file mode 100644 index 00000000..7d74ec36 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/models/ModelVersions.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 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.aaisimulator.models; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; +import java.util.List; + +public class ModelVersions { + + @SerializedName("model-ver") + @Expose + private List<ModelVersion> modelVer = null; + + public List<ModelVersion> getModelVer() { + return modelVer; + } + + public void setModelVer(List<ModelVersion> modelVer) { + this.modelVer = modelVer; + } +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/models/ServiceModelVersion.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/models/ServiceModelVersion.java new file mode 100644 index 00000000..d0a879c4 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/models/ServiceModelVersion.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 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.aaisimulator.models; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class ServiceModelVersion { + + @SerializedName("model-vers") + @Expose + private ModelVersions modelVers; + + public ModelVersions getModelVers() { + return modelVers; + } + + public void setModelVers(ModelVersions modelVers) { + this.modelVers = modelVers; + } +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/ServiceDesignAndCreationControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/ServiceDesignAndCreationControllerTest.java index d0e652bd..8bda17e4 100644 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/ServiceDesignAndCreationControllerTest.java +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/ServiceDesignAndCreationControllerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ package org.onap.aaisimulator.controller; import org.junit.Test; +import org.onap.aaisimulator.models.ServiceModelVersion; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.http.HttpStatus; @@ -37,31 +38,35 @@ public class ServiceDesignAndCreationControllerTest extends AbstractSpringBootTe @Test public void should_reply_sample_modelvers_response() { - final String url = getUrl(SERVICE_DESIGN_AND_CREATION_URL, - "/models/model/a51e2bef-961c-496f-b235-b4540400e885/model-vers"); - ResponseEntity<String> actual = testRestTemplateService.invokeHttpGet(url, String.class); - String expectedXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + - "<model-vers xmlns=\"http://org.onap.aai.inventory/v11\">\n" + - " <model-ver>\n" + - " <model-version-id>c0818142-324d-4a8c-8065-45a61df247a5</model-version-id>\n" + - " <model-name>EricService</model-name>\n" + - " <model-version>1.0</model-version>\n" + - " <model-description>blah</model-description>\n" + - " <resource-version>1594657102313</resource-version>\n" + - " </model-ver>\n" + - " <model-ver>\n" + - " <model-version-id>4442dfc1-0d2d-46b4-b0bc-a2ac10448269</model-version-id>\n" + - " <model-name>EricService</model-name>\n" + - " <model-version>2.0</model-version>\n" + - " <model-description>blahhhh</model-description>\n" + - " <resource-version>1594707742646</resource-version>\n" + - " </model-ver>\n" + - "</model-vers>"; + final String url = getUrl(SERVICE_DESIGN_AND_CREATION_URL, "/models/model/a51e2bef-961c-496f-b235-b4540400e885/model-vers"); + + ResponseEntity<?> actual = testRestTemplateService.invokeHttpGet(url, String.class); + + String expectedXml = "{\n" + + " \"model-vers\": {\n" + + " \"model-ver\": [\n" + + " {\n" + + " \"model-version-id\": \"cd4decf6-4f27-4775-9561-0e683ed43635\",\n" + + " \"model-name\": \"EricService\",\n" + + " \"model-version\": \"1.0\",\n" + + " \"model-description\": \"service_instance_1.0\",\n" + + " \"resource-version\": \"1594657102313\"\n" + + " },\n" + + " {\n" + + " \"model-version-id\": \"4442dfc1-0d2d-46b4-b0bc-a2ac10448269\",\n" + + " \"model-name\": \"EricService\",\n" + + " \"model-version\": \"2.0\",\n" + + " \"model-description\": \"service_instance_2.0\",\n" + + " \"resource-version\": \"1594707742646\"\n" + + " }\n" + + " ]\n" + + " }\n" + + "}"; assertEquals(HttpStatus.OK, actual.getStatusCode()); MediaType contentType = actual.getHeaders().getContentType(); assertNotNull(contentType); - assertTrue(contentType.isCompatibleWith(MediaType.APPLICATION_XML)); + assertTrue(contentType.isCompatibleWith(MediaType.APPLICATION_JSON)); assertEquals(expectedXml, actual.getBody()); } }
\ No newline at end of file diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/resources/test-data/service-design-and-creation-responses/a51e2bef-961c-496f-b235-b4540400e885.json b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/resources/test-data/service-design-and-creation-responses/a51e2bef-961c-496f-b235-b4540400e885.json new file mode 100644 index 00000000..fc42fa55 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/resources/test-data/service-design-and-creation-responses/a51e2bef-961c-496f-b235-b4540400e885.json @@ -0,0 +1,20 @@ +{ + "model-vers": { + "model-ver": [ + { + "model-version-id": "cd4decf6-4f27-4775-9561-0e683ed43635", + "model-name": "EricService", + "model-version": "1.0", + "model-description": "service_instance_1.0", + "resource-version": "1594657102313" + }, + { + "model-version-id": "4442dfc1-0d2d-46b4-b0bc-a2ac10448269", + "model-name": "EricService", + "model-version": "2.0", + "model-description": "service_instance_2.0", + "resource-version": "1594707742646" + } + ] + } +}
\ No newline at end of file diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/resources/test-data/service-design-and-creation-responses/a51e2bef-961c-496f-b235-b4540400e885.xml b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/resources/test-data/service-design-and-creation-responses/a51e2bef-961c-496f-b235-b4540400e885.xml deleted file mode 100644 index 55247be6..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/resources/test-data/service-design-and-creation-responses/a51e2bef-961c-496f-b235-b4540400e885.xml +++ /dev/null @@ -1,17 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<model-vers xmlns="http://org.onap.aai.inventory/v11"> - <model-ver> - <model-version-id>c0818142-324d-4a8c-8065-45a61df247a5</model-version-id> - <model-name>EricService</model-name> - <model-version>1.0</model-version> - <model-description>blah</model-description> - <resource-version>1594657102313</resource-version> - </model-ver> - <model-ver> - <model-version-id>4442dfc1-0d2d-46b4-b0bc-a2ac10448269</model-version-id> - <model-name>EricService</model-name> - <model-version>2.0</model-version> - <model-description>blahhhh</model-description> - <resource-version>1594707742646</resource-version> - </model-ver> -</model-vers>
\ No newline at end of file |