diff options
19 files changed, 818 insertions, 111 deletions
diff --git a/core/core-protocols/src/main/java/org/onap/policy/apex/core/protocols/Action.java b/core/core-protocols/src/main/java/org/onap/policy/apex/core/protocols/Action.java index 00d8055be..33679c0e1 100644 --- a/core/core-protocols/src/main/java/org/onap/policy/apex/core/protocols/Action.java +++ b/core/core-protocols/src/main/java/org/onap/policy/apex/core/protocols/Action.java @@ -20,14 +20,16 @@ package org.onap.policy.apex.core.protocols; +import java.io.Serializable; + /** * This interface is used to enforce a common type on actions in the Apex messasging protocol. Action types the Apex * messaging protocol supports implement this interface. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) */ -public interface Action { - +@FunctionalInterface +public interface Action extends Serializable { /** * Return a string representation of each action. * diff --git a/core/core-protocols/src/main/java/org/onap/policy/apex/core/protocols/engdep/messages/EngineServiceInfoResponse.java b/core/core-protocols/src/main/java/org/onap/policy/apex/core/protocols/engdep/messages/EngineServiceInfoResponse.java index be0bfb2c5..4cac23158 100644 --- a/core/core-protocols/src/main/java/org/onap/policy/apex/core/protocols/engdep/messages/EngineServiceInfoResponse.java +++ b/core/core-protocols/src/main/java/org/onap/policy/apex/core/protocols/engdep/messages/EngineServiceInfoResponse.java @@ -20,6 +20,7 @@ package org.onap.policy.apex.core.protocols.engdep.messages; +import java.util.Arrays; import java.util.Collection; import org.onap.policy.apex.core.protocols.Message; @@ -101,7 +102,12 @@ public class EngineServiceInfoResponse extends Response { * @param engineKeyCollection the engine key array */ public void setEngineKeyArray(final Collection<AxArtifactKey> engineKeyCollection) { - engineKeyArray = engineKeyCollection.toArray(new AxArtifactKey[engineKeyCollection.size()]); + if (engineKeyCollection != null) { + engineKeyArray = engineKeyCollection.toArray(new AxArtifactKey[engineKeyCollection.size()]); + } + else { + engineKeyArray = null; + } } /** @@ -121,4 +127,50 @@ public class EngineServiceInfoResponse extends Response { public void setApexModelKey(final AxArtifactKey apexModelKey) { this.apexModelKey = apexModelKey; } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((apexModelKey == null) ? 0 : apexModelKey.hashCode()); + result = prime * result + Arrays.hashCode(engineKeyArray); + result = prime * result + ((engineServiceKey == null) ? 0 : engineServiceKey.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + + EngineServiceInfoResponse other = (EngineServiceInfoResponse) obj; + if (apexModelKey == null) { + if (other.apexModelKey != null) { + return false; + } + } else if (!apexModelKey.equals(other.apexModelKey)) { + return false; + } + if (!Arrays.equals(engineKeyArray, other.engineKeyArray)) { + return false; + } + if (engineServiceKey == null) { + if (other.engineServiceKey != null) { + return false; + } + } else if (!engineServiceKey.equals(other.engineServiceKey)) { + return false; + } + return true; + } } diff --git a/core/core-protocols/src/main/java/org/onap/policy/apex/core/protocols/engdep/messages/Response.java b/core/core-protocols/src/main/java/org/onap/policy/apex/core/protocols/engdep/messages/Response.java index 530e1aba7..c9d4239a1 100644 --- a/core/core-protocols/src/main/java/org/onap/policy/apex/core/protocols/engdep/messages/Response.java +++ b/core/core-protocols/src/main/java/org/onap/policy/apex/core/protocols/engdep/messages/Response.java @@ -31,8 +31,6 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; * @author Liam Fallon (liam.fallon@ericsson.com) */ public class Response extends Message { - private static final int HASH_PRIME = 31; - private static final long serialVersionUID = -4162385039044294476L; private boolean successful = false; @@ -82,54 +80,39 @@ public class Response extends Message { return responseTo; } - /** - * Compare this message to another Response message. - * - * @param otherMessage the other message - * @return true, if successful + /* (non-Javadoc) + * @see java.lang.Object#hashCode() */ - public boolean equals(final Response otherMessage) { - return super.equals(otherMessage) && successful == otherMessage.successful - && responseTo.equals(otherMessage.responseTo); + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((responseTo == null) ? 0 : responseTo.hashCode()); + result = prime * result + (successful ? 1231 : 1237); + return result; } - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.protocols.Message#equals(java.lang.Object) + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) */ @Override - public boolean equals(final Object object) { - if (this == object) { + public boolean equals(Object obj) { + if (this == obj) { return true; } - if (object == null || getClass() != object.getClass()) { - return false; - } - if (!super.equals(object)) { + if (!super.equals(obj)) { return false; } - final Response response = (Response) object; - - if (successful != response.successful) { + Response other = (Response) obj; + if (responseTo == null) { + if (other.responseTo != null) { + return false; + } + } else if (!responseTo.equals(other.responseTo)) { return false; } - return !(responseTo != null ? !responseTo.equals(response.responseTo) : response.responseTo != null); - - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.protocols.Message#hashCode() - */ - @Override - public int hashCode() { - int result = super.hashCode(); - result = HASH_PRIME * result + (successful ? 1 : 0); - result = HASH_PRIME * result + (responseTo != null ? responseTo.hashCode() : 0); - return result; + return successful == other.successful; } /* diff --git a/core/core-protocols/src/main/java/org/onap/policy/apex/core/protocols/engdep/messages/UpdateModel.java b/core/core-protocols/src/main/java/org/onap/policy/apex/core/protocols/engdep/messages/UpdateModel.java index 8d6d315ce..e29889ea8 100644 --- a/core/core-protocols/src/main/java/org/onap/policy/apex/core/protocols/engdep/messages/UpdateModel.java +++ b/core/core-protocols/src/main/java/org/onap/policy/apex/core/protocols/engdep/messages/UpdateModel.java @@ -97,4 +97,35 @@ public class UpdateModel extends Message { public String toString() { return "UpdateModel {" + super.toString() + "}[]"; } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (forceInstall ? 1231 : 1237); + result = prime * result + (ignoreConflicts ? 1231 : 1237); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + + UpdateModel other = (UpdateModel) obj; + if (forceInstall != other.forceInstall) { + return false; + } + return ignoreConflicts == other.ignoreConflicts; + } } 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 new file mode 100644 index 000000000..9f63e5294 --- /dev/null +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/DummyAction.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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========================================================= + */ + +package org.onap.policy.apex.core.protocols; + +import org.onap.policy.apex.core.protocols.Action; + +/** + * Dummy action for testing. + */ +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; + } + + /* (non-Javadoc) + * @see org.onap.policy.apex.core.protocols.Action#getActionString() + */ + @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/DummyMessage.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/DummyMessage.java new file mode 100644 index 000000000..735c20e5d --- /dev/null +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/DummyMessage.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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========================================================= + */ + +package org.onap.policy.apex.core.protocols; + +import org.onap.policy.apex.core.protocols.Action; +import org.onap.policy.apex.core.protocols.Message; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; + +/** + * A dummy message class for testing. + * + */ +public class DummyMessage extends Message { + private static final long serialVersionUID = 8671295165136561708L; + + public DummyMessage(final Action action, final AxArtifactKey targetKey) { + super(action, targetKey); + } + + public DummyMessage(final Action action, final AxArtifactKey targetKey, final String messageData) { + super(action, targetKey, messageData); + } +} diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/MessageTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/MessageTest.java new file mode 100644 index 000000000..a9c86d618 --- /dev/null +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/MessageTest.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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========================================================= + */ + +package org.onap.policy.apex.core.protocols; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.policy.apex.core.protocols.engdep.messages.StartEngine; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; + +/** + * Test of the abstract Message class. + */ +public class MessageTest { + + @SuppressWarnings("unlikely-arg-type") + @Test + public void testMessage() { + assertNotNull(new DummyMessage(new DummyAction(null), new AxArtifactKey())); + assertNotNull(new DummyMessage(new DummyAction(null), new AxArtifactKey(), "Message Data")); + + 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), data=null]", dummyMessage.toString()); + + dummyMessage.setMessageData("Message Data"); + assertEquals("Message Data", dummyMessage.getMessageData()); + dummyMessage.appendMessageData("\nMore Message Data"); + assertEquals("Message Data\nMore Message Data", dummyMessage.getMessageData()); + dummyMessage.setMessageData(null); + dummyMessage.appendMessageData("\nMore Message Data"); + assertEquals("\nMore Message Data", dummyMessage.getMessageData()); + + dummyMessage.setReplyTimeout(123); + assertEquals(123, dummyMessage.getReplyTimeout()); + assertEquals(new AxArtifactKey("Target:0.0.1"), dummyMessage.getTarget()); + assertEquals("Target", dummyMessage.getTargetName()); + + assertTrue(dummyMessage.hashCode() != 0); + dummyMessage.setMessageData(null); + assertTrue(dummyMessage.hashCode() != 0); + dummyMessage = new DummyMessage(null, null, null); + assertEquals(0, dummyMessage.hashCode()); + + assertTrue(dummyMessage.equals(dummyMessage)); + assertFalse(dummyMessage.equals(null)); + assertFalse(dummyMessage.equals(new StartEngine(new AxArtifactKey()))); + + dummyMessage = new DummyMessage(new DummyAction(null), null, null); + DummyMessage otherDummyMessage = new DummyMessage(null, null, null); + assertFalse(dummyMessage.equals(otherDummyMessage)); + otherDummyMessage = new DummyMessage(new DummyAction(null), null, null); + assertTrue(dummyMessage.equals(otherDummyMessage)); + dummyMessage = new DummyMessage(null, null, null); + assertFalse(dummyMessage.equals(otherDummyMessage)); + otherDummyMessage = new DummyMessage(null, null, null); + assertTrue(dummyMessage.equals(otherDummyMessage)); + + dummyMessage = new DummyMessage(null, new AxArtifactKey(), null); + otherDummyMessage = new DummyMessage(null, null, null); + assertFalse(dummyMessage.equals(otherDummyMessage)); + otherDummyMessage = new DummyMessage(null, new AxArtifactKey(), null); + assertTrue(dummyMessage.equals(otherDummyMessage)); + dummyMessage = new DummyMessage(null, null, null); + assertFalse(dummyMessage.equals(otherDummyMessage)); + otherDummyMessage = new DummyMessage(null, null, null); + assertTrue(dummyMessage.equals(otherDummyMessage)); + + dummyMessage = new DummyMessage(null, null, "Message"); + otherDummyMessage = new DummyMessage(null, null, null); + assertFalse(dummyMessage.equals(otherDummyMessage)); + otherDummyMessage = new DummyMessage(null, null, "Message"); + assertTrue(dummyMessage.equals(otherDummyMessage)); + dummyMessage = new DummyMessage(null, null, null); + assertFalse(dummyMessage.equals(otherDummyMessage)); + otherDummyMessage = new DummyMessage(null, null, null); + assertTrue(dummyMessage.equals(otherDummyMessage)); + } +} diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/EngDepActionTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/EngDepActionTest.java new file mode 100644 index 000000000..1602dac1a --- /dev/null +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/EngDepActionTest.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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========================================================= + */ + +package org.onap.policy.apex.core.protocols.engdep; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.policy.apex.core.protocols.engdep.EngDepAction; + +/** + * Test the Eng Dep Action class. + * + */ +public class EngDepActionTest { + + @Test + public void test() { + assertEquals("gets runtime information an Apex engine service", EngDepAction.GET_ENGINE_INFO.getActionString()); + assertEquals("Apex engine service information", EngDepAction.GET_ENGINE_SERVICE_INFO.getActionString()); + assertEquals("gets the status of an Apex engine service", EngDepAction.GET_ENGINE_STATUS.getActionString()); + assertEquals("response from Apex engine service", EngDepAction.RESPONSE.getActionString()); + assertEquals("starts an Apex engine", EngDepAction.START_ENGINE.getActionString()); + assertEquals("starts periodic events on an Apex engine service", + EngDepAction.START_PERIODIC_EVENTS.getActionString()); + assertEquals("stops an Apex engine service", EngDepAction.STOP_ENGINE.getActionString()); + assertEquals("stops periodic events on an Apex engine service", + EngDepAction.STOP_PERIODIC_EVENTS.getActionString()); + assertEquals("update model on Apex engine service", EngDepAction.UPDATE_MODEL.getActionString()); + } + +} diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/GetPolicyStatusTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/GetPolicyStatusTest.java deleted file mode 100644 index 97cc8d5b9..000000000 --- a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/GetPolicyStatusTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. 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========================================================= - */ - -package org.onap.policy.apex.core.protocols.engdep; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.net.UnknownHostException; - -import org.junit.Test; -import org.onap.policy.apex.core.protocols.engdep.messages.GetEngineStatus; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The Class GetPolicyStatusTest. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class GetPolicyStatusTest { - // Logger for this class - private static final XLogger logger = XLoggerFactory.getXLogger(GetPolicyStatusTest.class); - - GetEngineStatus message = null; - - /** - * Test register entity. - * - * @throws UnknownHostException the unknown host exception - */ - @Test - public void testRegisterEntity() throws UnknownHostException { - final AxArtifactKey targetKey = new AxArtifactKey("PolicyStatusTest", "0.0.1"); - message = new GetEngineStatus(targetKey); - assertNotNull(message); - logger.debug(message.toString()); - assertTrue((message.toString()).contains("PolicyStatusTest")); - } -} diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/EngineServiceInfoResponseTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/EngineServiceInfoResponseTest.java new file mode 100644 index 000000000..e1f709779 --- /dev/null +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/EngineServiceInfoResponseTest.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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========================================================= + */ + +package org.onap.policy.apex.core.protocols.engdep.messages; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; + +/** + * Test the start engine message. + */ +public class EngineServiceInfoResponseTest { + + @Test + public void test() { + AxArtifactKey targetKey = new AxArtifactKey("Target:0.0.1"); + GetEngineServiceInfo request = new GetEngineServiceInfo(targetKey); + + EngineServiceInfoResponse response = new EngineServiceInfoResponse(targetKey, true, request); + assertNotNull(response); + response = new EngineServiceInfoResponse(targetKey, true, "Response Data", request); + assertNotNull(response); + assertEquals("Response Data", response.getMessageData()); + + AxArtifactKey apexModelKey = new AxArtifactKey("Model:0.0.1"); + response.setApexModelKey(apexModelKey); + assertEquals(apexModelKey, response.getApexModelKey()); + + AxArtifactKey engineServiceKey = new AxArtifactKey("EngineService:0.0.1"); + response.setEngineServiceKey(engineServiceKey);; + assertEquals(engineServiceKey, response.getEngineServiceKey()); + + List<AxArtifactKey> engineKeyArrayList = new ArrayList<>(); + AxArtifactKey engineKey = new AxArtifactKey("Engine:0.0.1"); + engineKeyArrayList.add(engineKey); + response.setEngineKeyArray(engineKeyArrayList); + assertEquals(engineKeyArrayList.get(0), response.getEngineKeyArray()[0]); + + response = new EngineServiceInfoResponse(null, false, null); + assertTrue(response.hashCode() != 0); + response.setApexModelKey(apexModelKey); + assertTrue(response.hashCode() != 0); + response.setApexModelKey(null); + response.setEngineServiceKey(engineServiceKey);; + assertTrue(response.hashCode() != 0); + response.setEngineServiceKey(null); + response.setEngineKeyArray(engineKeyArrayList); + assertTrue(response.hashCode() != 0); + response.setEngineKeyArray(null); + + assertTrue(response.equals(response)); + assertFalse(response.equals(null)); + assertFalse(response.equals(new StartEngine(new AxArtifactKey()))); + + response = new EngineServiceInfoResponse(null, false, null); + EngineServiceInfoResponse otherResponse = new EngineServiceInfoResponse(null, false, null); + + response.setApexModelKey(apexModelKey); + assertFalse(response.equals(otherResponse)); + otherResponse.setApexModelKey(apexModelKey); + assertTrue(response.equals(otherResponse)); + response.setApexModelKey(null); + assertFalse(response.equals(otherResponse)); + otherResponse.setApexModelKey(null); + assertTrue(response.equals(otherResponse)); + + response.setEngineServiceKey(engineServiceKey); + assertFalse(response.equals(otherResponse)); + otherResponse.setEngineServiceKey(engineServiceKey); + assertTrue(response.equals(otherResponse)); + response.setEngineServiceKey(null); + assertFalse(response.equals(otherResponse)); + otherResponse.setEngineServiceKey(null); + assertTrue(response.equals(otherResponse)); + + response.setEngineKeyArray(engineKeyArrayList); + assertFalse(response.equals(otherResponse)); + otherResponse.setEngineKeyArray(engineKeyArrayList); + assertTrue(response.equals(otherResponse)); + response.setEngineKeyArray(null); + assertFalse(response.equals(otherResponse)); + otherResponse.setEngineKeyArray(null); + assertTrue(response.equals(otherResponse)); + + } +} diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/GetEngineInfoTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/GetEngineInfoTest.java new file mode 100644 index 000000000..5bdf4a9ce --- /dev/null +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/GetEngineInfoTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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========================================================= + */ + +package org.onap.policy.apex.core.protocols.engdep.messages; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; + +/** + * Test the start engine message. + */ +public class GetEngineInfoTest { + + @Test + public void test() { + assertNotNull(new GetEngineInfo(new AxArtifactKey())); + assertNotNull(new GetEngineInfo(new AxArtifactKey(), "Start Engine Data")); + assertEquals("GetEngineInfo {Message [action=GET_ENGINE_INFO, " + + "targetKey=AxArtifactKey:(name=NULL,version=0.0.0), data=null]}[]", + new GetEngineInfo(new AxArtifactKey()).toString()); + } +} diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/GetEngineServiceInfoTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/GetEngineServiceInfoTest.java new file mode 100644 index 000000000..1bf4d6b28 --- /dev/null +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/GetEngineServiceInfoTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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========================================================= + */ + +package org.onap.policy.apex.core.protocols.engdep.messages; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; + +/** + * Test the start engine message. + */ +public class GetEngineServiceInfoTest { + + @Test + public void test() { + assertNotNull(new GetEngineServiceInfo(new AxArtifactKey())); + assertNotNull(new GetEngineServiceInfo(new AxArtifactKey(), "Start Engine Data")); + assertEquals("GetEngineServiceInfo {Message [action=GET_ENGINE_SERVICE_INFO, " + + "targetKey=AxArtifactKey:(name=NULL,version=0.0.0), data=null]}[]", + new GetEngineServiceInfo(new AxArtifactKey()).toString()); + } +} diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/GetExecutionStatusTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/GetEngineStatusTest.java index d5cf2bcba..62cb5911f 100644 --- a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/GetExecutionStatusTest.java +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/GetEngineStatusTest.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.apex.core.protocols.engdep; +package org.onap.policy.apex.core.protocols.engdep.messages; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -36,9 +36,9 @@ import org.slf4j.ext.XLoggerFactory; * * @author Liam Fallon (liam.fallon@ericsson.com) */ -public class GetExecutionStatusTest { +public class GetEngineStatusTest { // Logger for this class - private static final XLogger logger = XLoggerFactory.getXLogger(GetExecutionStatusTest.class); + private static final XLogger logger = XLoggerFactory.getXLogger(GetEngineStatusTest.class); GetEngineStatus message = null; diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/ResponseTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/ResponseTest.java index 74def7cc0..447ceeace 100644 --- a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/ResponseTest.java +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/ResponseTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Copyright (C) 2018 Ericsson. 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. @@ -18,8 +18,9 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.apex.core.protocols.engdep; +package org.onap.policy.apex.core.protocols.engdep.messages; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -41,25 +42,56 @@ public class ResponseTest { // Logger for this class private static final XLogger logger = XLoggerFactory.getXLogger(ResponseTest.class); - Response message = null; - /** * Test response. * * @throws UnknownHostException the unknown host exception */ + @SuppressWarnings("unlikely-arg-type") @Test public void testResponse() throws UnknownHostException { final AxArtifactKey responseKey = new AxArtifactKey("ResponseTest", "0.0.1"); - final AxArtifactKey responseToKey = new AxArtifactKey("ResponseTestTO", "0.0.1"); - message = new Response(responseKey, false, new UpdateModel(responseToKey)); + final AxArtifactKey responseToKey = new AxArtifactKey("ResponseTestTo", "0.0.1"); + UpdateModel responseTo = new UpdateModel(responseToKey); + + Response message = new Response(responseKey, false, responseTo); logger.debug(message.toString()); assertTrue(message.toString().contains("ResponseTest")); assertFalse(message.isSuccessful()); - message = new Response(responseKey, true, new UpdateModel(responseToKey)); + message = new Response(responseKey, true, responseTo); logger.debug(message.toString()); assertTrue(message.toString().contains("ResponseTest")); assertTrue(message.isSuccessful()); + assertEquals(responseTo, message.getResponseTo()); + + message = new Response(null, false, null); + assertTrue(message.hashCode() != 0); + message = new Response(responseKey, false, null); + assertTrue(message.hashCode() != 0); + message = new Response(responseKey, true, null); + assertTrue(message.hashCode() != 0); + message = new Response(responseKey, true, new UpdateModel(null)); + assertTrue(message.hashCode() != 0); + + assertTrue(message.equals(message)); + assertFalse(message.equals(null)); + assertFalse(message.equals(new StartEngine(new AxArtifactKey()))); + + message = new Response(null, false, responseTo); + Response otherMessage = new Response(null, false, null); + assertFalse(message.equals(otherMessage)); + otherMessage = new Response(null, false, responseTo); + assertTrue(message.equals(otherMessage)); + message = new Response(null, false, null); + assertFalse(message.equals(otherMessage)); + otherMessage = new Response(null, false, null); + assertTrue(message.equals(otherMessage)); + + message = new Response(null, false, null); + otherMessage = new Response(null, true, null); + assertFalse(message.equals(otherMessage)); + otherMessage = new Response(null, false, null); + assertTrue(message.equals(otherMessage)); } } diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/StartEngineTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/StartEngineTest.java new file mode 100644 index 000000000..037f7580e --- /dev/null +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/StartEngineTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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========================================================= + */ + +package org.onap.policy.apex.core.protocols.engdep.messages; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; + +/** + * Test the start engine message. + */ +public class StartEngineTest { + + @Test + public void test() { + assertNotNull(new StartEngine(new AxArtifactKey())); + assertNotNull(new StartEngine(new AxArtifactKey(), "Start Engine Data")); + assertEquals("StartEngine {Message [action=START_ENGINE, " + + "targetKey=AxArtifactKey:(name=NULL,version=0.0.0), data=null]}[]", + new StartEngine(new AxArtifactKey()).toString()); + } +} diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/StartPeriodicEventsTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/StartPeriodicEventsTest.java new file mode 100644 index 000000000..2f3efc754 --- /dev/null +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/StartPeriodicEventsTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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========================================================= + */ + +package org.onap.policy.apex.core.protocols.engdep.messages; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; + +/** + * Test the start engine message. + */ +public class StartPeriodicEventsTest { + + @Test + public void test() { + assertNotNull(new StartPeriodicEvents(new AxArtifactKey())); + assertNotNull(new StartPeriodicEvents(new AxArtifactKey(), "Start Periodic Events Data")); + assertEquals("StartPeriodicEvents {Message [action=START_PERIODIC_EVENTS, " + + "targetKey=AxArtifactKey:(name=NULL,version=0.0.0), data=null]}[]", + new StartPeriodicEvents(new AxArtifactKey()).toString()); + } +} diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/StopEngineTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/StopEngineTest.java new file mode 100644 index 000000000..a9f8dcb29 --- /dev/null +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/StopEngineTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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========================================================= + */ + +package org.onap.policy.apex.core.protocols.engdep.messages; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; + +/** + * Test the start engine message. + */ +public class StopEngineTest { + + @Test + public void test() { + assertNotNull(new StopEngine(new AxArtifactKey())); + assertNotNull(new StopEngine(new AxArtifactKey(), "Stop Engine Data")); + assertEquals("StopEngine {Message [action=STOP_ENGINE, " + + "targetKey=AxArtifactKey:(name=NULL,version=0.0.0), data=null]}[]", + new StopEngine(new AxArtifactKey()).toString()); + } +} diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/StopPeriodicEventsTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/StopPeriodicEventsTest.java new file mode 100644 index 000000000..e174031ef --- /dev/null +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/StopPeriodicEventsTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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========================================================= + */ + +package org.onap.policy.apex.core.protocols.engdep.messages; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; + +/** + * Test the start engine message. + */ +public class StopPeriodicEventsTest { + + @Test + public void test() { + assertNotNull(new StopPeriodicEvents(new AxArtifactKey())); + assertNotNull(new StopPeriodicEvents(new AxArtifactKey(), "Stop Periodic Events Data")); + assertEquals("StopPeriodicEvents {Message [action=STOP_PERIODIC_EVENTS, " + + "targetKey=AxArtifactKey:(name=NULL,version=0.0.0), data=null]}[]", + new StopPeriodicEvents(new AxArtifactKey()).toString()); + } +} diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/UpdateModelTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/UpdateModelTest.java index ca919c389..b14d168b8 100644 --- a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/UpdateModelTest.java +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/engdep/messages/UpdateModelTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Copyright (C) 2018 Ericsson. 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. @@ -18,8 +18,9 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.apex.core.protocols.engdep; +package org.onap.policy.apex.core.protocols.engdep.messages; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -47,12 +48,41 @@ public class UpdateModelTest { * * @throws UnknownHostException the unknown host exception */ + @SuppressWarnings("unlikely-arg-type") @Test public void testRegisterEntity() throws UnknownHostException { + assertNotNull(new UpdateModel(new AxArtifactKey())); final AxArtifactKey targetKey = new AxArtifactKey("UpdateModelTest", "0.0.1"); message = new UpdateModel(targetKey, new String("Placeholder for Apex model XML"), false, false); assertNotNull(message); logger.debug(message.toString()); assertTrue((message.toString()).contains("Placeholder for Apex model XML")); + assertFalse(message.isIgnoreConflicts()); + assertFalse(message.isForceInstall()); + + message = new UpdateModel(null, null, false, false); + assertTrue(message.hashCode() != 0); + message = new UpdateModel(null, null, true, false); + assertTrue(message.hashCode() != 0); + message = new UpdateModel(null, null, true, true); + assertTrue(message.hashCode() != 0); + message = new UpdateModel(null, null, false, true); + assertTrue(message.hashCode() != 0); + + assertTrue(message.equals(message)); + assertFalse(message.equals(null)); + assertFalse(message.equals(new StartEngine(new AxArtifactKey()))); + + message = new UpdateModel(null, null, false, false); + UpdateModel otherMessage = new UpdateModel(null, null, false, false); + assertTrue(message.equals(otherMessage)); + message = new UpdateModel(null, null, true, false); + assertFalse(message.equals(otherMessage)); + otherMessage = new UpdateModel(null, null, true, false); + assertTrue(message.equals(otherMessage)); + message = new UpdateModel(null, null, false, true); + assertFalse(message.equals(otherMessage)); + otherMessage = new UpdateModel(null, null, false, true); + assertTrue(message.equals(otherMessage)); } } |