summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest-stub/src
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-rest-stub/src')
-rw-r--r--cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/Application.java32
-rw-r--r--cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java172
-rw-r--r--cps-ncmp-rest-stub/src/main/resources/application.yml39
-rw-r--r--cps-ncmp-rest-stub/src/main/resources/stubs/cmHandlesSearch.json10
-rw-r--r--cps-ncmp-rest-stub/src/main/resources/stubs/passthrough-operational-example.json45
-rw-r--r--cps-ncmp-rest-stub/src/test/java/org/onap/cps/TestApplication.java30
6 files changed, 328 insertions, 0 deletions
diff --git a/cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/Application.java b/cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/Application.java
new file mode 100644
index 0000000000..0f0035dab5
--- /dev/null
+++ b/cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/Application.java
@@ -0,0 +1,32 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Bell Canada.
+ * ================================================================================
+ * 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.cps.ncmp.rest.stub;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+
+ public static void main(final String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+}
diff --git a/cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java b/cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java
new file mode 100644
index 0000000000..6362cf1e15
--- /dev/null
+++ b/cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java
@@ -0,0 +1,172 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Bell Canada
+ * ================================================================================
+ * 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.cps.ncmp.rest.stub.controller;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi;
+import org.onap.cps.ncmp.rest.model.CmHandleQueryRestParameters;
+import org.onap.cps.ncmp.rest.model.CmHandles;
+import org.onap.cps.ncmp.rest.model.Conditions;
+import org.onap.cps.ncmp.rest.model.RestModuleReference;
+import org.onap.cps.ncmp.rest.model.RestOutputCmHandle;
+import org.onap.cps.ncmp.rest.model.RestOutputCmHandlePublicProperties;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Slf4j
+@RestController
+@RequestMapping("${rest.api.ncmp-stub-base-path}")
+public class NetworkCmProxyStubController implements NetworkCmProxyApi {
+
+ public static final String ASYNC_REQUEST_ID = "requestId";
+
+ @Value("${stub.path}")
+ private String pathToResponseFiles;
+
+ @Override
+ public ResponseEntity<Void> createResourceDataRunningForCmHandle(@NotNull @Valid final String resourceIdentifier,
+ final String cmHandleId, @Valid final Object body, final String contentType) {
+ return new ResponseEntity<>(HttpStatus.CREATED);
+ }
+
+ @Override
+ public ResponseEntity<Void> deleteResourceDataRunningForCmHandle(final String cmHandleId,
+ @NotNull @Valid final String resourceIdentifier, final String contentType) {
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+ }
+
+ @Override
+ public ResponseEntity<CmHandles> executeCmHandleSearch(@Valid final Conditions body) {
+ final ObjectMapper mapper = new ObjectMapper();
+ CmHandles cmHandles = new CmHandles();
+ // read JSON file and map/convert to java POJO
+ final ClassPathResource resource = new ClassPathResource(pathToResponseFiles + "cmHandlesSearch.json");
+ try (InputStream inputStream = resource.getInputStream()) {
+ final String string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
+ cmHandles = mapper.readValue(string, CmHandles.class);
+ } catch (final IOException exception) {
+ log.error("Error reading the file.", exception);
+ }
+ return ResponseEntity.ok(cmHandles);
+ }
+
+ @Override
+ public ResponseEntity<RestOutputCmHandlePublicProperties> getCmHandlePublicPropertiesByCmHandleId(
+ final String cmHandleId) {
+ return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ }
+
+ @Override
+ public ResponseEntity<List<RestModuleReference>> getModuleReferencesByCmHandle(final String cmHandleId) {
+ return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ }
+
+ /**
+ * Get resource data from operational datastore.
+ *
+ * @param cmHandleId cm handle identifier
+ * @param resourceIdentifier resource identifier
+ * @param optionsParamInQuery options query parameter
+ * @param topicParamInQuery topic query parameter
+ * @return {@code ResponseEntity} response from dmi plugin
+ */
+ @Override
+ public ResponseEntity<Object> getResourceDataOperationalForCmHandle(final String cmHandleId,
+ final String resourceIdentifier, final String optionsParamInQuery, final String topicParamInQuery) {
+ final ResponseEntity<Map<String, Object>> asyncResponse = populateAsyncResponse(topicParamInQuery);
+ final Map<String, Object> asyncResponseData = asyncResponse.getBody();
+ final ObjectMapper mapper = new ObjectMapper();
+ Object responseObject = null;
+ // read JSON file and map/convert to java POJO
+ final ClassPathResource resource = new ClassPathResource(pathToResponseFiles
+ + "passthrough-operational-example.json");
+ try (InputStream inputStream = resource.getInputStream()) {
+ final String string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
+ responseObject = mapper.readValue(string, Object.class);
+ } catch (final IOException exception) {
+ log.error("Error reading the file.", exception);
+ }
+ if (asyncResponseData == null) {
+ return ResponseEntity.ok(responseObject);
+ }
+ return ResponseEntity.ok(asyncResponse);
+
+ }
+
+ @Override
+ public ResponseEntity<Object> getResourceDataRunningForCmHandle(final String cmHandleId,
+ final String resourceIdentifier, final String options, final String topic) {
+ return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ }
+
+ @Override
+ public ResponseEntity<Object> patchResourceDataRunningForCmHandle(final String resourceIdentifier,
+ final String cmHandleId, final Object body, final String contentType) {
+ return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ }
+
+ @Override
+ public ResponseEntity<List<String>> queryCmHandles(final CmHandleQueryRestParameters body) {
+ return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ }
+
+ @Override
+ public ResponseEntity<RestOutputCmHandle> retrieveCmHandleDetailsById(final String cmHandleId) {
+ return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ }
+
+ @Override
+ public ResponseEntity<Object> updateResourceDataRunningForCmHandle(@NotNull @Valid final String resourceIdentifier,
+ final String cmHandleId, @Valid final Object body, final String contentType) {
+ return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ }
+
+ private ResponseEntity<Map<String, Object>> populateAsyncResponse(final String topicParamInQuery) {
+ final Map<String, Object> responseData;
+ if (topicParamInQuery != null) {
+ responseData = getAsyncResponseData();
+ } else {
+ responseData = null;
+ }
+ return ResponseEntity.ok().body(responseData);
+ }
+
+ private Map<String, Object> getAsyncResponseData() {
+ final Map<String, Object> asyncResponseData = new HashMap<>(1);
+ final String resourceDataRequestId = UUID.randomUUID().toString();
+ asyncResponseData.put(ASYNC_REQUEST_ID, resourceDataRequestId);
+ return asyncResponseData;
+ }
+}
diff --git a/cps-ncmp-rest-stub/src/main/resources/application.yml b/cps-ncmp-rest-stub/src/main/resources/application.yml
new file mode 100644
index 0000000000..9fbd359655
--- /dev/null
+++ b/cps-ncmp-rest-stub/src/main/resources/application.yml
@@ -0,0 +1,39 @@
+# ============LICENSE_START=======================================================
+# Copyright (C) 2022 Bell Canada
+# ================================================================================
+# 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=========================================================
+server:
+ port: 8091
+
+rest:
+ api:
+ ncmp-stub-base-path: /ncmp
+
+spring:
+ main:
+ banner-mode: "off"
+ application:
+ name: "cps-ncmp-rest-stub"
+
+logging:
+ level:
+ org:
+ springframework: INFO
+ onap:
+ cps: INFO
+
+stub:
+ path: "/stubs/" \ No newline at end of file
diff --git a/cps-ncmp-rest-stub/src/main/resources/stubs/cmHandlesSearch.json b/cps-ncmp-rest-stub/src/main/resources/stubs/cmHandlesSearch.json
new file mode 100644
index 0000000000..409d56fa44
--- /dev/null
+++ b/cps-ncmp-rest-stub/src/main/resources/stubs/cmHandlesSearch.json
@@ -0,0 +1,10 @@
+{
+ "cmHandles": [
+ {
+ "cmHandleId": "stub-cm-handle-id"
+ },
+ {
+ "cmHandleId": "stub-cm-handle-id2"
+ }
+ ]
+} \ No newline at end of file
diff --git a/cps-ncmp-rest-stub/src/main/resources/stubs/passthrough-operational-example.json b/cps-ncmp-rest-stub/src/main/resources/stubs/passthrough-operational-example.json
new file mode 100644
index 0000000000..1838b47ca9
--- /dev/null
+++ b/cps-ncmp-rest-stub/src/main/resources/stubs/passthrough-operational-example.json
@@ -0,0 +1,45 @@
+{
+ "stores:bookstore": {
+ "categories": [
+ {
+ "code": "02",
+ "books": [
+ {
+ "title": "A Horror book",
+ "price": "2000",
+ "pub_year": 2003,
+ "lang": "English",
+ "authors": [
+ "Joe"
+ ]
+ },
+ {
+ "title": "Another Horror Book",
+ "price": "2000",
+ "pub_year": 2003,
+ "lang": "English",
+ "authors": [
+ "Joe"
+ ]
+ }
+ ],
+ "name": "Horror"
+ },
+ {
+ "code": "100",
+ "books": [
+ {
+ "title": "A Cook book",
+ "price": "2011",
+ "pub_year": 2019,
+ "lang": "English",
+ "authors": [
+ "Rahul"
+ ]
+ }
+ ],
+ "name": "Cooking Books"
+ }
+ ]
+ }
+} \ No newline at end of file
diff --git a/cps-ncmp-rest-stub/src/test/java/org/onap/cps/TestApplication.java b/cps-ncmp-rest-stub/src/test/java/org/onap/cps/TestApplication.java
new file mode 100644
index 0000000000..a095edc422
--- /dev/null
+++ b/cps-ncmp-rest-stub/src/test/java/org/onap/cps/TestApplication.java
@@ -0,0 +1,30 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Bell Canada.
+ * ================================================================================
+ * 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.cps;
+
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * The @SpringBootApplication annotated class is required in order to run tests
+ * marked with @SpringBootTest annotation.
+ */
+@SpringBootApplication
+public class TestApplication {
+}