From 8b3c9e2b928e3a0308974482e2645ace4838c468 Mon Sep 17 00:00:00 2001 From: Guangrong Fu Date: Mon, 31 Jul 2017 19:20:25 +0800 Subject: Change the package name from openo to onap Change the package name & maven from openo to onap Change-Id: I9c1fcaaa1c357fbd2b5c3bc2108d7cebd2b0ffc6 Issue-ID: HOLMES-10 Signed-off-by: Guangrong Fu --- .../common/api/entity/AlarmsCorrelationTest.java | 132 +++++++++++++ .../common/api/entity/CorrelationResultTest.java | 78 ++++++++ .../common/api/entity/CorrelationRuleTest.java | 146 +++++++++++++++ .../holmes/common/api/entity/ServiceNodeTest.java | 48 +++++ .../api/entity/ServiceRegisterEntityTest.java | 62 ++++++ .../org/onap/holmes/common/api/stat/AlarmTest.java | 207 +++++++++++++++++++++ .../onap/holmes/common/config/MQConfigTest.java | 28 +++ .../common/config/MicroServiceConfigTest.java | 39 ++++ .../common/exception/CorrelationExceptionTest.java | 29 +++ .../holmes/common/producer/MQProducerTest.java | 173 +++++++++++++++++ .../onap/holmes/common/utils/DbDaoUtilTest.java | 188 +++++++++++++++++++ .../holmes/common/utils/ExceptionUtilTest.java | 29 +++ .../onap/holmes/common/utils/JacksonUtilTest.java | 49 +++++ .../holmes/common/utils/JudgeNullUtilTest.java | 43 +++++ .../onap/holmes/common/utils/LanguageUtilTest.java | 118 ++++++++++++ .../holmes/common/utils/MSBRegisterUtilTest.java | 72 +++++++ .../org/onap/holmes/common/utils/UserUtilTest.java | 67 +++++++ .../onap/holmes/common/utils/bean/TestBean.java | 32 ++++ .../common/api/entity/AlarmsCorrelationTest.java | 133 ------------- .../common/api/entity/CorrelationResultTest.java | 78 -------- .../common/api/entity/CorrelationRuleTest.java | 146 --------------- .../holmes/common/api/entity/ServiceNodeTest.java | 48 ----- .../api/entity/ServiceRegisterEntityTest.java | 62 ------ .../openo/holmes/common/api/stat/AlarmTest.java | 207 --------------------- .../openo/holmes/common/config/MQConfigTest.java | 28 --- .../common/config/MicroServiceConfigTest.java | 39 ---- .../common/exception/CorrelationExceptionTest.java | 29 --- .../holmes/common/producer/MQProducerTest.java | 173 ----------------- .../openo/holmes/common/utils/DbDaoUtilTest.java | 188 ------------------- .../holmes/common/utils/ExceptionUtilTest.java | 31 --- .../openo/holmes/common/utils/I18nProxyTest.java | 62 ------ .../openo/holmes/common/utils/JacksonUtilTest.java | 49 ----- .../holmes/common/utils/JudgeNullUtilTest.java | 43 ----- .../holmes/common/utils/LanguageUtilTest.java | 118 ------------ .../holmes/common/utils/MSBRegisterUtilTest.java | 72 ------- .../openo/holmes/common/utils/UserUtilTest.java | 67 ------- .../openo/holmes/common/utils/bean/TestBean.java | 32 ---- 37 files changed, 1540 insertions(+), 1605 deletions(-) create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationResultTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationRuleTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/api/entity/ServiceNodeTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/api/entity/ServiceRegisterEntityTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/config/MQConfigTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/exception/CorrelationExceptionTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/producer/MQProducerTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/utils/DbDaoUtilTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/utils/ExceptionUtilTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/utils/JacksonUtilTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/utils/JudgeNullUtilTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/utils/LanguageUtilTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/utils/UserUtilTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/utils/bean/TestBean.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/api/entity/AlarmsCorrelationTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationResultTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationRuleTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/api/entity/ServiceNodeTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/api/entity/ServiceRegisterEntityTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/config/MQConfigTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/config/MicroServiceConfigTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/exception/CorrelationExceptionTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/producer/MQProducerTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/DbDaoUtilTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/ExceptionUtilTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/I18nProxyTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/JacksonUtilTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/JudgeNullUtilTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/LanguageUtilTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/MSBRegisterUtilTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/UserUtilTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/bean/TestBean.java (limited to 'holmes-actions/src/test') diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java new file mode 100644 index 0000000..dd940c4 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java @@ -0,0 +1,132 @@ +/** + * 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.common.api.entity; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.Date; +import org.junit.Test; +import org.junit.Before; +import org.junit.After; + +public class AlarmsCorrelationTest { + + private AlarmsCorrelation alarmsCorrelation; + + @Before + public void before() throws Exception { + alarmsCorrelation = new AlarmsCorrelation(); + } + + @After + public void after() throws Exception { + + } + + + @Test + public void getterAndSetter4RuleId() throws Exception { + final String ruleId = "ruleId"; + alarmsCorrelation.setRuleId(ruleId); + assertThat(alarmsCorrelation.getRuleId(), equalTo(ruleId)); + } + + + @Test + public void getterAndSetter4RuleInfo() throws Exception { + final String ruleInfo = "ruleInfo"; + alarmsCorrelation.setRuleInfo(ruleInfo); + assertThat(alarmsCorrelation.getRuleInfo(), equalTo(ruleInfo)); + } + + + @Test + public void getterAndSetter4ResultType() throws Exception { + final byte resultType = 1; + alarmsCorrelation.setResultType(resultType); + assertThat(alarmsCorrelation.getResultType(), equalTo(resultType)); + } + + + @Test + public void getterAndSetter4CreateTime() throws Exception { + final Date createTime = new Date(); + alarmsCorrelation.setCreateTime(createTime); + assertThat(alarmsCorrelation.getCreateTime(), equalTo(createTime)); + } + + + @Test + public void getterAndSetter4ParentAlarmId() throws Exception { + final long pad = 11L; + alarmsCorrelation.setParentAlarmId(pad); + assertThat(alarmsCorrelation.getParentAlarmId(), equalTo(pad)); + } + + + @Test + public void getterAndSetter4ChildAlarmId() throws Exception { + final long childAlarmId = 11L; + alarmsCorrelation.setChildAlarmId(childAlarmId); + assertThat(alarmsCorrelation.getChildAlarmId(), equalTo(childAlarmId)); + } + + + @Test + public void getterAndSetter4Reserve1() throws Exception { + final long reserve1 = 11L; + alarmsCorrelation.setReserve1(reserve1); + assertThat(alarmsCorrelation.getReserve1(), equalTo(reserve1)); + } + + + @Test + public void getterAndSetter4Reserve2() throws Exception { + final long reserve2 = 11L; + alarmsCorrelation.setReserve2(reserve2); + assertThat(alarmsCorrelation.getReserve2(), equalTo(reserve2)); + } + + + @Test + public void getterAndSetter4Reserve3() throws Exception { + final long reserve3 = 11L; + alarmsCorrelation.setReserve3(reserve3); + assertThat(alarmsCorrelation.getReserve3(), equalTo(reserve3)); + } + + + @Test + public void testToString() throws Exception { + final AlarmsCorrelation alarmsCorrelationTemp = new AlarmsCorrelation(); + String ruleId = "ruleId"; + alarmsCorrelationTemp.setRuleId(ruleId); + alarmsCorrelation.setRuleId(ruleId); + assertThat(alarmsCorrelation.toString(), equalTo(alarmsCorrelationTemp.toString())); + } + + + @Test + public void testEqualsAndHashCode() throws Exception { + final AlarmsCorrelation alarmsCorrelationTemp = new AlarmsCorrelation(); + String ruleId = "ruleId"; + alarmsCorrelationTemp.setRuleId(ruleId); + alarmsCorrelation.setRuleId(ruleId); + assertThat(alarmsCorrelation, equalTo(alarmsCorrelationTemp)); + } +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationResultTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationResultTest.java new file mode 100644 index 0000000..1e30fab --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationResultTest.java @@ -0,0 +1,78 @@ +/** + * 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.common.api.entity; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.Date; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.holmes.common.api.stat.Alarm; + +public class CorrelationResultTest { + + private CorrelationResult correlationResult; + + @Before + public void before() throws Exception { + correlationResult = new CorrelationResult(); + } + + @After + public void after() throws Exception { + } + + @Test + public void getterAndSetter4RuleId() throws Exception { + final String ruleId = "ruleId"; + correlationResult.setRuleId(ruleId); + assertThat(correlationResult.getRuleId(), equalTo(ruleId)); + } + + @Test + public void getterAndSetter4CreateTimeL() throws Exception { + final long createTimeL = new Date().getTime(); + correlationResult.setCreateTimeL( + createTimeL); + assertThat(correlationResult.getCreateTimeL(), equalTo(createTimeL)); + } + + @Test + public void getterAndSetter4GetResultType() throws Exception { + final byte resultType = 2; + correlationResult.setResultType(resultType); + assertThat(correlationResult.getResultType(), equalTo(resultType)); + } + + @Test + public void getterAndSetter4AffectedAlarms() throws Exception { + final Alarm alarm[] = new Alarm[2]; + correlationResult.setAffectedAlarms(alarm); + assertThat(correlationResult.getAffectedAlarms(), equalTo(alarm)); + } + + @Test + public void testToString() throws Exception { + CorrelationResult resultTemp = new CorrelationResult(); + final String tempStr = "aa"; + resultTemp.setRuleId(tempStr); + correlationResult.setRuleId(tempStr); + assertThat(correlationResult.toString(), equalTo(resultTemp.toString())); + } +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationRuleTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationRuleTest.java new file mode 100644 index 0000000..25ee5c6 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationRuleTest.java @@ -0,0 +1,146 @@ +/** + * 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.common.api.entity; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.Date; +import java.util.Properties; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class CorrelationRuleTest { + + private CorrelationRule correlationRule; + + @Before + public void before() throws Exception { + correlationRule = new CorrelationRule(); + } + + @After + public void after() throws Exception { + + } + + @Test + public void getterAndSetter4Rid() throws Exception { + final String rid = "rid"; + correlationRule.setRid(rid); + assertThat(correlationRule.getRid(), equalTo(rid)); + } + + @Test + public void getterAndSetter4Name() throws Exception { + final String name = "name"; + correlationRule.setName(name); + assertThat(correlationRule.getName(), equalTo(name)); + } + + @Test + public void getterAndSetter4Description() throws Exception { + final String description = "description"; + correlationRule.setDescription(description); + assertThat(correlationRule.getDescription(), equalTo(description)); + } + + @Test + public void getterAndSetter4Enabled() throws Exception { + final int enabled = 1; + correlationRule.setEnabled(enabled); + assertThat(correlationRule.getEnabled(), equalTo(enabled)); + } + + @Test + public void getterAndSetter4TemplateID() throws Exception { + final int templateId = 1; + correlationRule.setTemplateID(templateId); + assertThat(correlationRule.getTemplateID(), equalTo(templateId)); + } + + @Test + public void getterAndSetter4EngineId() throws Exception { + final String engineId = "engineId"; + correlationRule.setEngineID(engineId); + assertThat(correlationRule.getEngineID(), equalTo(engineId)); + } + + @Test + public void getterAndSetter4EngineType() throws Exception { + final String engineType = "engineType"; + correlationRule.setEngineType(engineType); + assertThat(correlationRule.getEngineType(), equalTo(engineType)); + } + + @Test + public void getterAndSetter4Creator() throws Exception { + final String creator = "creator"; + correlationRule.setCreator(creator); + assertThat(correlationRule.getCreator(), equalTo(creator)); + } + + @Test + public void getterAndSetter4Modifier() throws Exception { + final String modifier = "modifier"; + correlationRule.setModifier(modifier); + assertThat(correlationRule.getModifier(), equalTo(modifier)); + } + + @Test + public void getterAndSetter4Params() throws Exception { + final Properties params = new Properties(); + correlationRule.setParams(params); + assertThat(correlationRule.getParams(), equalTo(params)); + } + + @Test + public void getterAndSetter4Content() throws Exception { + final String content = "content"; + correlationRule.setContent(content); + assertThat(correlationRule.getContent(), equalTo(content)); + } + + @Test + public void getterAndSetter4Vendor() throws Exception { + final String vendor = "vendor"; + correlationRule.setVendor(vendor); + assertThat(correlationRule.getVendor(), equalTo(vendor)); + } + + @Test + public void getterAndSetter4CreateTime() throws Exception { + Date createTime = new Date(); + correlationRule.setCreateTime(createTime); + assertThat(correlationRule.getCreateTime(), equalTo(createTime)); + } + + @Test + public void getterAndSetter4UpdateTime() throws Exception { + final Date updateTime = new Date(); + correlationRule.setUpdateTime(updateTime); + assertThat(correlationRule.getUpdateTime(), equalTo(updateTime)); + } + + @Test + public void getterAndSetter4PackageName() throws Exception { + final String packageName = "packageName"; + correlationRule.setPackageName(packageName); + assertThat(correlationRule.getPackageName(), equalTo(packageName)); + } +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/ServiceNodeTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/ServiceNodeTest.java new file mode 100644 index 0000000..d1b800b --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/ServiceNodeTest.java @@ -0,0 +1,48 @@ +/** + * 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.common.api.entity; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +public class ServiceNodeTest { + + private ServiceNode serviceNode = new ServiceNode(); + + @Test + public void getterAndSetter4ip() { + String ip = "test"; + serviceNode.setIp(ip); + assertThat(serviceNode.getIp(), equalTo(ip)); + } + + @Test + public void getterAndSetter4port() { + String port = "test"; + serviceNode.setPort(port); + assertThat(serviceNode.getPort(), equalTo(port)); + } + + @Test + public void getterAndSetter4ttl() { + int ttl = 1; + serviceNode.setTtl(ttl); + assertThat(serviceNode.getTtl(), equalTo(ttl)); + } +} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/ServiceRegisterEntityTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/ServiceRegisterEntityTest.java new file mode 100644 index 0000000..266c8bc --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/ServiceRegisterEntityTest.java @@ -0,0 +1,62 @@ +/** + * 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.common.api.entity; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +public class ServiceRegisterEntityTest { + + private ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity(); + + @Test + public void getterAndSetter4protocol() { + String protocol = "test"; + serviceRegisterEntity.setProtocol(protocol); + assertThat(serviceRegisterEntity.getProtocol(), equalTo(protocol)); + } + + @Test + public void getterAndSetter4serviceName() { + String serviceName = "test"; + serviceRegisterEntity.setServiceName(serviceName); + assertThat(serviceRegisterEntity.getServiceName(), equalTo(serviceName)); + } + + @Test + public void getterAndSetter4url() { + String url = "test"; + serviceRegisterEntity.setUrl(url); + assertThat(serviceRegisterEntity.getUrl(), equalTo(url)); + } + + @Test + public void getterAndSetter4version() { + String version = "test"; + serviceRegisterEntity.setVersion(version); + assertThat(serviceRegisterEntity.getVersion(), equalTo(version)); + } + + @Test + public void getterAndSetter4visualRange() { + String visualRange = "test"; + serviceRegisterEntity.setVisualRange(visualRange); + assertThat(serviceRegisterEntity.getVisualRange(), equalTo(visualRange)); + } +} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java new file mode 100644 index 0000000..b0e3690 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java @@ -0,0 +1,207 @@ +/** + * 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.common.api.stat; + +import java.util.Date; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class AlarmTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private Alarm alarm; + + @Before + public void before() throws Exception { + alarm = new Alarm(); + } + + @After + public void after() throws Exception { + } + + @Test + public void testCompareLinkPosition_isEmpty() throws Exception { + final Map otherIdIdx = new HashMap<>(); + assertThat(999, equalTo(alarm.CompareLinkPosition(otherIdIdx))); + } + + @Test + public void testCompareLinkPosition_TempLinkId() throws Exception { + final Map otherIdIdx = new HashMap<>(); + otherIdIdx.put(1, 2); + alarm.addLinkIdNodeIdx(1, 3); + assertThat(1, equalTo(alarm.CompareLinkPosition(otherIdIdx))); + } + + @Test + public void testContainNode_NoContainLink() throws Exception { + alarm.addLinkIdNodeIdx(1, 2); + assertThat(false, equalTo(alarm.containNode(2, 2))); + } + + @Test + public void testContainNode_ContainLinkNoIdx() throws Exception { + alarm.addLinkIdNodeIdx(1, 2); + assertFalse(alarm.containNode(1, 3)); + } + + @Test + public void testContainNode_ContainLinkAndIdx() throws Exception { + alarm.addLinkIdNodeIdx(1, 2); + assertTrue(alarm.containNode(1, 2)); + } + + @Test + public void testGetDataType() throws Exception { + assertThat(Alarm.APLUS_EVENT, equalTo(alarm.getDataType())); + } + + @Test + public void testToString() throws Exception { + Alarm alarmTempA = new Alarm(); + Alarm alarmTempB = new Alarm(); + Date date = new Date(); + alarmTempA.setClearedTime(date); + alarmTempA.setRaisedTime(date); + alarmTempA.setRaisedServerTime(date); + alarmTempB.setClearedTime(date); + alarmTempB.setRaisedTime(date); + alarmTempB.setRaisedServerTime(date); + assertThat(alarmTempA.toString(),equalTo(alarmTempB.toString())); + } + + @Test + public void testHashCode() throws Exception { + final Alarm alarmTemp = new Alarm(); + final String alarmKey = "alarmKey"; + alarm.setAlarmKey(alarmKey); + alarmTemp.setAlarmKey(alarmKey); + assertThat(alarm.hashCode(), equalTo(alarmTemp.hashCode())); + } + + @Test + public void testEqualsAnd_NotNull() throws Exception { + final Alarm alarmTemp = new Alarm(); + final String alarmKey = "alarmKey"; + alarm.setAlarmKey(alarmKey); + alarmTemp.setAlarmKey(alarmKey); + assertTrue(alarm.equals(alarmTemp)); + } + + @Test + public void testEqualsAndH_isNull() throws Exception { + assertFalse(alarm.equals(null)); + } + + @Test + public void testClone() throws Exception { + alarm.setAlarmKey("alarmKey"); + Alarm alarmTemp = (Alarm) alarm.clone(); + assertTrue(alarm.equals(alarmTemp)); + assertFalse(alarm == alarmTemp); + } + + @Test + public void testGetObjectId() throws Exception { + alarm.setId(11); + assertThat("11", equalTo(alarm.getObjectId())); + } + + @Test + public void testAddLinkIds() throws Exception { + final int linkId = 11; + alarm.addLinkIds(linkId); + assertTrue(alarm.getLinkIds().contains(linkId)); + } + + @Test + public void testContainsPriority_true() throws Exception { + String ruleId = "ruleId"; + alarm.getPriorityMap().put(ruleId, 2); + assertTrue(alarm.containsPriority(ruleId)); + } + + @Test + public void testContainsPriority_false() throws Exception { + final String ruleId = "ruleId"; + assertFalse(alarm.containsPriority(ruleId)); + } + + @Test + public void testGetPriority_isNull() throws Exception { + final String ruleId = "ruleId"; + alarm.getPriorityMap().put(ruleId, null); + assertThat(0, equalTo(alarm.getPriority(ruleId))); + } + + @Test + public void testGetPriority_notNull() throws Exception { + final String ruleId = "ruleId"; + final int priority = 2; + alarm.getPriorityMap().put(ruleId, priority); + assertThat(priority, equalTo(alarm.getPriority(ruleId))); + } + + @Test + public void testGetAlarmTypeRuleId_isNull() throws Exception { + final String ruleId = "ruleId"; + alarm.getRootAlarmTypeMap().put(ruleId, null); + assertThat(-1, equalTo(alarm.getRootAlarmType(ruleId))); + } + + @Test + public void testGetAlarmTypeRuleId_notNull() throws Exception { + final String ruleId = "ruleId"; + final int rootAlarmType = 2; + alarm.getRootAlarmTypeMap().put(ruleId, rootAlarmType); + assertThat(rootAlarmType, equalTo(alarm.getRootAlarmType(ruleId))); + } + + @Test + public void getterAndSetter4CenterType() throws Exception { + final int centerType = 1; + alarm.setCenterType(centerType); + assertThat(centerType, equalTo(alarm.getCenterType())); + } + + @Test + public void valueOf_exception() { + thrown.expect(Exception.class); + String xmlString = ""; + Alarm.valueOf(xmlString); + } + + @Test + public void valueOf_normal() { + String xmlString = alarm.toString(); + Alarm alarmValue = Alarm.valueOf(xmlString); + assertThat(alarmValue, equalTo(alarm)); + } +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/config/MQConfigTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/config/MQConfigTest.java new file mode 100644 index 0000000..cc9dced --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/config/MQConfigTest.java @@ -0,0 +1,28 @@ +/** + * 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.common.config; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; + +public class MQConfigTest { + @Test + public void testNewClass() { + MQConfig mqConfig= new MQConfig(); + } +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java new file mode 100644 index 0000000..33431ff --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java @@ -0,0 +1,39 @@ +/** + * 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.common.config; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +public class MicroServiceConfigTest { + + @Test + public void getMsbServerAddrTest() { + System.setProperty("MSB_ADDR", "test"); + assertThat("http://test", equalTo(MicroServiceConfig.getMsbServerAddr())); + System.clearProperty("MSB_ADDR"); + } + + @Test + public void getServiceIpTest() { + System.setProperty("SERVICE_IP", "test"); + assertThat("test", equalTo(MicroServiceConfig.getServiceIp())); + System.clearProperty("SERVICE_IP"); + } +} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/exception/CorrelationExceptionTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/exception/CorrelationExceptionTest.java new file mode 100644 index 0000000..d924533 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/exception/CorrelationExceptionTest.java @@ -0,0 +1,29 @@ +/** + * 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.common.exception; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; + +public class CorrelationExceptionTest { + @Test + public void testConstructors() throws Exception { + CorrelationException ce1 = new CorrelationException("msg", new Exception()); + CorrelationException ce2 = new CorrelationException("msg"); + } +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/producer/MQProducerTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/producer/MQProducerTest.java new file mode 100644 index 0000000..7c561b0 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/producer/MQProducerTest.java @@ -0,0 +1,173 @@ +/** + * 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.common.producer; + +import static org.easymock.EasyMock.anyBoolean; +import static org.easymock.EasyMock.anyInt; +import static org.easymock.EasyMock.anyObject; +import static org.easymock.EasyMock.expect; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.MessageProducer; +import javax.jms.ObjectMessage; +import javax.jms.Session; +import javax.jms.Topic; +import org.glassfish.hk2.api.IterableProvider; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.holmes.common.api.stat.Alarm; +import org.onap.holmes.common.api.entity.CorrelationResult; +import org.onap.holmes.common.config.MQConfig; +import org.powermock.api.easymock.PowerMock; +import org.powermock.modules.junit4.rule.PowerMockRule; +import org.powermock.reflect.Whitebox; + +public class MQProducerTest { + + @Rule + public PowerMockRule powerMockRule = new PowerMockRule(); + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private IterableProvider mqConfigProvider; + + private ConnectionFactory connectionFactory; + + private MQProducer mqProducer; + + @Before + public void before() throws Exception { + mqProducer = new MQProducer(); + + mqConfigProvider = PowerMock.createMock(IterableProvider.class); + connectionFactory = PowerMock.createMock(ConnectionFactory.class); + + Whitebox.setInternalState(mqProducer, "mqConfigProvider", mqConfigProvider); + Whitebox.setInternalState(mqProducer, "connectionFactory", connectionFactory); + PowerMock.resetAll(); + } + + @Test + public void init() { + MQConfig mqConfig = new MQConfig(); + mqConfig.brokerIp = "127.0.0.1"; + mqConfig.brokerPort = 61616; + mqConfig.brokerPassword = "admin"; + mqConfig.brokerUsername = "admin"; + expect(mqConfigProvider.get()).andReturn(mqConfig).anyTimes(); + + PowerMock.replayAll(); + + mqProducer.init(); + + PowerMock.verifyAll(); + } + + @Test + public void sendAlarmMQTopicMsg() throws Exception { + Alarm alarm = new Alarm(); + Connection connection = PowerMock.createMock(Connection.class); + Session session = PowerMock.createMock(Session.class); + Destination destination = PowerMock.createMock(Topic.class); + MessageProducer messageProducer = PowerMock.createMock(MessageProducer.class); + ObjectMessage objMessage = PowerMock.createMock(ObjectMessage.class); + + expect(connectionFactory.createConnection()).andReturn(connection); + connection.start(); + expect(connection.createSession(anyBoolean(), anyInt())).andReturn(session); + expect(session.createTopic(anyObject(String.class))).andReturn((Topic) destination); + expect(session.createProducer(anyObject(Destination.class))).andReturn(messageProducer); + + expect(session.createObjectMessage(anyObject(Alarm.class))).andReturn(objMessage); + messageProducer.send(objMessage); + session.commit(); + connection.close(); + + PowerMock.replayAll(); + + mqProducer.sendAlarmMQTopicMsg(alarm); + + PowerMock.verifyAll(); + + } + + @Test + public void sendAlarmMQTopicMsg_exception() throws Exception { + thrown.expect(JMSException.class); + Alarm alarm = new Alarm(); + + expect(connectionFactory.createConnection()).andThrow(new JMSException("")); + + PowerMock.replayAll(); + + mqProducer.sendAlarmMQTopicMsg(alarm); + + PowerMock.verifyAll(); + } + + @Test + public void sendCorrelationMQTopicMsg() throws Exception { + + Connection connection = PowerMock.createMock(Connection.class); + Session session = PowerMock.createMock(Session.class); + Destination destination = PowerMock.createMock(Topic.class); + MessageProducer messageProducer = PowerMock.createMock(MessageProducer.class); + ObjectMessage objMessage = PowerMock.createMock(ObjectMessage.class); + + expect(connectionFactory.createConnection()).andReturn(connection); + connection.start(); + expect(connection.createSession(anyBoolean(), anyInt())).andReturn(session); + expect(session.createTopic(anyObject(String.class))).andReturn((Topic) destination); + expect(session.createProducer(anyObject(Destination.class))).andReturn(messageProducer); + + expect(session.createObjectMessage(anyObject(CorrelationResult.class))) + .andReturn(objMessage); + messageProducer.send(objMessage); + session.commit(); + connection.close(); + + PowerMock.replayAll(); + + Alarm parentAlarm = new Alarm(); + Alarm childAlarm = new Alarm(); + mqProducer.sendCorrelationMQTopicMsg("ruleId", 123L, parentAlarm, childAlarm); + + PowerMock.verifyAll(); + + } + + @Test + public void sendCorrelationMQTopicMsg_exception() throws Exception { + thrown.expect(JMSException.class); + + expect(connectionFactory.createConnection()).andThrow(new JMSException("")); + + PowerMock.replayAll(); + + Alarm parentAlarm = new Alarm(); + Alarm childAlarm = new Alarm(); + mqProducer.sendCorrelationMQTopicMsg("ruleId", 123L, parentAlarm, childAlarm); + + PowerMock.verifyAll(); + + } +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/DbDaoUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/DbDaoUtilTest.java new file mode 100644 index 0000000..e942eb4 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/DbDaoUtilTest.java @@ -0,0 +1,188 @@ +/** + * 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.common.utils; + +import static org.easymock.EasyMock.anyObject; +import static org.easymock.EasyMock.expect; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import io.dropwizard.db.DataSourceFactory; +import io.dropwizard.jdbi.DBIFactory; +import io.dropwizard.setup.Environment; +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.powermock.api.easymock.PowerMock; +import org.powermock.modules.junit4.rule.PowerMockRule; +import org.powermock.reflect.Whitebox; +import org.skife.jdbi.v2.DBI; +import org.skife.jdbi.v2.Handle; + +public class DbDaoUtilTest { + + @Rule + public PowerMockRule powerMockRule = new PowerMockRule(); + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private DBI jdbi; + + private Environment environmentProvider; + + private DataSourceFactory dataSourceFactoryProvider; + + private DbDaoUtil dbDaoUtil; + + private DBIFactory factory; + + @Before + public void before() throws Exception { + dbDaoUtil = new DbDaoUtil(); + + jdbi = PowerMock.createMock(DBI.class); + environmentProvider = PowerMock.createMock(Environment.class); + dataSourceFactoryProvider = PowerMock.createMock(DataSourceFactory.class); + factory = PowerMock.createMock(DBIFactory.class); + + Whitebox.setInternalState(dbDaoUtil, "environmentProvider", environmentProvider); + Whitebox.setInternalState(dbDaoUtil, "dataSourceFactoryProvider", + dataSourceFactoryProvider); + Whitebox.setInternalState(dbDaoUtil, "factory", factory); + + PowerMock.resetAll(); + } + + @Test + public void init() throws Exception { + DBI jdbi = PowerMock.createMock(DBI.class); + + expect(factory.build(anyObject(Environment.class), anyObject(DataSourceFactory.class), + anyObject(String.class))).andReturn(jdbi); + + PowerMock.replayAll(); + + dbDaoUtil.init(); + + PowerMock.verifyAll(); + } + + @Test + public void getDao_normal() throws Exception { + Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); + expect(jdbi.open(anyObject(Class.class))).andReturn(Class.class); + + PowerMock.replayAll(); + + dbDaoUtil.getDao(String.class); + + PowerMock.verifyAll(); + } + + @Test + public void getDao_exception() throws Exception { + Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); + + expect(jdbi.open(anyObject(Class.class))).andThrow(new RuntimeException("")); + + PowerMock.replayAll(); + + Object o = dbDaoUtil.getDao(String.class); + + PowerMock.verifyAll(); + + assertThat(o, equalTo(null)); + } + + @Test + public void getHandle_normal() throws Exception { + Handle handle = PowerMock.createMock(Handle.class); + + Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); + expect(jdbi.open()).andReturn(handle); + + PowerMock.replayAll(); + + dbDaoUtil.getHandle(); + + PowerMock.verifyAll(); + } + @Test + public void getHandle_exception() throws Exception { + Handle handle = PowerMock.createMock(Handle.class); + + Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); + expect(jdbi.open()).andThrow(new RuntimeException("")); + + PowerMock.replayAll(); + + Handle handle1 = dbDaoUtil.getHandle(); + + PowerMock.verifyAll(); + + assertThat(handle1, equalTo(null)); + } + + @Test + public void close_normal() throws Exception { + Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); + jdbi.close(anyObject()); + + PowerMock.replayAll(); + + dbDaoUtil.close(new Object()); + + PowerMock.verifyAll(); + } + + @Test + public void close_exception() throws Exception { + Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); + jdbi.close(anyObject()); + EasyMock.expectLastCall().andThrow(new RuntimeException("")); + PowerMock.replayAll(); + + dbDaoUtil.close(new Object()); + + PowerMock.verifyAll(); + } + @Test + public void testGetJdbiDaoByOnDemand() throws Exception { + Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); + expect(jdbi.onDemand(anyObject(Class.class))).andReturn(Class.class); + + PowerMock.replayAll(); + + dbDaoUtil.getJdbiDaoByOnDemand(String.class); + + PowerMock.verifyAll(); + } + + @Test + public void testGetJdbiDaoByOpen() throws Exception { + Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); + expect(jdbi.open(anyObject(Class.class))).andReturn(Class.class); + + PowerMock.replayAll(); + + dbDaoUtil.getJdbiDaoByOpen(String.class); + + PowerMock.verifyAll(); + } +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/ExceptionUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/ExceptionUtilTest.java new file mode 100644 index 0000000..98cac63 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/ExceptionUtilTest.java @@ -0,0 +1,29 @@ +/** + * 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.common.utils; + +import org.junit.Test; + +public class ExceptionUtilTest { + + @Test + public void testBuildExceptionResponse() throws Exception { + ExceptionUtil.buildExceptionResponse("test"); + } + + +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/JacksonUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/JacksonUtilTest.java new file mode 100644 index 0000000..5f90c2d --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/JacksonUtilTest.java @@ -0,0 +1,49 @@ +/** + * Copyright 2016 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.common.utils; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import org.junit.Test; +import org.onap.holmes.common.utils.bean.TestBean; + +public class JacksonUtilTest { + + @Test + public void testBeanToJson() throws Exception { + TestBean o = new TestBean(); + o.setId("id"); + String result = JacksonUtil.beanToJson(o); + assertThat("{\"id\":\"id\"}", equalTo(result)); + } + + @Test + public void jsonToBean_json_null() throws Exception { + String jsonNull = null; + TestBean testBean = JacksonUtil.jsonToBean(jsonNull, TestBean.class); + assertThat(testBean.getId(), equalTo(null)); + } + + @Test + public void jsonToBean_json_normal() throws Exception { + String json = "{\"id\":\"id\"}"; + TestBean testBean = JacksonUtil.jsonToBean(json, TestBean.class); + assertThat(testBean.getId(), equalTo("id")); + } +} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/JudgeNullUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/JudgeNullUtilTest.java new file mode 100644 index 0000000..5d38229 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/JudgeNullUtilTest.java @@ -0,0 +1,43 @@ +/** + * Copyright 2016 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.common.utils; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.List; +import org.junit.Test; + +public class JudgeNullUtilTest { + + @Test + public void isEmpty_array_length_zero() { + boolean resultShorts = JudgeNullUtil.isEmpty(new short[]{}); + boolean resultInts = JudgeNullUtil.isEmpty(new int[]{}); + boolean resultLongs = JudgeNullUtil.isEmpty(new long[]{}); + boolean resultObjects = JudgeNullUtil.isEmpty(new Object[]{}); + boolean resultStrings = JudgeNullUtil.isEmpty(new String[]{}); + boolean resultLists = JudgeNullUtil.isEmpty(new List[]{}); + assertThat(true, equalTo(resultShorts)); + assertThat(true, equalTo(resultInts)); + assertThat(true, equalTo(resultLongs)); + assertThat(true, equalTo(resultObjects)); + assertThat(true, equalTo(resultStrings)); + assertThat(true, equalTo(resultLists)); + } +} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/LanguageUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/LanguageUtilTest.java new file mode 100644 index 0000000..06759ec --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/LanguageUtilTest.java @@ -0,0 +1,118 @@ +/** + * 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.common.utils; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.Locale; +import javax.servlet.http.HttpServletRequest; +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; +import org.onap.holmes.common.constant.AlarmConst; +import org.powermock.api.easymock.PowerMock; + + +public class LanguageUtilTest { + + private HttpServletRequest request; + + @Before + public void setUp() { + request = PowerMock.createMock(HttpServletRequest.class); + } + + @Test + public void getLanguage_header_language_empty() { + EasyMock.expect(request.getHeader("language-option")).andReturn(""); + + PowerMock.replayAll(); + + String language = LanguageUtil.getLanguage(request); + + PowerMock.verifyAll(); + + assertThat(AlarmConst.I18N_EN, equalTo(language)); + } + + @Test + public void getLanguage_zh() { + EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_ZH); + + PowerMock.replayAll(); + + String language = LanguageUtil.getLanguage(request); + + PowerMock.verifyAll(); + + assertThat(AlarmConst.I18N_ZH, equalTo(language)); + } + + @Test + public void getLanguage_en() { + EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_EN); + + PowerMock.replayAll(); + + String language = LanguageUtil.getLanguage(request); + + PowerMock.verifyAll(); + + assertThat(AlarmConst.I18N_EN, equalTo(language)); + } + + @Test + public void getLocale_header_language_empty() { + EasyMock.expect(request.getHeader("language-option")).andReturn(""); + + PowerMock.replayAll(); + + Locale locale = LanguageUtil.getLocale(request); + + PowerMock.verifyAll(); + + assertThat(new Locale(AlarmConst.I18N_EN), equalTo(locale)); + } + + @Test + public void getLocale_zh() { + EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_ZH); + + PowerMock.replayAll(); + + Locale locale = LanguageUtil.getLocale(request); + + PowerMock.verifyAll(); + + assertThat(new Locale(AlarmConst.I18N_ZH), equalTo(locale)); + } + + @Test + public void getLocale_en() { + EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_EN); + + PowerMock.replayAll(); + + Locale locale = LanguageUtil.getLocale(request); + + PowerMock.verifyAll(); + + assertThat(new Locale(AlarmConst.I18N_EN), equalTo(locale)); + } +} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java new file mode 100644 index 0000000..a38c26e --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java @@ -0,0 +1,72 @@ +/** + * 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.common.utils; + +import com.eclipsesource.jaxrs.consumer.ConsumerFactory; +import javax.ws.rs.QueryParam; +import org.easymock.EasyMock; +import org.junit.Rule; +import org.junit.Test; +import org.onap.holmes.common.msb.MicroserviceBusRest; +import org.onap.holmes.common.api.entity.ServiceRegisterEntity; +import org.onap.holmes.common.config.MicroServiceConfig; +import org.powermock.api.easymock.PowerMock; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.rule.PowerMockRule; + +@PrepareForTest(ConsumerFactory.class) +public class MSBRegisterUtilTest { + + @Rule + public PowerMockRule powerMockRule = new PowerMockRule(); + private MSBRegisterUtil msbRegisterUtil = new MSBRegisterUtil(); + private MicroserviceBusRest microserviceBusRest = new MicroserviceBusRestProxy(); + + @Test + public void registerTest() throws Exception { + ServiceRegisterEntity entity = initServiceEntity(); + PowerMock.mockStatic(ConsumerFactory.class); + EasyMock.expect(ConsumerFactory + .createConsumer(EasyMock.anyObject(String.class), EasyMock.anyObject(Class.class))) + .andReturn(microserviceBusRest); + PowerMock.replayAll(); + + msbRegisterUtil.register(initServiceEntity()); + + PowerMock.verifyAll(); + } + + private ServiceRegisterEntity initServiceEntity() { + ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity(); + serviceRegisterEntity.setServiceName("holmes-rule-mgmt"); + serviceRegisterEntity.setProtocol("REST"); + serviceRegisterEntity.setVersion("v1"); + serviceRegisterEntity.setUrl("/onapapi/holmes-rule-mgmt/v1"); + serviceRegisterEntity.setSingleNode(MicroServiceConfig.getServiceIp(), "9101", 0); + serviceRegisterEntity.setVisualRange("1|0"); + return serviceRegisterEntity; + } + + class MicroserviceBusRestProxy implements MicroserviceBusRest { + + @Override + public ServiceRegisterEntity registerServce(@QueryParam("createOrUpdate") String createOrUpdate, + ServiceRegisterEntity entity) { + return null; + } + } +} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/UserUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/UserUtilTest.java new file mode 100644 index 0000000..d88525a --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/UserUtilTest.java @@ -0,0 +1,67 @@ +/** + * 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.common.utils; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import javax.servlet.http.HttpServletRequest; +import org.easymock.EasyMock; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.powermock.api.easymock.PowerMock; +public class UserUtilTest { + + private HttpServletRequest request; + + @Before + public void before() throws Exception { + request = PowerMock.createMock(HttpServletRequest.class); + } + + @After + public void after() throws Exception { + } + + @Test + public void getUserName_header_name_empty() throws Exception { + EasyMock.expect(request.getHeader("username")).andReturn(null); + + PowerMock.replayAll(); + + String userName = UserUtil.getUserName(request); + + PowerMock.verifyAll(); + + assertThat("admin", equalTo(userName)); + } + + @Test + public void getUserName_normal() throws Exception { + EasyMock.expect(request.getHeader("username")).andReturn("name1"); + + PowerMock.replayAll(); + + String userName = UserUtil.getUserName(request); + + PowerMock.verifyAll(); + + assertThat("name1", equalTo(userName)); + } + +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/bean/TestBean.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/bean/TestBean.java new file mode 100644 index 0000000..d8466d4 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/bean/TestBean.java @@ -0,0 +1,32 @@ +/** + * Copyright 2016 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.common.utils.bean; + +import java.io.Serializable; + +public class TestBean implements Serializable { + String id; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } +} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/AlarmsCorrelationTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/AlarmsCorrelationTest.java deleted file mode 100644 index 7dc1fab..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/AlarmsCorrelationTest.java +++ /dev/null @@ -1,133 +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.openo.holmes.common.api.entity; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.Date; -import org.junit.Test; -import org.junit.Before; -import org.junit.After; -import sun.util.resources.cldr.ga.LocaleNames_ga; - -public class AlarmsCorrelationTest { - - private AlarmsCorrelation alarmsCorrelation; - - @Before - public void before() throws Exception { - alarmsCorrelation = new AlarmsCorrelation(); - } - - @After - public void after() throws Exception { - - } - - - @Test - public void getterAndSetter4RuleId() throws Exception { - final String ruleId = "ruleId"; - alarmsCorrelation.setRuleId(ruleId); - assertThat(alarmsCorrelation.getRuleId(), equalTo(ruleId)); - } - - - @Test - public void getterAndSetter4RuleInfo() throws Exception { - final String ruleInfo = "ruleInfo"; - alarmsCorrelation.setRuleInfo(ruleInfo); - assertThat(alarmsCorrelation.getRuleInfo(), equalTo(ruleInfo)); - } - - - @Test - public void getterAndSetter4ResultType() throws Exception { - final byte resultType = 1; - alarmsCorrelation.setResultType(resultType); - assertThat(alarmsCorrelation.getResultType(), equalTo(resultType)); - } - - - @Test - public void getterAndSetter4CreateTime() throws Exception { - final Date createTime = new Date(); - alarmsCorrelation.setCreateTime(createTime); - assertThat(alarmsCorrelation.getCreateTime(), equalTo(createTime)); - } - - - @Test - public void getterAndSetter4ParentAlarmId() throws Exception { - final long pad = 11L; - alarmsCorrelation.setParentAlarmId(pad); - assertThat(alarmsCorrelation.getParentAlarmId(), equalTo(pad)); - } - - - @Test - public void getterAndSetter4ChildAlarmId() throws Exception { - final long childAlarmId = 11L; - alarmsCorrelation.setChildAlarmId(childAlarmId); - assertThat(alarmsCorrelation.getChildAlarmId(), equalTo(childAlarmId)); - } - - - @Test - public void getterAndSetter4Reserve1() throws Exception { - final long reserve1 = 11L; - alarmsCorrelation.setReserve1(reserve1); - assertThat(alarmsCorrelation.getReserve1(), equalTo(reserve1)); - } - - - @Test - public void getterAndSetter4Reserve2() throws Exception { - final long reserve2 = 11L; - alarmsCorrelation.setReserve2(reserve2); - assertThat(alarmsCorrelation.getReserve2(), equalTo(reserve2)); - } - - - @Test - public void getterAndSetter4Reserve3() throws Exception { - final long reserve3 = 11L; - alarmsCorrelation.setReserve3(reserve3); - assertThat(alarmsCorrelation.getReserve3(), equalTo(reserve3)); - } - - - @Test - public void testToString() throws Exception { - final AlarmsCorrelation alarmsCorrelationTemp = new AlarmsCorrelation(); - String ruleId = "ruleId"; - alarmsCorrelationTemp.setRuleId(ruleId); - alarmsCorrelation.setRuleId(ruleId); - assertThat(alarmsCorrelation.toString(), equalTo(alarmsCorrelationTemp.toString())); - } - - - @Test - public void testEqualsAndHashCode() throws Exception { - final AlarmsCorrelation alarmsCorrelationTemp = new AlarmsCorrelation(); - String ruleId = "ruleId"; - alarmsCorrelationTemp.setRuleId(ruleId); - alarmsCorrelation.setRuleId(ruleId); - assertThat(alarmsCorrelation, equalTo(alarmsCorrelationTemp)); - } -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationResultTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationResultTest.java deleted file mode 100644 index 14a52c0..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationResultTest.java +++ /dev/null @@ -1,78 +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.openo.holmes.common.api.entity; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.Date; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openo.holmes.common.api.stat.Alarm; - -public class CorrelationResultTest { - - private CorrelationResult correlationResult; - - @Before - public void before() throws Exception { - correlationResult = new CorrelationResult(); - } - - @After - public void after() throws Exception { - } - - @Test - public void getterAndSetter4RuleId() throws Exception { - final String ruleId = "ruleId"; - correlationResult.setRuleId(ruleId); - assertThat(correlationResult.getRuleId(), equalTo(ruleId)); - } - - @Test - public void getterAndSetter4CreateTimeL() throws Exception { - final long createTimeL = new Date().getTime(); - correlationResult.setCreateTimeL( - createTimeL); - assertThat(correlationResult.getCreateTimeL(), equalTo(createTimeL)); - } - - @Test - public void getterAndSetter4GetResultType() throws Exception { - final byte resultType = 2; - correlationResult.setResultType(resultType); - assertThat(correlationResult.getResultType(), equalTo(resultType)); - } - - @Test - public void getterAndSetter4AffectedAlarms() throws Exception { - final Alarm alarm[] = new Alarm[2]; - correlationResult.setAffectedAlarms(alarm); - assertThat(correlationResult.getAffectedAlarms(), equalTo(alarm)); - } - - @Test - public void testToString() throws Exception { - CorrelationResult resultTemp = new CorrelationResult(); - final String tempStr = "aa"; - resultTemp.setRuleId(tempStr); - correlationResult.setRuleId(tempStr); - assertThat(correlationResult.toString(), equalTo(resultTemp.toString())); - } -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationRuleTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationRuleTest.java deleted file mode 100644 index 8b6268c..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationRuleTest.java +++ /dev/null @@ -1,146 +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.openo.holmes.common.api.entity; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.Date; -import java.util.Properties; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class CorrelationRuleTest { - - private CorrelationRule correlationRule; - - @Before - public void before() throws Exception { - correlationRule = new CorrelationRule(); - } - - @After - public void after() throws Exception { - - } - - @Test - public void getterAndSetter4Rid() throws Exception { - final String rid = "rid"; - correlationRule.setRid(rid); - assertThat(correlationRule.getRid(), equalTo(rid)); - } - - @Test - public void getterAndSetter4Name() throws Exception { - final String name = "name"; - correlationRule.setName(name); - assertThat(correlationRule.getName(), equalTo(name)); - } - - @Test - public void getterAndSetter4Description() throws Exception { - final String description = "description"; - correlationRule.setDescription(description); - assertThat(correlationRule.getDescription(), equalTo(description)); - } - - @Test - public void getterAndSetter4Enabled() throws Exception { - final int enabled = 1; - correlationRule.setEnabled(enabled); - assertThat(correlationRule.getEnabled(), equalTo(enabled)); - } - - @Test - public void getterAndSetter4TemplateID() throws Exception { - final int templateId = 1; - correlationRule.setTemplateID(templateId); - assertThat(correlationRule.getTemplateID(), equalTo(templateId)); - } - - @Test - public void getterAndSetter4EngineId() throws Exception { - final String engineId = "engineId"; - correlationRule.setEngineID(engineId); - assertThat(correlationRule.getEngineID(), equalTo(engineId)); - } - - @Test - public void getterAndSetter4EngineType() throws Exception { - final String engineType = "engineType"; - correlationRule.setEngineType(engineType); - assertThat(correlationRule.getEngineType(), equalTo(engineType)); - } - - @Test - public void getterAndSetter4Creator() throws Exception { - final String creator = "creator"; - correlationRule.setCreator(creator); - assertThat(correlationRule.getCreator(), equalTo(creator)); - } - - @Test - public void getterAndSetter4Modifier() throws Exception { - final String modifier = "modifier"; - correlationRule.setModifier(modifier); - assertThat(correlationRule.getModifier(), equalTo(modifier)); - } - - @Test - public void getterAndSetter4Params() throws Exception { - final Properties params = new Properties(); - correlationRule.setParams(params); - assertThat(correlationRule.getParams(), equalTo(params)); - } - - @Test - public void getterAndSetter4Content() throws Exception { - final String content = "content"; - correlationRule.setContent(content); - assertThat(correlationRule.getContent(), equalTo(content)); - } - - @Test - public void getterAndSetter4Vendor() throws Exception { - final String vendor = "vendor"; - correlationRule.setVendor(vendor); - assertThat(correlationRule.getVendor(), equalTo(vendor)); - } - - @Test - public void getterAndSetter4CreateTime() throws Exception { - Date createTime = new Date(); - correlationRule.setCreateTime(createTime); - assertThat(correlationRule.getCreateTime(), equalTo(createTime)); - } - - @Test - public void getterAndSetter4UpdateTime() throws Exception { - final Date updateTime = new Date(); - correlationRule.setUpdateTime(updateTime); - assertThat(correlationRule.getUpdateTime(), equalTo(updateTime)); - } - - @Test - public void getterAndSetter4PackageName() throws Exception { - final String packageName = "packageName"; - correlationRule.setPackageName(packageName); - assertThat(correlationRule.getPackageName(), equalTo(packageName)); - } -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/ServiceNodeTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/ServiceNodeTest.java deleted file mode 100644 index 383cb91..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/ServiceNodeTest.java +++ /dev/null @@ -1,48 +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.openo.holmes.common.api.entity; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import org.junit.Test; - -public class ServiceNodeTest { - - private ServiceNode serviceNode = new ServiceNode(); - - @Test - public void getterAndSetter4ip() { - String ip = "test"; - serviceNode.setIp(ip); - assertThat(serviceNode.getIp(), equalTo(ip)); - } - - @Test - public void getterAndSetter4port() { - String port = "test"; - serviceNode.setPort(port); - assertThat(serviceNode.getPort(), equalTo(port)); - } - - @Test - public void getterAndSetter4ttl() { - int ttl = 1; - serviceNode.setTtl(ttl); - assertThat(serviceNode.getTtl(), equalTo(ttl)); - } -} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/ServiceRegisterEntityTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/ServiceRegisterEntityTest.java deleted file mode 100644 index 442549d..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/ServiceRegisterEntityTest.java +++ /dev/null @@ -1,62 +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.openo.holmes.common.api.entity; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import org.junit.Test; - -public class ServiceRegisterEntityTest { - - private ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity(); - - @Test - public void getterAndSetter4protocol() { - String protocol = "test"; - serviceRegisterEntity.setProtocol(protocol); - assertThat(serviceRegisterEntity.getProtocol(), equalTo(protocol)); - } - - @Test - public void getterAndSetter4serviceName() { - String serviceName = "test"; - serviceRegisterEntity.setServiceName(serviceName); - assertThat(serviceRegisterEntity.getServiceName(), equalTo(serviceName)); - } - - @Test - public void getterAndSetter4url() { - String url = "test"; - serviceRegisterEntity.setUrl(url); - assertThat(serviceRegisterEntity.getUrl(), equalTo(url)); - } - - @Test - public void getterAndSetter4version() { - String version = "test"; - serviceRegisterEntity.setVersion(version); - assertThat(serviceRegisterEntity.getVersion(), equalTo(version)); - } - - @Test - public void getterAndSetter4visualRange() { - String visualRange = "test"; - serviceRegisterEntity.setVisualRange(visualRange); - assertThat(serviceRegisterEntity.getVisualRange(), equalTo(visualRange)); - } -} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java deleted file mode 100644 index c42ee60..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java +++ /dev/null @@ -1,207 +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.openo.holmes.common.api.stat; - -import java.util.Date; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.HashMap; -import java.util.Map; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -public class AlarmTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private Alarm alarm; - - @Before - public void before() throws Exception { - alarm = new Alarm(); - } - - @After - public void after() throws Exception { - } - - @Test - public void testCompareLinkPosition_isEmpty() throws Exception { - final Map otherIdIdx = new HashMap<>(); - assertThat(999, equalTo(alarm.CompareLinkPosition(otherIdIdx))); - } - - @Test - public void testCompareLinkPosition_TempLinkId() throws Exception { - final Map otherIdIdx = new HashMap<>(); - otherIdIdx.put(1, 2); - alarm.addLinkIdNodeIdx(1, 3); - assertThat(1, equalTo(alarm.CompareLinkPosition(otherIdIdx))); - } - - @Test - public void testContainNode_NoContainLink() throws Exception { - alarm.addLinkIdNodeIdx(1, 2); - assertThat(false, equalTo(alarm.containNode(2, 2))); - } - - @Test - public void testContainNode_ContainLinkNoIdx() throws Exception { - alarm.addLinkIdNodeIdx(1, 2); - assertFalse(alarm.containNode(1, 3)); - } - - @Test - public void testContainNode_ContainLinkAndIdx() throws Exception { - alarm.addLinkIdNodeIdx(1, 2); - assertTrue(alarm.containNode(1, 2)); - } - - @Test - public void testGetDataType() throws Exception { - assertThat(Alarm.APLUS_EVENT, equalTo(alarm.getDataType())); - } - - @Test - public void testToString() throws Exception { - Alarm alarmTempA = new Alarm(); - Alarm alarmTempB = new Alarm(); - Date date = new Date(); - alarmTempA.setClearedTime(date); - alarmTempA.setRaisedTime(date); - alarmTempA.setRaisedServerTime(date); - alarmTempB.setClearedTime(date); - alarmTempB.setRaisedTime(date); - alarmTempB.setRaisedServerTime(date); - assertThat(alarmTempA.toString(),equalTo(alarmTempB.toString())); - } - - @Test - public void testHashCode() throws Exception { - final Alarm alarmTemp = new Alarm(); - final String alarmKey = "alarmKey"; - alarm.setAlarmKey(alarmKey); - alarmTemp.setAlarmKey(alarmKey); - assertThat(alarm.hashCode(), equalTo(alarmTemp.hashCode())); - } - - @Test - public void testEqualsAnd_NotNull() throws Exception { - final Alarm alarmTemp = new Alarm(); - final String alarmKey = "alarmKey"; - alarm.setAlarmKey(alarmKey); - alarmTemp.setAlarmKey(alarmKey); - assertTrue(alarm.equals(alarmTemp)); - } - - @Test - public void testEqualsAndH_isNull() throws Exception { - assertFalse(alarm.equals(null)); - } - - @Test - public void testClone() throws Exception { - alarm.setAlarmKey("alarmKey"); - Alarm alarmTemp = (Alarm) alarm.clone(); - assertTrue(alarm.equals(alarmTemp)); - assertFalse(alarm == alarmTemp); - } - - @Test - public void testGetObjectId() throws Exception { - alarm.setId(11); - assertThat("11", equalTo(alarm.getObjectId())); - } - - @Test - public void testAddLinkIds() throws Exception { - final int linkId = 11; - alarm.addLinkIds(linkId); - assertTrue(alarm.getLinkIds().contains(linkId)); - } - - @Test - public void testContainsPriority_true() throws Exception { - String ruleId = "ruleId"; - alarm.getPriorityMap().put(ruleId, 2); - assertTrue(alarm.containsPriority(ruleId)); - } - - @Test - public void testContainsPriority_false() throws Exception { - final String ruleId = "ruleId"; - assertFalse(alarm.containsPriority(ruleId)); - } - - @Test - public void testGetPriority_isNull() throws Exception { - final String ruleId = "ruleId"; - alarm.getPriorityMap().put(ruleId, null); - assertThat(0, equalTo(alarm.getPriority(ruleId))); - } - - @Test - public void testGetPriority_notNull() throws Exception { - final String ruleId = "ruleId"; - final int priority = 2; - alarm.getPriorityMap().put(ruleId, priority); - assertThat(priority, equalTo(alarm.getPriority(ruleId))); - } - - @Test - public void testGetAlarmTypeRuleId_isNull() throws Exception { - final String ruleId = "ruleId"; - alarm.getRootAlarmTypeMap().put(ruleId, null); - assertThat(-1, equalTo(alarm.getRootAlarmType(ruleId))); - } - - @Test - public void testGetAlarmTypeRuleId_notNull() throws Exception { - final String ruleId = "ruleId"; - final int rootAlarmType = 2; - alarm.getRootAlarmTypeMap().put(ruleId, rootAlarmType); - assertThat(rootAlarmType, equalTo(alarm.getRootAlarmType(ruleId))); - } - - @Test - public void getterAndSetter4CenterType() throws Exception { - final int centerType = 1; - alarm.setCenterType(centerType); - assertThat(centerType, equalTo(alarm.getCenterType())); - } - - @Test - public void valueOf_exception() { - thrown.expect(Exception.class); - String xmlString = ""; - Alarm.valueOf(xmlString); - } - - @Test - public void valueOf_normal() { - String xmlString = alarm.toString(); - Alarm alarmValue = Alarm.valueOf(xmlString); - assertThat(alarmValue, equalTo(alarm)); - } -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/config/MQConfigTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/config/MQConfigTest.java deleted file mode 100644 index bb79c8a..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/config/MQConfigTest.java +++ /dev/null @@ -1,28 +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.openo.holmes.common.config; - -import org.junit.Test; -import org.junit.Before; -import org.junit.After; - -public class MQConfigTest { - @Test - public void testNewClass() { - MQConfig mqConfig= new MQConfig(); - } -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/config/MicroServiceConfigTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/config/MicroServiceConfigTest.java deleted file mode 100644 index 7ec7fe6..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/config/MicroServiceConfigTest.java +++ /dev/null @@ -1,39 +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.openo.holmes.common.config; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import org.junit.Test; - -public class MicroServiceConfigTest { - - @Test - public void getMsbServerAddrTest() { - System.setProperty("MSB_ADDR", "test"); - assertThat("http://test", equalTo(MicroServiceConfig.getMsbServerAddr())); - System.clearProperty("MSB_ADDR"); - } - - @Test - public void getServiceIpTest() { - System.setProperty("SERVICE_IP", "test"); - assertThat("test", equalTo(MicroServiceConfig.getServiceIp())); - System.clearProperty("SERVICE_IP"); - } -} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/exception/CorrelationExceptionTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/exception/CorrelationExceptionTest.java deleted file mode 100644 index bca63b2..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/exception/CorrelationExceptionTest.java +++ /dev/null @@ -1,29 +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.openo.holmes.common.exception; - -import org.junit.Test; -import org.junit.Before; -import org.junit.After; - -public class CorrelationExceptionTest { - @Test - public void testConstructors() throws Exception { - CorrelationException ce1 = new CorrelationException("msg", new Exception()); - CorrelationException ce2 = new CorrelationException("msg"); - } -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/producer/MQProducerTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/producer/MQProducerTest.java deleted file mode 100644 index 1390b77..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/producer/MQProducerTest.java +++ /dev/null @@ -1,173 +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.openo.holmes.common.producer; - -import static org.easymock.EasyMock.anyBoolean; -import static org.easymock.EasyMock.anyInt; -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.expect; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.MessageProducer; -import javax.jms.ObjectMessage; -import javax.jms.Session; -import javax.jms.Topic; -import org.glassfish.hk2.api.IterableProvider; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.openo.holmes.common.api.entity.CorrelationResult; -import org.openo.holmes.common.api.stat.Alarm; -import org.openo.holmes.common.config.MQConfig; -import org.powermock.api.easymock.PowerMock; -import org.powermock.modules.junit4.rule.PowerMockRule; -import org.powermock.reflect.Whitebox; - -public class MQProducerTest { - - @Rule - public PowerMockRule powerMockRule = new PowerMockRule(); - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private IterableProvider mqConfigProvider; - - private ConnectionFactory connectionFactory; - - private MQProducer mqProducer; - - @Before - public void before() throws Exception { - mqProducer = new MQProducer(); - - mqConfigProvider = PowerMock.createMock(IterableProvider.class); - connectionFactory = PowerMock.createMock(ConnectionFactory.class); - - Whitebox.setInternalState(mqProducer, "mqConfigProvider", mqConfigProvider); - Whitebox.setInternalState(mqProducer, "connectionFactory", connectionFactory); - PowerMock.resetAll(); - } - - @Test - public void init() { - MQConfig mqConfig = new MQConfig(); - mqConfig.brokerIp = "127.0.0.1"; - mqConfig.brokerPort = 61616; - mqConfig.brokerPassword = "admin"; - mqConfig.brokerUsername = "admin"; - expect(mqConfigProvider.get()).andReturn(mqConfig).anyTimes(); - - PowerMock.replayAll(); - - mqProducer.init(); - - PowerMock.verifyAll(); - } - - @Test - public void sendAlarmMQTopicMsg() throws Exception { - Alarm alarm = new Alarm(); - Connection connection = PowerMock.createMock(Connection.class); - Session session = PowerMock.createMock(Session.class); - Destination destination = PowerMock.createMock(Topic.class); - MessageProducer messageProducer = PowerMock.createMock(MessageProducer.class); - ObjectMessage objMessage = PowerMock.createMock(ObjectMessage.class); - - expect(connectionFactory.createConnection()).andReturn(connection); - connection.start(); - expect(connection.createSession(anyBoolean(), anyInt())).andReturn(session); - expect(session.createTopic(anyObject(String.class))).andReturn((Topic) destination); - expect(session.createProducer(anyObject(Destination.class))).andReturn(messageProducer); - - expect(session.createObjectMessage(anyObject(Alarm.class))).andReturn(objMessage); - messageProducer.send(objMessage); - session.commit(); - connection.close(); - - PowerMock.replayAll(); - - mqProducer.sendAlarmMQTopicMsg(alarm); - - PowerMock.verifyAll(); - - } - - @Test - public void sendAlarmMQTopicMsg_exception() throws Exception { - thrown.expect(JMSException.class); - Alarm alarm = new Alarm(); - - expect(connectionFactory.createConnection()).andThrow(new JMSException("")); - - PowerMock.replayAll(); - - mqProducer.sendAlarmMQTopicMsg(alarm); - - PowerMock.verifyAll(); - } - - @Test - public void sendCorrelationMQTopicMsg() throws Exception { - - Connection connection = PowerMock.createMock(Connection.class); - Session session = PowerMock.createMock(Session.class); - Destination destination = PowerMock.createMock(Topic.class); - MessageProducer messageProducer = PowerMock.createMock(MessageProducer.class); - ObjectMessage objMessage = PowerMock.createMock(ObjectMessage.class); - - expect(connectionFactory.createConnection()).andReturn(connection); - connection.start(); - expect(connection.createSession(anyBoolean(), anyInt())).andReturn(session); - expect(session.createTopic(anyObject(String.class))).andReturn((Topic) destination); - expect(session.createProducer(anyObject(Destination.class))).andReturn(messageProducer); - - expect(session.createObjectMessage(anyObject(CorrelationResult.class))) - .andReturn(objMessage); - messageProducer.send(objMessage); - session.commit(); - connection.close(); - - PowerMock.replayAll(); - - Alarm parentAlarm = new Alarm(); - Alarm childAlarm = new Alarm(); - mqProducer.sendCorrelationMQTopicMsg("ruleId", 123L, parentAlarm, childAlarm); - - PowerMock.verifyAll(); - - } - - @Test - public void sendCorrelationMQTopicMsg_exception() throws Exception { - thrown.expect(JMSException.class); - - expect(connectionFactory.createConnection()).andThrow(new JMSException("")); - - PowerMock.replayAll(); - - Alarm parentAlarm = new Alarm(); - Alarm childAlarm = new Alarm(); - mqProducer.sendCorrelationMQTopicMsg("ruleId", 123L, parentAlarm, childAlarm); - - PowerMock.verifyAll(); - - } -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/DbDaoUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/DbDaoUtilTest.java deleted file mode 100644 index 18c774e..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/DbDaoUtilTest.java +++ /dev/null @@ -1,188 +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.openo.holmes.common.utils; - -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.expect; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import io.dropwizard.db.DataSourceFactory; -import io.dropwizard.jdbi.DBIFactory; -import io.dropwizard.setup.Environment; -import org.easymock.EasyMock; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.powermock.api.easymock.PowerMock; -import org.powermock.modules.junit4.rule.PowerMockRule; -import org.powermock.reflect.Whitebox; -import org.skife.jdbi.v2.DBI; -import org.skife.jdbi.v2.Handle; - -public class DbDaoUtilTest { - - @Rule - public PowerMockRule powerMockRule = new PowerMockRule(); - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private DBI jdbi; - - private Environment environmentProvider; - - private DataSourceFactory dataSourceFactoryProvider; - - private DbDaoUtil dbDaoUtil; - - private DBIFactory factory; - - @Before - public void before() throws Exception { - dbDaoUtil = new DbDaoUtil(); - - jdbi = PowerMock.createMock(DBI.class); - environmentProvider = PowerMock.createMock(Environment.class); - dataSourceFactoryProvider = PowerMock.createMock(DataSourceFactory.class); - factory = PowerMock.createMock(DBIFactory.class); - - Whitebox.setInternalState(dbDaoUtil, "environmentProvider", environmentProvider); - Whitebox.setInternalState(dbDaoUtil, "dataSourceFactoryProvider", - dataSourceFactoryProvider); - Whitebox.setInternalState(dbDaoUtil, "factory", factory); - - PowerMock.resetAll(); - } - - @Test - public void init() throws Exception { - DBI jdbi = PowerMock.createMock(DBI.class); - - expect(factory.build(anyObject(Environment.class), anyObject(DataSourceFactory.class), - anyObject(String.class))).andReturn(jdbi); - - PowerMock.replayAll(); - - dbDaoUtil.init(); - - PowerMock.verifyAll(); - } - - @Test - public void getDao_normal() throws Exception { - Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); - expect(jdbi.open(anyObject(Class.class))).andReturn(Class.class); - - PowerMock.replayAll(); - - dbDaoUtil.getDao(String.class); - - PowerMock.verifyAll(); - } - - @Test - public void getDao_exception() throws Exception { - Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); - - expect(jdbi.open(anyObject(Class.class))).andThrow(new RuntimeException("")); - - PowerMock.replayAll(); - - Object o = dbDaoUtil.getDao(String.class); - - PowerMock.verifyAll(); - - assertThat(o, equalTo(null)); - } - - @Test - public void getHandle_normal() throws Exception { - Handle handle = PowerMock.createMock(Handle.class); - - Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); - expect(jdbi.open()).andReturn(handle); - - PowerMock.replayAll(); - - dbDaoUtil.getHandle(); - - PowerMock.verifyAll(); - } - @Test - public void getHandle_exception() throws Exception { - Handle handle = PowerMock.createMock(Handle.class); - - Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); - expect(jdbi.open()).andThrow(new RuntimeException("")); - - PowerMock.replayAll(); - - Handle handle1 = dbDaoUtil.getHandle(); - - PowerMock.verifyAll(); - - assertThat(handle1, equalTo(null)); - } - - @Test - public void close_normal() throws Exception { - Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); - jdbi.close(anyObject()); - - PowerMock.replayAll(); - - dbDaoUtil.close(new Object()); - - PowerMock.verifyAll(); - } - - @Test - public void close_exception() throws Exception { - Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); - jdbi.close(anyObject()); - EasyMock.expectLastCall().andThrow(new RuntimeException("")); - PowerMock.replayAll(); - - dbDaoUtil.close(new Object()); - - PowerMock.verifyAll(); - } - @Test - public void testGetJdbiDaoByOnDemand() throws Exception { - Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); - expect(jdbi.onDemand(anyObject(Class.class))).andReturn(Class.class); - - PowerMock.replayAll(); - - dbDaoUtil.getJdbiDaoByOnDemand(String.class); - - PowerMock.verifyAll(); - } - - @Test - public void testGetJdbiDaoByOpen() throws Exception { - Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); - expect(jdbi.open(anyObject(Class.class))).andReturn(Class.class); - - PowerMock.replayAll(); - - dbDaoUtil.getJdbiDaoByOpen(String.class); - - PowerMock.verifyAll(); - } -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/ExceptionUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/ExceptionUtilTest.java deleted file mode 100644 index caa45e3..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/ExceptionUtilTest.java +++ /dev/null @@ -1,31 +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.openo.holmes.common.utils; - -import static org.openo.holmes.common.utils.ExceptionUtil.buildExceptionResponse; - -import org.junit.Test; - -public class ExceptionUtilTest { - - @Test - public void testBuildExceptionResponse() throws Exception { - buildExceptionResponse("test"); - } - - -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/I18nProxyTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/I18nProxyTest.java deleted file mode 100644 index c3631ac..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/I18nProxyTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright 2016 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.openo.holmes.common.utils; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.Locale; -import java.util.Map; -import org.junit.Before; -import org.junit.Test; - -public class I18nProxyTest { - - private I18nProxy i18nProxy; - - @Before - public void setUp() { - i18nProxy = I18nProxy.getInstance(); - } - - @Test - public void getValue_locale_and_key() { - String result = i18nProxy.getValue(new Locale("zh"), "test"); - assertThat(result, equalTo(null)); - } - @Test - public void getValueByArgs(){ - String result = i18nProxy.getValueByArgs(new Locale("zh"), "test",new String[]{"1"}); - assertThat(result,equalTo(null)); - } - @Test - public void getValue_by_key(){ - Map result = i18nProxy.getValue("test"); - assertThat(result, equalTo(null)); - } - @Test - public void jsonI18n(){ - String result = i18nProxy.jsonI18n("test"); - assertThat(result,equalTo(null)); - } - @Test - public void i18nWithArgs(){ - String result = i18nProxy.i18nWithArgs("test",new String[]{}); - assertThat(result,equalTo("null")); - } -} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/JacksonUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/JacksonUtilTest.java deleted file mode 100644 index 22d628e..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/JacksonUtilTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright 2016 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.openo.holmes.common.utils; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import org.junit.Test; -import org.openo.holmes.common.utils.bean.TestBean; - -public class JacksonUtilTest { - - @Test - public void testBeanToJson() throws Exception { - TestBean o = new TestBean(); - o.setId("id"); - String result = JacksonUtil.beanToJson(o); - assertThat("{\"id\":\"id\"}", equalTo(result)); - } - - @Test - public void jsonToBean_json_null() throws Exception { - String jsonNull = null; - TestBean testBean = JacksonUtil.jsonToBean(jsonNull, TestBean.class); - assertThat(testBean.getId(), equalTo(null)); - } - - @Test - public void jsonToBean_json_normal() throws Exception { - String json = "{\"id\":\"id\"}"; - TestBean testBean = JacksonUtil.jsonToBean(json, TestBean.class); - assertThat(testBean.getId(), equalTo("id")); - } -} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/JudgeNullUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/JudgeNullUtilTest.java deleted file mode 100644 index a2a0542..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/JudgeNullUtilTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2016 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.openo.holmes.common.utils; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.List; -import org.junit.Test; - -public class JudgeNullUtilTest { - - @Test - public void isEmpty_array_length_zero() { - boolean resultShorts = JudgeNullUtil.isEmpty(new short[]{}); - boolean resultInts = JudgeNullUtil.isEmpty(new int[]{}); - boolean resultLongs = JudgeNullUtil.isEmpty(new long[]{}); - boolean resultObjects = JudgeNullUtil.isEmpty(new Object[]{}); - boolean resultStrings = JudgeNullUtil.isEmpty(new String[]{}); - boolean resultLists = JudgeNullUtil.isEmpty(new List[]{}); - assertThat(true, equalTo(resultShorts)); - assertThat(true, equalTo(resultInts)); - assertThat(true, equalTo(resultLongs)); - assertThat(true, equalTo(resultObjects)); - assertThat(true, equalTo(resultStrings)); - assertThat(true, equalTo(resultLists)); - } -} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/LanguageUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/LanguageUtilTest.java deleted file mode 100644 index d688a35..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/LanguageUtilTest.java +++ /dev/null @@ -1,118 +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.openo.holmes.common.utils; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.Locale; -import javax.servlet.http.HttpServletRequest; -import org.easymock.EasyMock; -import org.junit.Before; -import org.junit.Test; -import org.openo.holmes.common.constant.AlarmConst; -import org.powermock.api.easymock.PowerMock; - - -public class LanguageUtilTest { - - private HttpServletRequest request; - - @Before - public void setUp() { - request = PowerMock.createMock(HttpServletRequest.class); - } - - @Test - public void getLanguage_header_language_empty() { - EasyMock.expect(request.getHeader("language-option")).andReturn(""); - - PowerMock.replayAll(); - - String language = LanguageUtil.getLanguage(request); - - PowerMock.verifyAll(); - - assertThat(AlarmConst.I18N_EN, equalTo(language)); - } - - @Test - public void getLanguage_zh() { - EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_ZH); - - PowerMock.replayAll(); - - String language = LanguageUtil.getLanguage(request); - - PowerMock.verifyAll(); - - assertThat(AlarmConst.I18N_ZH, equalTo(language)); - } - - @Test - public void getLanguage_en() { - EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_EN); - - PowerMock.replayAll(); - - String language = LanguageUtil.getLanguage(request); - - PowerMock.verifyAll(); - - assertThat(AlarmConst.I18N_EN, equalTo(language)); - } - - @Test - public void getLocale_header_language_empty() { - EasyMock.expect(request.getHeader("language-option")).andReturn(""); - - PowerMock.replayAll(); - - Locale locale = LanguageUtil.getLocale(request); - - PowerMock.verifyAll(); - - assertThat(new Locale(AlarmConst.I18N_EN), equalTo(locale)); - } - - @Test - public void getLocale_zh() { - EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_ZH); - - PowerMock.replayAll(); - - Locale locale = LanguageUtil.getLocale(request); - - PowerMock.verifyAll(); - - assertThat(new Locale(AlarmConst.I18N_ZH), equalTo(locale)); - } - - @Test - public void getLocale_en() { - EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_EN); - - PowerMock.replayAll(); - - Locale locale = LanguageUtil.getLocale(request); - - PowerMock.verifyAll(); - - assertThat(new Locale(AlarmConst.I18N_EN), equalTo(locale)); - } -} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/MSBRegisterUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/MSBRegisterUtilTest.java deleted file mode 100644 index 5d04c1a..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/MSBRegisterUtilTest.java +++ /dev/null @@ -1,72 +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.openo.holmes.common.utils; - -import com.eclipsesource.jaxrs.consumer.ConsumerFactory; -import javax.ws.rs.QueryParam; -import org.easymock.EasyMock; -import org.junit.Rule; -import org.junit.Test; -import org.openo.holmes.common.api.entity.ServiceRegisterEntity; -import org.openo.holmes.common.config.MicroServiceConfig; -import org.openo.holmes.common.msb.MicroserviceBusRest; -import org.powermock.api.easymock.PowerMock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.rule.PowerMockRule; - -@PrepareForTest(ConsumerFactory.class) -public class MSBRegisterUtilTest { - - @Rule - public PowerMockRule powerMockRule = new PowerMockRule(); - private MSBRegisterUtil msbRegisterUtil = new MSBRegisterUtil(); - private MicroserviceBusRest microserviceBusRest = new MicroserviceBusRestProxy(); - - @Test - public void registerTest() throws Exception { - ServiceRegisterEntity entity = initServiceEntity(); - PowerMock.mockStatic(ConsumerFactory.class); - EasyMock.expect(ConsumerFactory - .createConsumer(EasyMock.anyObject(String.class), EasyMock.anyObject(Class.class))) - .andReturn(microserviceBusRest); - PowerMock.replayAll(); - - msbRegisterUtil.register(initServiceEntity()); - - PowerMock.verifyAll(); - } - - private ServiceRegisterEntity initServiceEntity() { - ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity(); - serviceRegisterEntity.setServiceName("holmes-rule-mgmt"); - serviceRegisterEntity.setProtocol("REST"); - serviceRegisterEntity.setVersion("v1"); - serviceRegisterEntity.setUrl("/openoapi/holmes-rule-mgmt/v1"); - serviceRegisterEntity.setSingleNode(MicroServiceConfig.getServiceIp(), "9101", 0); - serviceRegisterEntity.setVisualRange("1|0"); - return serviceRegisterEntity; - } - - class MicroserviceBusRestProxy implements MicroserviceBusRest { - - @Override - public ServiceRegisterEntity registerServce(@QueryParam("createOrUpdate") String createOrUpdate, - ServiceRegisterEntity entity) { - return null; - } - } -} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/UserUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/UserUtilTest.java deleted file mode 100644 index d81c919..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/UserUtilTest.java +++ /dev/null @@ -1,67 +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.openo.holmes.common.utils; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import javax.servlet.http.HttpServletRequest; -import org.easymock.EasyMock; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.powermock.api.easymock.PowerMock; -public class UserUtilTest { - - private HttpServletRequest request; - - @Before - public void before() throws Exception { - request = PowerMock.createMock(HttpServletRequest.class); - } - - @After - public void after() throws Exception { - } - - @Test - public void getUserName_header_name_empty() throws Exception { - EasyMock.expect(request.getHeader("username")).andReturn(null); - - PowerMock.replayAll(); - - String userName = UserUtil.getUserName(request); - - PowerMock.verifyAll(); - - assertThat("admin", equalTo(userName)); - } - - @Test - public void getUserName_normal() throws Exception { - EasyMock.expect(request.getHeader("username")).andReturn("name1"); - - PowerMock.replayAll(); - - String userName = UserUtil.getUserName(request); - - PowerMock.verifyAll(); - - assertThat("name1", equalTo(userName)); - } - -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/bean/TestBean.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/bean/TestBean.java deleted file mode 100644 index fab78c2..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/bean/TestBean.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright 2016 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.openo.holmes.common.utils.bean; - -import java.io.Serializable; - -public class TestBean implements Serializable { - String id; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } -} \ No newline at end of file -- cgit 1.2.3-korg