From 08d766437dc19037f21b57578448748e013bc031 Mon Sep 17 00:00:00 2001 From: jhh Date: Tue, 14 Jan 2020 22:48:45 -0600 Subject: Added Time agnostic Onset and Abated classes These classes can be used for comparison of alarm skeletons independently of the time at which they were produced. Issue-ID: POLICY-2323 Signed-off-by: jhh Change-Id: I85b9d6a429de56f056eb0a6caa9e4f90fbd68918 Signed-off-by: jhh --- .../org/onap/policy/controlloop/AbatedTest.java | 55 ++++++++++++++++++++ .../policy/controlloop/CanonicalAbatedTest.java | 59 ++++++++++++++++++++++ .../policy/controlloop/CanonicalOnsetTest.java | 59 ++++++++++++++++++++++ .../org/onap/policy/controlloop/OnsetTest.java | 56 ++++++++++++++++++++ 4 files changed, 229 insertions(+) create mode 100644 models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/AbatedTest.java create mode 100644 models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/CanonicalAbatedTest.java create mode 100644 models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/CanonicalOnsetTest.java create mode 100644 models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/OnsetTest.java (limited to 'models-interactions/model-impl/events/src/test/java/org/onap') diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/AbatedTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/AbatedTest.java new file mode 100644 index 000000000..e1ef77e22 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/AbatedTest.java @@ -0,0 +1,55 @@ +/* + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop; + +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import java.time.Instant; +import org.junit.Test; + +public class AbatedTest { + + @Test + public void testConstructors() { + VirtualControlLoopEvent event = new VirtualControlLoopEvent(); + event.setClosedLoopEventStatus(ControlLoopEventStatus.ABATED); + event.setClosedLoopAlarmStart(Instant.now()); + event.setClosedLoopAlarmEnd(Instant.now()); + + Abated abated = new Abated(event); + assertEquals(abated, event); + assertEquals(event.getClosedLoopAlarmStart(), abated.getClosedLoopAlarmStart()); + assertEquals(ControlLoopEventStatus.ABATED, abated.getClosedLoopEventStatus()); + + abated.setClosedLoopAlarmEnd(Instant.now()); + assertNotEquals(abated, event); + + assertEquals(new Abated(abated), abated); + } + + @Test + public void testSetClosedLoopEventStatus() { + assertThatIllegalArgumentException() + .isThrownBy(() -> new Abated().setClosedLoopEventStatus(ControlLoopEventStatus.ONSET)); + } +} \ No newline at end of file diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/CanonicalAbatedTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/CanonicalAbatedTest.java new file mode 100644 index 000000000..d7007bc97 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/CanonicalAbatedTest.java @@ -0,0 +1,59 @@ +/* + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import java.time.Instant; +import java.util.UUID; +import org.junit.Test; + +public class CanonicalAbatedTest { + + @Test + public void testConstructors() { + CanonicalAbated abated1 = new CanonicalAbated(new VirtualControlLoopEvent()); + abated1.setRequestId(UUID.randomUUID()); + abated1.setClosedLoopAlarmStart(Instant.now()); + abated1.setClosedLoopAlarmEnd(Instant.now()); + + CanonicalAbated abated2 = new CanonicalAbated(new Abated()); + abated2.setRequestId(UUID.randomUUID()); + abated2.setClosedLoopAlarmStart(Instant.now()); + abated2.setClosedLoopAlarmEnd(Instant.now()); + + CanonicalAbated abated3 = new CanonicalAbated(abated2); + + assertEquals(abated1, abated2); + assertEquals(abated1, abated3); + assertEquals(ControlLoopEventStatus.ABATED, abated1.getClosedLoopEventStatus()); + assertEquals(ControlLoopEventStatus.ABATED, abated2.getClosedLoopEventStatus()); + assertEquals(ControlLoopEventStatus.ABATED, abated3.getClosedLoopEventStatus()); + + assertNotEquals(abated1.getRequestId(), abated2.getRequestId()); + assertNotEquals(abated1.getClosedLoopAlarmStart(), abated2.getClosedLoopAlarmStart()); + assertNotEquals(abated1.getClosedLoopAlarmEnd(), abated2.getClosedLoopAlarmEnd()); + + abated2.setFrom("here"); + assertNotEquals(abated1, abated2); + } +} \ No newline at end of file diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/CanonicalOnsetTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/CanonicalOnsetTest.java new file mode 100644 index 000000000..7b0a43f9e --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/CanonicalOnsetTest.java @@ -0,0 +1,59 @@ +/* + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import java.time.Instant; +import java.util.UUID; +import org.junit.Test; + +public class CanonicalOnsetTest { + + @Test + public void testConstructors() { + CanonicalOnset onset1 = new CanonicalOnset(new VirtualControlLoopEvent()); + onset1.setRequestId(UUID.randomUUID()); + onset1.setClosedLoopAlarmStart(Instant.now()); + onset1.setClosedLoopAlarmEnd(Instant.now()); + + CanonicalOnset onset2 = new CanonicalOnset(new Onset()); + onset2.setRequestId(UUID.randomUUID()); + onset2.setClosedLoopAlarmStart(Instant.now()); + onset2.setClosedLoopAlarmEnd(Instant.now()); + + CanonicalOnset onset3 = new CanonicalOnset(onset2); + + assertEquals(onset1, onset2); + assertEquals(onset1, onset3); + assertEquals(ControlLoopEventStatus.ONSET, onset1.getClosedLoopEventStatus()); + assertEquals(ControlLoopEventStatus.ONSET, onset2.getClosedLoopEventStatus()); + assertEquals(ControlLoopEventStatus.ONSET, onset3.getClosedLoopEventStatus()); + + assertNotEquals(onset1.getRequestId(), onset2.getRequestId()); + assertNotEquals(onset1.getClosedLoopAlarmStart(), onset2.getClosedLoopAlarmStart()); + assertNotEquals(onset1.getClosedLoopAlarmEnd(), onset2.getClosedLoopAlarmEnd()); + + onset2.setFrom("here"); + assertNotEquals(onset1, onset2); + } +} \ No newline at end of file diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/OnsetTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/OnsetTest.java new file mode 100644 index 000000000..b229b024b --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/OnsetTest.java @@ -0,0 +1,56 @@ +/* + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop; + +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import java.time.Instant; +import org.junit.Test; + +public class OnsetTest { + + @Test + public void testConstructors() { + VirtualControlLoopEvent event = new VirtualControlLoopEvent(); + event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); + event.setClosedLoopAlarmStart(Instant.now()); + event.setClosedLoopAlarmEnd(Instant.now()); + + Onset onset = new Onset(event); + assertEquals(onset, event); + assertEquals(event.getClosedLoopAlarmStart(), onset.getClosedLoopAlarmStart()); + assertEquals(ControlLoopEventStatus.ONSET, onset.getClosedLoopEventStatus()); + assertEquals(event.getClosedLoopAlarmEnd(), onset.getClosedLoopAlarmEnd()); + + onset.setClosedLoopAlarmEnd(Instant.now()); + assertNotEquals(onset, event); + + assertEquals(new Onset(onset), onset); + } + + @Test + public void testSetClosedLoopEventStatus() { + assertThatIllegalArgumentException() + .isThrownBy(() -> new Onset().setClosedLoopEventStatus(ControlLoopEventStatus.ABATED)); + } +} \ No newline at end of file -- cgit 1.2.3-korg