From 632b6e2d2c2951ccb20b187a5100a8f5b258669a Mon Sep 17 00:00:00 2001 From: ZhangZihao Date: Thu, 11 Jul 2019 15:18:33 +0800 Subject: design modify 1 Change-Id: I32ef0ff484b786b9c5b73df8fd1b8cc97c5dc227 Issue-ID: DCAEGEN2-1658 Signed-off-by: ZhangZihao --- .../feeder/controller/DesignController.java | 179 +++++++++++++++++++ .../feeder/controller/PortalDesignController.java | 179 ------------------- .../org/onap/datalake/feeder/domain/Design.java | 92 ++++++++++ .../onap/datalake/feeder/domain/DesignType.java | 8 +- .../onap/datalake/feeder/domain/PortalDesign.java | 93 ---------- .../org/onap/datalake/feeder/domain/TopicName.java | 2 +- .../org/onap/datalake/feeder/dto/DesignConfig.java | 44 +++++ .../onap/datalake/feeder/dto/DesignTypeConfig.java | 5 +- .../datalake/feeder/dto/PortalDesignConfig.java | 52 ------ .../feeder/repository/DesignRepository.java | 36 ++++ .../feeder/repository/PortalDesignRepository.java | 39 ---- .../datalake/feeder/service/DesignService.java | 182 +++++++++++++++++++ .../feeder/service/PortalDesignService.java | 198 --------------------- .../feeder/controller/DesignControllerTest.java | 178 ++++++++++++++++++ .../feeder/controller/KafkaControllerTest.java | 2 +- .../controller/PortalDesignControllerTest.java | 181 ------------------- .../onap/datalake/feeder/domain/DesignTest.java | 56 ++++++ .../datalake/feeder/domain/PortalDesignTest.java | 56 ------ .../onap/datalake/feeder/dto/DesignConfigTest.java | 61 +++++++ .../feeder/dto/PortalDesignConfigTest.java | 63 ------- .../datalake/feeder/service/DesignServiceTest.java | 64 +++++++ .../datalake/feeder/service/KafkaServiceTest.java | 2 +- .../feeder/service/PortalDesignServiceTest.java | 64 ------- 23 files changed, 902 insertions(+), 934 deletions(-) create mode 100644 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignController.java delete mode 100644 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java create mode 100644 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Design.java delete mode 100644 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java create mode 100755 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignConfig.java delete mode 100755 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java create mode 100644 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignRepository.java delete mode 100644 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalDesignRepository.java create mode 100755 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java delete mode 100755 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java create mode 100644 components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignControllerTest.java delete mode 100644 components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/PortalDesignControllerTest.java create mode 100644 components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTest.java delete mode 100644 components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/PortalDesignTest.java create mode 100644 components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java delete mode 100644 components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/PortalDesignConfigTest.java create mode 100644 components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java delete mode 100644 components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PortalDesignServiceTest.java (limited to 'components/datalake-handler/feeder') 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 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 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 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 mkPostReturnBody(int statusCode, Design design) { + PostReturnBody 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 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 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 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 mkPostReturnBody(int statusCode, PortalDesign portalDesign) { - PostReturnBody 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/Design.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Design.java new file mode 100644 index 00000000..dde17b33 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Design.java @@ -0,0 +1,92 @@ +/* + * ============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.domain; + +import com.fasterxml.jackson.annotation.JsonBackReference; +import lombok.Getter; +import lombok.Setter; + +import java.util.Set; + +import javax.persistence.*; + +import org.onap.datalake.feeder.dto.DesignConfig; + +/** + * Domain class representing design + * + * @author guochunmeng + */ + +@Getter +@Setter +@Entity +@Table(name = "design") +public class Design { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "`id`") + private Integer id; + + @Column(name = "`name`") + private String name; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "topic_name_id", nullable = false) + private TopicName topicName;//topic name + + @Column(name = "`submitted`") + private Boolean submitted; + + @Column(name = "`body`") + private String body; + + @Column(name = "`note`") + private String note; + + @ManyToOne(fetch=FetchType.EAGER) + @JoinColumn(name = "design_type_id", nullable = false) + @JsonBackReference + private DesignType designType; + + //@ManyToMany(mappedBy = "topics", cascade=CascadeType.ALL) + @JsonBackReference + //@JsonManagedReference + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "map_db_design", joinColumns = { @JoinColumn(name = "design_id") }, inverseJoinColumns = { @JoinColumn(name = "db_id") }) + protected Set dbs; + + public DesignConfig getDesignConfig() { + + 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 designs = new HashSet<>(); + protected Set 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/PortalDesign.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java deleted file mode 100644 index 1cbf4e59..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java +++ /dev/null @@ -1,93 +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.domain; - -import com.fasterxml.jackson.annotation.JsonBackReference; -import lombok.Getter; -import lombok.Setter; - -import java.util.Set; - -import javax.persistence.*; - -import org.onap.datalake.feeder.dto.PortalDesignConfig; - -/** - * Domain class representing design - * - * @author guochunmeng - */ - -@Getter -@Setter -@Entity -@Table(name = "design") -public class PortalDesign { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "`id`") - private Integer id; - - @Column(name = "`name`") - private String name; - - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "topic_name_id", nullable = false) - private TopicName topicName;//topic name - - @Column(name = "`submitted`") - private Boolean submitted; - - @Column(name = "`body`") - private String body; - - @Column(name = "`note`") - private String note; - - @ManyToOne(fetch=FetchType.EAGER) - @JoinColumn(name = "design_type_id", nullable = false) - @JsonBackReference - private DesignType designType; - - //@ManyToMany(mappedBy = "topics", cascade=CascadeType.ALL) - @JsonBackReference - //@JsonManagedReference - @ManyToMany(fetch = FetchType.EAGER) - @JoinTable(name = "map_db_design", joinColumns = { @JoinColumn(name = "design_id") }, inverseJoinColumns = { @JoinColumn(name = "db_id") }) - protected Set dbs; - - public PortalDesignConfig getPortalDesignConfig() { - - 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; - } -} 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 designs; + protected Set designs; @OneToMany(fetch = FetchType.LAZY, mappedBy = "topicName") diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignConfig.java new file mode 100755 index 00000000..d115529d --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignConfig.java @@ -0,0 +1,44 @@ +/* + * ============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.dto; + +import lombok.Getter; +import lombok.Setter; + +/** + * JSON request body for portalDesign Config. + * + * @author guochunmeng + */ + +@Getter +@Setter +public class DesignConfig { + + private Integer id; + private String name; + private Boolean submitted; + private String body; + private String note; + private String topicName; + private String designType; + +} 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/dto/PortalDesignConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java deleted file mode 100755 index 49e1cde5..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java +++ /dev/null @@ -1,52 +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.dto; - -import lombok.Getter; -import lombok.Setter; - -/** - * JSON request body for portalDesign Config. - * - * @author guochunmeng - */ - -@Getter -@Setter -public class PortalDesignConfig { - - private Integer id; - - private String name; - - private Boolean submitted; - - private String body; - - private String note; - - private String topic; - - private String designType; - - private String display; - -} diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignRepository.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignRepository.java new file mode 100644 index 00000000..f144e905 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignRepository.java @@ -0,0 +1,36 @@ +/* + * ============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.repository; + +import org.onap.datalake.feeder.domain.Design; +import org.springframework.data.repository.CrudRepository; + +/** + * Design Repository + * + * @author guochunmeng + */ + +public interface DesignRepository extends CrudRepository { + + Design findByName(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/PortalDesignRepository.java deleted file mode 100644 index 181bc115..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalDesignRepository.java +++ /dev/null @@ -1,39 +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.repository; - -import org.onap.datalake.feeder.domain.PortalDesign; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.CrudRepository; - -import java.util.List; - -/** - * PortalDesign Repository - * - * @author guochunmeng - */ - -public interface PortalDesignRepository extends CrudRepository { - - PortalDesign 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 = 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 = designTypeRepository.findById(designConfig.getDesignType()); + if (!designType.isPresent()) + throw new IllegalArgumentException("designType is null"); + design.setDesignType(designType.get()); + + } + + public Design getDesign(Integer id) { + + Optional ret = designRepository.findById(id); + return ret.isPresent() ? ret.get() : null; + } + + public List queryAllDesign() { + + List designList = null; + List designConfigList = new ArrayList<>(); + designList = (List) 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 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 = 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 ret = portalDesignRepository.findById(id); - return ret.isPresent() ? ret.get() : null; - } - - public List queryAllPortalDesign() { - - List portalDesignList = null; - List portalDesignConfigList = new ArrayList<>(); - portalDesignList = (List) 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 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 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 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 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 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 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 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/DesignTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTest.java new file mode 100644 index 00000000..de6fec27 --- /dev/null +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTest.java @@ -0,0 +1,56 @@ +/* + * ============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.domain; + +import org.junit.Test; +import org.onap.datalake.feeder.util.TestUtil; + +import static org.junit.Assert.*; + +public class DesignTest { + + @Test + public void testIs() { + + 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_"); + design.setTopicName(topic.getTopicName()); + DesignType designType = new DesignType(); + designType.setName("Kibana"); + 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/domain/PortalDesignTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/PortalDesignTest.java deleted file mode 100644 index 9c3e8008..00000000 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/PortalDesignTest.java +++ /dev/null @@ -1,56 +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.domain; - -import org.junit.Test; -import org.onap.datalake.feeder.util.TestUtil; - -import static org.junit.Assert.*; - -public class PortalDesignTest { - - @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")); - Topic topic = TestUtil.newTopic("_DL_DEFAULT_"); - portalDesign.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()); - } - -} \ No newline at end of file diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java new file mode 100644 index 00000000..22ebe4f1 --- /dev/null +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java @@ -0,0 +1,61 @@ +/* + * ============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.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.TopicName; + +import static org.junit.Assert.*; + +public class DesignConfigTest { + + @Test + public void testIs() { + + Design testPortaldesign = new Design(); + testPortaldesign.setId(1); + testPortaldesign.setTopicName(new TopicName("test")); + DesignType testDesignType = new DesignType(); + testDesignType.setName("test"); + testPortaldesign.setDesignType(testDesignType); + + Design testPortaldesign2 = new Design(); + testPortaldesign2.setId(1); + testPortaldesign2.setTopicName(new TopicName("test")); + DesignType testDesignType2 = new DesignType(); + testDesignType2.setName("test"); + testPortaldesign2.setDesignType(testDesignType2); + + 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/dto/PortalDesignConfigTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/PortalDesignConfigTest.java deleted file mode 100644 index 1d0f2a8d..00000000 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/PortalDesignConfigTest.java +++ /dev/null @@ -1,63 +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.dto; - -import org.junit.Test; -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 { - - @Test - public void testIs() { - - PortalDesign testPortaldesign = new PortalDesign(); - testPortaldesign.setId(1); - testPortaldesign.setTopicName(new TopicName("test")); - DesignType testDesignType = new DesignType(); - testDesignType.setName("test"); - testPortaldesign.setDesignType(testDesignType); - - PortalDesign testPortaldesign2 = new PortalDesign(); - 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"); - } - -} \ No newline at end of file diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java new file mode 100644 index 00000000..3c877189 --- /dev/null +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java @@ -0,0 +1,64 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : DCAE + * ================================================================================ + * 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 org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +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 static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class DesignServiceTest { + + @Mock + private DesignType designType; + + @Mock + private ApplicationConfiguration applicationConfiguration; + + @InjectMocks + private DesignService designService; + + @Test(expected = RuntimeException.class) + public void testDeploy() { + when(designType.getId()).thenReturn("KIBANA_DB","ES_MAPPING"); + Design design = new Design(); + design.setDesignType(designType); + design.setBody("jsonString"); + + Portal portal = new Portal(); + Db db = new Db(); + db.setHost("localhost"); + portal.setDb(db); + when(designType.getPortal()).thenReturn(portal); + when(applicationConfiguration.getKibanaDashboardImportApi()).thenReturn("/api/kibana/dashboards/import?exclude=index-pattern"); + when(applicationConfiguration.getKibanaPort()).thenReturn(5601); + 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); 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/PortalDesignServiceTest.java deleted file mode 100644 index b66c52df..00000000 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PortalDesignServiceTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : DCAE - * ================================================================================ - * 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 org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -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.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 { - - @Mock - private DesignType designType; - - @Mock - private ApplicationConfiguration applicationConfiguration; - - @InjectMocks - private PortalDesignService 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"); - - Portal portal = new Portal(); - Db db = new Db(); - db.setHost("localhost"); - portal.setDb(db); - when(designType.getPortal()).thenReturn(portal); - when(applicationConfiguration.getKibanaDashboardImportApi()).thenReturn("/api/kibana/dashboards/import?exclude=index-pattern"); - when(applicationConfiguration.getKibanaPort()).thenReturn(5601); - designService.deploy(portalDesign); - System.out.println(); - } -} \ No newline at end of file -- cgit 1.2.3-korg