summaryrefslogtreecommitdiffstats
path: root/components/datalake-handler/feeder
diff options
context:
space:
mode:
authorZhangZihao <zhangzihao@chinamobile.com>2019-07-11 15:18:33 +0800
committerZihao Zhang <zhangzihao@chinamobile.com>2019-07-11 08:01:54 +0000
commit632b6e2d2c2951ccb20b187a5100a8f5b258669a (patch)
tree2f19bd1d38f801305a61e0ce0590f3edff266eb2 /components/datalake-handler/feeder
parent7f41677c4a422882d1a42202d0a1b3c1b1b63153 (diff)
design modify 1
Change-Id: I32ef0ff484b786b9c5b73df8fd1b8cc97c5dc227 Issue-ID: DCAEGEN2-1658 Signed-off-by: ZhangZihao <zhangzihao@chinamobile.com>
Diffstat (limited to 'components/datalake-handler/feeder')
-rw-r--r--components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignController.java179
-rw-r--r--components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java179
-rw-r--r--components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Design.java (renamed from components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java)29
-rw-r--r--components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java8
-rw-r--r--components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/TopicName.java2
-rwxr-xr-xcomponents/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignConfig.java (renamed from components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java)12
-rw-r--r--components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignTypeConfig.java5
-rw-r--r--components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignRepository.java (renamed from components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalDesignRepository.java)11
-rwxr-xr-xcomponents/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java182
-rwxr-xr-xcomponents/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java198
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignControllerTest.java178
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java2
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/PortalDesignControllerTest.java181
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTest.java (renamed from components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/PortalDesignTest.java)38
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java (renamed from components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/PortalDesignConfigTest.java)30
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java (renamed from components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PortalDesignServiceTest.java)16
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java2
17 files changed, 610 insertions, 642 deletions
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
index 00000000..0cac567c
--- /dev/null
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignController.java
@@ -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
index fa35b3ba..00000000
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java
+++ /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
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Design.java
index 1cbf4e59..dde17b33 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Design.java
@@ -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;
}
}
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java
index 83e1666a..dd327ea0 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java
@@ -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;
}
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/TopicName.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/TopicName.java
index 35e6ea54..83227ada 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/TopicName.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/TopicName.java
@@ -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")
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignConfig.java
index 49e1cde5..d115529d 100755
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignConfig.java
@@ -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;
-
}
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignTypeConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignTypeConfig.java
index a4ed6d33..ddedf38b 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignTypeConfig.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignTypeConfig.java
@@ -33,8 +33,7 @@ import lombok.Setter;
@Getter
public class DesignTypeConfig {
- private String designType;
-
- private String display;
+ private String id;
+ private String name;
}
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalDesignRepository.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignRepository.java
index 181bc115..f144e905 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalDesignRepository.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignRepository.java
@@ -20,20 +20,17 @@
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
index 00000000..61411a4d
--- /dev/null
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java
@@ -0,0 +1,182 @@
+/*
+ * ============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.service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+
+import org.onap.datalake.feeder.config.ApplicationConfiguration;
+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.enumeration.DesignTypeEnum;
+import org.onap.datalake.feeder.repository.DesignTypeRepository;
+import org.onap.datalake.feeder.repository.DesignRepository;
+import org.onap.datalake.feeder.repository.TopicNameRepository;
+import org.onap.datalake.feeder.util.HttpClientUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * Service for portalDesigns
+ *
+ * @author guochunmeng
+ */
+
+@Service
+public class DesignService {
+
+ private final Logger log = LoggerFactory.getLogger(this.getClass());
+
+ static String POST_FLAG;
+
+ @Autowired
+ private DesignRepository designRepository;
+
+ @Autowired
+ private TopicNameRepository topicNameRepository;
+
+ @Autowired
+ private DesignTypeRepository designTypeRepository;
+
+ @Autowired
+ private ApplicationConfiguration applicationConfiguration;
+
+ public Design fillDesignConfiguration(DesignConfig designConfig) {
+ Design design = new Design();
+ fillDesign(designConfig, design);
+ return design;
+ }
+
+ public void fillDesignConfiguration(DesignConfig designConfig, Design design) {
+ fillDesign(designConfig, design);
+ }
+
+ private void fillDesign(DesignConfig designConfig, Design design) throws IllegalArgumentException {
+
+ design.setId(designConfig.getId());
+ design.setBody(designConfig.getBody());
+ design.setName(designConfig.getName());
+ design.setNote(designConfig.getNote());
+ design.setSubmitted(designConfig.getSubmitted());
+
+ if (designConfig.getTopicName() == null)
+ throw new IllegalArgumentException("Can not find topicName in tpoic_name, topic name: " + designConfig.getTopicName());
+ Optional<TopicName> topicName = topicNameRepository.findById(designConfig.getTopicName());
+ if (!topicName.isPresent())
+ throw new IllegalArgumentException("topicName is null " + designConfig.getTopicName());
+ design.setTopicName(topicName.get());
+
+
+ if (designConfig.getDesignType() == null)
+ throw new IllegalArgumentException("Can not find designType in design_type, designType id " + designConfig.getDesignType());
+ Optional<DesignType> designType = designTypeRepository.findById(designConfig.getDesignType());
+ if (!designType.isPresent())
+ throw new IllegalArgumentException("designType is null");
+ design.setDesignType(designType.get());
+
+ }
+
+ public Design getDesign(Integer id) {
+
+ Optional<Design> ret = designRepository.findById(id);
+ return ret.isPresent() ? ret.get() : null;
+ }
+
+ public List<DesignConfig> queryAllDesign() {
+
+ List<Design> designList = null;
+ List<DesignConfig> designConfigList = new ArrayList<>();
+ designList = (List<Design>) designRepository.findAll();
+ if (designList != null && designList.size() > 0) {
+ log.info("PortalDesignList is not null");
+ for (Design design : designList) {
+ designConfigList.add(design.getDesignConfig());
+ }
+ }
+ return designConfigList;
+ }
+
+ public boolean deploy(Design design) {
+ DesignType designType = design.getDesignType();
+ DesignTypeEnum designTypeEnum = DesignTypeEnum.valueOf(designType.getId());
+
+ switch (designTypeEnum) {
+ case KIBANA_DB:
+ return deployKibanaImport(design);
+ case ES_MAPPING:
+ return postEsMappingTemplate(design, design.getTopicName().getId().toLowerCase());
+ default:
+ log.error("Not implemented {}", designTypeEnum);
+ return false;
+ }
+ }
+
+ private boolean deployKibanaImport(Design design) throws RuntimeException {
+ POST_FLAG = "KibanaDashboardImport";
+ String requestBody = design.getBody();
+ Portal portal = design.getDesignType().getPortal();
+ String portalHost = portal.getHost();
+ Integer portalPort = portal.getPort();
+ String url = "";
+
+ if (portalHost == null || portalPort == null) {
+ String dbHost = portal.getDb().getHost();
+ Integer dbPort = portal.getDb().getPort();
+ url = kibanaImportUrl(dbHost, dbPort);
+ } else {
+ url = kibanaImportUrl(portalHost, portalPort);
+ }
+ return HttpClientUtil.sendPostHttpClient(url, requestBody, POST_FLAG);
+
+ }
+
+ private String kibanaImportUrl(String host, Integer port) {
+ if (port == null) {
+ port = applicationConfiguration.getKibanaPort();
+ }
+ return "http://" + host + ":" + port + applicationConfiguration.getKibanaDashboardImportApi();
+ }
+
+ /**
+ * successed resp: { "acknowledged": true }
+ *
+ * @param design
+ * @param templateName
+ * @return flag
+ */
+ public boolean postEsMappingTemplate(Design design, String templateName) throws RuntimeException {
+ POST_FLAG = "ElasticsearchMappingTemplate";
+ String requestBody = design.getBody();
+
+ //FIXME
+ Set<Db> dbs = design.getDbs();
+ //submit to each ES in dbs
+
+ //return HttpClientUtil.sendPostHttpClient("http://"+dbService.getElasticsearch().getHost()+":9200/_template/"+templateName, requestBody, POST_FLAG);
+ return false;
+ }
+
+}
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
index 408e4971..00000000
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java
+++ /dev/null
@@ -1,198 +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.service;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-
-import org.onap.datalake.feeder.config.ApplicationConfiguration;
-import org.onap.datalake.feeder.domain.Db;
-import org.onap.datalake.feeder.domain.DbType;
-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.enumeration.DbTypeEnum;
-import org.onap.datalake.feeder.enumeration.DesignTypeEnum;
-import org.onap.datalake.feeder.repository.DesignTypeRepository;
-import org.onap.datalake.feeder.repository.PortalDesignRepository;
-import org.onap.datalake.feeder.repository.TopicNameRepository;
-import org.onap.datalake.feeder.service.db.CouchbaseService;
-import org.onap.datalake.feeder.service.db.DbStoreService;
-import org.onap.datalake.feeder.service.db.ElasticsearchService;
-import org.onap.datalake.feeder.service.db.HdfsService;
-import org.onap.datalake.feeder.service.db.MongodbService;
-import org.onap.datalake.feeder.util.HttpClientUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-/**
- * Service for portalDesigns
- *
- * @author guochunmeng
- */
-
-@Service
-public class PortalDesignService {
-
- private final Logger log = LoggerFactory.getLogger(this.getClass());
-
- static String POST_FLAG;
-
- @Autowired
- private PortalDesignRepository portalDesignRepository;
-
- @Autowired
- private TopicNameRepository topicNameRepository;
-
- @Autowired
- private DesignTypeRepository designTypeRepository;
-
- @Autowired
- private ApplicationConfiguration applicationConfiguration;
-
- public PortalDesign fillPortalDesignConfiguration(PortalDesignConfig portalDesignConfig) throws Exception {
- PortalDesign portalDesign = new PortalDesign();
- fillPortalDesign(portalDesignConfig, portalDesign);
- return portalDesign;
- }
-
- public void fillPortalDesignConfiguration(PortalDesignConfig portalDesignConfig, PortalDesign portalDesign) throws Exception {
- fillPortalDesign(portalDesignConfig, portalDesign);
- }
-
- private void fillPortalDesign(PortalDesignConfig portalDesignConfig, PortalDesign portalDesign) throws IllegalArgumentException {
-
- portalDesign.setId(portalDesignConfig.getId());
- portalDesign.setBody(portalDesignConfig.getBody());
- portalDesign.setName(portalDesignConfig.getName());
- portalDesign.setNote(portalDesignConfig.getNote());
- portalDesign.setSubmitted(portalDesignConfig.getSubmitted());
-
- if (portalDesignConfig.getTopic() != null) {
- Optional<TopicName> topicName = topicNameRepository.findById(portalDesignConfig.getTopic());
- if (topicName.isPresent()) {
- portalDesign.setTopicName(topicName.get());
- } else {
- throw new IllegalArgumentException("topic is null " + portalDesignConfig.getTopic());
- }
- } else {
- throw new IllegalArgumentException("Can not find topic in DB, topic name: " + portalDesignConfig.getTopic());
- }
-
- if (portalDesignConfig.getDesignType() != null) {
- DesignType designType = designTypeRepository.findById(portalDesignConfig.getDesignType()).get();
- if (designType == null)
- throw new IllegalArgumentException("designType is null");
- portalDesign.setDesignType(designType);
- } else {
- throw new IllegalArgumentException("Can not find designType in Design_type, designType name " + portalDesignConfig.getDesignType());
- }
-
- }
-
- public PortalDesign getPortalDesign(Integer id) {
-
- Optional<PortalDesign> ret = portalDesignRepository.findById(id);
- return ret.isPresent() ? ret.get() : null;
- }
-
- public List<PortalDesignConfig> queryAllPortalDesign() {
-
- List<PortalDesign> portalDesignList = null;
- List<PortalDesignConfig> portalDesignConfigList = new ArrayList<>();
- portalDesignList = (List<PortalDesign>) portalDesignRepository.findAll();
- if (portalDesignList != null && portalDesignList.size() > 0) {
- log.info("PortalDesignList is not null");
- for (PortalDesign portalDesign : portalDesignList) {
- portalDesignConfigList.add(portalDesign.getPortalDesignConfig());
- }
- }
- return portalDesignConfigList;
- }
-
- public boolean deploy(PortalDesign portalDesign) {
- DesignType designType = portalDesign.getDesignType();
- DesignTypeEnum designTypeEnum = DesignTypeEnum.valueOf(designType.getId());
-
- switch (designTypeEnum) {
- case KIBANA_DB:
- return deployKibanaImport(portalDesign);
- case ES_MAPPING:
- return postEsMappingTemplate(portalDesign, portalDesign.getTopicName().getId().toLowerCase());
- default:
- log.error("Not implemented {}", designTypeEnum);
- return false;
- }
- }
-
- private boolean deployKibanaImport(PortalDesign portalDesign) throws RuntimeException {
- POST_FLAG = "KibanaDashboardImport";
- String requestBody = portalDesign.getBody();
- Portal portal = portalDesign.getDesignType().getPortal();
- String portalHost = portal.getHost();
- Integer portalPort = portal.getPort();
- String url = "";
-
- if (portalHost == null || portalPort == null) {
- String dbHost = portal.getDb().getHost();
- Integer dbPort = portal.getDb().getPort();
- url = kibanaImportUrl(dbHost, dbPort);
- } else {
- url = kibanaImportUrl(portalHost, portalPort);
- }
- return HttpClientUtil.sendPostHttpClient(url, requestBody, POST_FLAG);
-
- }
-
- private String kibanaImportUrl(String host, Integer port) {
- if (port == null) {
- port = applicationConfiguration.getKibanaPort();
- }
- return "http://" + host + ":" + port + applicationConfiguration.getKibanaDashboardImportApi();
- }
-
- /**
- * successed resp: { "acknowledged": true }
- *
- * @param portalDesign
- * @param templateName
- * @return flag
- */
- public boolean postEsMappingTemplate(PortalDesign portalDesign, String templateName) throws RuntimeException {
- POST_FLAG = "ElasticsearchMappingTemplate";
- String requestBody = portalDesign.getBody();
-
- //FIXME
- Set<Db> dbs = portalDesign.getDbs();
- //submit to each ES in dbs
-
- //return HttpClientUtil.sendPostHttpClient("http://"+dbService.getElasticsearch().getHost()+":9200/_template/"+templateName, requestBody, POST_FLAG);
- return false;
- }
-
-}
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
index 00000000..9509bdd3
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignControllerTest.java
@@ -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
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java
index 1469e938..54ee2b2d 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java
@@ -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
index cfc7c552..00000000
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/PortalDesignControllerTest.java
+++ /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
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/PortalDesignTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTest.java
index 9c3e8008..de6fec27 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/PortalDesignTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTest.java
@@ -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
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/PortalDesignConfigTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java
index 1d0f2a8d..22ebe4f1 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/PortalDesignConfigTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java
@@ -21,43 +21,41 @@
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
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PortalDesignServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java
index b66c52df..3c877189 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PortalDesignServiceTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java
@@ -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
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java
index 3bdeb1a2..0274d309 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java
@@ -50,7 +50,7 @@ public class KafkaServiceTest {
@Test
public void testKafkaServer(){
- String kafkaId = "123";
+ int kafkaId = 123;
Kafka kafka = new Kafka();
kafka.setId(kafkaId);