X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=rulemgt%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fholmes%2Frulemgt%2Fdb%2FCorrelationRuleQueryDaoTest.java;fp=rulemgt%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fholmes%2Frulemgt%2Fdb%2FCorrelationRuleQueryDaoTest.java;h=0000000000000000000000000000000000000000;hb=a796bda2f8e2db093ce9f528f6e5960e4aa1b22c;hp=0e97e3a69b333f1b9cb6b6a7b3d14261820aecc0;hpb=71ad58788ebfd666f6922fd9c16f77a9a4e39e27;p=holmes%2Frule-management.git diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java deleted file mode 100644 index 0e97e3a..0000000 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java +++ /dev/null @@ -1,158 +0,0 @@ -/** - * Copyright 2017-2020 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.easymock.EasyMock; -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.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.*; - -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 { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private DbDaoUtil dbDaoUtil; - - private Handle handle; - - private Query query; - - private CorrelationRuleQueryDao correlationRuleQueryDao; - private RuleQueryCondition ruleQueryCondition; - - @Before - public void setUp() throws Exception { - correlationRuleQueryDao = new CorrelationRuleQueryDao(); - - dbDaoUtil = PowerMock.createMock(DbDaoUtil.class); - handle = PowerMock.createMock(Handle.class); - query = PowerMock.createMock(Query.class); - - Whitebox.setInternalState(correlationRuleQueryDao, "dbDaoUtil", dbDaoUtil); - - ruleQueryCondition = createRuleQueryCondition(); - } - - - @Test - public void getCorrelationRulesByCondition_db_exception() throws Exception { - - thrown.expect(CorrelationException.class); - thrown.expectMessage("Failed to query the rule."); - - EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle); - EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query); - EasyMock.expect(query.list()).andThrow(new RuntimeException()).anyTimes(); - dbDaoUtil.close(handle); - EasyMock.expectLastCall(); - - PowerMock.replayAll(); - - correlationRuleQueryDao.getCorrelationRulesByCondition(ruleQueryCondition); - - PowerMock.verifyAll(); - } - - @Test - public void getCorrelationRulesByCondition_normal() throws Exception { - EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle); - EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query); - EasyMock.expect(query.list()).andReturn(createQueryResult()).anyTimes(); - dbDaoUtil.close(handle); - EasyMock.expectLastCall(); - - PowerMock.replayAll(); - - List result = correlationRuleQueryDao.getCorrelationRulesByCondition(ruleQueryCondition); - assertThat(result.size(), is(1)); - - PowerMock.verifyAll(); - } - - @Test - public void getCorrelationRulesByCondition_get_where_sql_exception() throws Exception { - thrown.expect(CorrelationException.class); - thrown.expectMessage("An error occurred while building the query SQL."); - - EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle); - EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query); - EasyMock.expect(query.list()).andReturn(createQueryResult()).anyTimes(); - dbDaoUtil.close(handle); - EasyMock.expectLastCall(); - - PowerMock.replayAll(); - - correlationRuleQueryDao.getCorrelationRulesByCondition(null); - - PowerMock.verifyAll(); - } - - private List> createQueryResult() { - List> list = new ArrayList<>(); - Map value = new HashMap<>(); - value.put("name", "Rule-001"); - 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("creator", "admin"); - value.put("createTime", new Date()); - value.put("updator", "admin"); - value.put("updateTime", new Date()); - value.put("params", new Properties()); - value.put("domain", "Domain"); - value.put("isManual", 0); - value.put("vendor", "Vendor"); - value.put("content", "Contents"); - value.put("package", "package"); - list.add(value); - return list; - } - - private RuleQueryCondition createRuleQueryCondition() { - RuleQueryCondition ruleQueryCondition = new RuleQueryCondition(); - ruleQueryCondition.setRid("rule_" + System.currentTimeMillis()); - ruleQueryCondition.setName("Rule-001"); - ruleQueryCondition.setEnabled(0); - ruleQueryCondition.setCreator("admin"); - ruleQueryCondition.setModifier("admin"); - return ruleQueryCondition; - } - -}