add alarm synchronization related operation 57/38957/3
authorFei Tang <tang.fei4@zte.com.cn>
Tue, 27 Mar 2018 08:26:39 +0000 (16:26 +0800)
committerFei Tang <tang.fei4@zte.com.cn>
Tue, 27 Mar 2018 08:50:32 +0000 (16:50 +0800)
Issue-ID: HOLMES-106

Change-Id: I9020c29b69eb0e8bd5a0a33901c671fd02b9f0d1
Signed-off-by: FeiTang <tang.fei4@zte.com.cn>
holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java [new file with mode: 0644]
holmes-actions/src/main/java/org/onap/holmes/common/exception/AlarmInfoException.java [new file with mode: 0644]
holmes-actions/src/main/java/org/onap/holmes/common/utils/AlarmInfoMapper.java [new file with mode: 0644]
holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmInfoTest.java [new file with mode: 0644]
holmes-actions/src/test/java/org/onap/holmes/common/exception/AlarmInfoExceptionTest.java [new file with mode: 0644]
holmes-actions/src/test/java/org/onap/holmes/common/utils/AlarmInfoMapperTest.java [new file with mode: 0644]

diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java
new file mode 100644 (file)
index 0000000..fe1f677
--- /dev/null
@@ -0,0 +1,49 @@
+/**\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
+package org.onap.holmes.common.api.entity;\r
+\r
+import com.google.gson.annotations.SerializedName;\r
+import lombok.Data;\r
+import lombok.NoArgsConstructor;\r
+\r
+@Data\r
+@NoArgsConstructor\r
+public class AlarmInfo {\r
+\r
+    @SerializedName(value = "eventid")\r
+    private String eventId;\r
+\r
+    @SerializedName(value = "eventname")\r
+    private String eventName;\r
+\r
+    @SerializedName(value = "startepochmicrosec")\r
+    private Long startEpochMicroSec;\r
+\r
+    @SerializedName(value = "lastepochmicrosec")\r
+    private Long lastEpochMicroSec;\r
+\r
+    @SerializedName(value = "sourceid")\r
+    private String sourceId;\r
+\r
+    @SerializedName(value = "sourcename")\r
+    private String sourceName;\r
+\r
+    @SerializedName(value = "alarmiscleared")\r
+    private int alarmIsCleared;\r
+\r
+    @SerializedName(value = "rootflag")\r
+    private int rootFlag;\r
+}\r
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/exception/AlarmInfoException.java b/holmes-actions/src/main/java/org/onap/holmes/common/exception/AlarmInfoException.java
new file mode 100644 (file)
index 0000000..ab3eba7
--- /dev/null
@@ -0,0 +1,23 @@
+/**\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
+package org.onap.holmes.common.exception;\r
+\r
+public class AlarmInfoException extends Exception {\r
+\r
+    public AlarmInfoException(String msg, Exception e) { super(msg, e);}\r
+\r
+    public AlarmInfoException(String msg) { super(msg);}\r
+}\r
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/AlarmInfoMapper.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/AlarmInfoMapper.java
new file mode 100644 (file)
index 0000000..0c7d756
--- /dev/null
@@ -0,0 +1,39 @@
+/**\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
+package org.onap.holmes.common.utils;\r
+\r
+import org.onap.holmes.common.api.entity.AlarmInfo;\r
+import org.skife.jdbi.v2.StatementContext;\r
+import org.skife.jdbi.v2.tweak.ResultSetMapper;\r
+\r
+import java.sql.ResultSet;\r
+import java.sql.SQLException;\r
+\r
+public class AlarmInfoMapper implements ResultSetMapper<AlarmInfo> {\r
+    @Override\r
+    public AlarmInfo map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException {\r
+        AlarmInfo alarmInfo = new AlarmInfo();\r
+        alarmInfo.setAlarmIsCleared(resultSet.getInt("alarmiscleared"));\r
+        alarmInfo.setRootFlag(resultSet.getInt("rootflag"));\r
+        alarmInfo.setEventId(resultSet.getString("eventid"));\r
+        alarmInfo.setEventName(resultSet.getString("eventname"));\r
+        alarmInfo.setSourceId(resultSet.getString("sourceid"));\r
+        alarmInfo.setSourceName(resultSet.getString("sourcename"));\r
+        alarmInfo.setStartEpochMicroSec(resultSet.getLong("startepochmicrosec"));\r
+        alarmInfo.setLastEpochMicroSec(resultSet.getLong("lastepochmicrosec"));\r
+        return alarmInfo;\r
+    }\r
+}\r
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmInfoTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmInfoTest.java
new file mode 100644 (file)
index 0000000..a2e60ee
--- /dev/null
@@ -0,0 +1,94 @@
+/**\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
+package org.onap.holmes.common.api.entity;\r
+\r
+import org.junit.After;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.assertThat;\r
+\r
+public class AlarmInfoTest {\r
+\r
+    private AlarmInfo alarmInfo;\r
+\r
+    @Before\r
+    public void before() throws Exception {\r
+        alarmInfo = new AlarmInfo();\r
+    }\r
+\r
+    @After\r
+    public void after() throws Exception {\r
+\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4EventID() throws Exception {\r
+        final String eventID = "eventId";\r
+        alarmInfo.setEventId(eventID);\r
+        assertThat(alarmInfo.getEventId(), equalTo(eventID));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4EventName() throws Exception {\r
+        final String eventName = "eventName";\r
+        alarmInfo.setEventName(eventName);\r
+        assertThat(alarmInfo.getEventName(), equalTo(eventName));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4StartEpochMicroSec() throws Exception {\r
+        final long startEpochMicroSec = 1L;\r
+        alarmInfo.setStartEpochMicroSec(startEpochMicroSec);\r
+        assertThat(alarmInfo.getStartEpochMicroSec(), equalTo(startEpochMicroSec));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4LastEpochMicroSec() throws Exception {\r
+        final long lastEpochMicroSec = 1L;\r
+        alarmInfo.setLastEpochMicroSec(lastEpochMicroSec);\r
+        assertThat(alarmInfo.getLastEpochMicroSec(), equalTo(lastEpochMicroSec));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4SourceID() throws Exception {\r
+        final String sourceID = "sourceId";\r
+        alarmInfo.setSourceId(sourceID);\r
+        assertThat(alarmInfo.getSourceId(), equalTo(sourceID));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4SourceName() throws Exception {\r
+        final String sourceName = "sourceName";\r
+        alarmInfo.setSourceName(sourceName);\r
+        assertThat(alarmInfo.getSourceName(), equalTo(sourceName));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4AlarmIsCleared() throws Exception {\r
+        final int alarmIsCleared = 1;\r
+        alarmInfo.setAlarmIsCleared(alarmIsCleared);\r
+        assertThat(alarmInfo.getAlarmIsCleared(), equalTo(alarmIsCleared));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4RootFlag() throws Exception {\r
+        final int rootFlag = 1;\r
+        alarmInfo.setRootFlag(rootFlag);\r
+        assertThat(alarmInfo.getRootFlag(), equalTo(rootFlag));\r
+    }\r
+}\r
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/exception/AlarmInfoExceptionTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/exception/AlarmInfoExceptionTest.java
new file mode 100644 (file)
index 0000000..1263b73
--- /dev/null
@@ -0,0 +1,27 @@
+/**\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
+package org.onap.holmes.common.exception;\r
+\r
+import org.junit.Test;\r
+\r
+public class AlarmInfoExceptionTest {\r
+    @Test\r
+    public void testConstructors() throws Exception {\r
+        AlarmInfoException ae1 = new AlarmInfoException("msg", new Exception());\r
+        AlarmInfoException ae2 = new AlarmInfoException("msg");\r
+    }\r
+}\r
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/AlarmInfoMapperTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/AlarmInfoMapperTest.java
new file mode 100644 (file)
index 0000000..06bbfa8
--- /dev/null
@@ -0,0 +1,44 @@
+/**\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
+package org.onap.holmes.common.utils;\r
+\r
+import org.junit.Test;\r
+import org.powermock.api.easymock.PowerMock;\r
+\r
+import java.sql.ResultSet;\r
+\r
+import static org.easymock.EasyMock.expect;\r
+\r
+public class AlarmInfoMapperTest {\r
+\r
+    @Test\r
+    public void map() throws Exception {\r
+        AlarmInfoMapper mapper = new AlarmInfoMapper();\r
+        ResultSet resultSet = PowerMock.createMock(ResultSet.class);\r
+        expect(resultSet.getString("eventid")).andReturn("");\r
+        expect(resultSet.getString("eventname")).andReturn("");\r
+        expect(resultSet.getString("sourceid")).andReturn("");\r
+        expect(resultSet.getString("sourcename")).andReturn("");\r
+        expect(resultSet.getLong("startepochmicrosec")).andReturn(0L);\r
+        expect(resultSet.getLong("lastepochmicrosec")).andReturn(0L);\r
+        expect(resultSet.getInt("alarmiscleared")).andReturn(0);\r
+        expect(resultSet.getInt("rootflag")).andReturn(0);\r
+        PowerMock.replay(resultSet);\r
+        mapper.map(0, resultSet, null);\r
+        PowerMock.verify(resultSet);\r
+    }\r
+}\r