diff options
Diffstat (limited to 'rulemgt')
44 files changed, 594 insertions, 876 deletions
diff --git a/rulemgt/pom.xml b/rulemgt/pom.xml index 12ecd57..29bf27c 100644 --- a/rulemgt/pom.xml +++ b/rulemgt/pom.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- - ~ Copyright 2017-2020 ZTE Corporation. + ~ Copyright 2017-2022 ZTE Corporation. ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. @@ -14,7 +14,8 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -28,7 +29,11 @@ <packaging>jar</packaging> <properties> - <jetty.version>9.4.18.v20190429</jetty.version> + <main-class>org.onap.holmes.rulemgt.RuleActiveApp</main-class> + <sonar.coverage.jacoco.xmlReportPaths> + ${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml + </sonar.coverage.jacoco.xmlReportPaths> + <jacoco.version>0.8.5</jacoco.version> </properties> <build> @@ -36,10 +41,49 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> - <version>3.3</version> + <version>3.8.0</version> <configuration> - <source>1.8</source> - <target>1.8</target> + <source>8</source> + <target>8</target> + <release>11</release> + </configuration> + </plugin> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>${jacoco.version}</version> + <executions> + <execution> + <id>prepare-agent</id> + <goals> + <goal>prepare-agent</goal> + </goals> + </execution> + <execution> + <id>report</id> + <goals> + <goal>report</goal> + </goals> + <configuration> + <dataFile>${project.build.directory}/code-coverage/jacoco.exec</dataFile> + <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <version>${springboot.version}</version> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + </execution> + </executions> + <configuration> + <mainClass>${main-class}</mainClass> </configuration> </plugin> </plugins> diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java index 799f455..fc3e798 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java @@ -1,5 +1,5 @@ /** - * Copyright 2017-2018 ZTE Corporation. + * Copyright 2017-2022 ZTE Corporation. * <p> * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package org.onap.holmes.rulemgt; -import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.config.MicroServiceConfig; import org.onap.holmes.common.exception.CorrelationException; import org.onap.holmes.common.utils.CommonUtils; @@ -25,31 +24,32 @@ import org.onap.msb.sdk.discovery.entity.MicroServiceInfo; import org.onap.msb.sdk.discovery.entity.Node; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; -import javax.inject.Inject; import java.util.HashSet; import java.util.Set; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import static org.onap.holmes.common.config.MicroServiceConfig.POD_IP; import static org.onap.holmes.common.utils.CommonUtils.getEnv; import static org.onap.holmes.common.utils.CommonUtils.isIpAddress; -@Service -public class Initializer { +@Component +public class Initializer implements ApplicationRunner { private static final Logger logger = LoggerFactory.getLogger(Initializer.class); private volatile static boolean readyForMsbReg = false; private MsbRegister msbRegister; - @Inject + @Autowired public Initializer(MsbRegister msbRegister) { this.msbRegister = msbRegister; } - @PostConstruct - private void init() { + @Override + public void run(ApplicationArguments args) { Executors.newSingleThreadExecutor().execute(() -> { waitUntilReady(); try { @@ -93,7 +93,7 @@ public class Initializer { msinfo.setEnable_ssl(CommonUtils.isHttpsEnabled()); Set<Node> nodes = new HashSet<>(); Node node = new Node(); - node.setIp(isIpAddress(serviceIpAndPort[0]) ? serviceIpAndPort[0] : getEnv(POD_IP)); + node.setIp(isIpAddress(serviceIpAndPort[0]) ? serviceIpAndPort[0] : getEnv("HOLMES_RULE_MGMT_SERVICE_HOST")); node.setPort("9101"); /* Following codes will cause an unregistration from MSB (due to MSB malfunction), comment them for now String msbAddrTemplate = (CommonUtils.isHttpsEnabled() ? "https" : "http") diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java index cedcde0..3d60a11 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java @@ -1,5 +1,5 @@ /** - * Copyright 2017-2020 ZTE Corporation. + * Copyright 2017-2022 ZTE Corporation. * <p> * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,36 +16,37 @@ package org.onap.holmes.rulemgt; -import io.dropwizard.setup.Environment; +import lombok.extern.slf4j.Slf4j; import org.onap.holmes.common.ConfigFileScanner; -import org.onap.holmes.common.dropwizard.ioc.bundle.IOCApplication; -import org.onap.holmes.common.utils.transactionid.TransactionIdFilter; import org.onap.holmes.rulemgt.dcae.ConfigFileScanningTask; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.ServletComponentScan; +import org.springframework.context.annotation.ComponentScan; -import javax.servlet.DispatcherType; -import java.util.EnumSet; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -public class RuleActiveApp extends IOCApplication<RuleAppConfig> { +@Slf4j +@SpringBootApplication +@ServletComponentScan +@ComponentScan(basePackages = {"org.onap.holmes"}) +public class RuleActiveApp implements ApplicationRunner { - public static void main(String[] args) throws Exception { - new RuleActiveApp().run(args); + public static void main(String[] args) { + SpringApplication.run(RuleActiveApp.class, args); } @Override - public void run(RuleAppConfig configuration, Environment environment) throws Exception { - super.run(configuration, environment); - + public void run(ApplicationArguments args) { ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); service.scheduleAtFixedRate( new ConfigFileScanningTask(new ConfigFileScanner()), 60L, ConfigFileScanningTask.POLLING_PERIOD, TimeUnit.SECONDS); - environment.servlets().addFilter("customFilter", new TransactionIdFilter()).addMappingForUrlPatterns(EnumSet - .allOf(DispatcherType.class), true, "/*"); - Initializer.setReadyForMsbReg(true); } } diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAllocator.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAllocator.java index bf26b71..79ffa31 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAllocator.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAllocator.java @@ -17,27 +17,25 @@ package org.onap.holmes.rulemgt; import lombok.extern.slf4j.Slf4j; -import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.api.entity.CorrelationRule; import org.onap.holmes.common.exception.CorrelationException; -import org.onap.holmes.common.utils.DbDaoUtil; import org.onap.holmes.rulemgt.bolt.enginebolt.EngineWrapper; -import org.onap.holmes.rulemgt.db.CorrelationRuleDao; +import org.onap.holmes.rulemgt.db.CorrelationRuleService; import org.onap.holmes.rulemgt.tools.EngineTools; import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper; import org.onap.holmes.rulemgt.wrapper.RuleQueryWrapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; -import javax.inject.Inject; import java.util.*; -import java.util.concurrent.TimeUnit; import static java.util.concurrent.TimeUnit.SECONDS; @Slf4j -@Service +@Component public class RuleAllocator { private static final Logger LOGGER = LoggerFactory.getLogger(RuleAllocator.class); @@ -48,16 +46,16 @@ public class RuleAllocator { private RuleQueryWrapper ruleQueryWrapper; private EngineWrapper engineWrapper; private EngineTools engineTools; - private CorrelationRuleDao correlationRuleDao; + private CorrelationRuleService correlationRuleService; - @Inject + @Autowired public RuleAllocator(RuleMgtWrapper ruleMgtWrapper, RuleQueryWrapper ruleQueryWrapper, - EngineWrapper engineWrapper, EngineTools engineTools, DbDaoUtil daoUtil) { + EngineWrapper engineWrapper, EngineTools engineTools, CorrelationRuleService correlationRuleService) { this.ruleMgtWrapper = ruleMgtWrapper; this.ruleQueryWrapper = ruleQueryWrapper; this.engineWrapper = engineWrapper; this.engineTools = engineTools; - correlationRuleDao = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class); + this.correlationRuleService = correlationRuleService; } @PostConstruct @@ -228,7 +226,7 @@ public class RuleAllocator { for (int i = 0; i <= RETRY_TIMES; ++i) { try { ruleMgtWrapper.deployRule2Engine(rule, ip); - correlationRuleDao.updateRule(rule); + correlationRuleService.updateRule(rule); // If the codes reach here, it means everything's okay. There's no need to run the loop more. break; } catch (CorrelationException e) { diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAppConfig.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAppConfig.java deleted file mode 100644 index 20f96c2..0000000 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAppConfig.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright 2017 ZTE Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.holmes.rulemgt; - -import com.fasterxml.jackson.annotation.JsonProperty; -import io.dropwizard.Configuration; -import io.dropwizard.db.DataSourceFactory; -import javax.validation.Valid; -import javax.validation.constraints.NotNull; -import org.hibernate.validator.constraints.NotEmpty; -import org.jvnet.hk2.annotations.Service; - -@Service -public class RuleAppConfig extends Configuration { - - @NotEmpty - private String defaultName = "Holmes Rule Management"; - - @NotEmpty - private String apidescription = "Holmes rule management rest API"; - - @Valid - @NotNull - private DataSourceFactory database = new DataSourceFactory(); - - @JsonProperty("database") - public DataSourceFactory getDataSourceFactory() { - return database; - } - - @JsonProperty("database") - public void setDataSourceFactory(DataSourceFactory dataSourceFactory) { - this.database = dataSourceFactory; - } - - - public String getApidescription() { - return apidescription; - } - - public void setApidescription(String apidescription) { - this.apidescription = apidescription; - } - -} diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java index 714a95c..5abdab7 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java @@ -15,8 +15,6 @@ */
package org.onap.holmes.rulemgt.bean.request;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.Setter;
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java index 4b6e248..0d1dd05 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java @@ -1,5 +1,5 @@ /**
- * Copyright 2017-2021 ZTE Corporation.
+ * Copyright 2017-2022 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,14 +15,13 @@ */
package org.onap.holmes.rulemgt.bolt.enginebolt;
-import org.jvnet.hk2.annotations.Service;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.core.MediaType;
import org.onap.holmes.common.utils.CommonUtils;
import org.onap.holmes.common.utils.JerseyClient;
import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
-
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.core.MediaType;
+import org.springframework.stereotype.Service;
import static org.onap.holmes.rulemgt.constant.RuleMgtConstant.ENGINE_PATH;
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java index 7c927c0..e63b726 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java @@ -18,19 +18,18 @@ package org.onap.holmes.rulemgt.bolt.enginebolt; import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
-
-import javax.inject.Inject;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
@Service
@Slf4j
public class EngineWrapper {
- @Inject
+ @Autowired
private EngineService engineService;
public String deployEngine(CorrelationDeployRule4Engine correlationRule, String ip) throws CorrelationException {
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java index 73a2f2b..6149616 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java @@ -1,5 +1,5 @@ /** - * Copyright 2017 ZTE Corporation. + * Copyright 2017-2021 ZTE Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,5 +25,4 @@ public class RuleMgtConstant { public static final int STATUS_RULE_ALL = 2; public static final String PACKAGE = "packageName"; public static final String ENGINE_PATH = "/api/holmes-engine-mgmt/v1/rule"; - public static final int RESPONSE_STATUS_OK = 200; } diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/controller/EngineInstanceController.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/controller/EngineInstanceController.java index 2850708..a893413 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/controller/EngineInstanceController.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/controller/EngineInstanceController.java @@ -1,5 +1,5 @@ /** - * Copyright 2020 ZTE Corporation. + * Copyright 2020-2021 ZTE Corporation. * <p> * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,12 @@ package org.onap.holmes.rulemgt.controller; -import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.engine.entity.EngineEntity; import org.onap.holmes.common.engine.service.EngineEntityService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; -import javax.inject.Inject; -import javax.inject.Named; import java.util.List; import java.util.Timer; import java.util.TimerTask; @@ -36,7 +35,7 @@ public class EngineInstanceController extends TimerTask { private static final long THRESHOLD = 3 * INTERVAL; private Timer timer = new Timer("EngineInstanceController", true); - @Inject + @Autowired private EngineEntityService engineEntityService; @PostConstruct diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java deleted file mode 100644 index a9be49f..0000000 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java +++ /dev/null @@ -1,124 +0,0 @@ -/**
- * Copyright 2017 ZTE Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onap.holmes.rulemgt.db;
-
-import java.util.List;
-
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.common.api.entity.CorrelationRule;
-import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.CorrelationRuleMapper;
-import org.skife.jdbi.v2.sqlobject.Bind;
-import org.skife.jdbi.v2.sqlobject.BindBean;
-import org.skife.jdbi.v2.sqlobject.GetGeneratedKeys;
-import org.skife.jdbi.v2.sqlobject.SqlQuery;
-import org.skife.jdbi.v2.sqlobject.SqlUpdate;
-import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
-
-@Service
-@RegisterMapper(CorrelationRuleMapper.class)
-public abstract class CorrelationRuleDao {
-
- @GetGeneratedKeys
- @SqlUpdate("INSERT INTO APLUS_RULE (NAME,CTRLLOOP,DESCRIPTION,ENABLE,TEMPLATEID,ENGINETYPE,CREATOR,UPDATOR,PARAMS,CONTENT ,VENDOR,CREATETIME,UPDATETIME,ENGINEID,PACKAGE,RID, ENGINEINSTANCE) VALUES (:name,:closedControlLoopName,:description,:enabled,:templateID,:engineType,:creator,:modifier,:params,:content,:vendor,:createTime,:updateTime,:engineID,:packageName,:rid,:engineInstance)")
- protected abstract String addRule(@BindBean CorrelationRule correlationRule);
-
- @SqlUpdate("UPDATE APLUS_RULE SET CTRLLOOP=:closedControlLoopName,DESCRIPTION=:description,ENABLE=:enabled,CONTENT=:content,UPDATOR=:modifier,UPDATETIME=:updateTime, PACKAGE=:packageName, ENGINEINSTANCE=:engineInstance WHERE RID=:rid")
- protected abstract int updateRuleByRid(@BindBean CorrelationRule correlationRule);
-
- @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid")
- protected abstract int deleteRuleByRid(@Bind("rid") String rid);
-
- @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid AND NAME=:name")
- protected abstract int deleteRuleByRidAndName(@Bind("rid") String rid, @Bind("name") String name);
-
- @SqlQuery("SELECT * FROM APLUS_RULE")
- protected abstract List<CorrelationRule> queryAllRules();
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE RID=:rid")
- protected abstract CorrelationRule queryRuleById(@Bind("rid") String rid);
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name")
- protected abstract CorrelationRule queryRuleByName(@Bind("name") String name);
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE enable=:enable")
- public abstract List<CorrelationRule> queryRuleByEnable(@Bind("enable") int enable);
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE engineinstance=:engineinstance")
- public abstract List<CorrelationRule> queryRuleByEngineInstance(@Bind("engineinstance") String engineinstance);
-
- public List<CorrelationRule> queryRuleByRuleEngineInstance(String enginetype) {
- return queryRuleByEngineInstance(enginetype);
- }
-
- public List<CorrelationRule> queryRuleByRuleEnable(int enable) {
- return queryRuleByEnable(enable);
- }
-
-
- private void deleteRule2DbInner(CorrelationRule correlationRule) {
- String name = correlationRule.getName() != null ? correlationRule.getName().trim() : "";
- String rid = correlationRule.getRid() != null ? correlationRule.getRid().trim() : "";
- if (!"".equals(name) && !"".equals(rid)) {
- deleteRuleByRidAndName(rid, name);
- } else if (!"".equals(rid)) {
- deleteRuleByRid(rid);
- }
- }
-
- public CorrelationRule saveRule(CorrelationRule correlationRule) throws CorrelationException {
- try {
- addRule(correlationRule);
- return correlationRule;
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
- public void updateRule(CorrelationRule correlationRule) throws CorrelationException {
- try {
- updateRuleByRid(correlationRule);
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
- public void deleteRule(CorrelationRule correlationRule) throws CorrelationException {
- try {
- deleteRule2DbInner(correlationRule);
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
-
- public CorrelationRule queryRuleByRid(String rid) throws CorrelationException {
- try {
- return queryRuleById(rid);
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
- public CorrelationRule queryRuleByRuleName(String name) throws CorrelationException {
- try {
- return queryRuleByName(name);
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-}
-
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDao.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryService.java index 104f74d..9658ded 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDao.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryService.java @@ -1,5 +1,5 @@ /**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2021 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,31 +15,28 @@ */
package org.onap.holmes.rulemgt.db;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
-import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
+import org.jdbi.v3.core.Handle;
+import org.jdbi.v3.core.Jdbi;
+import org.jdbi.v3.core.statement.Query;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.DbDaoUtil;
-import org.skife.jdbi.v2.Handle;
-import org.skife.jdbi.v2.Query;
+import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
+import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.*;
@Service
@Slf4j
-public class CorrelationRuleQueryDao {
+public class CorrelationRuleQueryService {
- @Inject
- private DbDaoUtil dbDaoUtil;
+ @Autowired
+ private Jdbi jdbi;
public List<CorrelationRule> getCorrelationRulesByCondition(RuleQueryCondition ruleQueryCondition)
throws CorrelationException {
@@ -48,9 +45,9 @@ public class CorrelationRuleQueryDao { String whereStr = getWhereStrByRequestEntity(ruleQueryCondition);
try {
StringBuilder querySql = new StringBuilder("SELECT * FROM APLUS_RULE ").append(whereStr);
- handle = dbDaoUtil.getHandle();
+ handle = jdbi.open();
Query query = handle.createQuery(querySql.toString());
- for (Object value : query.list()) {
+ for (Object value : query.mapToMap().list()) {
CorrelationRule correlationRule = getCorrelationRule((Map) value);
correlationRules.add(correlationRule);
}
@@ -59,7 +56,7 @@ public class CorrelationRuleQueryDao { log.warn("Failed to query the rule: id =" + ruleQueryCondition.getRid() + ".");
throw new CorrelationException("Failed to query the rule.", e);
} finally {
- dbDaoUtil.close(handle);
+ handle.close();
}
}
@@ -69,19 +66,19 @@ public class CorrelationRuleQueryDao { correlationRule.setRid((String) value.get("rid"));
correlationRule.setDescription((String) value.get("description"));
correlationRule.setEnabled((Integer) value.get("enable"));
- correlationRule.setTemplateID((Long) value.get("templateID"));
- correlationRule.setEngineID((String) value.get("engineID"));
- correlationRule.setEngineType((String) value.get("engineType"));
+ correlationRule.setTemplateID((Long) value.get("templateid"));
+ correlationRule.setEngineID((String) value.get("engineid"));
+ correlationRule.setEngineType((String) value.get("enginetype"));
correlationRule.setCreator((String) value.get("creator"));
- correlationRule.setCreateTime((Date) value.get("createTime"));
+ correlationRule.setCreateTime((Date) value.get("createtime"));
correlationRule.setModifier((String) value.get("updator"));
- correlationRule.setUpdateTime((Date) value.get("updateTime"));
+ correlationRule.setUpdateTime((Date) value.get("updatetime"));
correlationRule.setParams((Properties) value.get("params"));
correlationRule.setContent((String) value.get("content"));
correlationRule.setVendor((String) value.get("vendor"));
correlationRule.setPackageName((String) value.get("package"));
correlationRule.setClosedControlLoopName((String) value.get("ctrlloop"));
- correlationRule.setEngineInstance((String) value.get("engineInstance"));
+ correlationRule.setEngineInstance((String) value.get("engineinstance"));
return correlationRule;
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleService.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleService.java new file mode 100644 index 0000000..62eae0c --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleService.java @@ -0,0 +1,94 @@ +/** + * Copyright 2021-2022 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.holmes.rulemgt.db; + +import org.apache.commons.lang3.StringUtils; +import org.onap.holmes.common.api.entity.CorrelationRule; +import org.onap.holmes.common.exception.CorrelationException; +import org.onap.holmes.rulemgt.db.jdbi.CorrelationRuleDao; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class CorrelationRuleService { + + @Autowired + private CorrelationRuleDao correlationRuleDao; + + public List<CorrelationRule> queryRuleByRuleEngineInstance(String enginetype) { + return correlationRuleDao.queryRuleByEngineInstance(enginetype); + } + + public List<CorrelationRule> queryRuleByRuleEnable(int enable) { + return correlationRuleDao.queryRuleByEnable(enable); + } + + + private void deleteRule2DbInner(CorrelationRule correlationRule) { + String name = correlationRule.getName() != null ? correlationRule.getName().trim() : ""; + String rid = correlationRule.getRid() != null ? correlationRule.getRid().trim() : ""; + if (!StringUtils.EMPTY.equals(name) && !StringUtils.EMPTY.equals(rid)) { + correlationRuleDao.deleteRuleByRidAndName(rid, name); + } else if (!"".equals(rid)) { + correlationRuleDao.deleteRuleByRid(rid); + } + } + + public CorrelationRule saveRule(CorrelationRule correlationRule) throws CorrelationException { + try { + correlationRuleDao.addRule(correlationRule); + return correlationRule; + } catch (Exception e) { + throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e); + } + } + + public void updateRule(CorrelationRule correlationRule) throws CorrelationException { + try { + correlationRuleDao.updateRuleByRid(correlationRule); + } catch (Exception e) { + throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e); + } + } + + public void deleteRule(CorrelationRule correlationRule) throws CorrelationException { + try { + deleteRule2DbInner(correlationRule); + } catch (Exception e) { + throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e); + } + } + + + public CorrelationRule queryRuleByRid(String rid) throws CorrelationException { + try { + return correlationRuleDao.queryRuleById(rid); + } catch (Exception e) { + throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e); + } + } + + public CorrelationRule queryRuleByRuleName(String name) throws CorrelationException { + try { + return correlationRuleDao.queryRuleByName(name); + } catch (Exception e) { + throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e); + } + } +} diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/DaoProvider.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/DaoProvider.java new file mode 100644 index 0000000..6addf0f --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/DaoProvider.java @@ -0,0 +1,31 @@ +/** + * Copyright 2022 ZTE Corporation. + * <p> + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.holmes.rulemgt.db; + +import org.jdbi.v3.core.Jdbi; +import org.onap.holmes.rulemgt.db.jdbi.CorrelationRuleDao; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class DaoProvider { + + @Bean + public CorrelationRuleDao correlationRuleDao(Jdbi jdbi) { + return jdbi.onDemand(CorrelationRuleDao.class); + } +} diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/jdbi/CorrelationRuleDao.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/jdbi/CorrelationRuleDao.java new file mode 100644 index 0000000..2ad1d17 --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/jdbi/CorrelationRuleDao.java @@ -0,0 +1,62 @@ +/**
+ * Copyright 2017-2021 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.holmes.rulemgt.db.jdbi;
+
+import org.jdbi.v3.sqlobject.config.RegisterRowMapper;
+import org.jdbi.v3.sqlobject.customizer.Bind;
+import org.jdbi.v3.sqlobject.customizer.BindBean;
+import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys;
+import org.jdbi.v3.sqlobject.statement.SqlQuery;
+import org.jdbi.v3.sqlobject.statement.SqlUpdate;
+import org.onap.holmes.common.api.entity.CorrelationRule;
+import org.onap.holmes.common.utils.CorrelationRuleMapper;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+@RegisterRowMapper(CorrelationRuleMapper.class)
+public interface CorrelationRuleDao {
+
+ @GetGeneratedKeys
+ @SqlUpdate("INSERT INTO APLUS_RULE (NAME,CTRLLOOP,DESCRIPTION,ENABLE,TEMPLATEID,ENGINETYPE,CREATOR,UPDATOR,PARAMS,CONTENT ,VENDOR,CREATETIME,UPDATETIME,ENGINEID,PACKAGE,RID, ENGINEINSTANCE) VALUES (:name,:closedControlLoopName,:description,:enabled,:templateID,:engineType,:creator,:modifier,:params,:content,:vendor,:createTime,:updateTime,:engineID,:packageName,:rid,:engineInstance)")
+ String addRule(@BindBean CorrelationRule correlationRule);
+
+ @SqlUpdate("UPDATE APLUS_RULE SET CTRLLOOP=:closedControlLoopName,DESCRIPTION=:description,ENABLE=:enabled,CONTENT=:content,UPDATOR=:modifier,UPDATETIME=:updateTime, PACKAGE=:packageName, ENGINEINSTANCE=:engineInstance WHERE RID=:rid")
+ int updateRuleByRid(@BindBean CorrelationRule correlationRule);
+
+ @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid")
+ int deleteRuleByRid(@Bind("rid") String rid);
+
+ @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid AND NAME=:name")
+ int deleteRuleByRidAndName(@Bind("rid") String rid, @Bind("name") String name);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE")
+ List<CorrelationRule> queryAllRules();
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE RID=:rid")
+ CorrelationRule queryRuleById(@Bind("rid") String rid);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name")
+ CorrelationRule queryRuleByName(@Bind("name") String name);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE enable=:enable")
+ List<CorrelationRule> queryRuleByEnable(@Bind("enable") int enable);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE engineinstance=:engineinstance")
+ List<CorrelationRule> queryRuleByEngineInstance(@Bind("engineinstance") String engineinstance);
+}
+
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java index 8423f3d..fc042ad 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java @@ -1,5 +1,5 @@ /** - * Copyright 2021 ZTE Corporation. + * Copyright 2021-2022 ZTE Corporation. * <p> * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.onap.holmes.common.ConfigFileScanner; import org.onap.holmes.common.utils.CommonUtils; import org.onap.holmes.common.utils.FileUtils; @@ -31,8 +31,8 @@ import org.onap.holmes.rulemgt.bean.response.RuleResult4API; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.MediaType; +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.core.MediaType; import java.io.File; import java.nio.file.Paths; import java.util.*; diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java deleted file mode 100644 index 8049e8f..0000000 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java +++ /dev/null @@ -1,122 +0,0 @@ -/** - * Copyright 2017-2021 ZTE Corporation. - * <p> - * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.onap.holmes.rulemgt.dcae; - - -import lombok.extern.slf4j.Slf4j; -import org.onap.holmes.common.dcae.DcaeConfigurationQuery; -import org.onap.holmes.common.dcae.entity.DcaeConfigurations; -import org.onap.holmes.common.dcae.entity.Rule; -import org.onap.holmes.common.exception.CorrelationException; -import org.onap.holmes.common.utils.JerseyClient; -import org.onap.holmes.common.utils.Md5Util; -import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest; -import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse; -import org.onap.holmes.rulemgt.bean.response.RuleResult4API; - -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.MediaType; -import java.util.List; - -@Slf4j -@Deprecated -public class DcaeConfigurationPolling implements Runnable { - - public static final long POLLING_PERIOD = 30 * 1000L; - - private String hostname; - - private String url = "https://127.0.0.1:9101/api/holmes-rule-mgmt/v1/rule"; - - public DcaeConfigurationPolling(String hostname) { - this.hostname = hostname; - } - - private String prevConfigMd5 = Md5Util.md5(null); - - private boolean prevResult = false; - - @Override - public void run() { - DcaeConfigurations dcaeConfigurations = null; - try { - dcaeConfigurations = DcaeConfigurationQuery.getDcaeConfigurations(hostname); - String md5 = Md5Util.md5(dcaeConfigurations); - if (prevResult && prevConfigMd5.equals(md5)) { - log.info("Operation aborted due to identical configurations."); - return; - } - prevConfigMd5 = md5; - prevResult = false; - } catch (CorrelationException e) { - log.error("Failed to fetch DCAE configurations. " + e.getMessage(), e); - } catch (Exception e) { - log.info("Failed to generate the MD5 information for new configurations.", e); - } - RuleQueryListResponse ruleQueryListResponse = null; - if (dcaeConfigurations != null) { - try { - ruleQueryListResponse = getAllCorrelationRules(); - } catch (Exception e) { - log.error("Failed to get deployed rules from the rule management module: " + e.getMessage(), e); - } - } - if (ruleQueryListResponse != null) { - List<RuleResult4API> ruleResult4APIs = ruleQueryListResponse.getCorrelationRules(); - deleteAllCorrelationRules(ruleResult4APIs); - try { - prevResult = addAllCorrelationRules(dcaeConfigurations); - } catch (CorrelationException e) { - log.error("Failed to add rules. " + e.getMessage(), e); - prevResult = false; - } - } - } - - private RuleQueryListResponse getAllCorrelationRules() { - return JerseyClient.newInstance().get(url, RuleQueryListResponse.class); - } - - private boolean addAllCorrelationRules(DcaeConfigurations dcaeConfigurations) throws CorrelationException { - boolean suc = false; - for (Rule rule : dcaeConfigurations.getDefaultRules()) { - RuleCreateRequest ruleCreateRequest = getRuleCreateRequest(rule); - suc = JerseyClient.newInstance().header("Accept", MediaType.APPLICATION_JSON) - .put(url, Entity.json(ruleCreateRequest)) != null; - - if (!suc) { - break; - } - } - return suc; - } - - private void deleteAllCorrelationRules(List<RuleResult4API> ruleResult4APIs) { - ruleResult4APIs.forEach(correlationRule -> { - if (null == JerseyClient.newInstance().delete(url + "/" + correlationRule.getRuleId())) { - log.warn("Failed to delete rule, the rule id is: {}", correlationRule.getRuleId()); - } - }); - } - - private RuleCreateRequest getRuleCreateRequest(Rule rule) { - RuleCreateRequest ruleCreateRequest = new RuleCreateRequest(); - ruleCreateRequest.setLoopControlName(rule.getLoopControlName()); - ruleCreateRequest.setRuleName(rule.getName()); - ruleCreateRequest.setContent(rule.getContents()); - ruleCreateRequest.setDescription(""); - ruleCreateRequest.setEnabled(1); - return ruleCreateRequest; - } -} diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java index 73d1c5b..c8befef 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 ZTE Corporation. + * Copyright 2017-2022 ZTE Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,24 +19,23 @@ package org.onap.holmes.rulemgt.resources; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.SwaggerDefinition; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import lombok.extern.slf4j.Slf4j; -import org.jvnet.hk2.annotations.Service; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; -@Service +@RestController @SwaggerDefinition -@Path("/healthcheck") +@RequestMapping("/healthcheck") @Api(tags = {"Health Check"}) @Produces(MediaType.TEXT_PLAIN) @Slf4j public class HealthCheck { - @GET - @Produces(MediaType.TEXT_PLAIN) + @GetMapping(produces = MediaType.TEXT_PLAIN) @ApiOperation(value = "Interface for the health check of the rule management module for Holmes") - public boolean healthCheck(){ - return true; + public void healthCheck(){ + } } diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java index 445c2f9..133e859 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java @@ -1,11 +1,11 @@ /**
- * Copyright 2017-2020 ZTE Corporation.
- *
+ * Copyright 2017-2022 ZTE Corporation.
+ * <p>
* 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
- *
+ * <p>
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
* 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
@@ -13,17 +13,15 @@ */
package org.onap.holmes.rulemgt.resources;
-import com.codahale.metrics.annotation.Timed;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.SwaggerDefinition;
+import jakarta.ws.rs.core.MediaType;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.ExceptionUtil;
import org.onap.holmes.common.utils.GsonUtil;
-import org.onap.holmes.common.utils.LanguageUtil;
import org.onap.holmes.common.utils.UserUtil;
import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
import org.onap.holmes.rulemgt.bean.request.RuleDeleteRequest;
@@ -33,37 +31,33 @@ import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse; import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
-import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.*;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import java.util.Locale;
-@Service
+@Slf4j
+@RestController
@SwaggerDefinition
-@Path("/rule")
+@RequestMapping("/rule")
@Api(tags = {"Holmes Rule Management"})
-@Produces(MediaType.APPLICATION_JSON)
-@Slf4j
public class RuleMgtResources {
- @Inject
+ @Autowired
private RuleMgtWrapper ruleMgtWrapper;
- @PUT
- @Produces(MediaType.APPLICATION_JSON)
+ @ResponseBody
+ @PutMapping(produces = MediaType.APPLICATION_JSON)
@ApiOperation(value = "Save a rule into the database; deploy it to the Drools engine if it is enabled.",
response = RuleAddAndUpdateResponse.class)
- @Timed
- public RuleAddAndUpdateResponse addCorrelationRule(@Context HttpServletRequest request,
- @ApiParam(value =
- "The request entity of the HTTP call, which comprises \"ruleName\"(required), "
- + "\"loopControlName\"(required), \"content\"(required), \"enabled\"(required) "
- + "and \"description\"(optional)", required = true)
- RuleCreateRequest ruleCreateRequest) {
- Locale locale = LanguageUtil.getLocale(request);
+ public RuleAddAndUpdateResponse addCorrelationRule(HttpServletRequest request,
+ @ApiParam(value =
+ "The request entity of the HTTP call, which comprises \"ruleName\"(required), "
+ + "\"loopControlName\"(required), \"content\"(required), \"enabled\"(required) "
+ + "and \"description\"(optional)", required = true)
+ @RequestBody RuleCreateRequest ruleCreateRequest) {
RuleAddAndUpdateResponse ruleChangeResponse;
try {
ruleChangeResponse = ruleMgtWrapper
@@ -76,16 +70,14 @@ public class RuleMgtResources { }
}
- @POST
- @Produces(MediaType.APPLICATION_JSON)
+ @ResponseBody
+ @PostMapping(produces = MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update an existing rule; deploy it to the Drools engine if it is enabled.", response = RuleAddAndUpdateResponse.class)
- @Timed
- public RuleAddAndUpdateResponse updateCorrelationRule(@Context HttpServletRequest request,
- @ApiParam(value =
- "The request entity of the HTTP call, which comprises \"ruleId\"(required), "
- + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)
- RuleUpdateRequest ruleUpdateRequest) {
- Locale locale = LanguageUtil.getLocale(request);
+ public RuleAddAndUpdateResponse updateCorrelationRule(HttpServletRequest request,
+ @ApiParam(value =
+ "The request entity of the HTTP call, which comprises \"ruleId\"(required), "
+ + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)
+ @RequestBody RuleUpdateRequest ruleUpdateRequest) {
RuleAddAndUpdateResponse ruleChangeResponse;
try {
ruleChangeResponse = ruleMgtWrapper
@@ -98,38 +90,31 @@ public class RuleMgtResources { }
}
- @DELETE
- @Produces(MediaType.APPLICATION_JSON)
+ @DeleteMapping("/{ruleid}")
@ApiOperation(value = "Remove a rule from Holmes.")
- @Timed
- @Path("/{ruleid}")
- public boolean deleteCorrelationRule(@Context HttpServletRequest request,
- @PathParam("ruleid") String ruleId) {
- Locale locale = LanguageUtil.getLocale(request);
+ public ResponseEntity deleteCorrelationRule(@PathVariable("ruleid") String ruleId) {
try {
ruleMgtWrapper.deleteCorrelationRule(new RuleDeleteRequest(ruleId));
log.info("delete rule:" + ruleId + " successful");
- return true;
+ return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
} catch (CorrelationException e) {
log.error("delete rule:" + ruleId + " failed", e);
throw ExceptionUtil.buildExceptionResponse(e.getMessage());
}
}
- @GET
- @Produces(MediaType.APPLICATION_JSON)
+ @ResponseBody
+ @GetMapping(produces = MediaType.APPLICATION_JSON)
@ApiOperation(value = "Query rules using certain criteria.", response = RuleQueryListResponse.class)
- @Timed
- public RuleQueryListResponse getCorrelationRules(@Context HttpServletRequest request,
- @ApiParam(value =
- "A JSON string used as a query parameter, which comprises \"ruleid\"(optional), "
- + "\"rulename\"(optional), \"creator\"(optional), "
- + "\"modifier\"(optional) and \"enabled\"(optional). E.g. {\"ruleid\":\"rule_1484727187317\"}",
- required = false) @QueryParam("queryrequest") String ruleQueryRequest) {
- Locale locale = LanguageUtil.getLocale(request);
+ public RuleQueryListResponse getCorrelationRules(
+ @ApiParam(value =
+ "A JSON string used as a query parameter, which comprises \"ruleid\"(optional), "
+ + "\"rulename\"(optional), \"creator\"(optional), "
+ + "\"modifier\"(optional) and \"enabled\"(optional). E.g. {\"ruleid\":\"rule_1484727187317\"}")
+ @RequestParam(value = "queryrequest", required = false) String ruleQueryRequest) {
RuleQueryListResponse ruleQueryListResponse;
- RuleQueryCondition ruleQueryCondition = getRuleQueryCondition(ruleQueryRequest, request);
+ RuleQueryCondition ruleQueryCondition = getRuleQueryCondition(ruleQueryRequest);
try {
ruleQueryListResponse = ruleMgtWrapper
.getCorrelationRuleByCondition(ruleQueryCondition);
@@ -141,9 +126,7 @@ public class RuleMgtResources { }
}
- private RuleQueryCondition getRuleQueryCondition(String queryRequest,
- HttpServletRequest request) {
- Locale locale = LanguageUtil.getLocale(request);
+ private RuleQueryCondition getRuleQueryCondition(String queryRequest) {
RuleQueryCondition ruleQueryCondition = GsonUtil
.jsonToBean(queryRequest, RuleQueryCondition.class);
if (queryRequest == null) {
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java index 83555b2..74996e5 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 ZTE Corporation. + * Copyright 2017-2022 ZTE Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,26 +16,23 @@ package org.onap.holmes.rulemgt.resources; -import io.swagger.annotations.Api; -import io.swagger.annotations.SwaggerDefinition; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.io.*; import java.net.URL; import java.net.URLDecoder; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import lombok.extern.slf4j.Slf4j; -import org.jvnet.hk2.annotations.Service; -@Service -@Path("/swagger.json") -@Produces(MediaType.APPLICATION_JSON) +@RestController +@RequestMapping("/swagger.json") @Slf4j public class SwaggerResource { - @GET + @GetMapping @Produces(MediaType.APPLICATION_JSON) public String getSwaggerJson() { URL url = SwaggerResource.class.getResource("/swagger.json"); diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/tools/EngineTools.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/tools/EngineTools.java index 2711d3b..f350c12 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/tools/EngineTools.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/tools/EngineTools.java @@ -1,5 +1,5 @@ /** - * Copyright 2017-2020 ZTE Corporation. + * Copyright 2017-2021 ZTE Corporation. * <p> * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,25 +17,25 @@ package org.onap.holmes.rulemgt.tools; import lombok.extern.slf4j.Slf4j; -import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.api.entity.CorrelationRule; import org.onap.holmes.common.engine.entity.EngineEntity; import org.onap.holmes.common.engine.service.EngineEntityService; import org.onap.holmes.rulemgt.wrapper.RuleQueryWrapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; -import javax.inject.Inject; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.stream.Collectors; -@Service +@Component @Slf4j public class EngineTools { - @Inject + @Autowired private RuleQueryWrapper ruleQueryWrapper; - @Inject + @Autowired private EngineEntityService engineEntityService; public List<String> getInstanceList() { diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java index 7fdae27..ec6e9b3 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java @@ -1,5 +1,5 @@ /** - * Copyright 2017 ZTE Corporation. + * Copyright 2017-2021 ZTE Corporation. * <p> * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,58 +15,44 @@ */ package org.onap.holmes.rulemgt.wrapper; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import javax.inject.Singleton; - import lombok.extern.slf4j.Slf4j; -import org.jvnet.hk2.annotations.Service; -import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine; -import org.onap.holmes.rulemgt.bean.response.RuleResult4API; -import org.onap.holmes.rulemgt.constant.RuleMgtConstant; -import org.onap.holmes.rulemgt.db.CorrelationRuleDao; import org.onap.holmes.common.api.entity.CorrelationRule; import org.onap.holmes.common.exception.CorrelationException; -import org.onap.holmes.common.utils.DbDaoUtil; -import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine; -import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest; -import org.onap.holmes.rulemgt.bean.request.RuleDeleteRequest; -import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition; -import org.onap.holmes.rulemgt.bean.request.RuleUpdateRequest; +import org.onap.holmes.rulemgt.bean.request.*; import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse; import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse; +import org.onap.holmes.rulemgt.bean.response.RuleResult4API; import org.onap.holmes.rulemgt.bolt.enginebolt.EngineWrapper; -import org.onap.holmes.rulemgt.db.CorrelationRuleQueryDao; +import org.onap.holmes.rulemgt.constant.RuleMgtConstant; +import org.onap.holmes.rulemgt.db.CorrelationRuleQueryService; +import org.onap.holmes.rulemgt.db.CorrelationRuleService; import org.onap.holmes.rulemgt.tools.EngineTools; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; @Service -@Singleton @Slf4j public class RuleMgtWrapper { - @Inject + @Autowired private EngineTools engineTools; - @Inject + @Autowired private RuleQueryWrapper ruleQueryWrapper; - @Inject - private CorrelationRuleQueryDao correlationRuleQueryDao; - @Inject - private EngineWrapper engineWarpper; - @Inject - private DbDaoUtil daoUtil; + @Autowired + private CorrelationRuleQueryService correlationRuleQueryDao; - private CorrelationRuleDao correlationRuleDao; + @Autowired + private EngineWrapper engineWarpper; - @PostConstruct - public void initDaoUtil() { - correlationRuleDao = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class); - } + @Autowired + private CorrelationRuleService correlationRuleService; public RuleAddAndUpdateResponse addCorrelationRule(String creator, RuleCreateRequest ruleCreateRequest) throws CorrelationException { @@ -76,7 +62,7 @@ public class RuleMgtWrapper { CorrelationRule correlationRule = convertCreateRequest2Rule(creator, ruleCreateRequest); validateCorrelationRule(correlationRule); - CorrelationRule ruleTemp = correlationRuleDao.queryRuleByRuleName(correlationRule.getName()); + CorrelationRule ruleTemp = correlationRuleService.queryRuleByRuleName(correlationRule.getName()); if (ruleTemp != null) { throw new CorrelationException("A rule with the same name already exists."); } @@ -91,7 +77,7 @@ public class RuleMgtWrapper { correlationRule.setEngineInstance(ip); CorrelationRule result = null; try { - result = correlationRuleDao.saveRule(correlationRule); + result = correlationRuleService.saveRule(correlationRule); } catch (CorrelationException e) { engineWarpper.deleteRuleFromEngine(packageName, ip); throw new CorrelationException(e.getMessage(), e); @@ -106,7 +92,7 @@ public class RuleMgtWrapper { if (ruleUpdateRequest == null) { throw new CorrelationException("The request object can not be empty!"); } - CorrelationRule oldCorrelationRule = correlationRuleDao.queryRuleByRid(ruleUpdateRequest.getRuleId()); + CorrelationRule oldCorrelationRule = correlationRuleService.queryRuleByRid(ruleUpdateRequest.getRuleId()); if (oldCorrelationRule == null) { throw new CorrelationException("You're trying to update a rule which does not exist in the system."); } @@ -131,7 +117,7 @@ public class RuleMgtWrapper { engineWarpper.deleteRuleFromEngine(oldCorrelationRule.getPackageName(), engineInstance); } newCorrelationRule.setPackageName(deployRule2Engine(newCorrelationRule, updateIp)); - correlationRuleDao.updateRule(newCorrelationRule); + correlationRuleService.updateRule(newCorrelationRule); return ruleChangeResponse; } @@ -172,7 +158,7 @@ public class RuleMgtWrapper { if (ruleDeleteRequest == null) { throw new CorrelationException("The request object can not be empty!"); } - CorrelationRule correlationRule = correlationRuleDao.queryRuleByRid(ruleDeleteRequest.getRuleId()); + CorrelationRule correlationRule = correlationRuleService.queryRuleByRid(ruleDeleteRequest.getRuleId()); if (correlationRule == null) { log.warn("the rule:rule id=" + ruleDeleteRequest.getRuleId() + " does not exist the database."); throw new CorrelationException("You're trying to delete a rule which does not exist in the system."); @@ -181,7 +167,7 @@ public class RuleMgtWrapper { String ip = correlationRule.getEngineInstance(); engineWarpper.deleteRuleFromEngine(correlationRule.getPackageName(), ip); } - correlationRuleDao.deleteRule(correlationRule); + correlationRuleService.deleteRule(correlationRule); } private CorrelationRule convertCreateRequest2Rule(String userName, diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapper.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapper.java index 0ad836f..1d245f8 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapper.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapper.java @@ -16,37 +16,28 @@ package org.onap.holmes.rulemgt.wrapper; -import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.api.entity.CorrelationRule; import org.onap.holmes.common.exception.CorrelationException; -import org.onap.holmes.common.utils.DbDaoUtil; -import org.onap.holmes.rulemgt.db.CorrelationRuleDao; +import org.onap.holmes.rulemgt.db.CorrelationRuleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; -import javax.annotation.PostConstruct; -import javax.inject.Inject; import java.util.List; @Service public class RuleQueryWrapper { - @Inject - private DbDaoUtil daoUtil; - private CorrelationRuleDao correlationRuleDao; + @Autowired + private CorrelationRuleService correlationRuleService; - @PostConstruct - public void initDaoUtil() { - correlationRuleDao = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class); - } - public List<CorrelationRule> queryRuleByEnable(int enable) throws CorrelationException { - List<CorrelationRule> ruleTemp = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class) - .queryRuleByRuleEnable(enable); + public List<CorrelationRule> queryRuleByEnable(int enable) { + List<CorrelationRule> ruleTemp = correlationRuleService.queryRuleByRuleEnable(enable); return ruleTemp; } public List<CorrelationRule> queryRuleByEngineInstance(String instance) throws CorrelationException { - List<CorrelationRule> ruleTemp = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class) - .queryRuleByRuleEngineInstance(instance); + List<CorrelationRule> ruleTemp = correlationRuleService.queryRuleByRuleEngineInstance(instance); return ruleTemp; } } diff --git a/rulemgt/src/main/resources/logback-spring.xml b/rulemgt/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..197057e --- /dev/null +++ b/rulemgt/src/main/resources/logback-spring.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configuration debug="false"> + <property name="LOG_HOME" value="/var/log/ONAP/holmes"/> + <property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss SSS} %-5p [%c][%t] - %msg%n" /> + + <appender name="Console" class="ch.qos.logback.core.ConsoleAppender"> + <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> + <pattern>${LOG_PATTERN}</pattern> + <charset>UTF-8</charset> + </encoder> + <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> + <level>debug</level> + </filter> + </appender> + + <appender name="FileOutputForDebug" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${LOG_HOME}/holmes-engine-mgmt-debug.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <fileNamePattern>${LOG_HOME}/archived/holmes-engine-mgmt-debug-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern> + <maxHistory>15</maxHistory> + <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> + <maxFileSize>100MB</maxFileSize> + </timeBasedFileNamingAndTriggeringPolicy> + </rollingPolicy> + <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> + <pattern>${LOG_PATTERN}</pattern> + <charset>UTF-8</charset> + </encoder> + <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> + <level>info</level> + </filter> + </appender> + + <appender name="FileOutputForError" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${LOG_HOME}/holmes-engine-mgmt-error.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <fileNamePattern>${LOG_HOME}/archived/holmes-engine-mgmt-error-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern> + <maxHistory>15</maxHistory> + <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> + <maxFileSize>10MB</maxFileSize> + </timeBasedFileNamingAndTriggeringPolicy> + </rollingPolicy> + <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> + <pattern>${LOG_PATTERN}</pattern> + <charset>UTF-8</charset> + </encoder> + <filter class="ch.qos.logback.classic.filter.LevelFilter"> + <level>error</level> + <onMatch>deny</onMatch> + <onMismatch>accept</onMismatch> + </filter> + </appender> + + <root level="info"> + <appender-ref ref="Console" /> + <appender-ref ref="FileOutputForDebug" /> + <appender-ref ref="FileOutputForError" /> + </root> +</configuration>
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java index 8e4a6fe..0687731 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2020 ZTE Corporation. + * Copyright 2020-2022 ZTE Corporation. * <p> * 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 @@ -22,15 +22,12 @@ import org.onap.holmes.common.utils.MsbRegister; import org.onap.msb.sdk.discovery.entity.MicroServiceInfo; import org.powermock.api.easymock.PowerMock; import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.internal.WhiteboxImpl; import java.util.concurrent.TimeUnit; @RunWith(PowerMockRunner.class) @PrepareForTest(MicroServiceConfig.class) -@SuppressStaticInitializationFor("org.onap.holmes.common.utils.CommonUtils") public class InitializerTest { @Test @@ -49,7 +46,7 @@ public class InitializerTest { setReadyFlagAfter(3); - WhiteboxImpl.invokeMethod(initializer, "init"); + initializer.run(null); TimeUnit.SECONDS.sleep(6); diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAllocatorTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAllocatorTest.java index 04be2e0..561f5d5 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAllocatorTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAllocatorTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2017-2020 ZTE Corporation. + * Copyright 2017-2021 ZTE Corporation. * <p> * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,24 +17,17 @@ package org.onap.holmes.rulemgt; -import org.glassfish.hk2.api.ServiceLocator; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; -import org.junit.runner.RunWith; import org.onap.holmes.common.api.entity.CorrelationRule; -import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder; -import org.onap.holmes.common.utils.DbDaoUtil; import org.onap.holmes.rulemgt.bolt.enginebolt.EngineWrapper; -import org.onap.holmes.rulemgt.db.CorrelationRuleDao; +import org.onap.holmes.rulemgt.db.CorrelationRuleService; import org.onap.holmes.rulemgt.tools.EngineTools; import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper; import org.onap.holmes.rulemgt.wrapper.RuleQueryWrapper; import org.powermock.api.easymock.PowerMock; import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; import java.util.ArrayList; import java.util.Calendar; @@ -44,17 +37,15 @@ import java.util.stream.Collectors; import static org.easymock.EasyMock.*; import static org.onap.holmes.rulemgt.RuleAllocator.ENABLE; -@RunWith(PowerMockRunner.class) -@PrepareForTest({ServiceLocator.class, RuleMgtWrapper.class, RuleQueryWrapper.class, EngineWrapper.class, - EngineTools.class, DbDaoUtil.class, ServiceLocatorHolder.class}) +@PrepareForTest({RuleMgtWrapper.class, RuleQueryWrapper.class, EngineWrapper.class, + EngineTools.class}) public class RuleAllocatorTest { private RuleMgtWrapper ruleMgtWrapperMock; private RuleQueryWrapper ruleQueryWrapperMock; private EngineWrapper engineWrapperMock; private EngineTools engineToolsMock; - private DbDaoUtil dbDaoUtilMock; - private CorrelationRuleDao correlationRuleDaoMock; + private CorrelationRuleService correlationRuleServiceMock; private List<CorrelationRule> rules; private List<String> existingIps; @@ -65,8 +56,7 @@ public class RuleAllocatorTest { ruleQueryWrapperMock = PowerMock.createMock(RuleQueryWrapper.class); engineWrapperMock = PowerMock.createMock(EngineWrapper.class); engineToolsMock = PowerMock.createMock(EngineTools.class); - dbDaoUtilMock = PowerMock.createMock(DbDaoUtil.class); - correlationRuleDaoMock = PowerMock.createMock(CorrelationRuleDao.class); + correlationRuleServiceMock = PowerMock.createMock(CorrelationRuleService.class); rules = new ArrayList<>(); for (int i = 0; i < 20; ++i) { @@ -107,7 +97,6 @@ public class RuleAllocatorTest { ipListFromMsb.addAll(newEngineInstances); ipListFromMsb.addAll(existingIps); - expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(correlationRuleDaoMock); expect(engineToolsMock.getInstanceList()).andReturn(ipListFromMsb); expect(engineToolsMock.getLegacyEngineInstances()).andReturn(existingIps); expect(ruleQueryWrapperMock.queryRuleByEnable(ENABLE)).andReturn(rules.stream() @@ -124,13 +113,13 @@ public class RuleAllocatorTest { expect(ruleMgtWrapperMock.deployRule2Engine(anyObject(CorrelationRule.class), anyObject(String.class))).andReturn("").anyTimes(); - correlationRuleDaoMock.updateRule(anyObject(CorrelationRule.class)); + correlationRuleServiceMock.updateRule(anyObject(CorrelationRule.class)); expectLastCall().anyTimes(); PowerMock.replayAll(); RuleAllocator ruleAllocator = new RuleAllocator(ruleMgtWrapperMock, ruleQueryWrapperMock, - engineWrapperMock, engineToolsMock, dbDaoUtilMock); + engineWrapperMock, engineToolsMock, correlationRuleServiceMock); ruleAllocator.allocateRules(); PowerMock.verifyAll(); @@ -144,7 +133,6 @@ public class RuleAllocatorTest { ipListFromMsb.addAll(existingIps); ipListFromMsb.remove(0); - expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(correlationRuleDaoMock); expect(engineToolsMock.getInstanceList()).andReturn(ipListFromMsb); expect(engineToolsMock.getLegacyEngineInstances()).andReturn(existingIps); for (String ip : existingIps) { @@ -153,13 +141,13 @@ public class RuleAllocatorTest { } expect(ruleMgtWrapperMock.deployRule2Engine(anyObject(CorrelationRule.class), anyString())).andReturn("anyId").times(2); - correlationRuleDaoMock.updateRule(anyObject(CorrelationRule.class)); + correlationRuleServiceMock.updateRule(anyObject(CorrelationRule.class)); expectLastCall().times(2); PowerMock.replayAll(); RuleAllocator ruleAllocator = new RuleAllocator(ruleMgtWrapperMock, ruleQueryWrapperMock, - engineWrapperMock, engineToolsMock, dbDaoUtilMock); + engineWrapperMock, engineToolsMock, correlationRuleServiceMock); ruleAllocator.allocateRules(); diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAppConfigTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAppConfigTest.java deleted file mode 100644 index d411603..0000000 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAppConfigTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/**
- * Copyright 2017 ZTE Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onap.holmes.rulemgt;
-
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.junit.Assert.assertThat;
-
-import io.dropwizard.db.DataSourceFactory;
-import org.junit.Before;
-import org.junit.Test;
-
-public class RuleAppConfigTest {
-
- private RuleAppConfig ruleAppConfig;
-
- @Before
- public void setUp() {
- ruleAppConfig = new RuleAppConfig();
- }
-
- @Test
- public void getDataSourceFactory() throws Exception {
- assertThat(ruleAppConfig.getDataSourceFactory(), notNullValue());
- }
-
- @Test
- public void setDataSourceFactory() throws Exception {
- final DataSourceFactory factory = new DataSourceFactory();
- ruleAppConfig.setDataSourceFactory(factory);
- assertThat(ruleAppConfig.getDataSourceFactory(), equalTo(factory));
- }
-
- @Test
- public void getApidescription() throws Exception {
- assertThat(ruleAppConfig.getApidescription(), equalTo("Holmes rule management rest API"));
- }
-
- @Test
- public void setApidescription() throws Exception {
- final String value = "desc";
- ruleAppConfig.setApidescription(value);
- assertThat(ruleAppConfig.getApidescription(), equalTo(value));
- }
-}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4EngineTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4EngineTest.java index e292e16..e5b42fe 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4EngineTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4EngineTest.java @@ -16,11 +16,11 @@ package org.onap.holmes.rulemgt.bean.request;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
import org.junit.Test;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
public class CorrelationCheckRule4EngineTest {
@Test
public void getterAndSetter4Content(){
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4EngineTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4EngineTest.java index 418ff41..82ad66d 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4EngineTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4EngineTest.java @@ -16,11 +16,11 @@ package org.onap.holmes.rulemgt.bean.request;
-import static org.junit.Assert.*;
-import static org.hamcrest.core.IsEqual.equalTo;
-
import org.junit.Test;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
public class CorrelationDeployRule4EngineTest {
@Test
public void getterAndSetter4Content(){
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationRestRequestTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationRestRequestTest.java index e616a71..52f7b50 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationRestRequestTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationRestRequestTest.java @@ -17,11 +17,11 @@ package org.onap.holmes.rulemgt.bean.request;
+import org.junit.Test;
+
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import org.junit.Test;
-
public class CorrelationRestRequestTest {
@Test
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequestTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequestTest.java index 54fa132..7fb874e 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequestTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequestTest.java @@ -16,11 +16,11 @@ package org.onap.holmes.rulemgt.bean.request;
+import org.junit.Test;
+
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
-import org.junit.Test;
+import static org.junit.Assert.assertThat;
public class RuleCreateRequestTest {
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequestTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequestTest.java index 3d49b2f..97bcd5c 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequestTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequestTest.java @@ -16,11 +16,11 @@ package org.onap.holmes.rulemgt.bean.request;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
import org.junit.Test;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
public class RuleDeleteRequestTest {
@Test
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleQueryConditionTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleQueryConditionTest.java index 36d5024..9488faa 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleQueryConditionTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleQueryConditionTest.java @@ -16,11 +16,11 @@ package org.onap.holmes.rulemgt.bean.request;
+import org.junit.Test;
+
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
-import org.junit.Test;
+import static org.junit.Assert.assertThat;
public class RuleQueryConditionTest {
@Test
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequestTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequestTest.java index 9f24c0c..f693c76 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequestTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequestTest.java @@ -16,11 +16,11 @@ package org.onap.holmes.rulemgt.bean.request;
+import org.junit.Test;
+
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
-import org.junit.Test;
+import static org.junit.Assert.assertThat;
public class RuleUpdateRequestTest {
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponseTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponseTest.java index a7db0fe..f36fdb4 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponseTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponseTest.java @@ -16,11 +16,11 @@ package org.onap.holmes.rulemgt.bean.response;
-import static org.junit.Assert.*;
-import static org.hamcrest.core.IsEqual.equalTo;
-
import org.junit.Test;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
public class RuleAddAndUpdateResponseTest {
@Test
public void getterAndSetter4RuleId(){
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponseTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponseTest.java index fa423db..aaa62f5 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponseTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponseTest.java @@ -16,13 +16,14 @@ package org.onap.holmes.rulemgt.bean.response;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
+import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
-import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
public class RuleQueryListResponseTest {
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleResult4APITest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleResult4APITest.java index 2c006ab..0953d10 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleResult4APITest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleResult4APITest.java @@ -16,12 +16,13 @@ package org.onap.holmes.rulemgt.bean.response;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
+import org.junit.Test;
import java.util.Date;
-import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
public class RuleResult4APITest {
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java index 6bfb387..5e7eb19 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java @@ -33,6 +33,7 @@ import static org.easymock.EasyMock.*; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
+import static org.powermock.api.easymock.PowerMock.createMock;
import static org.powermock.api.easymock.PowerMock.*;
@RunWith(PowerMockRunner.class)
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryServiceTest.java index 0e97e3a..a2bd863 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryServiceTest.java @@ -17,6 +17,10 @@ package org.onap.holmes.rulemgt.db;
import org.easymock.EasyMock;
+import org.jdbi.v3.core.Handle;
+import org.jdbi.v3.core.Jdbi;
+import org.jdbi.v3.core.result.ResultIterable;
+import org.jdbi.v3.core.statement.Query;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -24,14 +28,11 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.DbDaoUtil;
import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
-import org.skife.jdbi.v2.Handle;
-import org.skife.jdbi.v2.Query;
import java.util.*;
@@ -39,30 +40,28 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({DbDaoUtil.class, Handle.class, Query.class})
-public class CorrelationRuleQueryDaoTest {
+@PrepareForTest({Handle.class, Query.class})
+public class CorrelationRuleQueryServiceTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
-
- private DbDaoUtil dbDaoUtil;
-
private Handle handle;
-
private Query query;
-
- private CorrelationRuleQueryDao correlationRuleQueryDao;
+ private ResultIterable resultIterable;
+ private CorrelationRuleQueryService correlationRuleQueryDao;
private RuleQueryCondition ruleQueryCondition;
+ private Jdbi jdbi;
@Before
public void setUp() throws Exception {
- correlationRuleQueryDao = new CorrelationRuleQueryDao();
+ correlationRuleQueryDao = new CorrelationRuleQueryService();
- dbDaoUtil = PowerMock.createMock(DbDaoUtil.class);
+ jdbi = PowerMock.createMock(Jdbi.class);
handle = PowerMock.createMock(Handle.class);
query = PowerMock.createMock(Query.class);
+ resultIterable = PowerMock.createMock(ResultIterable.class);
- Whitebox.setInternalState(correlationRuleQueryDao, "dbDaoUtil", dbDaoUtil);
+ Whitebox.setInternalState(correlationRuleQueryDao, "jdbi", jdbi);
ruleQueryCondition = createRuleQueryCondition();
}
@@ -74,10 +73,10 @@ public class CorrelationRuleQueryDaoTest { thrown.expect(CorrelationException.class);
thrown.expectMessage("Failed to query the rule.");
- EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);
+ EasyMock.expect(jdbi.open()).andReturn(handle);
EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);
- EasyMock.expect(query.list()).andThrow(new RuntimeException()).anyTimes();
- dbDaoUtil.close(handle);
+ EasyMock.expect(query.mapToMap()).andThrow(new RuntimeException()).anyTimes();
+ handle.close();
EasyMock.expectLastCall();
PowerMock.replayAll();
@@ -89,10 +88,11 @@ public class CorrelationRuleQueryDaoTest { @Test
public void getCorrelationRulesByCondition_normal() throws Exception {
- EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);
+ EasyMock.expect(jdbi.open()).andReturn(handle);
EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);
- EasyMock.expect(query.list()).andReturn(createQueryResult()).anyTimes();
- dbDaoUtil.close(handle);
+ EasyMock.expect(query.mapToMap()).andReturn(resultIterable);
+ EasyMock.expect(resultIterable.list()).andReturn(createQueryResult());
+ handle.close();
EasyMock.expectLastCall();
PowerMock.replayAll();
@@ -108,10 +108,11 @@ public class CorrelationRuleQueryDaoTest { thrown.expect(CorrelationException.class);
thrown.expectMessage("An error occurred while building the query SQL.");
- EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);
+ EasyMock.expect(jdbi.open()).andReturn(handle);
EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);
- EasyMock.expect(query.list()).andReturn(createQueryResult()).anyTimes();
- dbDaoUtil.close(handle);
+ EasyMock.expect(query.mapToMap()).andReturn(resultIterable);
+ EasyMock.expect(resultIterable.list()).andReturn(createQueryResult());
+ handle.close();
EasyMock.expectLastCall();
PowerMock.replayAll();
@@ -128,16 +129,16 @@ public class CorrelationRuleQueryDaoTest { value.put("rid", "rule_" + System.currentTimeMillis());
value.put("description", "desc");
value.put("enable", 0);
- value.put("templateID", 1L);
- value.put("engineId", "engine-001");
- value.put("engineType", "engineType-001");
+ value.put("templateid", 1L);
+ value.put("engineid", "engine-001");
+ value.put("enginetype", "engineType-001");
value.put("creator", "admin");
- value.put("createTime", new Date());
+ value.put("createtime", new Date());
value.put("updator", "admin");
- value.put("updateTime", new Date());
+ value.put("updatetime", new Date());
value.put("params", new Properties());
value.put("domain", "Domain");
- value.put("isManual", 0);
+ value.put("ismanual", 0);
value.put("vendor", "Vendor");
value.put("content", "Contents");
value.put("package", "package");
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTaskTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTaskTest.java index 0f0f81a..396c2c1 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTaskTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTaskTest.java @@ -28,20 +28,15 @@ import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse; import org.onap.holmes.rulemgt.bean.response.RuleResult4API; import org.powermock.api.easymock.PowerMock; import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; -import java.util.HashMap; -import java.util.Map; - import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertThat; @RunWith(PowerMockRunner.class) @PrepareForTest({JerseyClient.class}) -@SuppressStaticInitializationFor({"org.onap.holmes.common.utils.JerseyClient"}) public class ConfigFileScanningTaskTest { @Rule diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java deleted file mode 100644 index b6e7149..0000000 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Copyright 2017-2021 ZTE Corporation. - * <p> - * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.holmes.rulemgt.dcae; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.holmes.common.dcae.DcaeConfigurationQuery; -import org.onap.holmes.common.dcae.entity.DcaeConfigurations; -import org.onap.holmes.common.dcae.entity.Rule; -import org.onap.holmes.common.utils.JerseyClient; -import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse; -import org.onap.holmes.rulemgt.bean.response.RuleResult4API; -import org.powermock.api.easymock.PowerMock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import java.util.ArrayList; -import java.util.List; - -import static org.easymock.EasyMock.*; -import static org.powermock.api.easymock.PowerMock.*; - -@RunWith(PowerMockRunner.class) -@SuppressStaticInitializationFor("org.onap.holmes.common.utils.JerseyClient") -@PrepareForTest({DcaeConfigurationPolling.class, DcaeConfigurationQuery.class}) -public class DcaeConfigurationPollingTest { - - @Test - public void run() throws Exception { - DcaeConfigurations dcaeConfigurations = new DcaeConfigurations(); - dcaeConfigurations.addDefaultRule(new Rule("test", "clName", "contents", 1)); - mockStatic(DcaeConfigurationQuery.class); - expect(DcaeConfigurationQuery.getDcaeConfigurations(anyObject(String.class))).andReturn(dcaeConfigurations); - DcaeConfigurationPolling dcaeConfigurationPolling = new DcaeConfigurationPolling("localhost"); - - Whitebox.setInternalState(dcaeConfigurationPolling, "url", "http://127.0.0.1"); - - RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse(); - List<RuleResult4API> ruleResult4APIList = new ArrayList<RuleResult4API>() { - { - add(new RuleResult4API()); - } - }; - ruleQueryListResponse.setCorrelationRules(ruleResult4APIList); - ruleQueryListResponse.setTotalCount(ruleResult4APIList.size()); - - JerseyClient mockedJerseyClient = PowerMock.createMock(JerseyClient.class); - PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient); - expect(mockedJerseyClient.get(anyString(), anyObject())).andReturn(ruleQueryListResponse); - - PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient); - expect(mockedJerseyClient.delete(anyString())).andReturn("true"); - - PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient); - expect(mockedJerseyClient.header(anyString(), anyString())).andReturn(mockedJerseyClient); - expect(mockedJerseyClient.put(anyString(), anyObject())).andReturn("true"); - - replayAll(); - - dcaeConfigurationPolling.run(); - - verifyAll(); - } - - @Test - public void run_identical_contents() throws Exception { - DcaeConfigurations dcaeConfigurations = new DcaeConfigurations(); - dcaeConfigurations.addDefaultRule(new Rule("test", "clName", "contents", 1)); - mockStatic(DcaeConfigurationQuery.class); - expect(DcaeConfigurationQuery.getDcaeConfigurations(anyObject(String.class))).andReturn(dcaeConfigurations).times(2); - DcaeConfigurationPolling dcaeConfigurationPolling = new DcaeConfigurationPolling("localhost"); - - Whitebox.setInternalState(dcaeConfigurationPolling, "url", "http://127.0.0.1"); - - RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse(); - List<RuleResult4API> ruleResult4APIList = new ArrayList<RuleResult4API>() { - { - add(new RuleResult4API()); - } - }; - ruleQueryListResponse.setCorrelationRules(ruleResult4APIList); - ruleQueryListResponse.setTotalCount(ruleResult4APIList.size()); - JerseyClient mockedJerseyClient = PowerMock.createMock(JerseyClient.class); - PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient); - expect(mockedJerseyClient.get(anyString(), anyObject())).andReturn(ruleQueryListResponse); - - PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient); - expect(mockedJerseyClient.delete(anyString())).andReturn("true"); - - PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient); - expect(mockedJerseyClient.header(anyString(), anyString())).andReturn(mockedJerseyClient); - expect(mockedJerseyClient.put(anyString(), anyObject())).andReturn("true"); - - replayAll(); - - dcaeConfigurationPolling.run(); - dcaeConfigurationPolling.run(); - - verifyAll(); - } -}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java index a35f6b8..a515196 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java @@ -1,5 +1,5 @@ /**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2022 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,25 +17,28 @@ package org.onap.holmes.rulemgt.resources;
import com.google.gson.JsonSyntaxException;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.WebApplicationException;
+import jakarta.ws.rs.WebApplicationException;
import org.easymock.EasyMock;
-import org.eclipse.jetty.server.Request;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
import org.onap.holmes.rulemgt.bean.request.RuleDeleteRequest;
-import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;
-import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
import org.onap.holmes.rulemgt.bean.request.RuleUpdateRequest;
import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;
import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
+import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;
import org.powermock.api.easymock.PowerMock;
+import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
+import javax.servlet.http.HttpServletRequest;
+
+@RunWith(PowerMockRunner.class)
public class RuleMgtResourcesTest {
@Rule
@@ -47,8 +50,6 @@ public class RuleMgtResourcesTest { private RuleMgtResources ruleMgtResources = new RuleMgtResources();
- private Request requestMock = PowerMock.createMock(Request.class);
-
@Before
public void setUp() throws Exception {
Whitebox.setInternalState(ruleMgtResources, "ruleMgtWrapper", ruleMgtWrapper);
@@ -63,7 +64,6 @@ public class RuleMgtResourcesTest { final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();
EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest))
.andThrow(new CorrelationException(EasyMock.anyObject(String.class)));
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
EasyMock.expect(request.getHeader("username")).andReturn("admin");
PowerMock.replayAll();
ruleMgtResources.addCorrelationRule(request, ruleCreateRequest);
@@ -76,7 +76,6 @@ public class RuleMgtResourcesTest { final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();
EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin",
ruleCreateRequest)).andReturn(new RuleAddAndUpdateResponse());
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
EasyMock.expect(request.getHeader("username")).andReturn("admin");
PowerMock.replayAll();
ruleMgtResources.addCorrelationRule(request, ruleCreateRequest);
@@ -90,7 +89,6 @@ public class RuleMgtResourcesTest { final RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();
EasyMock.expect(ruleMgtWrapper.updateCorrelationRule("admin", ruleUpdateRequest))
.andThrow(new CorrelationException(EasyMock.anyObject(String.class)));
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
EasyMock.expect(request.getHeader("username")).andReturn("admin");
PowerMock.replayAll();
ruleMgtResources.updateCorrelationRule(request, ruleUpdateRequest);
@@ -102,7 +100,6 @@ public class RuleMgtResourcesTest { final RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();
EasyMock.expect(ruleMgtWrapper.updateCorrelationRule("admin",
ruleUpdateRequest)).andReturn(new RuleAddAndUpdateResponse());
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
EasyMock.expect(request.getHeader("username")).andReturn("admin");
PowerMock.replayAll();
ruleMgtResources.updateCorrelationRule(request, ruleUpdateRequest);
@@ -115,10 +112,9 @@ public class RuleMgtResourcesTest { final String ruleId = "mockedRule";
ruleMgtWrapper.deleteCorrelationRule(EasyMock.anyObject(RuleDeleteRequest.class));
- EasyMock.expectLastCall().andThrow(new CorrelationException(EasyMock.anyObject(String.class)));
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
+ EasyMock.expectLastCall().andThrow(new CorrelationException("any string"));
PowerMock.replayAll();
- ruleMgtResources.deleteCorrelationRule(request, ruleId);
+ ruleMgtResources.deleteCorrelationRule(ruleId);
PowerMock.verifyAll();
}
@@ -127,9 +123,8 @@ public class RuleMgtResourcesTest { final String ruleId = "mockedRule";
ruleMgtWrapper.deleteCorrelationRule(EasyMock.anyObject(RuleDeleteRequest.class));
EasyMock.expectLastCall();
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
PowerMock.replayAll();
- ruleMgtResources.deleteCorrelationRule(request, ruleId);
+ ruleMgtResources.deleteCorrelationRule(ruleId);
PowerMock.verifyAll();
}
@@ -140,10 +135,9 @@ public class RuleMgtResourcesTest { final String requestStr = "{\"ruleid\":\"rule_001\",\"rulename\":\"Rule-001\","
+ "\"enabled\":0,\"creator\":\"admin\"}";
EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))
- .andThrow(new CorrelationException(EasyMock.anyObject(String.class)));
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);
+ .andThrow(new CorrelationException("any string"));
PowerMock.replayAll();
- ruleMgtResources.getCorrelationRules(request, requestStr);
+ ruleMgtResources.getCorrelationRules(requestStr);
PowerMock.verifyAll();
}
@@ -152,10 +146,9 @@ public class RuleMgtResourcesTest { thrown.expect(JsonSyntaxException.class);
String queryRequest = "this is error param";
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);
PowerMock.replayAll();
- ruleMgtResources.getCorrelationRules(request, queryRequest);
+ ruleMgtResources.getCorrelationRules(queryRequest);
PowerMock.verifyAll();
}
@@ -164,9 +157,8 @@ public class RuleMgtResourcesTest { public void getCorrelationRules_normal_request_string_null() throws Exception {
EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))
.andReturn(new RuleQueryListResponse());
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);
PowerMock.replayAll();
- ruleMgtResources.getCorrelationRules(request, null);
+ ruleMgtResources.getCorrelationRules(null);
PowerMock.verifyAll();
}
@@ -176,9 +168,8 @@ public class RuleMgtResourcesTest { + "\"creator\":\"admin\"}";
EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))
.andReturn(new RuleQueryListResponse());
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);
PowerMock.replayAll();
- ruleMgtResources.getCorrelationRules(request, requestStr);
+ ruleMgtResources.getCorrelationRules(requestStr);
PowerMock.verifyAll();
}
}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java index 626b91d..1ba93d4 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java @@ -22,19 +22,16 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; import org.onap.holmes.common.api.entity.CorrelationRule; import org.onap.holmes.common.exception.CorrelationException; -import org.onap.holmes.common.utils.DbDaoUtil; import org.onap.holmes.rulemgt.bean.request.*; import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse; import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse; import org.onap.holmes.rulemgt.bolt.enginebolt.EngineWrapper; -import org.onap.holmes.rulemgt.db.CorrelationRuleDao; -import org.onap.holmes.rulemgt.db.CorrelationRuleQueryDao; +import org.onap.holmes.rulemgt.db.CorrelationRuleQueryService; +import org.onap.holmes.rulemgt.db.CorrelationRuleService; import org.onap.holmes.rulemgt.tools.EngineTools; import org.powermock.api.easymock.PowerMock; -import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; import java.util.ArrayList; @@ -46,7 +43,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -@RunWith(PowerMockRunner.class) public class RuleMgtWrapperTest { @Rule @@ -56,42 +52,33 @@ public class RuleMgtWrapperTest { private EngineWrapper engineWrapperMock; - private DbDaoUtil dbDaoUtilMock; + private CorrelationRuleQueryService correlationRuleQueryDaoMock; - private CorrelationRuleQueryDao correlationRuleQueryDaoMock; - - private CorrelationRuleDao correlationRuleDaoMock; + private CorrelationRuleService correlationRuleServiceMock; private EngineTools engineToolsMock; private static final String USER_NAME = "admin"; @Before - public void setUp() throws Exception { + public void setUp() { ruleMgtWrapper = new RuleMgtWrapper(); engineWrapperMock = PowerMock.createMock(EngineWrapper.class); - correlationRuleQueryDaoMock = PowerMock.createMock(CorrelationRuleQueryDao.class); - dbDaoUtilMock = PowerMock.createMock(DbDaoUtil.class); - correlationRuleDaoMock = PowerMock.createMock(CorrelationRuleDao.class); + correlationRuleQueryDaoMock = PowerMock.createMock(CorrelationRuleQueryService.class); + correlationRuleServiceMock = PowerMock.createMock(CorrelationRuleService.class); engineToolsMock = PowerMock.createMock(EngineTools.class); - Whitebox.setInternalState(ruleMgtWrapper, "daoUtil", dbDaoUtilMock); + Whitebox.setInternalState(ruleMgtWrapper, "correlationRuleService", correlationRuleServiceMock); Whitebox.setInternalState(ruleMgtWrapper, "correlationRuleQueryDao", correlationRuleQueryDaoMock); Whitebox.setInternalState(ruleMgtWrapper, "engineWarpper", engineWrapperMock); - Whitebox.setInternalState(ruleMgtWrapper, "correlationRuleDao", correlationRuleDaoMock); Whitebox.setInternalState(ruleMgtWrapper,"engineTools", engineToolsMock); PowerMock.resetAll(); } @Test - public void initDaoUtil_normal() { - ruleMgtWrapper.initDaoUtil(); - } - - @Test public void addCorrelationRule_name_is_null() throws Exception { thrown.expect(CorrelationException.class); thrown.expectMessage("The name of the rule can not be empty."); @@ -147,7 +134,7 @@ public class RuleMgtWrapperTest { thrown.expect(CorrelationException.class); thrown.expectMessage("A rule with the same name already exists."); - EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName)).andReturn(correlationRule); + EasyMock.expect(correlationRuleServiceMock.queryRuleByRuleName(ruleName)).andReturn(correlationRule); PowerMock.replayAll(); ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest); @@ -166,7 +153,7 @@ public class RuleMgtWrapperTest { CorrelationRule correlationRuleRet = new CorrelationRule(); correlationRuleRet.setRid("rule_" + System.currentTimeMillis()); - EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName)).andReturn(null); + EasyMock.expect(correlationRuleServiceMock.queryRuleByRuleName(ruleName)).andReturn(null); EasyMock.expect(engineToolsMock.getEngineWithLeastRules()).andReturn("127.0.0.1"); EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class) , EasyMock.anyObject(String.class))) @@ -174,12 +161,13 @@ public class RuleMgtWrapperTest { EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class) , EasyMock.anyObject(String.class))) .andReturn("package-001"); - EasyMock.expect(correlationRuleDaoMock.saveRule(EasyMock.anyObject(CorrelationRule.class))) + EasyMock.expect(correlationRuleServiceMock.saveRule(EasyMock.anyObject(CorrelationRule.class))) .andReturn(correlationRuleRet); PowerMock.replayAll(); RuleAddAndUpdateResponse response = ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest); + PowerMock.verifyAll(); assertThat(response.getRuleId(), equalTo(correlationRuleRet.getRid())); @@ -206,10 +194,10 @@ public class RuleMgtWrapperTest { oldCorrelationRule.setEngineInstance("127.0.0.1"); RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_1", "cl-name", "des2", "contetnt2", 1); - EasyMock.expect(correlationRuleDaoMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule); + EasyMock.expect(correlationRuleServiceMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule); EasyMock.expect(engineToolsMock.getInstanceList()).andReturn(Arrays.asList("127.0.0.1", "127.0.0.2")).times(2); EasyMock.expect(engineWrapperMock.deleteRuleFromEngine("testName", "127.0.0.1")).andReturn(true); - correlationRuleDaoMock.updateRule(EasyMock.anyObject(CorrelationRule.class)); + correlationRuleServiceMock.updateRule(EasyMock.anyObject(CorrelationRule.class)); EasyMock.expectLastCall(); EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class) , EasyMock.anyObject(String.class))) @@ -239,7 +227,7 @@ public class RuleMgtWrapperTest { oldCorrelationRule.setEngineInstance("127.0.0.1"); RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_1", "cl-name", "des1", "content", 1); - EasyMock.expect(correlationRuleDaoMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule); + EasyMock.expect(correlationRuleServiceMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule); EasyMock.expect(engineToolsMock.getInstanceList()).andReturn(Arrays.asList("127.0.0.1", "127.0.0.2")); PowerMock.replayAll(); @@ -256,7 +244,7 @@ public class RuleMgtWrapperTest { thrown.expect(CorrelationException.class); thrown.expectMessage("You're trying to update a rule which does not exist in the system."); - EasyMock.expect(correlationRuleDaoMock.queryRuleByRid(EasyMock.anyObject(String.class))).andReturn(null); + EasyMock.expect(correlationRuleServiceMock.queryRuleByRid(EasyMock.anyObject(String.class))).andReturn(null); PowerMock.replayAll(); @@ -280,9 +268,7 @@ public class RuleMgtWrapperTest { RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis()); - EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn( - correlationRuleDaoMock).anyTimes(); - EasyMock.expect(correlationRuleDaoMock.queryRuleByRid(ruleDeleteRequest.getRuleId())) + EasyMock.expect(correlationRuleServiceMock.queryRuleByRid(ruleDeleteRequest.getRuleId())) .andReturn(null); PowerMock.replayAll(); @@ -297,11 +283,11 @@ public class RuleMgtWrapperTest { RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis()); CorrelationRule correlationRule = new CorrelationRule(); correlationRule.setEnabled(1); - EasyMock.expect(correlationRuleDaoMock.queryRuleByRid(ruleDeleteRequest.getRuleId())) + EasyMock.expect(correlationRuleServiceMock.queryRuleByRid(ruleDeleteRequest.getRuleId())) .andReturn(correlationRule); EasyMock.expect(engineWrapperMock.deleteRuleFromEngine(EasyMock.anyObject(String.class) , EasyMock.anyObject(String.class))).andReturn(true); - correlationRuleDaoMock.deleteRule(EasyMock.anyObject(CorrelationRule.class)); + correlationRuleServiceMock.deleteRule(EasyMock.anyObject(CorrelationRule.class)); EasyMock.expectLastCall(); PowerMock.replayAll(); @@ -319,11 +305,11 @@ public class RuleMgtWrapperTest { RuleQueryCondition.class))) .andThrow(new CorrelationException("An error occurred while building the query SQL.")); - PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class); + PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class); ruleMgtWrapper.getCorrelationRuleByCondition(new RuleQueryCondition()); - PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class); + PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class); } @Test @@ -335,11 +321,11 @@ public class RuleMgtWrapperTest { RuleQueryCondition.class))) .andThrow(new CorrelationException("Failed to query the rule.")); - PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class); + PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class); ruleMgtWrapper.getCorrelationRuleByCondition(new RuleQueryCondition()); - PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class); + PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class); } @Test @@ -362,11 +348,11 @@ public class RuleMgtWrapperTest { EasyMock.expect(correlationRuleQueryDaoMock.getCorrelationRulesByCondition(EasyMock.anyObject( RuleQueryCondition.class))).andReturn(correlationRuleList); - PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class); + PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class); RuleQueryListResponse response = ruleMgtWrapper.getCorrelationRuleByCondition(new RuleQueryCondition()); - PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class); + PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class); assertThat(response.getTotalCount(), is(10)); diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java index 4c7b1a0..8bb7e7a 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java @@ -22,7 +22,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.onap.holmes.common.api.entity.CorrelationRule; -import org.onap.holmes.rulemgt.db.CorrelationRuleDao; +import org.onap.holmes.rulemgt.db.jdbi.CorrelationRuleDao; import org.powermock.api.easymock.PowerMock; import java.util.ArrayList; |