Add action module unit tests
author6092002067 <wu.youbo@zte.com.cn>
Tue, 28 Feb 2017 09:22:05 +0000 (17:22 +0800)
committer6092002067 <wu.youbo@zte.com.cn>
Tue, 28 Feb 2017 09:22:05 +0000 (17:22 +0800)
Issue-ID:HOLMES-51

Change-Id: Iaab72cb42d7af3636736c505f62db295c20ba3c7
Signed-off-by: youbowu <wu.youbo@zte.com.cn>
15 files changed:
holmes-actions/src/test/java/org/openo/holmes/common/api/entity/AlarmsCorrelationTest.java [new file with mode: 0644]
holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationResultTest.java [new file with mode: 0644]
holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationRuleTest.java [new file with mode: 0644]
holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java [new file with mode: 0644]
holmes-actions/src/test/java/org/openo/holmes/common/config/MQConfigTest.java [new file with mode: 0644]
holmes-actions/src/test/java/org/openo/holmes/common/exception/CorrelationExceptionTest.java [new file with mode: 0644]
holmes-actions/src/test/java/org/openo/holmes/common/producer/MQProducerTest.java [new file with mode: 0644]
holmes-actions/src/test/java/org/openo/holmes/common/utils/DbDaoUtilTest.java [new file with mode: 0644]
holmes-actions/src/test/java/org/openo/holmes/common/utils/ExceptionUtilTest.java [new file with mode: 0644]
holmes-actions/src/test/java/org/openo/holmes/common/utils/I18nProxyTest.java [new file with mode: 0644]
holmes-actions/src/test/java/org/openo/holmes/common/utils/JacksonUtilTest.java [new file with mode: 0644]
holmes-actions/src/test/java/org/openo/holmes/common/utils/JudgeNullUtilTest.java [new file with mode: 0644]
holmes-actions/src/test/java/org/openo/holmes/common/utils/LanguageUtilTest.java [new file with mode: 0644]
holmes-actions/src/test/java/org/openo/holmes/common/utils/UserUtilTest.java [new file with mode: 0644]
holmes-actions/src/test/java/org/openo/holmes/common/utils/bean/TestBean.java [new file with mode: 0644]

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
new file mode 100644 (file)
index 0000000..7dc1fab
--- /dev/null
@@ -0,0 +1,133 @@
+/**
+ * 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
new file mode 100644 (file)
index 0000000..14a52c0
--- /dev/null
@@ -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.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
new file mode 100644 (file)
index 0000000..8b6268c
--- /dev/null
@@ -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.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/stat/AlarmTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java
new file mode 100644 (file)
index 0000000..b740d87
--- /dev/null
@@ -0,0 +1,198 @@
+/**
+ * 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 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<Integer, Integer> otherIdIdx = new HashMap<>();
+        assertThat(999, equalTo(alarm.CompareLinkPosition(otherIdIdx)));
+    }
+
+    @Test
+    public void testCompareLinkPosition_TempLinkId() throws Exception {
+        final Map<Integer, Integer> 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 {
+        final Alarm alarmTemp = new Alarm();
+        assertThat(alarmTemp.toString(), equalTo(alarm.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 rootAlarmTyep = 2;
+        alarm.getRootAlarmTypeMap().put(ruleId, rootAlarmTyep);
+        assertThat(rootAlarmTyep, 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
new file mode 100644 (file)
index 0000000..bb79c8a
--- /dev/null
@@ -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.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/exception/CorrelationExceptionTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/exception/CorrelationExceptionTest.java
new file mode 100644 (file)
index 0000000..bca63b2
--- /dev/null
@@ -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.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
new file mode 100644 (file)
index 0000000..58ea684
--- /dev/null
@@ -0,0 +1,157 @@
+/**
+ * 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<MQConfig> 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 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
new file mode 100644 (file)
index 0000000..b56e4ee
--- /dev/null
@@ -0,0 +1,144 @@
+/**
+ * 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 io.dropwizard.db.DataSourceFactory;
+import io.dropwizard.jdbi.DBIFactory;
+import io.dropwizard.setup.Environment;
+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() 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 testGetHandle() 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 testClose() throws Exception {
+        Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi);
+        jdbi.close(anyObject());
+
+        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
new file mode 100644 (file)
index 0000000..caa45e3
--- /dev/null
@@ -0,0 +1,31 @@
+/**
+ * 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
new file mode 100644 (file)
index 0000000..64b31f4
--- /dev/null
@@ -0,0 +1,41 @@
+/**\r
+ * Copyright 2016 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+\r
+package org.openo.holmes.common.utils;\r
+\r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.assertThat;\r
+\r
+import java.util.Locale;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+public class I18nProxyTest {\r
+\r
+    private I18nProxy i18nProxy;\r
+\r
+    @Before\r
+    public void setUp() {\r
+        i18nProxy = I18nProxy.getInstance();\r
+    }\r
+\r
+    @Test\r
+    public void testGetValue() {\r
+        String result = i18nProxy.getValue(new Locale("zh"), "test");\r
+        assertThat(result, equalTo(null));\r
+    }\r
+}
\ 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
new file mode 100644 (file)
index 0000000..22d628e
--- /dev/null
@@ -0,0 +1,49 @@
+/**\r
+ * Copyright 2016 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+\r
+package org.openo.holmes.common.utils;\r
+\r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.assertThat;\r
+\r
+import org.junit.Test;\r
+import org.openo.holmes.common.utils.bean.TestBean;\r
+\r
+public class JacksonUtilTest {\r
+\r
+    @Test\r
+    public void testBeanToJson() throws Exception {\r
+        TestBean o = new TestBean();\r
+        o.setId("id");\r
+        String result = JacksonUtil.beanToJson(o);\r
+        assertThat("{\"id\":\"id\"}", equalTo(result));\r
+    }\r
+\r
+    @Test\r
+    public void jsonToBean_json_null() throws Exception {\r
+        String jsonNull = null;\r
+        TestBean testBean = JacksonUtil.jsonToBean(jsonNull, TestBean.class);\r
+        assertThat(testBean.getId(), equalTo(null));\r
+    }\r
+\r
+    @Test\r
+    public void jsonToBean_json_normal() throws Exception {\r
+        String json = "{\"id\":\"id\"}";\r
+        TestBean testBean = JacksonUtil.jsonToBean(json, TestBean.class);\r
+        assertThat(testBean.getId(), equalTo("id"));\r
+    }\r
+}
\ 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
new file mode 100644 (file)
index 0000000..25da9ac
--- /dev/null
@@ -0,0 +1,44 @@
+/**\r
+ * Copyright 2016 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+\r
+package org.openo.holmes.common.utils;\r
+\r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.assertThat;\r
+\r
+import java.util.List;\r
+import org.junit.Test;\r
+\r
+public class JudgeNullUtilTest {\r
+\r
+    @Test\r
+    public void isEmpty_array() {\r
+        boolean resultShorts = JudgeNullUtil.isEmpty(new short[]{});\r
+        boolean resultInts = JudgeNullUtil.isEmpty(new int[]{});\r
+        boolean resultLongs = JudgeNullUtil.isEmpty(new long[]{});\r
+        boolean resultObjects = JudgeNullUtil.isEmpty(new Object[]{});\r
+        boolean resultStrings = JudgeNullUtil.isEmpty(new String[]{});\r
+        boolean resultLists = JudgeNullUtil.isEmpty(new List[]{});\r
+        assertThat(true, equalTo(resultShorts));\r
+        assertThat(true, equalTo(resultInts));\r
+        assertThat(true, equalTo(resultLongs));\r
+        assertThat(true, equalTo(resultObjects));\r
+        assertThat(true, equalTo(resultStrings));\r
+        assertThat(true, equalTo(resultLists));\r
+    }\r
+\r
+}
\ 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
new file mode 100644 (file)
index 0000000..d688a35
--- /dev/null
@@ -0,0 +1,118 @@
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+\r
+package org.openo.holmes.common.utils;\r
+\r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.assertThat;\r
+\r
+import java.util.Locale;\r
+import javax.servlet.http.HttpServletRequest;\r
+import org.easymock.EasyMock;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.openo.holmes.common.constant.AlarmConst;\r
+import org.powermock.api.easymock.PowerMock;\r
+\r
+\r
+public class LanguageUtilTest {\r
+\r
+    private HttpServletRequest request;\r
+\r
+    @Before\r
+    public void setUp() {\r
+        request = PowerMock.createMock(HttpServletRequest.class);\r
+    }\r
+\r
+    @Test\r
+    public void getLanguage_header_language_empty() {\r
+        EasyMock.expect(request.getHeader("language-option")).andReturn("");\r
+\r
+        PowerMock.replayAll();\r
+\r
+        String language = LanguageUtil.getLanguage(request);\r
+\r
+        PowerMock.verifyAll();\r
+\r
+        assertThat(AlarmConst.I18N_EN, equalTo(language));\r
+    }\r
+\r
+    @Test\r
+    public void getLanguage_zh() {\r
+        EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_ZH);\r
+\r
+        PowerMock.replayAll();\r
+\r
+        String language = LanguageUtil.getLanguage(request);\r
+\r
+        PowerMock.verifyAll();\r
+\r
+        assertThat(AlarmConst.I18N_ZH, equalTo(language));\r
+    }\r
+\r
+    @Test\r
+    public void getLanguage_en() {\r
+        EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_EN);\r
+\r
+        PowerMock.replayAll();\r
+\r
+        String language = LanguageUtil.getLanguage(request);\r
+\r
+        PowerMock.verifyAll();\r
+\r
+        assertThat(AlarmConst.I18N_EN, equalTo(language));\r
+    }\r
+\r
+    @Test\r
+    public void getLocale_header_language_empty() {\r
+        EasyMock.expect(request.getHeader("language-option")).andReturn("");\r
+\r
+        PowerMock.replayAll();\r
+\r
+        Locale locale = LanguageUtil.getLocale(request);\r
+\r
+        PowerMock.verifyAll();\r
+\r
+        assertThat(new Locale(AlarmConst.I18N_EN), equalTo(locale));\r
+    }\r
+\r
+    @Test\r
+    public void getLocale_zh() {\r
+        EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_ZH);\r
+\r
+        PowerMock.replayAll();\r
+\r
+        Locale locale = LanguageUtil.getLocale(request);\r
+\r
+        PowerMock.verifyAll();\r
+\r
+        assertThat(new Locale(AlarmConst.I18N_ZH), equalTo(locale));\r
+    }\r
+\r
+    @Test\r
+    public void getLocale_en() {\r
+        EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_EN);\r
+\r
+        PowerMock.replayAll();\r
+\r
+        Locale locale = LanguageUtil.getLocale(request);\r
+\r
+        PowerMock.verifyAll();\r
+\r
+        assertThat(new Locale(AlarmConst.I18N_EN), equalTo(locale));\r
+    }\r
+}
\ 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
new file mode 100644 (file)
index 0000000..d81c919
--- /dev/null
@@ -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.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
new file mode 100644 (file)
index 0000000..fab78c2
--- /dev/null
@@ -0,0 +1,32 @@
+/**\r
+ * Copyright 2016 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+\r
+package org.openo.holmes.common.utils.bean;\r
+\r
+import java.io.Serializable;\r
+\r
+public class TestBean implements Serializable {\r
+    String id;\r
+\r
+    public String getId() {\r
+        return id;\r
+    }\r
+\r
+    public void setId(String id) {\r
+        this.id = id;\r
+    }\r
+}
\ No newline at end of file