aboutsummaryrefslogtreecommitdiffstats
path: root/services/services-engine/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'services/services-engine/src/test')
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/DummyAction.java45
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/DummyEngineService.java276
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/DummyMessage.java41
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListenerTest.java162
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessagingServiceTest.java67
5 files changed, 0 insertions, 591 deletions
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/DummyAction.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/DummyAction.java
deleted file mode 100644
index 6b59b0754..000000000
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/DummyAction.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*-
- * ============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.service.engine.engdep;
-
-import org.apache.commons.lang3.NotImplementedException;
-import org.onap.policy.apex.core.protocols.Action;
-
-/**
- * Bad action class.
- */
-public class DummyAction implements Action {
- private static final long serialVersionUID = -6562765120898697138L;
-
- private String actionString;
-
- public DummyAction(final String actionString) {
- this.actionString = actionString;
- }
-
- @Override
- public String getActionString() {
- if (actionString == "throw exception") {
- throw new NotImplementedException("dummy IO excepton");
- }
- return actionString;
- }
-}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/DummyEngineService.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/DummyEngineService.java
deleted file mode 100644
index 52d4a7d5d..000000000
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/DummyEngineService.java
+++ /dev/null
@@ -1,276 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
- * ================================================================================
- * 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.service.engine.engdep;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import org.apache.commons.lang3.NotImplementedException;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
-import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
-import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel;
-import org.onap.policy.apex.model.enginemodel.concepts.AxEngineState;
-import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
-import org.onap.policy.apex.service.engine.runtime.ApexEventListener;
-import org.onap.policy.apex.service.engine.runtime.EngineService;
-import org.onap.policy.apex.service.engine.runtime.EngineServiceEventInterface;
-
-/**
- * A dummy engine service class.
- */
-public class DummyEngineService implements EngineService {
-
- private AxArtifactKey startEngineKey;
- private AxArtifactKey stopEngineKey;
- private long periodicPeriod;
- private AxArtifactKey statusKey;
- private AxArtifactKey runtimeInfoKey;
- private int modelKeyGetCalled;
- private AxArtifactKey updateModelKey;
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void registerActionListener(String listenerName, ApexEventListener listener) {
- throw new NotImplementedException("Not implemented on dummy class");
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void deregisterActionListener(String listenerName) {
- throw new NotImplementedException("Not implemented on dummy class");
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public EngineServiceEventInterface getEngineServiceEventInterface() {
- throw new NotImplementedException("Not implemented on dummy class");
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public AxArtifactKey getKey() {
- return new AxArtifactKey("DummyEngineService:0.0.1");
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public Collection<AxArtifactKey> getEngineKeys() {
- List<AxArtifactKey> keys = new ArrayList<>();
- keys.add(new AxArtifactKey("DummyEngineService:0.0.1"));
- return keys;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public AxArtifactKey getApexModelKey() {
- modelKeyGetCalled++;
-
- return new AxArtifactKey("DummyApexModelKey:0.0.1");
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void updateModel(AxArtifactKey engineServiceKey, String apexModelString, boolean forceFlag)
- throws ApexException {
- updateModelKey = engineServiceKey;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void updateModel(AxArtifactKey engineServiceKey, AxPolicyModel apexModel, boolean forceFlag)
- throws ApexException {
- throw new NotImplementedException("Not implemented on dummy class");
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public AxEngineState getState() {
- throw new NotImplementedException("Not implemented on dummy class");
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public List<AxEngineModel> getEngineStats() {
- throw new NotImplementedException("Not implemented on dummy class");
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void startAll() throws ApexException {
- throw new NotImplementedException("Not implemented on dummy class");
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void start(AxArtifactKey engineKey) throws ApexException {
- startEngineKey = engineKey;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void stop() throws ApexException {
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void stop(AxArtifactKey engineKey) throws ApexException {
- stopEngineKey = engineKey;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void clear() throws ApexException {
- throw new NotImplementedException("Not implemented on dummy class");
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void clear(AxArtifactKey engineKey) throws ApexException {
- throw new NotImplementedException("Not implemented on dummy class");
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public boolean isStarted() {
- throw new NotImplementedException("Not implemented on dummy class");
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public boolean isStarted(AxArtifactKey engineKey) {
- throw new NotImplementedException("Not implemented on dummy class");
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public boolean isStopped() {
- throw new NotImplementedException("Not implemented on dummy class");
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public boolean isStopped(AxArtifactKey engineKey) {
- throw new NotImplementedException("Not implemented on dummy class");
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void startPeriodicEvents(long period) throws ApexException {
- periodicPeriod = period;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void stopPeriodicEvents() throws ApexException {
- periodicPeriod = 0;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String getStatus(AxArtifactKey engineKey) throws ApexException {
- statusKey = engineKey;
- return "The Status";
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String getRuntimeInfo(AxArtifactKey engineKey) throws ApexException {
- runtimeInfoKey = engineKey;
- return "The Runtime Info";
- }
-
- public AxArtifactKey getStartEngineKey() {
- return startEngineKey;
- }
-
- public AxArtifactKey getStopEngineKey() {
- return stopEngineKey;
- }
-
- public long getPeriodicPeriod() {
- return periodicPeriod;
- }
-
- public AxArtifactKey getStatusKey() {
- return statusKey;
- }
-
- public AxArtifactKey getRuntimeInfoKey() {
- return runtimeInfoKey;
- }
-
- public int getModelKeyGetCalled() {
- return modelKeyGetCalled;
- }
-
- public AxArtifactKey getUpdateModelKey() {
- return updateModelKey;
- }
-}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/DummyMessage.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/DummyMessage.java
deleted file mode 100644
index 5d1b1ce8e..000000000
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/DummyMessage.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*-
- * ============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.service.engine.engdep;
-
-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;
-
-/**
- * Bad protocol message.
- */
-public class DummyMessage extends Message {
- private static final long serialVersionUID = 3827403727783909797L;
-
- /**
- * Constructor.
- * @param action the message action
- * @param targetKey the message target key
- */
- public DummyMessage(Action action, AxArtifactKey targetKey) {
- super(action, targetKey);
- }
-}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListenerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListenerTest.java
deleted file mode 100644
index 079be6bd2..000000000
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListenerTest.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
- * ================================================================================
- * 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.service.engine.engdep;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.awaitility.Awaitility.await;
-import static org.junit.Assert.assertEquals;
-
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.BlockingQueue;
-import org.java_websocket.WebSocket;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.mockito.internal.util.reflection.Whitebox;
-import org.onap.policy.apex.core.infrastructure.messaging.impl.ws.messageblock.MessageBlock;
-import org.onap.policy.apex.core.protocols.Message;
-import org.onap.policy.apex.core.protocols.engdep.messages.GetEngineInfo;
-import org.onap.policy.apex.core.protocols.engdep.messages.GetEngineServiceInfo;
-import org.onap.policy.apex.core.protocols.engdep.messages.GetEngineStatus;
-import org.onap.policy.apex.core.protocols.engdep.messages.Response;
-import org.onap.policy.apex.core.protocols.engdep.messages.StartEngine;
-import org.onap.policy.apex.core.protocols.engdep.messages.StartPeriodicEvents;
-import org.onap.policy.apex.core.protocols.engdep.messages.StopEngine;
-import org.onap.policy.apex.core.protocols.engdep.messages.StopPeriodicEvents;
-import org.onap.policy.apex.core.protocols.engdep.messages.UpdateModel;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
-import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
-
-/**
- * Test the EngDep messaging Service.
- */
-public class EngDepMessageListenerTest {
- @Mock
- private WebSocket webSocketMock;
-
- /**
- * Set up mocking of the engine service facade.
- *
- * @throws ApexException on engine service facade setup errors
- */
- @Before
- public void initializeMocking() throws ApexException {
- MockitoAnnotations.initMocks(this);
-
- Mockito.doReturn(new InetSocketAddress("HostAddress", 123)).when(webSocketMock).getRemoteSocketAddress();
- Mockito.doReturn(true).when(webSocketMock).isOpen();
- }
-
- @Test
- public void testMessageListener() throws ApexException {
- DummyEngineService dummyEngineService = new DummyEngineService();
- EngDepMessageListener listener = new EngDepMessageListener(dummyEngineService);
- listener.startProcessorThread();
-
- assertThatThrownBy(() -> listener.onMessage("bad string message"))
- .hasMessage("String messages are not supported on the EngDep protocol");
- List<Message> messageList = new ArrayList<>();
- messageList.add(new StartEngine(new AxArtifactKey("Start:0.0.1")));
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- BlockingQueue<?> messageQueue = (BlockingQueue<?>) Whitebox.getInternalState(listener, "messageQueue");
- await().until(messageQueue::isEmpty);
- assertEquals("Start:0.0.1", dummyEngineService.getStartEngineKey().getId());
-
- messageList.clear();
- messageList.add(new StopEngine(new AxArtifactKey("Stop:0.0.1")));
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
- assertEquals("Stop:0.0.1", dummyEngineService.getStopEngineKey().getId());
-
- messageList.clear();
- messageList.add(new StartPeriodicEvents(new AxArtifactKey("StartPeriodic:0.0.1"), "12345"));
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
- assertEquals(12345, dummyEngineService.getPeriodicPeriod());
-
- messageList.clear();
- messageList.add(new StopPeriodicEvents(new AxArtifactKey("StopPeriodic:0.0.1")));
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
- assertEquals(0, dummyEngineService.getPeriodicPeriod());
-
- messageList.clear();
- messageList.add(new GetEngineInfo(new AxArtifactKey("EngineInfo:0.0.1")));
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
- assertEquals("EngineInfo:0.0.1", dummyEngineService.getRuntimeInfoKey().getId());
-
- messageList.clear();
- messageList.add(new GetEngineStatus(new AxArtifactKey("EngineStatus:0.0.1")));
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
- assertEquals("EngineStatus:0.0.1", dummyEngineService.getStatusKey().getId());
-
- messageList.clear();
- messageList.add(new GetEngineServiceInfo(new AxArtifactKey("EngineServiceInfo:0.0.1")));
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
- assertEquals(1, dummyEngineService.getModelKeyGetCalled());
-
- messageList.clear();
- messageList.add(new UpdateModel(new AxArtifactKey("UpdateModel:0.0.1")));
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
- assertEquals("UpdateModel:0.0.1", dummyEngineService.getUpdateModelKey().getId());
-
- messageList.clear();
- messageList.add(new Response(new AxArtifactKey("UpdateModel:0.0.1"), false,
- new GetEngineInfo(new AxArtifactKey("EngineInfo:0.0.1"))));
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
- assertEquals("UpdateModel:0.0.1", dummyEngineService.getUpdateModelKey().getId());
- messageList.clear();
- Message badMessage0 = new DummyMessage(null, null);
- messageList.add(badMessage0);
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
-
- messageList.clear();
- Message badMessage1 = new DummyMessage(new DummyAction(null), null);
- messageList.add(badMessage1);
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
-
- messageList.clear();
- Message badMessage2 = new DummyMessage(new DummyAction("throw exception"), null);
- messageList.add(badMessage2);
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
-
- messageList.clear();
- Mockito.doReturn(false).when(webSocketMock).isOpen();
- messageList.add(new StartEngine(new AxArtifactKey("Start:0.0.1")));
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
-
- listener.stopProcessorThreads();
- }
-}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessagingServiceTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessagingServiceTest.java
deleted file mode 100644
index 10eece1cd..000000000
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessagingServiceTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
- * ================================================================================
- * 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.service.engine.engdep;
-
-import static org.awaitility.Awaitility.await;
-import static org.junit.Assert.assertFalse;
-
-import java.util.concurrent.TimeUnit;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.onap.policy.apex.core.infrastructure.messaging.MessagingService;
-import org.onap.policy.apex.core.protocols.Message;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
-
-/**
- * Test the EngDep messaging Service.
- */
-public class EngDepMessagingServiceTest {
- @Mock
- private MessagingService<Message> messageServiceMock;
- private EngDepMessagingService edMessagingService;
-
- /**
- * Set up mocking of the engine service facade.
- *
- * @throws ApexException on engine service facade setup errors
- */
- @Before
- public void initializeMocking() throws ApexException {
- MockitoAnnotations.initMocks(this);
-
- edMessagingService = Mockito.spy(new EngDepMessagingService(new DummyEngineService(), 12345));
- Mockito.doReturn(messageServiceMock).when(edMessagingService).getMessageService(12345);
- }
-
- @Test
- public void testStartStop() throws ApexException {
- edMessagingService.start();
- await().atMost(1, TimeUnit.SECONDS).until(() -> edMessagingService.isStarted());
- assertFalse(edMessagingService.isStopped());
- edMessagingService.stop();
- await().atMost(1, TimeUnit.SECONDS).until(() -> edMessagingService.isStopped());
- assertFalse(edMessagingService.isStarted());
- }
-}