diff options
author | ZhangZihao <zhangzihao@chinamobile.com> | 2019-07-16 16:49:27 +0800 |
---|---|---|
committer | Zihao Zhang <zhangzihao@chinamobile.com> | 2019-07-17 02:37:42 +0000 |
commit | 9cf94ff1acf4764085acf5b340b876ab82829e5f (patch) | |
tree | 879f66bb951af91d56a64d2a21839c7ab1e586bf /components/datalake-handler/feeder | |
parent | c4c391b68ed1a30b3b398c56efadf28b2f33388d (diff) |
design modify 2
Change-Id: I839bee562f03e12de9a3a4bfcd25f4db5fee6f7e
Issue-ID: DCAEGEN2-1658
Signed-off-by: ZhangZihao <zhangzihao@chinamobile.com>
Diffstat (limited to 'components/datalake-handler/feeder')
18 files changed, 43 insertions, 653 deletions
diff --git a/components/datalake-handler/feeder/src/assembly/scripts/init_db.sql b/components/datalake-handler/feeder/src/assembly/scripts/init_db.sql index 1fd9aa84..028305dd 100644 --- a/components/datalake-handler/feeder/src/assembly/scripts/init_db.sql +++ b/components/datalake-handler/feeder/src/assembly/scripts/init_db.sql @@ -34,30 +34,15 @@ CREATE TABLE `db` ( CONSTRAINT `FK3njadtw43ieph7ftt4kxdhcko` FOREIGN KEY (`db_type_id`) REFERENCES `db_type` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-CREATE TABLE `portal` (
- `name` varchar(255) NOT NULL,
- `enabled` bit(1) DEFAULT NULL,
- `host` varchar(255) DEFAULT NULL,
- `login` varchar(255) DEFAULT NULL,
- `pass` varchar(255) DEFAULT NULL,
- `port` int(11) DEFAULT NULL,
- `related_db` int(11) DEFAULT NULL,
- PRIMARY KEY (`name`),
- KEY `FKtl6e8ydm1k7k9r5ukv9j0bd0n` (`related_db`),
- CONSTRAINT `FKtl6e8ydm1k7k9r5ukv9j0bd0n` FOREIGN KEY (`related_db`) REFERENCES `db` (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
CREATE TABLE `design_type` (
`id` varchar(255) NOT NULL,
`name` varchar(255) DEFAULT NULL,
`note` varchar(255) DEFAULT NULL,
`db_type_id` varchar(255) NOT NULL,
- `portal` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FKm8rkv2qkq01gsmeq1c3y4w02x` (`db_type_id`),
KEY `FKs2nspbhf5wv5d152l4j69yjhi` (`portal`),
- CONSTRAINT `FKm8rkv2qkq01gsmeq1c3y4w02x` FOREIGN KEY (`db_type_id`) REFERENCES `db_type` (`id`),
- CONSTRAINT `FKs2nspbhf5wv5d152l4j69yjhi` FOREIGN KEY (`portal`) REFERENCES `portal` (`name`)
+ CONSTRAINT `FKm8rkv2qkq01gsmeq1c3y4w02x` FOREIGN KEY (`db_type_id`) REFERENCES `db_type` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `design` (
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalController.java deleted file mode 100644 index 2844facd..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalController.java +++ /dev/null @@ -1,115 +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 io.swagger.annotations.ApiOperation; -import org.onap.datalake.feeder.controller.domain.PostReturnBody; -import org.onap.datalake.feeder.domain.Portal; -import org.onap.datalake.feeder.dto.PortalConfig; -import org.onap.datalake.feeder.repository.PortalRepository; -import org.onap.datalake.feeder.service.PortalService; -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 javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -/** - * This controller manages Portal settings - * - * - * @author guochunmeng - */ -@RestController -@RequestMapping(value = "/portals", produces = { MediaType.APPLICATION_JSON_VALUE }) -public class PortalController { - - private final Logger log = LoggerFactory.getLogger(this.getClass()); - - @Autowired - private PortalRepository portalRepository; - - @Autowired - private PortalService portalService; - - @PutMapping("") - @ResponseBody - @ApiOperation("update portal") - public PostReturnBody<PortalConfig> updatePortal(@RequestBody PortalConfig portalConfig, BindingResult result, HttpServletResponse response) throws IOException { - - if (result.hasErrors()) { - sendError(response, 400, "Error binding PortalConfig: "+result.toString()); - return null; - } - - Portal portal = null; - try { - portal = portalRepository.findById(portalConfig.getName()).get(); - log.info("Update portal "+portalConfig); - portalService.fillPortalConfiguration(portalConfig, portal); - portalRepository.save(portal); - return mkPostReturnBody(200, portal); - } catch (Exception e) { - log.debug("Update or delete portal failed, Portal: "+portalConfig, e.getMessage()); - sendError(response, 400, "Error update or delete portal: "+portal); - return null; - } - } - - - @GetMapping("") - @ResponseBody - @ApiOperation(value = "List all portals") - public List<PortalConfig> getPortals() { - - List<Portal> portalList = null; - List<PortalConfig> portalConfigList = new ArrayList<>(); - portalList = (List<Portal>)portalRepository.findAll(); - if (portalList != null && portalList.size() > 0) { - log.info("PortalList is not null"); - for(Portal portal : portalList) { - portalConfigList.add(portal.getPortalConfig()); - } - } - return portalConfigList; - } - - - private void sendError(HttpServletResponse response, int sc, String msg) throws IOException { - log.info(msg); - response.sendError(sc, msg); - } - - - private PostReturnBody<PortalConfig> mkPostReturnBody(int statusCode, Portal portal) { - PostReturnBody<PortalConfig> retBody = new PostReturnBody<>(); - retBody.setStatusCode(statusCode); - retBody.setReturnBody(portal.getPortalConfig()); - return retBody; - } - -}
\ 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 index dde17b33..faf3755e 100644 --- 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 @@ -24,6 +24,8 @@ import com.fasterxml.jackson.annotation.JsonBackReference; import lombok.Getter; import lombok.Setter; +import java.util.ArrayList; +import java.util.List; import java.util.Set; import javax.persistence.*; @@ -86,6 +88,16 @@ public class Design { designConfig.setSubmitted(getSubmitted()); designConfig.setTopicName(getTopicName().getId()); designConfig.setDesignType(getDesignType().getId()); + designConfig.setDesignTypeName(getDesignType().getName()); + + Set<Db> designDb = getDbs(); + List<Integer> dbList = new ArrayList<>(); + if (designDb != null) { + for (Db item : designDb) { + dbList.add(item.getId()); + } + } + designConfig.setDbs(dbList); 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 dd327ea0..14026fe0 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 @@ -49,12 +49,6 @@ public class DesignType { @Column(name = "`name`") private String name; - //To be removed - @ManyToOne(fetch=FetchType.EAGER) - @JoinColumn(name="portal") - @JsonBackReference - private Portal portal; - @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="db_type_id", nullable = false) @JsonBackReference diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Portal.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Portal.java deleted file mode 100644 index d2214dce..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Portal.java +++ /dev/null @@ -1,79 +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 org.onap.datalake.feeder.dto.PortalConfig; - -import javax.persistence.*; - -/** - * Domain class representing portal - * - * @author guochunmeng - */ - -@Getter -@Setter -@Entity -@Table(name = "portal") -public class Portal { - - @Id - @Column(name = "`name`") - private String name; - - @Column(name = "`enabled`") - private Boolean enabled; - - @Column(name = "`host`") - private String host; - - @Column(name = "`port`") - private Integer port; - - @Column(name = "`login`") - private String login; - - @Column(name = "`pass`") - private String pass; - - @ManyToOne(fetch=FetchType.EAGER) - @JoinColumn(name = "related_db") - @JsonBackReference - private Db db; - - public PortalConfig getPortalConfig() { - PortalConfig portalConfig = new PortalConfig(); - - portalConfig.setName(getName()); - portalConfig.setLogin(getLogin()); - portalConfig.setPass(getPass()); - portalConfig.setEnabled(getEnabled()); - portalConfig.setHost(getHost()); - portalConfig.setPort(getPort()); - portalConfig.setDb(getDb().getName()); - - return portalConfig; - } -} 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 index d115529d..34256004 100755 --- 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 @@ -23,6 +23,8 @@ package org.onap.datalake.feeder.dto; import lombok.Getter; import lombok.Setter; +import java.util.List; + /** * JSON request body for portalDesign Config. * @@ -40,5 +42,7 @@ public class DesignConfig { private String note; private String topicName; private String designType; + private String designTypeName;//UI show name + private List<Integer> dbs; } diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalConfig.java deleted file mode 100644 index 76b1ceb7..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalConfig.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : DataLake - * ================================================================================ - * Copyright 2019 QCT - *================================================================================= - * 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 Portal Config. - * - * @author guochunmeng - * - */ -@Setter -@Getter -public class PortalConfig { - - private String name; - - private Boolean enabled; - - private String host; - - private Integer port; - - private String login; - - private String pass; - - private String db; - -} diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalRepository.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalRepository.java deleted file mode 100644 index f4ce0ee5..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalRepository.java +++ /dev/null @@ -1,42 +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.Portal; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.Repository; - -import java.util.List; - -/** - * Portal Repository - * - * @author guochunmeng - */ - -public interface PortalRepository extends CrudRepository<Portal, String> { - - List<Portal> findByEnabled(Boolean enabled); - -} diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/TopicRepository.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/TopicRepository.java index b4dd6374..8f72dfed 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/TopicRepository.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/TopicRepository.java @@ -19,9 +19,6 @@ */
package org.onap.datalake.feeder.repository;
-import java.util.List;
-
-import org.onap.datalake.feeder.domain.Portal;
import org.onap.datalake.feeder.domain.Topic;
import org.springframework.data.repository.CrudRepository;
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 index 61411a4d..4ba4f8f7 100755 --- 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 @@ -24,12 +24,14 @@ import java.util.ArrayList; import java.util.List;
import java.util.Optional;
import java.util.Set;
+import java.util.HashSet;
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.DbRepository;
import org.onap.datalake.feeder.repository.DesignTypeRepository;
import org.onap.datalake.feeder.repository.DesignRepository;
import org.onap.datalake.feeder.repository.TopicNameRepository;
@@ -64,6 +66,9 @@ public class DesignService { @Autowired
private ApplicationConfiguration applicationConfiguration;
+ @Autowired
+ private DbRepository dbRepository;
+
public Design fillDesignConfiguration(DesignConfig designConfig) {
Design design = new Design();
fillDesign(designConfig, design);
@@ -89,7 +94,6 @@ public class DesignService { 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());
@@ -97,6 +101,23 @@ public class DesignService { throw new IllegalArgumentException("designType is null");
design.setDesignType(designType.get());
+ Set<Db> dbs = new HashSet<>();
+ if (designConfig.getDbs() != null) {
+ for (Integer item : designConfig.getDbs()) {
+ Optional<Db> db = dbRepository.findById(item);
+ if (db.isPresent()) {
+ dbs.add(db.get());
+ }
+ }
+ if (dbs.size() > 0)
+ design.setDbs(dbs);
+ else {
+ design.getDbs().clear();
+ design.setDbs(dbs);
+ }
+ } else {
+ design.setDbs(dbs);
+ }
}
public Design getDesign(Integer id) {
@@ -111,7 +132,7 @@ public class DesignService { List<DesignConfig> designConfigList = new ArrayList<>();
designList = (List<Design>) designRepository.findAll();
if (designList != null && designList.size() > 0) {
- log.info("PortalDesignList is not null");
+ log.info("DesignList is not null");
for (Design design : designList) {
designConfigList.add(design.getDesignConfig());
}
@@ -137,18 +158,8 @@ public class DesignService { 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);
- }
+ //TODO
return HttpClientUtil.sendPostHttpClient(url, requestBody, POST_FLAG);
}
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalService.java deleted file mode 100644 index 28efd150..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalService.java +++ /dev/null @@ -1,79 +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 org.onap.datalake.feeder.domain.Portal; -import org.onap.datalake.feeder.dto.PortalConfig; -import org.onap.datalake.feeder.repository.PortalRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.List; - -/** - * Service for portals - * - * @author guochunmeng - * - */ -@Service -public class PortalService { - - @Autowired - private PortalRepository portalRepository; - - public Portal fillPortalConfiguration(PortalConfig portalConfig) - { - Portal portal = new Portal(); - fillPortal(portalConfig, portal); - return portal; - } - public void fillPortalConfiguration(PortalConfig portalConfig, Portal portal) - { - fillPortal(portalConfig, portal); - } - - private void fillPortal(PortalConfig portalConfig, Portal portal) { - - portal.setName(portalConfig.getName()); - portal.setLogin(portalConfig.getLogin()); - portal.setPass(portalConfig.getPass()); - portal.setEnabled(portalConfig.getEnabled()); - portal.setHost(portalConfig.getHost()); - portal.setPort(portalConfig.getPort()); - - } - - - public List<String> listNames(boolean enabled){ - - List<String> names = new ArrayList<>(); - Iterable<Portal> ret = portalRepository.findByEnabled(enabled); - for(Portal portal:ret) { - names.add(portal.getName()); - } - - return names; - } - -} 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 index 9509bdd3..670f100d 100644 --- 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 @@ -166,11 +166,6 @@ public class DesignControllerTest { 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; diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignTypeControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignTypeControllerTest.java index 69e592a2..79c0c846 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignTypeControllerTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignTypeControllerTest.java @@ -27,7 +27,6 @@ import org.mockito.InjectMocks; import org.mockito.MockitoAnnotations; import org.mockito.junit.MockitoJUnitRunner; import org.onap.datalake.feeder.domain.DesignType; -import org.onap.datalake.feeder.domain.Portal; import org.onap.datalake.feeder.service.DesignTypeService; import java.lang.reflect.Field; @@ -69,11 +68,6 @@ public class DesignTypeControllerTest { public DesignType fillDomain(){ 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); return designType; } }
\ No newline at end of file diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/PortalControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/PortalControllerTest.java deleted file mode 100644 index 9e843ea5..00000000 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/PortalControllerTest.java +++ /dev/null @@ -1,121 +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.controller.domain.PostReturnBody; -import org.onap.datalake.feeder.domain.Db; -import org.onap.datalake.feeder.domain.Portal; -import org.onap.datalake.feeder.dto.PortalConfig; -import org.onap.datalake.feeder.repository.PortalRepository; -import org.onap.datalake.feeder.service.PortalService; -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.assertEquals; -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class PortalControllerTest { - - @Mock - private HttpServletResponse httpServletResponse; - - @Mock - private BindingResult mockBindingResult; - - @Mock - private PortalRepository portalRepository; - - @InjectMocks - private PortalService portalService; - - @Before - public void setupTest() { - MockitoAnnotations.initMocks(this); - when(mockBindingResult.hasErrors()).thenReturn(false); - } - - - @Test - public void testUpdatePortal() throws NoSuchFieldException, IllegalAccessException, IOException { - - PortalController testPortalController = new PortalController(); - setAccessPrivateFields(testPortalController); - Portal testPortal = fillDomain(); - when(portalRepository.findById("Kibana")).thenReturn(Optional.of(testPortal)); - PostReturnBody<PortalConfig> postPortal = testPortalController.updatePortal(testPortal.getPortalConfig(), mockBindingResult, httpServletResponse); - assertEquals(postPortal.getStatusCode(), 200); - //when(mockBindingResult.hasErrors()).thenReturn(true); - - } - - - @Test - public void testGetPortals() throws NoSuchFieldException, IllegalAccessException { - - PortalController testPortalController = new PortalController(); - setAccessPrivateFields(testPortalController); - Portal testPortal = fillDomain(); - List<Portal> portalList = new ArrayList<>(); - portalList.add(testPortal); - when(portalRepository.findAll()).thenReturn(portalList); - assertEquals(1, testPortalController.getPortals().size()); - - } - - - public void setAccessPrivateFields(PortalController portalController) throws NoSuchFieldException, IllegalAccessException { - - Field testPortalService = portalController.getClass().getDeclaredField("portalService"); - testPortalService.setAccessible(true); - testPortalService.set(portalController, portalService); - Field testPortalRepository = portalController.getClass().getDeclaredField("portalRepository"); - testPortalRepository.setAccessible(true); - testPortalRepository.set(portalController, portalRepository); - } - - - public Portal fillDomain(){ - Portal portal = new Portal(); - portal.setName("Kibana"); - portal.setEnabled(true); - portal.setHost("127.0.0.1"); - portal.setPort(5601); - portal.setLogin("admin"); - portal.setPass("password"); - portal.setDb(new Db()); - return portal; - } -}
\ No newline at end of file diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTypeTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTypeTest.java index ad930630..e02c2d1c 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTypeTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTypeTest.java @@ -31,19 +31,13 @@ public class DesignTypeTest { DesignType designType = new DesignType(); designType.setName("Kibana Dashboard"); designType.setNote("test"); - Portal portal = new Portal(); - portal.setName("Kibana"); - designType.setPortal(portal); assertEquals("Kibana Dashboard", designType.getName()); assertEquals("test", designType.getNote()); - assertNotEquals("Kibana", designType.getPortal()); designType.setDbType(null); designType.getDbType(); - designType.setDesigns(null); designType.getDesigns(); - designType.getDesignTypeConfig(); } }
\ No newline at end of file diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/PortalTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/PortalTest.java deleted file mode 100644 index 442d7f19..00000000 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/PortalTest.java +++ /dev/null @@ -1,50 +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.*; -import static org.junit.Assert.assertTrue; - -public class PortalTest { - - @Test - public void testIs() { - - Portal portal = new Portal(); - portal.setName("Kibana"); - portal.setEnabled(true); - portal.setHost("localhost"); - portal.setPort(5601); - portal.setLogin("admin"); - portal.setPass("password"); - portal.setDb(TestUtil.newDb("Elasticsearch")); - assertTrue("Kibana".equals(portal.getName())); - assertFalse("true".equals(portal.getEnabled())); - assertTrue("localhost".equals(portal.getHost())); - assertFalse("5601".equals(portal.getPort())); - assertTrue("admin".equals(portal.getLogin())); - assertTrue("password".equals(portal.getPass())); - assertFalse("Elasticsearch".equals(portal.getDb())); - } -}
\ No newline at end of file diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/PortalConfigTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/PortalConfigTest.java deleted file mode 100644 index 4709b04a..00000000 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/PortalConfigTest.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 org.junit.Test; -import org.onap.datalake.feeder.domain.Db; -import org.onap.datalake.feeder.domain.Portal; -import org.onap.datalake.feeder.util.TestUtil; - -import static org.junit.Assert.*; - -public class PortalConfigTest { - - @Test - public void testIs(){ - - Portal testPortal = new Portal(); - testPortal.setName("Kibana"); - testPortal.setDb(TestUtil.newDb("Elasticsearch")); - Portal testPortal2 = new Portal(); - testPortal2.setName("Kibana"); - testPortal2.setDb(TestUtil.newDb("Elasticsearch")); - PortalConfig testPortalConfig = testPortal.getPortalConfig(); - assertNotEquals(testPortalConfig, testPortal2.getPortalConfig()); - assertNotEquals(testPortalConfig, testPortal); - assertNotEquals(testPortalConfig, null); - assertEquals(testPortalConfig.getHost(), null); - assertEquals(testPortalConfig.getPort(), null); - assertEquals(testPortalConfig.getEnabled(), null); - assertEquals(testPortalConfig.getLogin(), null); - assertEquals(testPortalConfig.getPass(), null); - assertEquals(testPortalConfig.getDb(), "Elasticsearch"); - } -}
\ 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 index 3c877189..65b373f5 100644 --- 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 @@ -25,10 +25,8 @@ 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; @@ -50,14 +48,8 @@ public class DesignServiceTest { 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); + //when(applicationConfiguration.getKibanaDashboardImportApi()).thenReturn("/api/kibana/dashboards/import?exclude=index-pattern"); + //when(applicationConfiguration.getKibanaPort()).thenReturn(5601); designService.deploy(design); System.out.println(); } |