diff options
author | Jim Hahn <jrh3@att.com> | 2021-08-24 13:20:26 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2021-08-24 15:51:34 -0400 |
commit | dc101c2ad5e27d5a0afd4e2feeb8885f24728806 (patch) | |
tree | 939e6f3690d1a9c6e63c4226a85fbda8c238d65a /core | |
parent | 53fe02c107eae2f45abfee02e5b56a8ab3c09523 (diff) |
Use CompareToBuilder
Also added lombok to test classes.
Issue-ID: POLICY-3391
Change-Id: I9ecf479f3861a2e5211b037e885029d1719b6a56
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'core')
7 files changed, 46 insertions, 97 deletions
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/DummyStateFinalizerExecutor.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/DummyStateFinalizerExecutor.java index 5a011b2aa..e4e3ddf0d 100644 --- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/DummyStateFinalizerExecutor.java +++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/DummyStateFinalizerExecutor.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -23,21 +24,19 @@ package org.onap.policy.apex.core.engine.executor; import java.util.Map; import java.util.Properties; +import lombok.NoArgsConstructor; import org.onap.policy.apex.context.ContextException; import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; /** * Dummy state finalizer executor for testing. */ +@NoArgsConstructor public class DummyStateFinalizerExecutor extends StateFinalizerExecutor { private boolean override; private boolean returnBad; - public DummyStateFinalizerExecutor() { - this(false); - } - public DummyStateFinalizerExecutor(final boolean override) { this.override = override; } diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskExecutor.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskExecutor.java index 75c4c0d7c..8172eefcc 100644 --- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskExecutor.java +++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskExecutor.java @@ -3,6 +3,7 @@ * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021 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. @@ -24,6 +25,8 @@ package org.onap.policy.apex.core.engine.executor; import java.util.Map; import java.util.Properties; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; import org.onap.policy.apex.context.ContextException; import org.onap.policy.apex.core.engine.event.EnEvent; import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; @@ -34,18 +37,12 @@ import org.onap.policy.apex.model.policymodel.concepts.AxTask; /** * Dummy task executor for testing. */ +@NoArgsConstructor +@AllArgsConstructor public class DummyTaskExecutor extends TaskExecutor { private static final String EVENT_KEY = "Event1:0.0.1"; private boolean override; - public DummyTaskExecutor() { - this(false); - } - - public DummyTaskExecutor(final boolean override) { - this.override = override; - } - @Override public void prepare() throws StateMachineException { if (!override) { diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskSelectExecutor.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskSelectExecutor.java index 02a32d4e7..a5525ac83 100644 --- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskSelectExecutor.java +++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskSelectExecutor.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -22,6 +23,9 @@ package org.onap.policy.apex.core.engine.executor; import java.util.Properties; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Setter; import org.onap.policy.apex.context.ContextException; import org.onap.policy.apex.core.engine.event.EnEvent; import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; @@ -30,19 +34,14 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; /** * Dummy task selection executor for testing. */ +@NoArgsConstructor +@AllArgsConstructor public class DummyTaskSelectExecutor extends TaskSelectExecutor { private boolean override; + @Setter private static int taskNo; - public DummyTaskSelectExecutor() { - this(false); - } - - public DummyTaskSelectExecutor(final boolean override) { - this.override = override; - } - @Override public void prepare() throws StateMachineException { if (!override) { @@ -63,10 +62,6 @@ public class DummyTaskSelectExecutor extends TaskSelectExecutor { return new AxArtifactKey("task" + (taskNo++) + ":0.0.1"); } - public void setTaskNo(int incomingTaskNo) { - taskNo = incomingTaskNo; - } - /** * {@inheritDoc}. */ diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutorTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutorTest.java index 2d274bd2e..5d91bd2b3 100644 --- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutorTest.java +++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutorTest.java @@ -3,6 +3,7 @@ * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021 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. @@ -222,26 +223,26 @@ public class StateMachineExecutorTest { executor.setContext(null, axPolicy, internalContextMock); executor.execute(0, null, incomingEventMock); - dummyTsle.setTaskNo(0); + DummyTaskSelectExecutor.setTaskNo(0); executor.execute(0, null, incomingEventMock); AxReferenceKey badStateKey = new AxReferenceKey("Policy:0.0.1:PName:BadState"); axPolicy.getStateMap().get("State1").getStateOutputs().get("stateOutput1").setNextState(badStateKey); - dummyTsle.setTaskNo(0); + DummyTaskSelectExecutor.setTaskNo(0); assertThatThrownBy(() -> executor.execute(0, null, incomingEventMock)) .hasMessage("state execution failed, next state \"Policy:0.0.1:PName:BadState\" not found"); axPolicy.getStateMap().get("State1").getStateOutputs().get("stateOutput1") .setNextState(AxReferenceKey.getNullKey()); - dummyTsle.setTaskNo(0); + DummyTaskSelectExecutor.setTaskNo(0); executor.execute(0, null, incomingEventMock); axPolicy.getStateMap().get("State1").setTrigger(new AxArtifactKey("BadTrigger:0.0.1")); - dummyTsle.setTaskNo(0); + DummyTaskSelectExecutor.setTaskNo(0); assertThatThrownBy(() -> executor.execute(0, null, incomingEventMock)) .hasMessage("incoming event \"Event1:0.0.1\" does not match trigger \"BadTrigger:0.0.1\" " + "of state \"Policy:0.0.1:NULL:state1\""); axPolicy.getStateMap().get("State1").setTrigger(new AxArtifactKey("Event1:0.0.1")); - dummyTsle.setTaskNo(0); + DummyTaskSelectExecutor.setTaskNo(0); executor.execute(0, null, incomingEventMock); AxStateFinalizerLogic savedSfl = axPolicy.getStateMap().get("State1").getStateFinalizerLogicMap().get("sfl"); @@ -255,7 +256,7 @@ public class StateMachineExecutorTest { axPolicy.getStateMap().get("State1").getStateFinalizerLogicMap().put("sfl", savedSfl); executor.setContext(null, axPolicy, internalContextMock); - dummyTsle.setTaskNo(0); + DummyTaskSelectExecutor.setTaskNo(0); executor.execute(0, null, incomingEventMock); AxArtifactKey task1Key = new AxArtifactKey("task1:0.0.1"); @@ -271,16 +272,16 @@ public class StateMachineExecutorTest { .setStateTaskOutputType(AxStateTaskOutputType.LOGIC); executor.setContext(null, axPolicy, internalContextMock); - dummyTsle.setTaskNo(0); + DummyTaskSelectExecutor.setTaskNo(0); executor.execute(0, null, incomingEventMock); - dummyTsle.setTaskNo(0); + DummyTaskSelectExecutor.setTaskNo(0); dummySfle.setReturnBad(true); assertThatThrownBy(() -> executor.execute(0, null, incomingEventMock)) .hasMessage("State execution of state \"Policy:0.0.1:NULL:state1\" on task \"task1:0.0.1\"" + " failed: state output definition for state output \"stateOutputBad\" not found for " + "state \"Policy:0.0.1:NULL:state1\""); - dummyTsle.setTaskNo(0); + DummyTaskSelectExecutor.setTaskNo(0); dummySfle.setReturnBad(false); executor.execute(0, null, incomingEventMock); diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/context/DummyContextAlbum.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/context/DummyContextAlbum.java index 156e64b16..efb53a682 100644 --- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/context/DummyContextAlbum.java +++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/context/DummyContextAlbum.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 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. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -23,6 +24,7 @@ package org.onap.policy.apex.core.engine.executor.context; import java.util.Collection; import java.util.Map; import java.util.Set; +import lombok.AllArgsConstructor; import org.apache.commons.lang3.NotImplementedException; import org.onap.policy.apex.context.ContextAlbum; import org.onap.policy.apex.context.ContextException; @@ -34,26 +36,18 @@ import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; /** * Dummy context album for testing. */ +@AllArgsConstructor public class DummyContextAlbum implements ContextAlbum { private final AxArtifactKey key; /** - * Constructor. - * @param key the key - */ - public DummyContextAlbum(AxArtifactKey key) { - super(); - this.key = key; - } - - /** * {@inheritDoc}. */ @Override public void clear() { throw new NotImplementedException("Not implemented on dummy class"); } - + /** * {@inheritDoc}. */ diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/DummyAction.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/DummyAction.java index 3d15a8c01..876052296 100644 --- a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/DummyAction.java +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/DummyAction.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -21,60 +22,20 @@ package org.onap.policy.apex.core.protocols; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; + /** * Dummy action for testing. */ +@Getter +@Setter +@EqualsAndHashCode +@AllArgsConstructor public class DummyAction implements Action { private static final long serialVersionUID = 9178856761163651594L; private String actionString = "An Action String"; - - public DummyAction(final String actionString) { - this.actionString = actionString; - } - - /** - * {@inheritDoc}. - */ - @Override - public String getActionString() { - return actionString; - } - - public void setActionString(final String actionString) { - this.actionString = actionString; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((actionString == null) ? 0 : actionString.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null) { - return false; - } - - if (getClass() != obj.getClass()) { - return false; - } - - DummyAction other = (DummyAction) obj; - if (actionString == null) { - if (other.actionString != null) { - return false; - } - } else if (!actionString.equals(other.actionString)) { - return false; - } - return true; - } } diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTester.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTester.java index f275f4b79..7bc352025 100644 --- a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTester.java +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTester.java @@ -22,6 +22,7 @@ package org.onap.policy.apex.core.protocols; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; @@ -41,8 +42,9 @@ public class SupportMessageTester { DummyMessage dummyMessage = new DummyMessage(new DummyAction(null), new AxArtifactKey("Target:0.0.1")); assertEquals(new DummyAction(null), dummyMessage.getAction()); - assertEquals("Message(action=org.onap.policy.apex.core.protocols.DummyAction@1f, " - + "targetKey=AxArtifactKey:(name=Target,version=0.0.1), messageData=null)", dummyMessage.toString()); + assertThat(dummyMessage.toString()) + .startsWith("Message(action=org.onap.policy.apex.core.protocols.DummyAction@") + .endsWith("targetKey=AxArtifactKey:(name=Target,version=0.0.1), messageData=null)"); dummyMessage.setMessageData("Message Data"); assertEquals("Message Data", dummyMessage.getMessageData()); |