design modify 1 26/91226/4
authorZhangZihao <zhangzihao@chinamobile.com>
Thu, 11 Jul 2019 07:18:33 +0000 (15:18 +0800)
committerZihao Zhang <zhangzihao@chinamobile.com>
Thu, 11 Jul 2019 08:01:54 +0000 (08:01 +0000)
Change-Id: I32ef0ff484b786b9c5b73df8fd1b8cc97c5dc227
Issue-ID: DCAEGEN2-1658
Signed-off-by: ZhangZihao <zhangzihao@chinamobile.com>
17 files changed:
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignController.java [new file with mode: 0644]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java [deleted file]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Design.java [moved from components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java with 77% similarity]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/TopicName.java
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignConfig.java [moved from components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java with 93% similarity]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignTypeConfig.java
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignRepository.java [moved from components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalDesignRepository.java with 79% similarity]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java [new file with mode: 0755]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java [deleted file]
components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignControllerTest.java [new file with mode: 0644]
components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java
components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/PortalDesignControllerTest.java [deleted file]
components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTest.java [moved from components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/PortalDesignTest.java with 56% similarity]
components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java [moved from components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/PortalDesignConfigTest.java with 64% similarity]
components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java [moved from components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PortalDesignServiceTest.java with 85% similarity]
components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java

diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignController.java
new file mode 100644 (file)
index 0000000..0cac567
--- /dev/null
@@ -0,0 +1,179 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DataLake
+ * ================================================================================
+ * Copyright 2019 China Mobile
+ *=================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.datalake.feeder.controller;
+
+import org.onap.datalake.feeder.controller.domain.PostReturnBody;
+import org.onap.datalake.feeder.domain.Design;
+import org.onap.datalake.feeder.dto.DesignConfig;
+import org.onap.datalake.feeder.repository.DesignRepository;
+import org.onap.datalake.feeder.service.DesignService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.*;
+
+import io.swagger.annotations.ApiOperation;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.servlet.http.HttpServletResponse;
+
+
+/**
+ * This controller manages design settings
+ *
+ * @author guochunmeng
+ */
+@RestController
+@RequestMapping(value = "/designs", produces = MediaType.APPLICATION_JSON_VALUE)
+public class DesignController {
+
+    private final Logger log = LoggerFactory.getLogger(this.getClass());
+
+    @Autowired
+    private DesignRepository designRepository;
+    
+    @Autowired
+    private DesignService designService;
+
+       @PostMapping("")
+       @ResponseBody
+       @ApiOperation(value="Create a design.")
+    public PostReturnBody<DesignConfig> createDesign(@RequestBody DesignConfig designConfig, BindingResult result, HttpServletResponse response) throws IOException {
+
+               if (result.hasErrors()) {
+                       sendError(response, 400, "Error parsing DesignConfig: "+result.toString());
+                       return null;
+               }
+
+               Design design = null;
+               try {
+                       design = designService.fillDesignConfiguration(designConfig);
+               } catch (Exception e) {
+                       log.debug("FillDesignConfiguration failed", e.getMessage());
+                       sendError(response, 400, "Error FillDesignConfiguration: "+e.getMessage());
+                       return null;
+               }
+               designRepository.save(design);
+               log.info("Design save successed");
+               return mkPostReturnBody(200, design);
+    }
+
+
+       @PutMapping("{id}")
+       @ResponseBody
+       @ApiOperation(value="Update a design.")
+       public PostReturnBody<DesignConfig> updateDesign(@RequestBody DesignConfig designConfig, BindingResult result, @PathVariable Integer id, HttpServletResponse response) throws IOException {
+
+               if (result.hasErrors()) {
+                       sendError(response, 400, "Error parsing DesignConfig: "+result.toString());
+                       return null;
+               }
+
+               Design design = designService.getDesign(id);
+               if (design != null) {
+                       try {
+                               designService.fillDesignConfiguration(designConfig, design);
+                       } catch (Exception e) {
+                               log.debug("FillDesignConfiguration failed", e.getMessage());
+                               sendError(response, 400, "Error FillDesignConfiguration: "+e.getMessage());
+                               return null;
+                       }
+                       designRepository.save(design);
+                       log.info("Design update successed");
+                       return mkPostReturnBody(200, design);
+               } else {
+                       sendError(response, 400, "Design not found: "+id);
+                       return null;
+               }
+
+       }
+
+
+       @DeleteMapping("/{id}")
+       @ResponseBody
+       @ApiOperation(value="delete a design.")
+    public void deleteDesign(@PathVariable("id") Integer id, HttpServletResponse response) throws IOException{
+               
+               Design oldDesign = designService.getDesign(id);
+               if (oldDesign == null) {
+                       sendError(response, 400, "design not found "+id);
+               } else {
+                       designRepository.delete(oldDesign);
+                       response.setStatus(204);
+               }
+    }
+
+
+       @GetMapping("")
+       @ResponseBody
+       @ApiOperation(value="List all Designs")
+    public List<DesignConfig> queryAllDesign(){
+               return designService.queryAllDesign();
+    }
+
+
+       @PostMapping("/deploy/{id}")
+       @ResponseBody
+       @ApiOperation(value="Design deploy")
+       public void deployDesign(@PathVariable Integer id, HttpServletResponse response) throws IOException {
+
+               Design design = null;
+               try {
+                       design = designRepository.findById(id).get();
+                       boolean flag;
+                       try {
+                               flag = designService.deploy(design);
+                               if (flag) {
+                                       design.setSubmitted(true);
+                                       designRepository.save(design);
+                                       response.setStatus(204);
+                               } else {
+                                       sendError(response, 400, "DeployDesign failed, id: "+id);
+                               }
+                       } catch (Exception e) {
+                               log.debug("The request failed", e.getMessage());
+                               sendError(response, 400, "The request failed : "+e.getMessage());
+                       }
+               } catch (Exception e) {
+                       log.debug("Design is null", e.getMessage());
+                       sendError(response, 400, "Design not found, id: "+id);
+               }
+
+       }
+
+
+       private PostReturnBody<DesignConfig> mkPostReturnBody(int statusCode, Design design) {
+               PostReturnBody<DesignConfig> retBody = new PostReturnBody<>();
+        retBody.setStatusCode(statusCode);
+        retBody.setReturnBody(design.getDesignConfig());
+        return retBody;
+       }
+    
+       private void sendError(HttpServletResponse response, int sc, String msg) throws IOException {
+               log.info(msg);
+               response.sendError(sc, msg);            
+       }
+    
+}
\ No newline at end of file
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java
deleted file mode 100644 (file)
index fa35b3b..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : DataLake
- * ================================================================================
- * Copyright 2019 China Mobile
- *=================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.datalake.feeder.controller;
-
-import org.onap.datalake.feeder.controller.domain.PostReturnBody;
-import org.onap.datalake.feeder.domain.PortalDesign;
-import org.onap.datalake.feeder.dto.PortalDesignConfig;
-import org.onap.datalake.feeder.repository.PortalDesignRepository;
-import org.onap.datalake.feeder.service.PortalDesignService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.MediaType;
-import org.springframework.validation.BindingResult;
-import org.springframework.web.bind.annotation.*;
-
-import io.swagger.annotations.ApiOperation;
-
-import java.io.IOException;
-import java.util.List;
-
-import javax.servlet.http.HttpServletResponse;
-
-
-/**
- * This controller manages portalDesign settings
- *
- * @author guochunmeng
- */
-@RestController
-@RequestMapping(value = "/portalDesigns", produces = MediaType.APPLICATION_JSON_VALUE)
-public class PortalDesignController {
-
-    private final Logger log = LoggerFactory.getLogger(this.getClass());
-
-    @Autowired
-    private PortalDesignRepository portalDesignRepository;
-    
-    @Autowired
-    private PortalDesignService portalDesignService;
-
-       @PostMapping("")
-       @ResponseBody
-       @ApiOperation(value="Create a portalDesign.")
-    public PostReturnBody<PortalDesignConfig> createPortalDesign(@RequestBody PortalDesignConfig portalDesignConfig, BindingResult result, HttpServletResponse response) throws IOException {
-
-               if (result.hasErrors()) {
-                       sendError(response, 400, "Error parsing PortalDesignConfig: "+result.toString());
-                       return null;
-               }
-
-               PortalDesign portalDesign = null;
-               try {
-                       portalDesign = portalDesignService.fillPortalDesignConfiguration(portalDesignConfig);
-               } catch (Exception e) {
-                       log.debug("FillPortalDesignConfiguration failed", e.getMessage());
-                       sendError(response, 400, "Error FillPortalDesignConfiguration: "+e.getMessage());
-                       return null;
-               }
-               portalDesignRepository.save(portalDesign);
-               log.info("PortalDesign save successed");
-               return mkPostReturnBody(200, portalDesign);
-    }
-
-
-       @PutMapping("{id}")
-       @ResponseBody
-       @ApiOperation(value="Update a portalDesign.")
-       public PostReturnBody<PortalDesignConfig> updatePortalDesign(@RequestBody PortalDesignConfig portalDesignConfig, BindingResult result, @PathVariable Integer id, HttpServletResponse response) throws IOException {
-
-               if (result.hasErrors()) {
-                       sendError(response, 400, "Error parsing PortalDesignConfig: "+result.toString());
-                       return null;
-               }
-
-               PortalDesign portalDesign = portalDesignService.getPortalDesign(id);
-               if (portalDesign != null) {
-                       try {
-                               portalDesignService.fillPortalDesignConfiguration(portalDesignConfig, portalDesign);
-                       } catch (Exception e) {
-                               log.debug("FillPortalDesignConfiguration failed", e.getMessage());
-                               sendError(response, 400, "Error FillPortalDesignConfiguration: "+e.getMessage());
-                               return null;
-                       }
-                       portalDesignRepository.save(portalDesign);
-                       log.info("PortalDesign update successed");
-                       return mkPostReturnBody(200, portalDesign);
-               } else {
-                       sendError(response, 400, "PortalDesign not found: "+id);
-                       return null;
-               }
-
-       }
-
-
-       @DeleteMapping("/{id}")
-       @ResponseBody
-       @ApiOperation(value="delete a portalDesign.")
-    public void deletePortalDesign(@PathVariable("id") Integer id, HttpServletResponse response) throws IOException{
-               
-               PortalDesign oldPortalDesign= portalDesignService.getPortalDesign(id);
-               if (oldPortalDesign == null) {
-                       sendError(response, 400, "portalDesign not found "+id);
-               } else {
-                       portalDesignRepository.delete(oldPortalDesign);
-                       response.setStatus(204);
-               }
-    }
-
-
-       @GetMapping("")
-       @ResponseBody
-       @ApiOperation(value="List all PortalDesigns")
-    public List<PortalDesignConfig> queryAllPortalDesign(){
-               return portalDesignService.queryAllPortalDesign();
-    }
-
-
-       @PostMapping("/deploy/{id}")
-       @ResponseBody
-       @ApiOperation(value="PortalDesign deploy")
-       public void deployPortalDesign(@PathVariable Integer id, HttpServletResponse response) throws IOException {
-
-               PortalDesign portalDesign = null;
-               try {
-                       portalDesign = portalDesignRepository.findById(id).get();
-                       boolean flag;
-                       try {
-                               flag = portalDesignService.deploy(portalDesign);
-                               if (flag) {
-                                       portalDesign.setSubmitted(true);
-                                       portalDesignRepository.save(portalDesign);
-                                       response.setStatus(204);
-                               } else {
-                                       sendError(response, 400, "DeployPortalDesign failed, id: "+id);
-                               }
-                       } catch (Exception e) {
-                               log.debug("The request failed", e.getMessage());
-                               sendError(response, 400, "The request failed : "+e.getMessage());
-                       }
-               } catch (Exception e) {
-                       log.debug("PortalDesign is null", e.getMessage());
-                       sendError(response, 400, "PortalDesign not found, id: "+id);
-               }
-
-       }
-
-
-       private PostReturnBody<PortalDesignConfig> mkPostReturnBody(int statusCode, PortalDesign portalDesign) {
-               PostReturnBody<PortalDesignConfig> retBody = new PostReturnBody<>();
-        retBody.setStatusCode(statusCode);
-        retBody.setReturnBody(portalDesign.getPortalDesignConfig());
-        return retBody;
-       }
-    
-       private void sendError(HttpServletResponse response, int sc, String msg) throws IOException {
-               log.info(msg);
-               response.sendError(sc, msg);            
-       }
-    
-}
\ No newline at end of file
@@ -28,7 +28,7 @@ import java.util.Set;
 
 import javax.persistence.*;
 
-import org.onap.datalake.feeder.dto.PortalDesignConfig;
+import org.onap.datalake.feeder.dto.DesignConfig;
 
 /**
  * Domain class representing design
@@ -40,7 +40,7 @@ import org.onap.datalake.feeder.dto.PortalDesignConfig;
 @Setter
 @Entity
 @Table(name = "design")
-public class PortalDesign {
+public class Design {
 
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -75,19 +75,18 @@ public class PortalDesign {
        @JoinTable(name = "map_db_design", joinColumns = { @JoinColumn(name = "design_id") }, inverseJoinColumns = { @JoinColumn(name = "db_id") })
        protected Set<Db> dbs;
 
-    public PortalDesignConfig getPortalDesignConfig() {
+    public DesignConfig getDesignConfig() {
        
-       PortalDesignConfig portalDesignConfig = new PortalDesignConfig();
-
-        portalDesignConfig.setId(getId());
-               portalDesignConfig.setBody(getBody());
-               portalDesignConfig.setName(getName());
-               portalDesignConfig.setNote(getNote());
-               portalDesignConfig.setSubmitted(getSubmitted());
-               portalDesignConfig.setTopic(getTopicName().getId());
-               portalDesignConfig.setDesignType(getDesignType().getId());
-        portalDesignConfig.setDisplay(getDesignType().getName());
-               
-               return portalDesignConfig;
+       DesignConfig designConfig = new DesignConfig();
+
+        designConfig.setId(getId());
+               designConfig.setBody(getBody());
+               designConfig.setName(getName());
+               designConfig.setNote(getNote());
+               designConfig.setSubmitted(getSubmitted());
+               designConfig.setTopicName(getTopicName().getId());
+        designConfig.setDesignType(getDesignType().getId());
+
+               return designConfig;
     }
 }
index 83e1666..dd327ea 100644 (file)
@@ -61,7 +61,7 @@ public class DesignType {
     private DbType dbType;    
 
        @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "designType")
-       protected Set<PortalDesign> designs = new HashSet<>();
+       protected Set<Design> designs = new HashSet<>();
 
     @Column(name = "`note`")
     private String note;
@@ -69,8 +69,10 @@ public class DesignType {
     public DesignTypeConfig getDesignTypeConfig() {
 
         DesignTypeConfig designTypeConfig = new DesignTypeConfig();
-        designTypeConfig.setDesignType(getName());
-        //designTypeConfig.setDisplay(getDisplay());
+
+        designTypeConfig.setId(getId());
+        designTypeConfig.setName(getName());
+
         return designTypeConfig;
     }
 
index 35e6ea5..83227ad 100644 (file)
@@ -49,7 +49,7 @@ public class TopicName {
 
 
        @OneToMany(fetch = FetchType.LAZY, mappedBy = "topicName")
-       protected Set<PortalDesign> designs;
+       protected Set<Design> designs;
        
 
        @OneToMany(fetch = FetchType.LAZY, mappedBy = "topicName")
@@ -31,22 +31,14 @@ import lombok.Setter;
 
 @Getter
 @Setter
-public class PortalDesignConfig {
+public class DesignConfig {
 
     private Integer id;
-
     private String name;
-
     private Boolean submitted;
-
     private String body;
-
     private String note;
-
-    private String topic;
-
+    private String topicName;
     private String designType;
 
-    private String display;
-
 }
 
 package org.onap.datalake.feeder.repository;
 
-import org.onap.datalake.feeder.domain.PortalDesign;
-import org.springframework.data.jpa.repository.Query;
+import org.onap.datalake.feeder.domain.Design;
 import org.springframework.data.repository.CrudRepository;
 
-import java.util.List;
-
 /**
- * PortalDesign Repository
+ * Design Repository
  *
  * @author guochunmeng
  */
 
-public interface PortalDesignRepository extends CrudRepository<PortalDesign, Integer> {
+public interface DesignRepository extends CrudRepository<Design, Integer> {
     
-    PortalDesign findByName(String name);
+    Design findByName(String name);
     
 }
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java
new file mode 100755 (executable)
index 0000000..61411a4
--- /dev/null
@@ -0,0 +1,182 @@
+/*\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP : DataLake\r
+ * ================================================================================\r
+ * Copyright 2019 China Mobile\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
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.datalake.feeder.service;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Optional;\r
+import java.util.Set;\r
+\r
+import org.onap.datalake.feeder.config.ApplicationConfiguration;\r
+import org.onap.datalake.feeder.domain.*;\r
+import org.onap.datalake.feeder.domain.Design;\r
+import org.onap.datalake.feeder.dto.DesignConfig;\r
+import org.onap.datalake.feeder.enumeration.DesignTypeEnum;\r
+import org.onap.datalake.feeder.repository.DesignTypeRepository;\r
+import org.onap.datalake.feeder.repository.DesignRepository;\r
+import org.onap.datalake.feeder.repository.TopicNameRepository;\r
+import org.onap.datalake.feeder.util.HttpClientUtil;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.stereotype.Service;\r
+\r
+/**\r
+ * Service for portalDesigns\r
+ *\r
+ * @author guochunmeng\r
+ */\r
+\r
+@Service\r
+public class DesignService {\r
+\r
+       private final Logger log = LoggerFactory.getLogger(this.getClass());\r
+\r
+       static String POST_FLAG;\r
+\r
+       @Autowired\r
+       private DesignRepository designRepository;\r
+\r
+       @Autowired\r
+       private TopicNameRepository topicNameRepository;\r
+\r
+       @Autowired\r
+       private DesignTypeRepository designTypeRepository;\r
+\r
+       @Autowired\r
+       private ApplicationConfiguration applicationConfiguration;\r
+\r
+       public Design fillDesignConfiguration(DesignConfig designConfig) {\r
+               Design design = new Design();\r
+               fillDesign(designConfig, design);\r
+               return design;\r
+       }\r
+\r
+       public void fillDesignConfiguration(DesignConfig designConfig, Design design) {\r
+               fillDesign(designConfig, design);\r
+       }\r
+\r
+       private void fillDesign(DesignConfig designConfig, Design design) throws IllegalArgumentException {\r
+\r
+               design.setId(designConfig.getId());\r
+               design.setBody(designConfig.getBody());\r
+               design.setName(designConfig.getName());\r
+               design.setNote(designConfig.getNote());\r
+               design.setSubmitted(designConfig.getSubmitted());\r
+\r
+               if (designConfig.getTopicName() == null)\r
+                       throw new IllegalArgumentException("Can not find topicName in tpoic_name, topic name: " + designConfig.getTopicName());\r
+               Optional<TopicName> topicName = topicNameRepository.findById(designConfig.getTopicName());\r
+               if (!topicName.isPresent())\r
+                       throw new IllegalArgumentException("topicName is null " + designConfig.getTopicName());\r
+               design.setTopicName(topicName.get());\r
+\r
+\r
+               if (designConfig.getDesignType() == null)\r
+                       throw new IllegalArgumentException("Can not find designType in design_type, designType id " + designConfig.getDesignType());\r
+               Optional<DesignType> designType = designTypeRepository.findById(designConfig.getDesignType());\r
+               if (!designType.isPresent())\r
+                       throw new IllegalArgumentException("designType is null");\r
+               design.setDesignType(designType.get());\r
+\r
+       }\r
+\r
+       public Design getDesign(Integer id) {\r
+\r
+               Optional<Design> ret = designRepository.findById(id);\r
+               return ret.isPresent() ? ret.get() : null;\r
+       }\r
+\r
+       public List<DesignConfig> queryAllDesign() {\r
+\r
+               List<Design> designList = null;\r
+               List<DesignConfig> designConfigList = new ArrayList<>();\r
+               designList = (List<Design>) designRepository.findAll();\r
+               if (designList != null && designList.size() > 0) {\r
+                       log.info("PortalDesignList is not null");\r
+                       for (Design design : designList) {\r
+                               designConfigList.add(design.getDesignConfig());\r
+                       }\r
+               }\r
+               return designConfigList;\r
+       }\r
+\r
+       public boolean deploy(Design design) {\r
+               DesignType designType = design.getDesignType();\r
+               DesignTypeEnum designTypeEnum = DesignTypeEnum.valueOf(designType.getId());\r
+\r
+               switch (designTypeEnum) {\r
+               case KIBANA_DB:\r
+                       return deployKibanaImport(design);\r
+               case ES_MAPPING:\r
+                       return postEsMappingTemplate(design, design.getTopicName().getId().toLowerCase());\r
+               default:\r
+                       log.error("Not implemented {}", designTypeEnum);\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       private boolean deployKibanaImport(Design design) throws RuntimeException {\r
+               POST_FLAG = "KibanaDashboardImport";\r
+               String requestBody = design.getBody();\r
+               Portal portal = design.getDesignType().getPortal();\r
+               String portalHost = portal.getHost();\r
+               Integer portalPort = portal.getPort();\r
+               String url = "";\r
+\r
+               if (portalHost == null || portalPort == null) {\r
+                       String dbHost = portal.getDb().getHost();\r
+                       Integer dbPort = portal.getDb().getPort();\r
+                       url = kibanaImportUrl(dbHost, dbPort);\r
+               } else {\r
+                       url = kibanaImportUrl(portalHost, portalPort);\r
+               }\r
+               return HttpClientUtil.sendPostHttpClient(url, requestBody, POST_FLAG);\r
+\r
+       }\r
+\r
+       private String kibanaImportUrl(String host, Integer port) {\r
+               if (port == null) {\r
+                       port = applicationConfiguration.getKibanaPort();\r
+               }\r
+               return "http://" + host + ":" + port + applicationConfiguration.getKibanaDashboardImportApi();\r
+       }\r
+\r
+       /**\r
+        * successed resp: { "acknowledged": true }\r
+        * \r
+        * @param design\r
+        * @param templateName\r
+        * @return flag\r
+        */\r
+       public boolean postEsMappingTemplate(Design design, String templateName) throws RuntimeException {\r
+               POST_FLAG = "ElasticsearchMappingTemplate";\r
+               String requestBody = design.getBody();\r
+\r
+               //FIXME\r
+               Set<Db> dbs = design.getDbs();\r
+               //submit to each ES in dbs\r
+\r
+               //return HttpClientUtil.sendPostHttpClient("http://"+dbService.getElasticsearch().getHost()+":9200/_template/"+templateName, requestBody, POST_FLAG);\r
+               return false;\r
+       }\r
+\r
+}\r
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java
deleted file mode 100755 (executable)
index 408e497..0000000
+++ /dev/null
@@ -1,198 +0,0 @@
-/*\r
- * ============LICENSE_START=======================================================\r
- * ONAP : DataLake\r
- * ================================================================================\r
- * Copyright 2019 China Mobile\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
- * ============LICENSE_END=========================================================\r
- */\r
-\r
-package org.onap.datalake.feeder.service;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Optional;\r
-import java.util.Set;\r
-\r
-import org.onap.datalake.feeder.config.ApplicationConfiguration;\r
-import org.onap.datalake.feeder.domain.Db;\r
-import org.onap.datalake.feeder.domain.DbType;\r
-import org.onap.datalake.feeder.domain.DesignType;\r
-import org.onap.datalake.feeder.domain.Portal;\r
-import org.onap.datalake.feeder.domain.PortalDesign;\r
-import org.onap.datalake.feeder.domain.Topic;\r
-import org.onap.datalake.feeder.domain.TopicName;\r
-import org.onap.datalake.feeder.dto.PortalDesignConfig;\r
-import org.onap.datalake.feeder.enumeration.DbTypeEnum;\r
-import org.onap.datalake.feeder.enumeration.DesignTypeEnum;\r
-import org.onap.datalake.feeder.repository.DesignTypeRepository;\r
-import org.onap.datalake.feeder.repository.PortalDesignRepository;\r
-import org.onap.datalake.feeder.repository.TopicNameRepository;\r
-import org.onap.datalake.feeder.service.db.CouchbaseService;\r
-import org.onap.datalake.feeder.service.db.DbStoreService;\r
-import org.onap.datalake.feeder.service.db.ElasticsearchService;\r
-import org.onap.datalake.feeder.service.db.HdfsService;\r
-import org.onap.datalake.feeder.service.db.MongodbService;\r
-import org.onap.datalake.feeder.util.HttpClientUtil;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.stereotype.Service;\r
-\r
-/**\r
- * Service for portalDesigns\r
- *\r
- * @author guochunmeng\r
- */\r
-\r
-@Service\r
-public class PortalDesignService {\r
-\r
-       private final Logger log = LoggerFactory.getLogger(this.getClass());\r
-\r
-       static String POST_FLAG;\r
-\r
-       @Autowired\r
-       private PortalDesignRepository portalDesignRepository;\r
-\r
-       @Autowired\r
-       private TopicNameRepository topicNameRepository;\r
-\r
-       @Autowired\r
-       private DesignTypeRepository designTypeRepository;\r
-\r
-       @Autowired\r
-       private ApplicationConfiguration applicationConfiguration;\r
-\r
-       public PortalDesign fillPortalDesignConfiguration(PortalDesignConfig portalDesignConfig) throws Exception {\r
-               PortalDesign portalDesign = new PortalDesign();\r
-               fillPortalDesign(portalDesignConfig, portalDesign);\r
-               return portalDesign;\r
-       }\r
-\r
-       public void fillPortalDesignConfiguration(PortalDesignConfig portalDesignConfig, PortalDesign portalDesign) throws Exception {\r
-               fillPortalDesign(portalDesignConfig, portalDesign);\r
-       }\r
-\r
-       private void fillPortalDesign(PortalDesignConfig portalDesignConfig, PortalDesign portalDesign) throws IllegalArgumentException {\r
-\r
-               portalDesign.setId(portalDesignConfig.getId());\r
-               portalDesign.setBody(portalDesignConfig.getBody());\r
-               portalDesign.setName(portalDesignConfig.getName());\r
-               portalDesign.setNote(portalDesignConfig.getNote());\r
-               portalDesign.setSubmitted(portalDesignConfig.getSubmitted());\r
-\r
-               if (portalDesignConfig.getTopic() != null) {\r
-                       Optional<TopicName> topicName = topicNameRepository.findById(portalDesignConfig.getTopic());\r
-                       if (topicName.isPresent()) {\r
-                               portalDesign.setTopicName(topicName.get());\r
-                       } else {\r
-                               throw new IllegalArgumentException("topic is null " + portalDesignConfig.getTopic());\r
-                       }\r
-               } else {\r
-                       throw new IllegalArgumentException("Can not find topic in DB, topic name: " + portalDesignConfig.getTopic());\r
-               }\r
-\r
-               if (portalDesignConfig.getDesignType() != null) {\r
-                       DesignType designType = designTypeRepository.findById(portalDesignConfig.getDesignType()).get();\r
-                       if (designType == null)\r
-                               throw new IllegalArgumentException("designType is null");\r
-                       portalDesign.setDesignType(designType);\r
-               } else {\r
-                       throw new IllegalArgumentException("Can not find designType in Design_type, designType name " + portalDesignConfig.getDesignType());\r
-               }\r
-\r
-       }\r
-\r
-       public PortalDesign getPortalDesign(Integer id) {\r
-\r
-               Optional<PortalDesign> ret = portalDesignRepository.findById(id);\r
-               return ret.isPresent() ? ret.get() : null;\r
-       }\r
-\r
-       public List<PortalDesignConfig> queryAllPortalDesign() {\r
-\r
-               List<PortalDesign> portalDesignList = null;\r
-               List<PortalDesignConfig> portalDesignConfigList = new ArrayList<>();\r
-               portalDesignList = (List<PortalDesign>) portalDesignRepository.findAll();\r
-               if (portalDesignList != null && portalDesignList.size() > 0) {\r
-                       log.info("PortalDesignList is not null");\r
-                       for (PortalDesign portalDesign : portalDesignList) {\r
-                               portalDesignConfigList.add(portalDesign.getPortalDesignConfig());\r
-                       }\r
-               }\r
-               return portalDesignConfigList;\r
-       }\r
-\r
-       public boolean deploy(PortalDesign portalDesign) {\r
-               DesignType designType = portalDesign.getDesignType();\r
-               DesignTypeEnum designTypeEnum = DesignTypeEnum.valueOf(designType.getId());\r
-\r
-               switch (designTypeEnum) {\r
-               case KIBANA_DB:\r
-                       return deployKibanaImport(portalDesign);\r
-               case ES_MAPPING:\r
-                       return postEsMappingTemplate(portalDesign, portalDesign.getTopicName().getId().toLowerCase());\r
-               default:\r
-                       log.error("Not implemented {}", designTypeEnum);\r
-                       return false;\r
-               }\r
-       }\r
-\r
-       private boolean deployKibanaImport(PortalDesign portalDesign) throws RuntimeException {\r
-               POST_FLAG = "KibanaDashboardImport";\r
-               String requestBody = portalDesign.getBody();\r
-               Portal portal = portalDesign.getDesignType().getPortal();\r
-               String portalHost = portal.getHost();\r
-               Integer portalPort = portal.getPort();\r
-               String url = "";\r
-\r
-               if (portalHost == null || portalPort == null) {\r
-                       String dbHost = portal.getDb().getHost();\r
-                       Integer dbPort = portal.getDb().getPort();\r
-                       url = kibanaImportUrl(dbHost, dbPort);\r
-               } else {\r
-                       url = kibanaImportUrl(portalHost, portalPort);\r
-               }\r
-               return HttpClientUtil.sendPostHttpClient(url, requestBody, POST_FLAG);\r
-\r
-       }\r
-\r
-       private String kibanaImportUrl(String host, Integer port) {\r
-               if (port == null) {\r
-                       port = applicationConfiguration.getKibanaPort();\r
-               }\r
-               return "http://" + host + ":" + port + applicationConfiguration.getKibanaDashboardImportApi();\r
-       }\r
-\r
-       /**\r
-        * successed resp: { "acknowledged": true }\r
-        * \r
-        * @param portalDesign\r
-        * @param templateName\r
-        * @return flag\r
-        */\r
-       public boolean postEsMappingTemplate(PortalDesign portalDesign, String templateName) throws RuntimeException {\r
-               POST_FLAG = "ElasticsearchMappingTemplate";\r
-               String requestBody = portalDesign.getBody();\r
-\r
-               //FIXME\r
-               Set<Db> dbs = portalDesign.getDbs();\r
-               //submit to each ES in dbs\r
-\r
-               //return HttpClientUtil.sendPostHttpClient("http://"+dbService.getElasticsearch().getHost()+":9200/_template/"+templateName, requestBody, POST_FLAG);\r
-               return false;\r
-       }\r
-\r
-}\r
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignControllerTest.java
new file mode 100644 (file)
index 0000000..9509bdd
--- /dev/null
@@ -0,0 +1,178 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DATALAKE
+ * ================================================================================
+ * Copyright 2019 China Mobile
+ *=================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.datalake.feeder.controller;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.datalake.feeder.config.ApplicationConfiguration;
+import org.onap.datalake.feeder.controller.domain.PostReturnBody;
+import org.onap.datalake.feeder.domain.*;
+import org.onap.datalake.feeder.domain.Design;
+import org.onap.datalake.feeder.dto.DesignConfig;
+import org.onap.datalake.feeder.repository.DesignTypeRepository;
+import org.onap.datalake.feeder.repository.DesignRepository;
+import org.onap.datalake.feeder.service.DesignService;
+import org.onap.datalake.feeder.service.TopicService;
+import org.springframework.validation.BindingResult;
+
+import javax.servlet.http.HttpServletResponse;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class DesignControllerTest {
+  
+    //static String Kibana_Dashboard_Import_Api = "/api/kibana/dashboards/import?exclude=index-pattern";
+
+    @Mock
+    private HttpServletResponse httpServletResponse;
+
+    @Mock
+    private BindingResult mockBindingResult;
+
+    @Mock
+    private ApplicationConfiguration applicationConfiguration;
+
+    @Mock
+    private DesignRepository designRepository;
+
+    @Mock
+    private TopicService topicService;
+
+    @Mock
+    private DesignTypeRepository designTypeRepository;
+
+    @InjectMocks
+    private DesignService designService;
+
+
+    @Before
+    public void setupTest() {
+        MockitoAnnotations.initMocks(this);
+        when(mockBindingResult.hasErrors()).thenReturn(false);
+    }
+
+    @Test
+    public void testCreateDesign() throws NoSuchFieldException, IllegalAccessException, IOException {
+
+        DesignController testDesignController = new DesignController();
+        setAccessPrivateFields(testDesignController);
+        Design testDesign = fillDomain();
+        //when(topicService.getTopic(0)).thenReturn(new Topic("unauthenticated.SEC_FAULT_OUTPUT"));
+//        when(designTypeRepository.findById("Kibana Dashboard")).thenReturn(Optional.of(testDesign.getDesignType()));
+        PostReturnBody<DesignConfig> postPortal = testDesignController.createDesign(testDesign.getDesignConfig(), mockBindingResult, httpServletResponse);
+        //assertEquals(postPortal.getStatusCode(), 200);
+        assertNull(postPortal);
+    }
+
+    @Test
+    public void testUpdateDesign() throws NoSuchFieldException, IllegalAccessException, IOException {
+
+        DesignController testDesignController = new DesignController();
+        setAccessPrivateFields(testDesignController);
+        Design testDesign = fillDomain();
+        Integer id = 1;
+        when(designRepository.findById(id)).thenReturn((Optional.of(testDesign)));
+        //when(topicService.getTopic(0)).thenReturn(new Topic("unauthenticated.SEC_FAULT_OUTPUT"));
+ //       when(designTypeRepository.findById("Kibana Dashboard")).thenReturn(Optional.of(testDesign.getDesignType()));
+        PostReturnBody<DesignConfig> postPortal = testDesignController.updateDesign(testDesign.getDesignConfig(), mockBindingResult, id, httpServletResponse);
+        //assertEquals(postPortal.getStatusCode(), 200);
+        assertNull(postPortal);
+    }
+
+    @Test
+    public void testDeleteDesign() throws NoSuchFieldException, IllegalAccessException, IOException {
+
+        DesignController testDesignController = new DesignController();
+        setAccessPrivateFields(testDesignController);
+        Design testDesign = fillDomain();
+        Integer id = 1;
+        testDesign.setId(1);
+        when(designRepository.findById(id)).thenReturn((Optional.of(testDesign)));
+        testDesignController.deleteDesign(id, httpServletResponse);
+    }
+
+    @Test
+    public void testQueryAllDesign() throws NoSuchFieldException, IllegalAccessException {
+
+        DesignController testDesignController = new DesignController();
+        setAccessPrivateFields(testDesignController);
+        Design testDesign = fillDomain();
+        List<Design> designList = new ArrayList<>();
+        designList.add(testDesign);
+        when(designRepository.findAll()).thenReturn(designList);
+        assertEquals(1, testDesignController.queryAllDesign().size());
+    }
+
+    @Test
+    public void testDeployDesign() throws NoSuchFieldException, IllegalAccessException, IOException {
+
+        DesignController testDesignController = new DesignController();
+        setAccessPrivateFields(testDesignController);
+        Design testDesign = fillDomain();
+        Integer id = 1;
+        testDesign.setId(1);
+       //when(applicationConfiguration.getKibanaDashboardImportApi()).thenReturn(Kibana_Dashboard_Import_Api);
+        when(designRepository.findById(id)).thenReturn((Optional.of(testDesign)));
+        testDesignController.deployDesign(id, httpServletResponse);
+    }
+
+    public void setAccessPrivateFields(DesignController designController) throws NoSuchFieldException, IllegalAccessException {
+
+        Field testPortalDesignService = designController.getClass().getDeclaredField("designService");
+        testPortalDesignService.setAccessible(true);
+        testPortalDesignService.set(designController, designService);
+        Field testPortalDesignRepository = designController.getClass().getDeclaredField("designRepository");
+        testPortalDesignRepository.setAccessible(true);
+        testPortalDesignRepository.set(designController, designRepository);
+    }
+
+
+    public Design fillDomain(){
+        Design design = new Design();
+        design.setName("Kibana");
+        design.setBody("jsonString");
+        design.setSubmitted(false);
+        design.setNote("test");
+        DesignType designType = new DesignType();
+        designType.setName("Kibana Dashboard");
+        Portal portal = new Portal();
+        portal.setName("Kibana");
+        portal.setHost("127.0.0.1");
+        portal.setPort(5601);
+        designType.setPortal(portal);
+        design.setDesignType(designType);
+        design.setTopicName(new TopicName("unauthenticated.SEC_FAULT_OUTPUT"));
+        return design;
+    }
+}
\ No newline at end of file
index 1469e93..54ee2b2 100644 (file)
@@ -60,7 +60,7 @@ public class KafkaControllerTest {
     private KafkaController kafkaController;
     @Test
     public void createKafka() throws IOException {
-        String id = "123";
+        int id = 123;
         KafkaConfig kafkaConfig = new KafkaConfig();
         kafkaConfig.setId(id);
         kafkaConfig.setName("123");
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/PortalDesignControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/PortalDesignControllerTest.java
deleted file mode 100644 (file)
index cfc7c55..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : DATALAKE
- * ================================================================================
- * Copyright 2019 China Mobile
- *=================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.datalake.feeder.controller;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.datalake.feeder.config.ApplicationConfiguration;
-import org.onap.datalake.feeder.controller.domain.PostReturnBody;
-import org.onap.datalake.feeder.domain.DesignType;
-import org.onap.datalake.feeder.domain.Portal;
-import org.onap.datalake.feeder.domain.PortalDesign;
-import org.onap.datalake.feeder.domain.Topic;
-import org.onap.datalake.feeder.domain.TopicName;
-import org.onap.datalake.feeder.dto.PortalDesignConfig;
-import org.onap.datalake.feeder.repository.DesignTypeRepository;
-import org.onap.datalake.feeder.repository.PortalDesignRepository;
-import org.onap.datalake.feeder.service.PortalDesignService;
-import org.onap.datalake.feeder.service.TopicService;
-import org.springframework.validation.BindingResult;
-
-import javax.servlet.http.HttpServletResponse;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class PortalDesignControllerTest {
-  
-    //static String Kibana_Dashboard_Import_Api = "/api/kibana/dashboards/import?exclude=index-pattern";
-
-    @Mock
-    private HttpServletResponse httpServletResponse;
-
-    @Mock
-    private BindingResult mockBindingResult;
-
-    @Mock
-    private ApplicationConfiguration applicationConfiguration;
-
-    @Mock
-    private PortalDesignRepository portalDesignRepository;
-
-    @Mock
-    private TopicService topicService;
-
-    @Mock
-    private DesignTypeRepository designTypeRepository;
-
-    @InjectMocks
-    private PortalDesignService portalDesignService;
-
-
-    @Before
-    public void setupTest() {
-        MockitoAnnotations.initMocks(this);
-        when(mockBindingResult.hasErrors()).thenReturn(false);
-    }
-
-    @Test
-    public void testCreatePortalDesign() throws NoSuchFieldException, IllegalAccessException, IOException {
-
-        PortalDesignController testPortalDesignController = new PortalDesignController();
-        setAccessPrivateFields(testPortalDesignController);
-        PortalDesign testPortalDesign = fillDomain();
-        //when(topicService.getTopic(0)).thenReturn(new Topic("unauthenticated.SEC_FAULT_OUTPUT"));
-//        when(designTypeRepository.findById("Kibana Dashboard")).thenReturn(Optional.of(testPortalDesign.getDesignType()));
-        PostReturnBody<PortalDesignConfig> postPortal = testPortalDesignController.createPortalDesign(testPortalDesign.getPortalDesignConfig(), mockBindingResult, httpServletResponse);
-        //assertEquals(postPortal.getStatusCode(), 200);
-        assertNull(postPortal);
-    }
-
-    @Test
-    public void testUpdatePortalDesign() throws NoSuchFieldException, IllegalAccessException, IOException {
-
-        PortalDesignController testPortalDesignController = new PortalDesignController();
-        setAccessPrivateFields(testPortalDesignController);
-        PortalDesign testPortalDesign = fillDomain();
-        Integer id = 1;
-        when(portalDesignRepository.findById(id)).thenReturn((Optional.of(testPortalDesign)));
-        //when(topicService.getTopic(0)).thenReturn(new Topic("unauthenticated.SEC_FAULT_OUTPUT"));
- //       when(designTypeRepository.findById("Kibana Dashboard")).thenReturn(Optional.of(testPortalDesign.getDesignType()));
-        PostReturnBody<PortalDesignConfig> postPortal = testPortalDesignController.updatePortalDesign(testPortalDesign.getPortalDesignConfig(), mockBindingResult, id, httpServletResponse);
-        //assertEquals(postPortal.getStatusCode(), 200);
-        assertNull(postPortal);
-    }
-
-    @Test
-    public void testDeletePortalDesign() throws NoSuchFieldException, IllegalAccessException, IOException {
-
-        PortalDesignController testPortalDesignController = new PortalDesignController();
-        setAccessPrivateFields(testPortalDesignController);
-        PortalDesign testPortalDesign = fillDomain();
-        Integer id = 1;
-        testPortalDesign.setId(1);
-        when(portalDesignRepository.findById(id)).thenReturn((Optional.of(testPortalDesign)));
-        testPortalDesignController.deletePortalDesign(id, httpServletResponse);
-    }
-
-    @Test
-    public void testQueryAllPortalDesign() throws NoSuchFieldException, IllegalAccessException {
-
-        PortalDesignController testPortalDesignController = new PortalDesignController();
-        setAccessPrivateFields(testPortalDesignController);
-        PortalDesign testPortalDesign = fillDomain();
-        List<PortalDesign> portalDesignList = new ArrayList<>();
-        portalDesignList.add(testPortalDesign);
-        when(portalDesignRepository.findAll()).thenReturn(portalDesignList);
-        assertEquals(1, testPortalDesignController.queryAllPortalDesign().size());
-    }
-
-    @Test
-    public void testDeployPortalDesign() throws NoSuchFieldException, IllegalAccessException, IOException {
-
-        PortalDesignController testPortalDesignController = new PortalDesignController();
-        setAccessPrivateFields(testPortalDesignController);
-        PortalDesign testPortalDesign = fillDomain();
-        Integer id = 1;
-        testPortalDesign.setId(1);
-       //when(applicationConfiguration.getKibanaDashboardImportApi()).thenReturn(Kibana_Dashboard_Import_Api);
-        when(portalDesignRepository.findById(id)).thenReturn((Optional.of(testPortalDesign)));
-        testPortalDesignController.deployPortalDesign(id, httpServletResponse);
-    }
-
-    public void setAccessPrivateFields(PortalDesignController portalDesignController) throws NoSuchFieldException, IllegalAccessException {
-
-        Field testPortalDesignService = portalDesignController.getClass().getDeclaredField("portalDesignService");
-        testPortalDesignService.setAccessible(true);
-        testPortalDesignService.set(portalDesignController, portalDesignService);
-        Field testPortalDesignRepository = portalDesignController.getClass().getDeclaredField("portalDesignRepository");
-        testPortalDesignRepository.setAccessible(true);
-        testPortalDesignRepository.set(portalDesignController, portalDesignRepository);
-    }
-
-
-    public PortalDesign fillDomain(){
-        PortalDesign portalDesign = new PortalDesign();
-        portalDesign.setName("Kibana");
-        portalDesign.setBody("jsonString");
-        portalDesign.setSubmitted(false);
-        portalDesign.setNote("test");
-        DesignType designType = new DesignType();
-        designType.setName("Kibana Dashboard");
-        Portal portal = new Portal();
-        portal.setName("Kibana");
-        portal.setHost("127.0.0.1");
-        portal.setPort(5601);
-        designType.setPortal(portal);
-        portalDesign.setDesignType(designType);
-        portalDesign.setTopicName(new TopicName("unauthenticated.SEC_FAULT_OUTPUT"));
-        return  portalDesign;
-    }
-}
\ No newline at end of file
@@ -25,32 +25,32 @@ import org.onap.datalake.feeder.util.TestUtil;
 
 import static org.junit.Assert.*;
 
-public class PortalDesignTest {
+public class DesignTest {
 
     @Test
     public void testIs() {
 
-        PortalDesign portalDesign = new PortalDesign();
-        portalDesign.setId(1);
-        portalDesign.setSubmitted(false);
-        portalDesign.setBody("jsonString");
-        portalDesign.setName("templateTest");
-        portalDesign.setTopicName(new TopicName("x"));
+        Design design = new Design();
+        design.setId(1);
+        design.setSubmitted(false);
+        design.setBody("jsonString");
+        design.setName("templateTest");
+        design.setTopicName(new TopicName("x"));
         Topic topic = TestUtil.newTopic("_DL_DEFAULT_");
-        portalDesign.setTopicName(topic.getTopicName());
+        design.setTopicName(topic.getTopicName());
         DesignType designType = new DesignType();
         designType.setName("Kibana");
-        portalDesign.setDesignType(designType);
-        portalDesign.setNote("test");
-        portalDesign.setDbs(null);
-        assertFalse("1".equals(portalDesign.getId()));
-        assertTrue("templateTest".equals(portalDesign.getName()));
-        assertTrue("jsonString".equals(portalDesign.getBody()));
-        assertFalse("_DL_DEFAULT_".equals(portalDesign.getTopicName()));
-        assertTrue("test".equals(portalDesign.getNote()));
-        assertFalse("Kibana".equals(portalDesign.getDesignType()));
-        assertFalse("false".equals(portalDesign.getSubmitted()));
-        assertNull(portalDesign.getDbs());
+        design.setDesignType(designType);
+        design.setNote("test");
+        design.setDbs(null);
+        assertFalse("1".equals(design.getId()));
+        assertTrue("templateTest".equals(design.getName()));
+        assertTrue("jsonString".equals(design.getBody()));
+        assertFalse("_DL_DEFAULT_".equals(design.getTopicName()));
+        assertTrue("test".equals(design.getNote()));
+        assertFalse("Kibana".equals(design.getDesignType()));
+        assertFalse("false".equals(design.getSubmitted()));
+        assertNull(design.getDbs());
     }
 
 }
\ No newline at end of file
 package org.onap.datalake.feeder.dto;
 
 import org.junit.Test;
+import org.onap.datalake.feeder.domain.Design;
 import org.onap.datalake.feeder.domain.DesignType;
-import org.onap.datalake.feeder.domain.PortalDesign;
-import org.onap.datalake.feeder.domain.Topic;
 import org.onap.datalake.feeder.domain.TopicName;
 
 import static org.junit.Assert.*;
 
-public class PortalDesignConfigTest {
+public class DesignConfigTest {
 
     @Test
     public void testIs() {
 
-        PortalDesign testPortaldesign = new PortalDesign();
+        Design testPortaldesign = new Design();
         testPortaldesign.setId(1);
         testPortaldesign.setTopicName(new TopicName("test"));
         DesignType testDesignType = new DesignType();
         testDesignType.setName("test");
         testPortaldesign.setDesignType(testDesignType);
 
-        PortalDesign testPortaldesign2 = new PortalDesign();
+        Design testPortaldesign2 = new Design();
         testPortaldesign2.setId(1);
         testPortaldesign2.setTopicName(new TopicName("test"));
         DesignType testDesignType2 = new DesignType();
         testDesignType2.setName("test");
         testPortaldesign2.setDesignType(testDesignType2);
 
-        PortalDesignConfig testPortalDesignConfig = testPortaldesign.getPortalDesignConfig();
-
-        assertNotEquals(testPortalDesignConfig, testPortaldesign2.getPortalDesignConfig());
-        assertNotEquals(testPortalDesignConfig, null);
-        assertNotEquals(testPortalDesignConfig.getId(), null);
-        assertEquals(testPortalDesignConfig.getBody(), null);
-        assertEquals(testPortalDesignConfig.getNote(), null);
-        assertEquals(testPortalDesignConfig.getName(), null);
-        assertEquals(testPortalDesignConfig.getSubmitted(), null);
-        assertEquals(testPortalDesignConfig.getDesignType(), null);
-        assertEquals(testPortalDesignConfig.getDisplay(), "test");
+        DesignConfig testDesignConfig = testPortaldesign.getDesignConfig();
+
+        assertNotEquals(testDesignConfig, testPortaldesign2.getDesignConfig());
+        assertNotEquals(testDesignConfig, null);
+        assertNotEquals(testDesignConfig.getId(), null);
+        assertEquals(testDesignConfig.getBody(), null);
+        assertEquals(testDesignConfig.getNote(), null);
+        assertEquals(testDesignConfig.getName(), null);
+        assertEquals(testDesignConfig.getSubmitted(), null);
+        assertEquals(testDesignConfig.getDesignType(), null);
     }
 
 }
\ No newline at end of file
@@ -26,14 +26,14 @@ import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.onap.datalake.feeder.config.ApplicationConfiguration;
 import org.onap.datalake.feeder.domain.Db;
+import org.onap.datalake.feeder.domain.Design;
 import org.onap.datalake.feeder.domain.DesignType;
 import org.onap.datalake.feeder.domain.Portal;
-import org.onap.datalake.feeder.domain.PortalDesign;
-import static org.junit.Assert.*;
+
 import static org.mockito.Mockito.when;
 
 @RunWith(MockitoJUnitRunner.class)
-public class PortalDesignServiceTest {
+public class DesignServiceTest {
 
     @Mock
     private DesignType designType;
@@ -42,14 +42,14 @@ public class PortalDesignServiceTest {
     private ApplicationConfiguration applicationConfiguration;
 
     @InjectMocks
-    private PortalDesignService designService;
+    private DesignService designService;
 
     @Test(expected = RuntimeException.class)
     public void testDeploy() {
         when(designType.getId()).thenReturn("KIBANA_DB","ES_MAPPING");
-        PortalDesign portalDesign = new PortalDesign();
-        portalDesign.setDesignType(designType);
-        portalDesign.setBody("jsonString");
+        Design design = new Design();
+        design.setDesignType(designType);
+        design.setBody("jsonString");
 
         Portal portal = new Portal();
         Db db = new Db();
@@ -58,7 +58,7 @@ public class PortalDesignServiceTest {
         when(designType.getPortal()).thenReturn(portal);
         when(applicationConfiguration.getKibanaDashboardImportApi()).thenReturn("/api/kibana/dashboards/import?exclude=index-pattern");
         when(applicationConfiguration.getKibanaPort()).thenReturn(5601);
-        designService.deploy(portalDesign);
+        designService.deploy(design);
         System.out.println();
     }
 }
\ No newline at end of file
index 3bdeb1a..0274d30 100644 (file)
@@ -50,7 +50,7 @@ public class KafkaServiceTest {
 
     @Test
     public void testKafkaServer(){
-        String kafkaId = "123";
+        int kafkaId = 123;
         Kafka kafka = new Kafka();
         kafka.setId(kafkaId);