Integration test at API level
authorVinal <vinal.narendrabhai.patel@ibm.com>
Wed, 16 Jan 2019 16:09:27 +0000 (11:09 -0500)
committerVinal <vinal.narendrabhai.patel@ibm.com>
Thu, 24 Jan 2019 18:54:09 +0000 (13:54 -0500)
Change-Id: I6f15b5693f494e39bf8d135a96730f2379f5e3fd
Issue-ID: CCSDK-954
Signed-off-by: Vinal <vinal.narendrabhai.patel@ibm.com>
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java [deleted file]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java [deleted file]
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelRest.kt [new file with mode: 0644]
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ControllerBlueprintExeptionHandler.kt
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt [new file with mode: 0644]
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt
ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelServiceTest.java [deleted file]
ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelRestTest.kt [new file with mode: 0644]

diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java
deleted file mode 100644 (file)
index 3cf144f..0000000
+++ /dev/null
@@ -1,293 +0,0 @@
-/*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- * Modifications Copyright © 2019 Bell Canada.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.ccsdk.apps.controllerblueprints.service;\r
-\r
-import java.io.IOException;
-import java.nio.file.Path;
-import java.util.List;
-import java.util.Optional;
-import org.jetbrains.annotations.NotNull;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils;\r
-import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel;\r
-import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch;\r
-import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelContentRepository;\r
-import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelRepository;\r
-import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelSearchRepository;\r
-import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.core.io.ByteArrayResource;\r
-import org.springframework.core.io.Resource;\r
-import org.springframework.http.HttpHeaders;\r
-import org.springframework.http.MediaType;\r
-import org.springframework.http.ResponseEntity;\r
-import org.springframework.http.codec.multipart.FilePart;\r
-import org.springframework.stereotype.Service;\r
-import org.springframework.transaction.annotation.Transactional;\r
-import reactor.core.publisher.Mono;\r
-\r
-/**\r
- * BlueprintModelService.java Purpose: Provide Service Template Service processing BlueprintModelService\r
- *\r
- * @author Brinda Santh\r
- * @version 1.0\r
- */\r
-\r
-@Service\r
-public class BlueprintModelService {\r
-\r
-    @Autowired\r
-    private BluePrintLoadConfiguration bluePrintLoadConfiguration;\r
-\r
-    @Autowired\r
-    private BluePrintCatalogService bluePrintCatalogService;\r
-\r
-    @Autowired\r
-    private ControllerBlueprintModelSearchRepository blueprintModelSearchRepository;\r
-\r
-    @Autowired\r
-    private ControllerBlueprintModelRepository blueprintModelRepository;\r
-\r
-    @Autowired\r
-    private ControllerBlueprintModelContentRepository blueprintModelContentRepository;\r
-\r
-    private static final String BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%s) from repo";\r
-    private static final String BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%s)" +\r
-        " and version(%s) from repo";
-\r
-    /**\r
-     * This is a saveBlueprintModel method\r
-     *\r
-     * @param filePart filePart\r
-     * @return Mono<BlueprintModelSearch>\r
-     * @throws BluePrintException BluePrintException\r
-     */\r
-    public Mono<BlueprintModelSearch> saveBlueprintModel(FilePart filePart) throws BluePrintException {\r
-        try {\r
-            Path cbaLocation = BluePrintFileUtils.Companion\r
-                .getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath);
-            return BluePrintEnhancerUtils.Companion.saveCBAFile(filePart, cbaLocation).map(fileName -> {\r
-                String blueprintId = null;
-                try {
-                    blueprintId = bluePrintCatalogService
-                        .saveToDatabase(cbaLocation.toFile(), false);
-                } catch (BluePrintException e) {
-                    // FIXME handle expection
-                }
-                return blueprintModelSearchRepository.findById(blueprintId).get();\r
-            });\r
-        } catch (IOException e) {\r
-            throw new BluePrintException(ErrorCode.IO_FILE_INTERRUPT.getValue(),\r
-                String.format("I/O Error while uploading the CBA file: %s", e.getMessage()), e);
-        }\r
-    }\r
-\r
-    /**\r
-     * This is a publishBlueprintModel method to change the status published to YES\r
-     *\r
-     * @param id id\r
-     * @return BlueprintModelSearch\r
-     * @throws BluePrintException BluePrintException\r
-     */\r
-    public BlueprintModelSearch publishBlueprintModel(String id) throws BluePrintException {\r
-        BlueprintModelSearch blueprintModelSearch;\r
-        Optional<BlueprintModelSearch> dbBlueprintModel = blueprintModelSearchRepository.findById(id);\r
-        if (dbBlueprintModel.isPresent()) {\r
-            blueprintModelSearch = dbBlueprintModel.get();\r
-        } else {\r
-            String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id);\r
-            throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);\r
-        }\r
-        blueprintModelSearch.setPublished(ApplicationConstants.ACTIVE_Y);\r
-        return blueprintModelSearchRepository.saveAndFlush(blueprintModelSearch);\r
-    }\r
-\r
-    /**\r
-     * This is a searchBlueprintModels method\r
-     *\r
-     * @param tags tags\r
-     * @return List<BlueprintModelSearch>\r
-     */\r
-    public List<BlueprintModelSearch> searchBlueprintModels(String tags) {\r
-        return blueprintModelSearchRepository.findByTagsContainingIgnoreCase(tags);\r
-    }\r
-\r
-    /**\r
-     * This is a getBlueprintModelSearchByNameAndVersion method\r
-     *\r
-     * @param name name\r
-     * @param version version\r
-     * @return BlueprintModelSearch\r
-     * @throws BluePrintException BluePrintException\r
-     */\r
-    public BlueprintModelSearch getBlueprintModelSearchByNameAndVersion(@NotNull String name, @NotNull String version)\r
-        throws BluePrintException {
-        BlueprintModelSearch blueprintModelSearch;\r
-        Optional<BlueprintModelSearch> dbBlueprintModel = blueprintModelSearchRepository\r
-            .findByArtifactNameAndArtifactVersion(name, version);
-        if (dbBlueprintModel.isPresent()) {\r
-            blueprintModelSearch = dbBlueprintModel.get();\r
-        } else {\r
-            throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(),\r
-                String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version));
-        }\r
-        return blueprintModelSearch;\r
-    }\r
-\r
-    /**\r
-     * This is a downloadBlueprintModelFileByNameAndVersion method to download a Blueprint by Name and Version\r
-     *\r
-     * @param name name
-     * @param version version\r
-     * @return ResponseEntity<Resource>\r
-     * @throws BluePrintException BluePrintException\r
-     */\r
-    public ResponseEntity<Resource> downloadBlueprintModelFileByNameAndVersion(@NotNull String name,
-        @NotNull String version)
-        throws BluePrintException {
-        BlueprintModel blueprintModel;\r
-        try {\r
-            blueprintModel = getBlueprintModelByNameAndVersion(name, version);\r
-        } catch (BluePrintException e) {\r
-            throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), String.format("Error while " +\r
-                "downloading the CBA file: %s", e.getMessage()), e);
-        }\r
-        String fileName = blueprintModel.getId() + ".zip";\r
-        byte[] file = blueprintModel.getBlueprintModelContent().getContent();\r
-        return prepareResourceEntity(fileName, file);\r
-    }\r
-\r
-    /**\r
-     * This is a downloadBlueprintModelFile method to find the target file to download and return a file resource\r
-     *\r
-     * @return ResponseEntity<Resource>\r
-     * @throws BluePrintException BluePrintException\r
-     */\r
-    public ResponseEntity<Resource> downloadBlueprintModelFile(@NotNull String id) throws BluePrintException {\r
-        BlueprintModel blueprintModel;\r
-        try {\r
-            blueprintModel = getBlueprintModel(id);\r
-        } catch (BluePrintException e) {\r
-            throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), String.format("Error while " +\r
-                "downloading the CBA file: %s", e.getMessage()), e);
-        }\r
-        String fileName = blueprintModel.getId() + ".zip";\r
-        byte[] file = blueprintModel.getBlueprintModelContent().getContent();\r
-        return prepareResourceEntity(fileName, file);\r
-    }\r
-\r
-    /**\r
-     * @return ResponseEntity<Resource>\r
-     */\r
-    private ResponseEntity<Resource> prepareResourceEntity(String fileName, byte[] file) {\r
-        return ResponseEntity.ok()\r
-            .contentType(MediaType.parseMediaType("text/plain"))
-            .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"")
-            .body(new ByteArrayResource(file));
-    }\r
-\r
-    /**\r
-     * This is a getBlueprintModel method\r
-     *\r
-     * @param id id\r
-     * @return BlueprintModel\r
-     * @throws BluePrintException BluePrintException\r
-     */\r
-    private BlueprintModel getBlueprintModel(@NotNull String id) throws BluePrintException {\r
-        BlueprintModel blueprintModel;\r
-        Optional<BlueprintModel> dbBlueprintModel = blueprintModelRepository.findById(id);\r
-        if (dbBlueprintModel.isPresent()) {\r
-            blueprintModel = dbBlueprintModel.get();\r
-        } else {\r
-            String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id);\r
-            throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);\r
-        }\r
-        return blueprintModel;\r
-    }\r
-\r
-    /**\r
-     * This is a getBlueprintModelByNameAndVersion method\r
-     *\r
-     * @param name name
-     * @param version version\r
-     * @return BlueprintModel\r
-     * @throws BluePrintException BluePrintException\r
-     */\r
-    private BlueprintModel getBlueprintModelByNameAndVersion(@NotNull String name, @NotNull String version)\r
-        throws BluePrintException {
-        BlueprintModel blueprintModel = blueprintModelRepository
-            .findByArtifactNameAndArtifactVersion(name, version);
-        if (blueprintModel != null) {
-            return blueprintModel;
-        } else {\r
-            String msg = String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version);\r
-            throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);\r
-        }\r
-    }\r
-\r
-    /**\r
-     * This is a getBlueprintModelSearch method\r
-     *\r
-     * @param id id\r
-     * @return BlueprintModelSearch\r
-     * @throws BluePrintException BluePrintException\r
-     */\r
-    public BlueprintModelSearch getBlueprintModelSearch(@NotNull String id) throws BluePrintException {\r
-        BlueprintModelSearch blueprintModelSearch;\r
-        Optional<BlueprintModelSearch> dbBlueprintModel = blueprintModelSearchRepository.findById(id);\r
-        if (dbBlueprintModel.isPresent()) {\r
-            blueprintModelSearch = dbBlueprintModel.get();\r
-        } else {\r
-            String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id);\r
-            throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);\r
-        }\r
-\r
-        return blueprintModelSearch;\r
-    }\r
-\r
-    /**\r
-     * This is a deleteBlueprintModel method\r
-     *\r
-     * @param id id\r
-     * @throws BluePrintException BluePrintException\r
-     */\r
-    @Transactional\r
-    public void deleteBlueprintModel(@NotNull String id) throws BluePrintException {\r
-        Optional<BlueprintModel> dbBlueprintModel = blueprintModelRepository.findById(id);\r
-        if (dbBlueprintModel.isPresent()) {\r
-            blueprintModelContentRepository.deleteByBlueprintModel(dbBlueprintModel.get());\r
-            blueprintModelRepository.delete(dbBlueprintModel.get());\r
-        } else {\r
-            String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id);\r
-            throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);\r
-        }\r
-    }\r
-\r
-    /**\r
-     * This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database\r
-     *\r
-     * @return List<BlueprintModelSearch> list of the controller blueprint archives\r
-     */\r
-    public List<BlueprintModelSearch> getAllBlueprintModel() {\r
-        return blueprintModelSearchRepository.findAll();\r
-    }\r
-}\r
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java
deleted file mode 100644 (file)
index 255137b..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- * Modifications Copyright © 2019 Bell Canada.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.ccsdk.apps.controllerblueprints.service.rs;\r
-\r
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
-import org.onap.ccsdk.apps.controllerblueprints.service.BlueprintModelService;\r
-import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.core.io.Resource;\r
-import org.springframework.http.MediaType;\r
-import org.springframework.http.ResponseEntity;\r
-import org.springframework.http.codec.multipart.FilePart;\r
-import org.springframework.web.bind.annotation.*;\r
-import reactor.core.publisher.Mono;\r
-\r
-import java.util.List;\r
-\r
-/**\r
- * {@inheritDoc}\r
- */\r
-@RestController\r
-@RequestMapping(value = "/api/v1/blueprint-model")\r
-public class BlueprintModelRest {\r
-\r
-    @Autowired\r
-    private BlueprintModelService blueprintModelService;\r
-\r
-    @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)\r
-    public @ResponseBody\r
-    Mono<BlueprintModelSearch> saveBlueprint(@RequestPart("file") FilePart file) throws BluePrintException{\r
-        return blueprintModelService.saveBlueprintModel(file);\r
-    }\r
-\r
-    @DeleteMapping(path = "/{id}")\r
-    public void deleteBlueprint(@PathVariable(value = "id") String id) throws BluePrintException {\r
-        this.blueprintModelService.deleteBlueprintModel(id);\r
-    }\r
-\r
-    @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE)\r
-    public @ResponseBody\r
-    BlueprintModelSearch getBlueprintByNameAndVersion(@PathVariable(value = "name") String name,\r
-                                                      @PathVariable(value = "version") String version) throws BluePrintException {\r
-        return this.blueprintModelService.getBlueprintModelSearchByNameAndVersion(name, version);\r
-    }\r
-\r
-    @GetMapping(path = "/download/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE)\r
-    public @ResponseBody\r
-    ResponseEntity<Resource> downloadBlueprintByNameAndVersion(@PathVariable(value = "name") String name,\r
-                                                               @PathVariable(value = "version") String version) throws BluePrintException {\r
-        return this.blueprintModelService.downloadBlueprintModelFileByNameAndVersion(name, version);\r
-    }\r
-\r
-    @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)\r
-    public @ResponseBody\r
-    BlueprintModelSearch getBlueprintModel(@PathVariable(value = "id") String id) throws BluePrintException {\r
-        return this.blueprintModelService.getBlueprintModelSearch(id);\r
-    }\r
-\r
-    @GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE)\r
-    public @ResponseBody\r
-    List<BlueprintModelSearch> getAllBlueprintModel() {\r
-        return this.blueprintModelService.getAllBlueprintModel();\r
-    }\r
-\r
-    @GetMapping(path = "/download/{id}", produces = MediaType.APPLICATION_JSON_VALUE)\r
-    public @ResponseBody\r
-    ResponseEntity<Resource> downloadBluePrint(@PathVariable(value = "id") String id) throws BluePrintException {\r
-        return this.blueprintModelService.downloadBlueprintModelFile(id);\r
-    }\r
-\r
-    @PutMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE)\r
-    public @ResponseBody\r
-    BlueprintModelSearch publishBlueprintModel(@PathVariable(value = "id") String id) throws BluePrintException {\r
-        return this.blueprintModelService.publishBlueprintModel(id);\r
-    }\r
-\r
-    @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE)\r
-    public @ResponseBody\r
-    List<BlueprintModelSearch> searchBlueprintModels(@PathVariable(value = "tags") String tags) {\r
-        return this.blueprintModelService.searchBlueprintModels(tags);\r
-    }\r
-}\r
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelRest.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelRest.kt
new file mode 100644 (file)
index 0000000..0fca07b
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Copyright © 2019 Bell Canada Intellectual Property.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.service.controller
+
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch
+import org.onap.ccsdk.apps.controllerblueprints.service.handler.BluePrintModelHandler
+import org.springframework.core.io.Resource
+import org.springframework.http.MediaType
+import org.springframework.http.ResponseEntity
+import org.springframework.http.codec.multipart.FilePart
+import org.springframework.web.bind.annotation.*
+import reactor.core.publisher.Mono
+
+/**
+ * BlueprintModelRest Purpose: Handle controllerBlueprint API request
+ *
+ * @author Vinal Patel
+ * @version 1.0
+ */
+@RestController
+@RequestMapping("/api/v1/blueprint-model")
+open class BlueprintModelRest(private val bluePrintModelHandler: BluePrintModelHandler) {
+
+    @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
+    @ResponseBody
+    @Throws(BluePrintException::class)
+    fun saveBlueprint(@RequestPart("file") file: FilePart): Mono<BlueprintModelSearch> {
+        return bluePrintModelHandler.saveBlueprintModel(file)
+    }
+
+    @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE])
+    @ResponseBody
+    fun allBlueprintModel(): List<BlueprintModelSearch> {
+        return this.bluePrintModelHandler.allBlueprintModel()
+    }
+
+    @DeleteMapping("/{id}")
+    @Throws(BluePrintException::class)
+    fun deleteBlueprint(@PathVariable(value = "id") id: String) {
+        this.bluePrintModelHandler.deleteBlueprintModel(id)
+    }
+
+    @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
+    @ResponseBody
+    @Throws(BluePrintException::class)
+    fun getBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
+                                     @PathVariable(value = "version") version: String): BlueprintModelSearch {
+        return this.bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version)
+    }
+
+    @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
+    @ResponseBody
+    @Throws(BluePrintException::class)
+    fun downloadBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
+                                          @PathVariable(value = "version") version: String): ResponseEntity<Resource> {
+        return this.bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version)
+    }
+
+    @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
+    @ResponseBody
+    @Throws(BluePrintException::class)
+    fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch {
+        return this.bluePrintModelHandler.getBlueprintModelSearch(id)
+    }
+
+    @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
+    @ResponseBody
+    @Throws(BluePrintException::class)
+    fun downloadBluePrint(@PathVariable(value = "id") id: String): ResponseEntity<Resource> {
+        return this.bluePrintModelHandler.downloadBlueprintModelFile(id)
+    }
+
+    @PutMapping("/publish/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
+    @ResponseBody
+    @Throws(BluePrintException::class)
+    fun publishBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch {
+        return this.bluePrintModelHandler.publishBlueprintModel(id)
+    }
+
+    @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE])
+    @ResponseBody
+    fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List<BlueprintModelSearch> {
+        return this.bluePrintModelHandler.searchBlueprintModels(tags)
+    }
+}
index a0e47d7..0475339 100644 (file)
@@ -25,7 +25,7 @@ import org.springframework.http.ResponseEntity
 import org.springframework.web.bind.annotation.ExceptionHandler
 
 /**
- * ControllerBlueprintExceptionHandler.java Purpose: Handle exceptions in controllerBlueprint API and provide the wright
+ * ControllerBlueprintExceptionHandler Purpose: Handle exceptions in controllerBlueprint API and provide the right
  * HTTP code status
  *
  * @author Vinal Patel
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt
new file mode 100644 (file)
index 0000000..907566c
--- /dev/null
@@ -0,0 +1,283 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 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.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.service.handler
+
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils
+import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel
+import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch
+import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelContentRepository
+import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelRepository
+import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelSearchRepository
+import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils
+import org.springframework.core.io.ByteArrayResource
+import org.springframework.core.io.Resource
+import org.springframework.http.HttpHeaders
+import org.springframework.http.MediaType
+import org.springframework.http.ResponseEntity
+import org.springframework.http.codec.multipart.FilePart
+import org.springframework.stereotype.Service
+import org.springframework.transaction.annotation.Transactional
+import reactor.core.publisher.Mono
+import java.io.IOException
+
+/**
+ * BlueprintModelHandler Purpose: Handler service to handle the request from BlurPrintModelRest
+ *
+ * @author Brinda Santh
+ * @version 1.0
+ */
+
+@Service
+open class BluePrintModelHandler(private val bluePrintCatalogService: BluePrintCatalogService, private val bluePrintLoadConfiguration: BluePrintLoadConfiguration,
+                                 private val blueprintModelSearchRepository: ControllerBlueprintModelSearchRepository,
+                                 private val blueprintModelRepository: ControllerBlueprintModelRepository,
+                                 private val blueprintModelContentRepository: ControllerBlueprintModelContentRepository) {
+
+    /**
+     * This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database
+     *
+     * @return List<BlueprintModelSearch> list of the controller blueprint archives
+    </BlueprintModelSearch> */
+    open fun allBlueprintModel(): List<BlueprintModelSearch> {
+        return blueprintModelSearchRepository.findAll()
+    }
+
+    /**
+     * This is a saveBlueprintModel method
+     *
+     * @param filePart filePart
+     * @return Mono<BlueprintModelSearch>
+     * @throws BluePrintException BluePrintException
+    </BlueprintModelSearch> */
+    @Throws(BluePrintException::class)
+    open fun saveBlueprintModel(filePart: FilePart): Mono<BlueprintModelSearch> {
+        try {
+            val cbaLocation = BluePrintFileUtils.getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath)
+            return BluePrintEnhancerUtils.saveCBAFile(filePart, cbaLocation).map { fileName ->
+                var blueprintId: String? = null
+                try {
+                    blueprintId = bluePrintCatalogService.saveToDatabase(cbaLocation.resolve(fileName).toFile(), false)
+                } catch (e: BluePrintException) {
+                    // FIXME handle expection
+                }
+                blueprintModelSearchRepository.findById(blueprintId!!).get()
+            }
+        } catch (e: IOException) {
+            throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value,
+                    String.format("I/O Error while uploading the CBA file: %s", e.message), e)
+        }
+
+    }
+
+    /**
+     * This is a publishBlueprintModel method to change the status published to YES
+     *
+     * @param id id
+     * @return BlueprintModelSearch
+     * @throws BluePrintException BluePrintException
+     */
+    @Throws(BluePrintException::class)
+    open fun publishBlueprintModel(id: String): BlueprintModelSearch {
+        val blueprintModelSearch: BlueprintModelSearch
+        val dbBlueprintModel = blueprintModelSearchRepository.findById(id)
+        if (dbBlueprintModel.isPresent) {
+            blueprintModelSearch = dbBlueprintModel.get()
+        } else {
+            val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)
+            throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg)
+        }
+        blueprintModelSearch.published = ApplicationConstants.ACTIVE_Y
+        return blueprintModelSearchRepository.saveAndFlush(blueprintModelSearch)
+    }
+
+    /**
+     * This is a searchBlueprintModels method
+     *
+     * @param tags tags
+     * @return List<BlueprintModelSearch>
+    </BlueprintModelSearch> */
+    open fun searchBlueprintModels(tags: String): List<BlueprintModelSearch> {
+        return blueprintModelSearchRepository.findByTagsContainingIgnoreCase(tags)
+    }
+
+    /**
+     * This is a getBlueprintModelSearchByNameAndVersion method
+     *
+     * @param name name
+     * @param version version
+     * @return BlueprintModelSearch
+     * @throws BluePrintException BluePrintException
+     */
+    @Throws(BluePrintException::class)
+    open fun getBlueprintModelSearchByNameAndVersion(name: String, version: String): BlueprintModelSearch {
+        val blueprintModelSearch: BlueprintModelSearch
+        val dbBlueprintModel = blueprintModelSearchRepository
+                .findByArtifactNameAndArtifactVersion(name, version)
+        if (dbBlueprintModel.isPresent) {
+            blueprintModelSearch = dbBlueprintModel.get()
+        } else {
+            throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value,
+                    String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version))
+        }
+        return blueprintModelSearch
+    }
+
+    /**
+     * This is a downloadBlueprintModelFileByNameAndVersion method to download a Blueprint by Name and Version
+     *
+     * @param name name
+     * @param version version
+     * @return ResponseEntity<Resource>
+     * @throws BluePrintException BluePrintException
+    </Resource> */
+    @Throws(BluePrintException::class)
+    open fun downloadBlueprintModelFileByNameAndVersion(name: String,
+                                                        version: String): ResponseEntity<Resource> {
+        val blueprintModel: BlueprintModel
+        try {
+            blueprintModel = getBlueprintModelByNameAndVersion(name, version)
+        } catch (e: BluePrintException) {
+            throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, String.format("Error while " + "downloading the CBA file: %s", e.message), e)
+        }
+
+        val fileName = blueprintModel.id + ".zip"
+        val file = blueprintModel.blueprintModelContent.content
+        return prepareResourceEntity(fileName, file)
+    }
+
+    /**
+     * This is a downloadBlueprintModelFile method to find the target file to download and return a file resource
+     *
+     * @return ResponseEntity<Resource>
+     * @throws BluePrintException BluePrintException
+    </Resource> */
+    @Throws(BluePrintException::class)
+    open fun downloadBlueprintModelFile(id: String): ResponseEntity<Resource> {
+        val blueprintModel: BlueprintModel
+        try {
+            blueprintModel = getBlueprintModel(id)
+        } catch (e: BluePrintException) {
+            throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, String.format("Error while " + "downloading the CBA file: %s", e.message), e)
+        }
+
+        val fileName = blueprintModel.id + ".zip"
+        val file = blueprintModel.blueprintModelContent.content
+        return prepareResourceEntity(fileName, file)
+    }
+
+    /**
+     * @return ResponseEntity<Resource>
+    </Resource> */
+    private fun prepareResourceEntity(fileName: String, file: ByteArray): ResponseEntity<Resource> {
+        return ResponseEntity.ok()
+                .contentType(MediaType.parseMediaType("text/plain"))
+                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"$fileName\"")
+                .body(ByteArrayResource(file))
+    }
+
+    /**
+     * This is a getBlueprintModel method
+     *
+     * @param id id
+     * @return BlueprintModel
+     * @throws BluePrintException BluePrintException
+     */
+    @Throws(BluePrintException::class)
+    open fun getBlueprintModel(id: String): BlueprintModel {
+        val blueprintModel: BlueprintModel
+        val dbBlueprintModel = blueprintModelRepository.findById(id)
+        if (dbBlueprintModel.isPresent) {
+            blueprintModel = dbBlueprintModel.get()
+        } else {
+            val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)
+            throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg)
+        }
+        return blueprintModel
+    }
+
+    /**
+     * This is a getBlueprintModelByNameAndVersion method
+     *
+     * @param name name
+     * @param version version
+     * @return BlueprintModel
+     * @throws BluePrintException BluePrintException
+     */
+    @Throws(BluePrintException::class)
+    open fun getBlueprintModelByNameAndVersion(name: String, version: String): BlueprintModel {
+        val blueprintModel = blueprintModelRepository
+                .findByArtifactNameAndArtifactVersion(name, version)
+        if (blueprintModel != null) {
+            return blueprintModel
+        } else {
+            val msg = String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version)
+            throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg)
+        }
+    }
+
+    /**
+     * This is a getBlueprintModelSearch method
+     *
+     * @param id id
+     * @return BlueprintModelSearch
+     * @throws BluePrintException BluePrintException
+     */
+    @Throws(BluePrintException::class)
+    open fun getBlueprintModelSearch(id: String): BlueprintModelSearch {
+        val blueprintModelSearch: BlueprintModelSearch
+        val dbBlueprintModel = blueprintModelSearchRepository.findById(id)
+        if (dbBlueprintModel.isPresent) {
+            blueprintModelSearch = dbBlueprintModel.get()
+        } else {
+            val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)
+            throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg)
+        }
+
+        return blueprintModelSearch
+    }
+
+    /**
+     * This is a deleteBlueprintModel method
+     *
+     * @param id id
+     * @throws BluePrintException BluePrintException
+     */
+    @Transactional
+    @Throws(BluePrintException::class)
+    open fun deleteBlueprintModel(id: String) {
+        val dbBlueprintModel = blueprintModelRepository.findById(id)
+        if (dbBlueprintModel.isPresent) {
+            blueprintModelContentRepository.deleteByBlueprintModel(dbBlueprintModel.get())
+            blueprintModelRepository.delete(dbBlueprintModel.get())
+        } else {
+            val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)
+            throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg)
+        }
+    }
+
+    companion object {
+
+        private const val BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%s) from repo"
+        private const val BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%s)" + " and version(%s) from repo"
+    }
+}
index 04071dd..779be65 100755 (executable)
@@ -97,6 +97,8 @@ class ControllerBlueprintCatalogServiceImpl(bluePrintValidatorService: BluePrint
         blueprintModelContent.description = "$artifactName:$artifactVersion CBA Zip Content"
         blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath())
         blueprintModelContent.blueprintModel = blueprintModel
+        // Set the Blueprint Model Content into blueprintModel
+        blueprintModel.blueprintModelContent = blueprintModelContent
 
         try {
             blueprintModelRepository.saveAndFlush(blueprintModel)
diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelServiceTest.java
deleted file mode 100644 (file)
index 0ce93b1..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- *  Copyright © 2018 IBM.
- *
- *  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.
- */
-
-package org.onap.ccsdk.apps.controllerblueprints.service;
-
-import org.junit.Test;
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
-import org.springframework.beans.factory.annotation.Autowired;
-
-public class BlueprintModelServiceTest {
-    @Autowired
-    private BlueprintModelService blueprintModelService;
-
-    @Test
-    public void testGetInitialConfigModel() throws BluePrintException {
-    }
-}
diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelRestTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelRestTest.kt
new file mode 100644 (file)
index 0000000..f82aace
--- /dev/null
@@ -0,0 +1,192 @@
+/*
+ * Copyright © 2019 Bell Canada Intellectual Property.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.service.controller
+
+import com.google.gson.Gson
+import org.json.JSONException
+import org.json.JSONObject
+import org.junit.After
+import org.junit.Before
+import org.junit.FixMethodOrder
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.MethodSorters
+import org.onap.ccsdk.apps.controllerblueprints.TestApplication
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
+import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.beans.factory.annotation.Value
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.core.io.ByteArrayResource
+import org.springframework.http.HttpMethod
+import org.springframework.http.HttpStatus
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.junit4.SpringRunner
+import org.springframework.test.web.reactive.server.WebTestClient
+import org.springframework.util.Base64Utils
+import org.springframework.web.reactive.function.BodyInserters
+import java.io.File
+import java.io.IOException
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+import java.nio.file.Paths
+
+/**
+ * BlueprintModelRestTest Purpose: Integration test at API level
+ *
+ * @author Vinal Patel
+ * @version 1.0
+ */
+
+@RunWith(SpringRunner::class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ContextConfiguration(classes = [TestApplication::class])
+@ComponentScan(basePackages = ["org.onap.ccsdk.apps.controllerblueprints"])
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+@EnableAutoConfiguration
+class BlueprintModelRestTest {
+
+    companion object {
+
+        private var id: String? = null
+        private var name: String? = null
+        private var version: String? = null
+        private var tag: String? = null
+        private var result: String? = null
+    }
+
+    @Value("\${controllerblueprints.loadBluePrintPaths}")
+    private val loadBluePrintPaths: String? = null
+
+    @Autowired
+    private val webTestClient: WebTestClient? = null
+
+    @Value("\${controllerblueprints.loadBlueprintsExamplesPath}")
+    private val blueprintArchivePath: String? = null
+
+    private val filename = "test.zip"
+    private var blueprintFile: File? = null
+    private var zipBlueprintFile: File? = null
+
+    @Before
+    @Throws(Exception::class)
+    fun setUp() {
+        blueprintFile = File(loadBluePrintPaths+"/baseconfiguration")
+        if (blueprintFile!!.isDirectory) {
+            zipBlueprintFile = File(Paths.get(blueprintArchivePath).resolve(filename).toString())
+            BluePrintArchiveUtils.compress(blueprintFile!!, zipBlueprintFile!!, true)
+        }
+    }
+
+    @After
+    @Throws(Exception::class)
+    fun tearDown() {
+        zipBlueprintFile!!.delete()
+    }
+
+    @Test
+    @Throws(IOException::class, JSONException::class)
+    fun test1_saveBluePrint() {
+        webTestClient(HttpMethod.POST,
+                BodyInserters.fromMultipartData("file", object : ByteArrayResource(Files.readAllBytes(zipBlueprintFile!!.toPath())) {
+                    override fun getFilename(): String? {
+                        return "test.zip"
+                    }
+                }),
+                "/api/v1/blueprint-model",
+                HttpStatus.OK, true)
+    }
+
+    @Test
+    @Throws(JSONException::class)
+    fun test2_getBluePrintByNameAndVersion() {
+        webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/by-name/$name/version/$version", HttpStatus.OK, false)
+    }
+
+
+    @Test
+    @Throws(JSONException::class)
+    fun test3_getBlueprintModel() {
+        webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/$id", HttpStatus.OK, false)
+    }
+
+    @Test
+    @Throws(JSONException::class)
+    fun test4_getAllBlueprintModel() {
+        webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model", HttpStatus.OK, false)
+    }
+
+    @Test
+    @Throws(JSONException::class)
+    fun test5_downloadBluePrint() {
+        webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/download/$id", HttpStatus.OK, false)
+    }
+
+    @Test
+    fun test6_publishBlueprintModel() {
+    }
+
+    @Test
+    @Throws(JSONException::class)
+    fun test7_searchBlueprintModels() {
+        webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/search/$name", HttpStatus.OK, false)
+    }
+
+    @Test
+    @Throws(JSONException::class)
+    fun test8_downloadBlueprintByNameAndVersion() {
+        webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/download/by-name/$name/version/$version", HttpStatus.OK, false)
+    }
+
+    @Test
+    fun test9_deleteBluePrint() {
+        //TODO: Use webTestClient function
+        //webTestClient(HttpMethod.DELETE, null, "/api/v1/blueprint-model/" + id, HttpStatus.OK, false);
+        webTestClient!!.delete().uri("/api/v1/blueprint-model/$id")
+                .header("Authorization", "Basic " + Base64Utils
+                        .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8)))
+                .exchange()
+                .expectStatus().is2xxSuccessful
+    }
+
+    @Throws(JSONException::class)
+    private fun webTestClient(requestMethod: HttpMethod, body: BodyInserters.MultipartInserter?, uri: String, expectedResponceStatus: HttpStatus, setParam: Boolean) {
+
+        result = String(webTestClient!!.method(requestMethod).uri(uri)
+                .header("Authorization", "Basic " + Base64Utils
+                        .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8)))
+                .body(body)
+                .exchange()
+                .expectStatus().isEqualTo(expectedResponceStatus)
+                .expectBody()
+                .returnResult().responseBody!!)
+
+        if (setParam) {
+            val jsonResponse = JSONObject(result)
+            val blueprintModelSearchJSON = jsonResponse.getJSONObject("blueprintModel")
+            val gson = Gson()
+            val blueprintModelSearch = gson.fromJson(blueprintModelSearchJSON.toString(), BlueprintModelSearch::class.java)
+            id = blueprintModelSearch.id
+            name = blueprintModelSearch.artifactName
+            version = blueprintModelSearch.artifactVersion
+            tag = blueprintModelSearch.tags
+        }
+    }
+
+}
\ No newline at end of file