From: Fei Tang Date: Tue, 27 Mar 2018 08:26:39 +0000 (+0800) Subject: add alarm synchronization related operation X-Git-Tag: 1.2.0~28 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=holmes%2Fcommon.git;a=commitdiff_plain;h=6c4fde1fd6dcf484d2c567d3fabf0496ed8b30e0 add alarm synchronization related operation Issue-ID: HOLMES-106 Change-Id: I9020c29b69eb0e8bd5a0a33901c671fd02b9f0d1 Signed-off-by: FeiTang --- 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 index 0000000..fe1f677 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java @@ -0,0 +1,49 @@ +/** + * 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 com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class AlarmInfo { + + @SerializedName(value = "eventid") + private String eventId; + + @SerializedName(value = "eventname") + private String eventName; + + @SerializedName(value = "startepochmicrosec") + private Long startEpochMicroSec; + + @SerializedName(value = "lastepochmicrosec") + private Long lastEpochMicroSec; + + @SerializedName(value = "sourceid") + private String sourceId; + + @SerializedName(value = "sourcename") + private String sourceName; + + @SerializedName(value = "alarmiscleared") + private int alarmIsCleared; + + @SerializedName(value = "rootflag") + private int rootFlag; +} 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 index 0000000..ab3eba7 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/exception/AlarmInfoException.java @@ -0,0 +1,23 @@ +/** + * 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; + +public class AlarmInfoException extends Exception { + + public AlarmInfoException(String msg, Exception e) { super(msg, e);} + + public AlarmInfoException(String msg) { super(msg);} +} 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 index 0000000..0c7d756 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/AlarmInfoMapper.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.utils; + +import org.onap.holmes.common.api.entity.AlarmInfo; +import org.skife.jdbi.v2.StatementContext; +import org.skife.jdbi.v2.tweak.ResultSetMapper; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class AlarmInfoMapper implements ResultSetMapper { + @Override + public AlarmInfo map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException { + AlarmInfo alarmInfo = new AlarmInfo(); + alarmInfo.setAlarmIsCleared(resultSet.getInt("alarmiscleared")); + alarmInfo.setRootFlag(resultSet.getInt("rootflag")); + alarmInfo.setEventId(resultSet.getString("eventid")); + alarmInfo.setEventName(resultSet.getString("eventname")); + alarmInfo.setSourceId(resultSet.getString("sourceid")); + alarmInfo.setSourceName(resultSet.getString("sourcename")); + alarmInfo.setStartEpochMicroSec(resultSet.getLong("startepochmicrosec")); + alarmInfo.setLastEpochMicroSec(resultSet.getLong("lastepochmicrosec")); + return alarmInfo; + } +} 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 index 0000000..a2e60ee --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmInfoTest.java @@ -0,0 +1,94 @@ +/** + * 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 org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +public class AlarmInfoTest { + + private AlarmInfo alarmInfo; + + @Before + public void before() throws Exception { + alarmInfo = new AlarmInfo(); + } + + @After + public void after() throws Exception { + + } + + @Test + public void getterAndSetter4EventID() throws Exception { + final String eventID = "eventId"; + alarmInfo.setEventId(eventID); + assertThat(alarmInfo.getEventId(), equalTo(eventID)); + } + + @Test + public void getterAndSetter4EventName() throws Exception { + final String eventName = "eventName"; + alarmInfo.setEventName(eventName); + assertThat(alarmInfo.getEventName(), equalTo(eventName)); + } + + @Test + public void getterAndSetter4StartEpochMicroSec() throws Exception { + final long startEpochMicroSec = 1L; + alarmInfo.setStartEpochMicroSec(startEpochMicroSec); + assertThat(alarmInfo.getStartEpochMicroSec(), equalTo(startEpochMicroSec)); + } + + @Test + public void getterAndSetter4LastEpochMicroSec() throws Exception { + final long lastEpochMicroSec = 1L; + alarmInfo.setLastEpochMicroSec(lastEpochMicroSec); + assertThat(alarmInfo.getLastEpochMicroSec(), equalTo(lastEpochMicroSec)); + } + + @Test + public void getterAndSetter4SourceID() throws Exception { + final String sourceID = "sourceId"; + alarmInfo.setSourceId(sourceID); + assertThat(alarmInfo.getSourceId(), equalTo(sourceID)); + } + + @Test + public void getterAndSetter4SourceName() throws Exception { + final String sourceName = "sourceName"; + alarmInfo.setSourceName(sourceName); + assertThat(alarmInfo.getSourceName(), equalTo(sourceName)); + } + + @Test + public void getterAndSetter4AlarmIsCleared() throws Exception { + final int alarmIsCleared = 1; + alarmInfo.setAlarmIsCleared(alarmIsCleared); + assertThat(alarmInfo.getAlarmIsCleared(), equalTo(alarmIsCleared)); + } + + @Test + public void getterAndSetter4RootFlag() throws Exception { + final int rootFlag = 1; + alarmInfo.setRootFlag(rootFlag); + assertThat(alarmInfo.getRootFlag(), equalTo(rootFlag)); + } +} 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 index 0000000..1263b73 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/exception/AlarmInfoExceptionTest.java @@ -0,0 +1,27 @@ +/** + * 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; + +public class AlarmInfoExceptionTest { + @Test + public void testConstructors() throws Exception { + AlarmInfoException ae1 = new AlarmInfoException("msg", new Exception()); + AlarmInfoException ae2 = new AlarmInfoException("msg"); + } +} 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 index 0000000..06bbfa8 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/AlarmInfoMapperTest.java @@ -0,0 +1,44 @@ +/** + * 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; +import org.powermock.api.easymock.PowerMock; + +import java.sql.ResultSet; + +import static org.easymock.EasyMock.expect; + +public class AlarmInfoMapperTest { + + @Test + public void map() throws Exception { + AlarmInfoMapper mapper = new AlarmInfoMapper(); + ResultSet resultSet = PowerMock.createMock(ResultSet.class); + expect(resultSet.getString("eventid")).andReturn(""); + expect(resultSet.getString("eventname")).andReturn(""); + expect(resultSet.getString("sourceid")).andReturn(""); + expect(resultSet.getString("sourcename")).andReturn(""); + expect(resultSet.getLong("startepochmicrosec")).andReturn(0L); + expect(resultSet.getLong("lastepochmicrosec")).andReturn(0L); + expect(resultSet.getInt("alarmiscleared")).andReturn(0); + expect(resultSet.getInt("rootflag")).andReturn(0); + PowerMock.replay(resultSet); + mapper.map(0, resultSet, null); + PowerMock.verify(resultSet); + } +}