From: saul.gill Date: Thu, 10 Aug 2023 15:58:48 +0000 (+0100) Subject: Java 17 Upgrade X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F25%2F135725%2F2;p=policy%2Fapex-pdp.git Java 17 Upgrade Updated dependencies to latest versions Made Java 17 changes Moved all version numbers to main apex pom Issue-ID: POLICY-4675 Change-Id: Ia0c17f17ef1e536bbfddd5f488ed9510a557842f Signed-off-by: saul.gill --- diff --git a/auth/cli-codegen/pom.xml b/auth/cli-codegen/pom.xml index bcd147c45..28a8fa889 100644 --- a/auth/cli-codegen/pom.xml +++ b/auth/cli-codegen/pom.xml @@ -1,6 +1,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/core/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ApplicationThreadFactory.java b/core/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ApplicationThreadFactory.java index 9345abaaa..cea505854 100644 --- a/core/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ApplicationThreadFactory.java +++ b/core/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ApplicationThreadFactory.java @@ -3,6 +3,7 @@ * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,7 +72,11 @@ public class ApplicationThreadFactory implements ThreadFactory { * @param stackSize the stack size * @param threadPriority the thread priority */ + @SuppressWarnings({ + "deprecation", "removal" + }) public ApplicationThreadFactory(final String nameLocal, final long stackSize, final int threadPriority) { + @SuppressWarnings("removal") final var s = System.getSecurityManager(); group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup(); name = APPLICATION_NAME + nameLocal + HYPHEN + NEXT_POOL_NUMBER.getAndIncrement(); diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java index 3b682acd6..8d7df45cd 100644 --- a/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java +++ b/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2021 Nordix Foundation. + * Modifications Copyright (C) 2019-2021, 2023 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -39,9 +39,10 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.apex.context.parameters.ContextParameterConstants; import org.onap.policy.apex.context.parameters.DistributorParameters; import org.onap.policy.apex.context.parameters.LockManagerParameters; @@ -70,6 +71,7 @@ import org.onap.policy.common.parameters.ParameterService; /** * Test the engine implementation. */ +@RunWith(MockitoJUnitRunner.class) public class ApexEngineImplTest { private static final String ENGINE_ID = "Engine:0.0.1"; @@ -97,10 +99,8 @@ public class ApexEngineImplTest { */ @Before public void initializeMocking() throws ApexException { - MockitoAnnotations.initMocks(this); - Mockito.doThrow(new StateMachineException("mocked state machine exception", - new IOException("nexted exception"))).when(smHandlerMock).execute(Mockito.anyObject()); + new IOException("nexted exception"))).when(smHandlerMock).execute(Mockito.any()); } /** diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateExecutorTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateExecutorTest.java index f3e12cc1f..fc1b339d2 100644 --- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateExecutorTest.java +++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateExecutorTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020, 2023 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,9 +26,10 @@ import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.apex.core.engine.ExecutorParameters; import org.onap.policy.apex.core.engine.context.ApexInternalContext; import org.onap.policy.apex.core.engine.event.EnEvent; @@ -38,6 +39,7 @@ import org.onap.policy.apex.model.policymodel.concepts.AxState; /** * Test task executor. */ +@RunWith(MockitoJUnitRunner.class) public class StateExecutorTest { @Mock private ApexInternalContext internalContextMock; @@ -56,7 +58,6 @@ public class StateExecutorTest { */ @Before public void startMocking() { - MockitoAnnotations.initMocks(this); Mockito.doReturn(new AxReferenceKey("Policy:0.0.1:PolName:State0")).when(axStateMock).getKey(); } diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutorTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutorTest.java index 8f6544497..e140291b4 100644 --- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutorTest.java +++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutorTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020, 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,9 +28,10 @@ import java.util.Map; import java.util.Properties; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.apex.context.ContextException; import org.onap.policy.apex.core.engine.ExecutorParameters; import org.onap.policy.apex.core.engine.context.ApexInternalContext; @@ -43,6 +44,7 @@ import org.onap.policy.apex.model.policymodel.concepts.AxStateFinalizerLogic; /** * Test task executor. */ +@RunWith(MockitoJUnitRunner.class) public class StateFinalizerExecutorTest { @Mock private Executor parentMock; @@ -64,7 +66,6 @@ public class StateFinalizerExecutorTest { */ @Before public void startMocking() { - MockitoAnnotations.initMocks(this); AxState state = new AxState(); state.getStateOutputs().put("ValidOutput", null); diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutorTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutorTest.java index 5d91bd2b3..14cc89ee8 100644 --- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutorTest.java +++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutorTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020, 2023 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -35,9 +35,10 @@ import java.util.Map; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.apex.context.ContextException; import org.onap.policy.apex.context.parameters.SchemaParameters; import org.onap.policy.apex.core.engine.ExecutorParameters; @@ -65,6 +66,7 @@ import org.onap.policy.common.parameters.ParameterService; /** * Test task executor. */ +@RunWith(MockitoJUnitRunner.class) public class StateMachineExecutorTest { @Mock private ApexInternalContext internalContextMock; @@ -89,8 +91,6 @@ public class StateMachineExecutorTest { */ @Before public void startMocking() { - MockitoAnnotations.initMocks(this); - axPolicy.setKey(new AxArtifactKey("Policy:0.0.1")); AxReferenceKey state0Key = new AxReferenceKey(axPolicy.getKey(), "state0"); @@ -169,16 +169,16 @@ public class StateMachineExecutorTest { AxStateTaskReference str1 = new AxStateTaskReference(str1Key, AxStateTaskOutputType.LOGIC, sflKey); state1.getTaskReferences().put(task1Key, str1); - Mockito.doReturn(new DummyTaskExecutor(true)).when(executorFactoryMock).getTaskExecutor(Mockito.anyObject(), - Mockito.anyObject(), Mockito.anyObject()); + Mockito.doReturn(new DummyTaskExecutor(true)).when(executorFactoryMock).getTaskExecutor(Mockito.any(), + Mockito.any(), Mockito.any()); dummyTsle = new DummyTaskSelectExecutor(true); - Mockito.doReturn(dummyTsle).when(executorFactoryMock).getTaskSelectionExecutor(Mockito.anyObject(), - Mockito.anyObject(), Mockito.anyObject()); + Mockito.doReturn(dummyTsle).when(executorFactoryMock).getTaskSelectionExecutor(Mockito.any(), + Mockito.any(), Mockito.any()); dummySfle = new DummyStateFinalizerExecutor(true); - Mockito.doReturn(dummySfle).when(executorFactoryMock).getStateFinalizerExecutor(Mockito.anyObject(), - Mockito.anyObject(), Mockito.anyObject()); + Mockito.doReturn(dummySfle).when(executorFactoryMock).getStateFinalizerExecutor(Mockito.any(), + Mockito.any(), Mockito.any()); } @After diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java index 4160a9f19..1c4ffe4fc 100644 --- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java +++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020, 2023 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -36,9 +36,10 @@ import java.util.Properties; import java.util.TreeMap; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.apex.context.ContextException; import org.onap.policy.apex.core.engine.ExecutorParameters; import org.onap.policy.apex.core.engine.TaskParameters; @@ -57,6 +58,7 @@ import org.onap.policy.apex.model.policymodel.concepts.AxTaskParameter; /** * Test task excutor. */ +@RunWith(MockitoJUnitRunner.class) public class TaskExecutorTest { @Mock private AxTask axTaskMock; @@ -96,7 +98,6 @@ public class TaskExecutorTest { */ @Before public void startMocking() { - MockitoAnnotations.initMocks(this); AxArtifactKey task0Key = new AxArtifactKey("Task0:0.0.1"); Mockito.doReturn(task0Key).when(axTaskMock).getKey(); @@ -117,12 +118,9 @@ public class TaskExecutorTest { AxArtifactKey schemaKey = new AxArtifactKey("Schema:0.0.1"); Mockito.doReturn(schemaKey).when(axInputFieldMock).getSchema(); Mockito.doReturn(schemaKey).when(axOptionalInputFieldMock).getSchema(); - Mockito.doReturn(schemaKey).when(axOutputFieldMock).getSchema(); - Mockito.doReturn(schemaKey).when(axOptionalOutputFieldMock).getSchema(); Mockito.doReturn(schemaKey).when(axMissingOutputFieldMock).getSchema(); Mockito.doReturn(true).when(axOptionalInputFieldMock).getOptional(); - Mockito.doReturn(true).when(axOptionalOutputFieldMock).getOptional(); Mockito.doReturn(false).when(axMissingOutputFieldMock).getOptional(); Mockito.doReturn(taskLogicMock).when(axTaskMock).getTaskLogic(); diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java index 613d1ae01..cf3c59fa9 100644 --- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java +++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020, 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,9 +29,10 @@ import java.util.Map; import java.util.Properties; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.apex.core.engine.ExecutorParameters; import org.onap.policy.apex.core.engine.context.ApexInternalContext; import org.onap.policy.apex.core.engine.event.EnEvent; @@ -45,6 +46,7 @@ import org.onap.policy.apex.model.policymodel.concepts.AxTaskSelectionLogic; /** * Test task executor. */ +@RunWith(MockitoJUnitRunner.class) public class TaskSelectExecutorTest { @Mock private AxState axStateMock; @@ -66,11 +68,9 @@ public class TaskSelectExecutorTest { */ @Before public void startMocking() { - MockitoAnnotations.initMocks(this); AxReferenceKey state0Key = new AxReferenceKey("State0Parent:0.0.1:Parent:State0"); Mockito.doReturn(state0Key).when(axStateMock).getKey(); - Mockito.doReturn(state0Key.getId()).when(axStateMock).getId(); Map taskReferences = new LinkedHashMap<>(); taskReferences.put(new AxArtifactKey("Task0:0.0.0"), null); @@ -79,8 +79,6 @@ public class TaskSelectExecutorTest { Mockito.doReturn(new AxArtifactKey("Task1:0.0.0")).when(axStateMock).getDefaultTask(); Mockito.doReturn(taskSelectionLogicMock).when(axStateMock).getTaskSelectionLogic(); - - Mockito.doReturn(new AxArtifactKey("Context:0.0.1")).when(internalContextMock).getKey(); } @Test diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacadeTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacadeTest.java index 68d478877..54013e943 100644 --- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacadeTest.java +++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacadeTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,9 +28,10 @@ import java.util.LinkedHashMap; import java.util.Map; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; import org.onap.policy.apex.model.basicmodel.service.ModelService; @@ -40,6 +42,7 @@ import org.onap.policy.apex.model.policymodel.concepts.AxTasks; /** * Test the state facade. */ +@RunWith(MockitoJUnitRunner.class) public class AxStateFacadeTest { @Mock private AxState axStateMock; @@ -52,8 +55,6 @@ public class AxStateFacadeTest { */ @Before public void startMocking() { - MockitoAnnotations.initMocks(this); - AxReferenceKey stateKey = new AxReferenceKey("StateParent:0.0.1:ParentName:StateName"); Mockito.doReturn(stateKey).when(axStateMock).getKey(); diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacadeTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacadeTest.java index 9da8ecfad..634b3b35c 100644 --- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacadeTest.java +++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacadeTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020, 2023 Nordix Foundation * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,9 +31,10 @@ import java.util.TreeMap; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.apex.context.parameters.ContextParameterConstants; import org.onap.policy.apex.context.parameters.SchemaParameters; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; @@ -51,6 +52,7 @@ import org.onap.policy.common.parameters.ParameterService; /** * Test the state facade. */ +@RunWith(MockitoJUnitRunner.class) public class AxTaskFacadeTest { @Mock private AxTask axTaskMock; @@ -80,8 +82,6 @@ public class AxTaskFacadeTest { ModelService.registerModel(AxContextSchemas.class, schemas); - MockitoAnnotations.initMocks(this); - AxArtifactKey task0Key = new AxArtifactKey("Task0:0.0.1"); Mockito.doReturn(task0Key).when(axTaskMock).getKey(); Mockito.doReturn(task0Key.getId()).when(axTaskMock).getId(); diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContextTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContextTest.java index c540f51ad..9c6aa2f07 100644 --- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContextTest.java +++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContextTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020, 2023 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,9 +31,10 @@ import java.util.Map; import java.util.Set; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.apex.context.ContextAlbum; import org.onap.policy.apex.core.engine.context.ApexInternalContext; import org.onap.policy.apex.core.engine.executor.StateFinalizerExecutor; @@ -44,6 +45,7 @@ import org.onap.policy.apex.model.policymodel.concepts.AxState; /** * Test Task Execution Context. */ +@RunWith(MockitoJUnitRunner.class) public class StateFinalizerExecutionContextTest { @Mock private StateFinalizerExecutor stateFinalizerExecutorMock; @@ -62,7 +64,6 @@ public class StateFinalizerExecutionContextTest { */ @Before public void startMocking() { - MockitoAnnotations.initMocks(this); Set contextAlbumReferences = new LinkedHashSet<>(); contextAlbumReferences.add(new AxArtifactKey(("AlbumKey0:0.0.1"))); diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContextTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContextTest.java index 24c504822..7f813cc01 100644 --- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContextTest.java +++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContextTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020, 2023 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,9 +35,10 @@ import java.util.Map; import java.util.Set; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.apex.context.ContextAlbum; import org.onap.policy.apex.core.engine.context.ApexInternalContext; import org.onap.policy.apex.core.engine.executor.TaskExecutor; @@ -49,6 +50,7 @@ import org.onap.policy.apex.model.policymodel.concepts.AxTaskParameter; /** * Test Task Execution Context. */ +@RunWith(MockitoJUnitRunner.class) public class TaskExecutionContextTest { @Mock private TaskExecutor taskExecutorMock; @@ -67,7 +69,6 @@ public class TaskExecutionContextTest { */ @Before public void startMocking() { - MockitoAnnotations.initMocks(this); Set contextAlbumReferences = new LinkedHashSet<>(); contextAlbumReferences.add(new AxArtifactKey(("AlbumKey0:0.0.1"))); diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContextTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContextTest.java index 5857e0513..84f4817e0 100644 --- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContextTest.java +++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContextTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020, 2023 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,9 +31,10 @@ import java.util.Map; import java.util.Set; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.apex.context.ContextAlbum; import org.onap.policy.apex.core.engine.context.ApexInternalContext; import org.onap.policy.apex.core.engine.event.EnEvent; @@ -45,6 +46,7 @@ import org.onap.policy.apex.model.policymodel.concepts.AxState; /** * Test Task Execution Context. */ +@RunWith(MockitoJUnitRunner.class) public class TaskSelectionExecutionContextTest { @Mock private TaskSelectExecutor taskSelectExecutorMock; @@ -66,7 +68,6 @@ public class TaskSelectionExecutionContextTest { */ @Before public void startMocking() { - MockitoAnnotations.initMocks(this); Set contextAlbumReferences = new LinkedHashSet<>(); contextAlbumReferences.add(new AxArtifactKey(("AlbumKey0:0.0.1"))); diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/impl/ExceutorFactoryImplTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/impl/ExceutorFactoryImplTest.java index 5957ff347..c8aa7eb08 100644 --- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/impl/ExceutorFactoryImplTest.java +++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/impl/ExceutorFactoryImplTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020, 2023 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,9 +28,10 @@ import static org.junit.Assert.assertNull; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.apex.core.engine.EngineParameters; import org.onap.policy.apex.core.engine.ExecutorParameters; import org.onap.policy.apex.core.engine.context.ApexInternalContext; @@ -47,6 +48,7 @@ import org.onap.policy.common.parameters.ParameterService; * Test the executor factory implementation. * */ +@RunWith(MockitoJUnitRunner.class) public class ExceutorFactoryImplTest { @Mock private ApexInternalContext internalContextMock; @@ -76,7 +78,6 @@ public class ExceutorFactoryImplTest { */ @Before public void startMocking() { - MockitoAnnotations.initMocks(this); Mockito.doReturn(tslMock).when(stateMock).getTaskSelectionLogic(); Mockito.doReturn("Dummy").when(tslMock).getLogicFlavour(); @@ -163,8 +164,6 @@ public class ExceutorFactoryImplTest { final ExecutorFactoryImpl factory = new ExecutorFactoryImpl(); - Mockito.doReturn(true).when(stateMock).checkSetTaskSelectionLogic(); - assertThatThrownBy(() -> factory.getTaskExecutor(null, taskMock, internalContextMock)) .hasMessage("Executor plugin class not defined for \"Dummy\" executor of type " + "\"org.onap.policy.apex.core.engine.executor.TaskExecutor\""); diff --git a/examples/examples-acm/src/main/java/org/onap/policy/apex/examples/acm/AcmTestRestDmaapEndpoint.java b/examples/examples-acm/src/main/java/org/onap/policy/apex/examples/acm/AcmTestRestDmaapEndpoint.java index a3af9406c..8aed72080 100644 --- a/examples/examples-acm/src/main/java/org/onap/policy/apex/examples/acm/AcmTestRestDmaapEndpoint.java +++ b/examples/examples-acm/src/main/java/org/onap/policy/apex/examples/acm/AcmTestRestDmaapEndpoint.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +20,14 @@ package org.onap.policy.apex.examples.acm; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.QueryParam; +import jakarta.ws.rs.core.Response; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Response; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; diff --git a/examples/examples-acm/src/test/java/org/onap/policy/apex/examples/acm/TestApexAcmExample.java b/examples/examples-acm/src/test/java/org/onap/policy/apex/examples/acm/TestApexAcmExample.java index 5b8cbdfe7..9df25e678 100644 --- a/examples/examples-acm/src/test/java/org/onap/policy/apex/examples/acm/TestApexAcmExample.java +++ b/examples/examples-acm/src/test/java/org/onap/policy/apex/examples/acm/TestApexAcmExample.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,8 @@ package org.onap.policy.apex.examples.acm; import static org.awaitility.Awaitility.await; +import jakarta.ws.rs.client.ClientBuilder; import java.util.concurrent.TimeUnit; -import javax.ws.rs.client.ClientBuilder; import org.junit.Test; import org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaEditorMain; import org.onap.policy.apex.service.engine.main.ApexMain; diff --git a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java index 17b99c986..3d46e6a80 100644 --- a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java +++ b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. + * Copyright (C) 2020-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +20,14 @@ package org.onap.policy.apex.examples.grpc; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; +import jakarta.ws.rs.core.Response; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Response; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; diff --git a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java index f5a51a7fe..d3c0c87b3 100644 --- a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java +++ b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. + * Copyright (C) 2020-2023 Nordix Foundation. * Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,12 +24,12 @@ package org.onap.policy.apex.examples.grpc; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.core.Response; import java.nio.file.Files; import java.nio.file.Paths; import java.util.concurrent.TimeUnit; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.core.Response; import org.junit.Test; import org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaEditorMain; import org.onap.policy.apex.service.engine.main.ApexMain; diff --git a/examples/examples-onap-bbs/pom.xml b/examples/examples-onap-bbs/pom.xml index 058833c02..c67343883 100644 --- a/examples/examples-onap-bbs/pom.xml +++ b/examples/examples-onap-bbs/pom.xml @@ -2,7 +2,7 @@ ============LICENSE_START======================================================= Copyright (C) 2018 Ericsson. All rights reserved. Copyright (C) 2019 Huawei. - Modifications Copyright (C) 2019 Nordix Foundation. + Modifications Copyright (C) 2019, 2023 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -86,7 +86,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java b/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java index 5fb74a307..1f52e1115 100644 --- a/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java +++ b/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 huawei. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,6 +33,7 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; +// TODO javax libraries used here too. Ok, to keep? Liam's review ignored these. public class WebClientTest { HttpsURLConnection mockedHttpsUrlConnection; diff --git a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSimEndpoint.java b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSimEndpoint.java index a6c85fb0e..3e7962823 100644 --- a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSimEndpoint.java +++ b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSimEndpoint.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020,2022 Nordix Foundation. + * Modifications Copyright (C) 2019-2020,2022-2023 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,6 +29,12 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonParser; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.PUT; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; +import jakarta.ws.rs.core.Response; import java.io.IOException; import java.time.Instant; import java.util.Map; @@ -37,12 +43,6 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Response; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.common.gson.InstantAsMillisTypeAdapter; import org.onap.policy.common.utils.resources.TextFileUtils; diff --git a/examples/examples-servlet/pom.xml b/examples/examples-servlet/pom.xml index 37377da7b..1cf149eeb 100644 --- a/examples/examples-servlet/pom.xml +++ b/examples/examples-servlet/pom.xml @@ -1,7 +1,7 @@ - 5.17.3 - 2.28.0 - 1.11.1 - 3.1.3 - 5.4.0 - 4.1.5.Final - 1.3.10 - 3.1.16 - 9.4.1.0 - 2.1.48 + 5.18.2 + 4.3.4 + 4.13.0 + 2.30.0 + 1.11.2 + 3.1.8 + 5.5.0 + 5.3.1 + 14.0.13.Final + 2.13.5 + 3.1.3 + 5.2.18.Final + 3.1.0 + 1.3.11 + 3.1.17 + 9.4.3.0 + 2.2.1 1.0.15 2.7.3 - 7.3.1 - 3.2.4 + 3.5.1 + 7.4.0 + 3.2.5 + 0.16.0 1.7.14 - 3.8.1 - + 11.0.15 + 2.1.1 + 3.9.0 + @@ -80,6 +91,21 @@ junit test + + org.springframework + spring-test + + + org.mockito + mockito-core + test + + + org.mockito + mockito-junit-jupiter + test + 5.4.0 + org.assertj assertj-core diff --git a/services/services-engine/pom.xml b/services/services-engine/pom.xml index ca9d6a2fd..d2649883d 100644 --- a/services/services-engine/pom.xml +++ b/services/services-engine/pom.xml @@ -1,7 +1,7 @@ - - io.netty - * - - - log4j - log4j - - org.apache.zookeeper @@ -146,13 +135,9 @@ test - - io.netty - * - org.slf4j - slf4j-log4j12 + slf4j-reload4j @@ -162,21 +147,27 @@ netty-all - org.apache.activemq.tooling - activemq-junit - ${version.activemq} + org.apache.activemq + artemis-core-client + ${version.artemis} test org.apache.activemq - activemq-broker - ${version.activemq} + artemis-jakarta-client + ${version.artemis} test org.apache.activemq - activemq-jaas - ${version.activemq} + artemis-server + ${version.artemis} + test + + + jakarta.jms + jakarta.jms-api + ${version.jms} test @@ -184,6 +175,11 @@ awaitility test + + com.fasterxml.jackson.core + jackson-databind + ${version.jackson-databind} + diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java index a626ff520..119b306b0 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2023 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,15 +22,15 @@ package org.onap.policy.apex.testsuites.integration.uservice.adapt.jms; -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageProducer; -import javax.jms.Session; -import javax.jms.Topic; +import jakarta.jms.Connection; +import jakarta.jms.ConnectionFactory; +import jakarta.jms.JMSException; +import jakarta.jms.Message; +import jakarta.jms.MessageProducer; +import jakarta.jms.Session; +import jakarta.jms.Topic; import lombok.Getter; -import org.apache.activemq.command.ActiveMQTopic; +import org.apache.activemq.artemis.jms.client.ActiveMQTopic; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; import org.onap.policy.apex.testsuites.integration.common.testclasses.PingTestClass; diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java index 2bdacb66e..7f0cd8751 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2023 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,17 +22,17 @@ package org.onap.policy.apex.testsuites.integration.uservice.adapt.jms; -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.ObjectMessage; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.jms.Topic; +import jakarta.jms.Connection; +import jakarta.jms.ConnectionFactory; +import jakarta.jms.JMSException; +import jakarta.jms.Message; +import jakarta.jms.MessageConsumer; +import jakarta.jms.ObjectMessage; +import jakarta.jms.Session; +import jakarta.jms.TextMessage; +import jakarta.jms.Topic; import lombok.Getter; -import org.apache.activemq.command.ActiveMQTopic; +import org.apache.activemq.artemis.jms.client.ActiveMQTopic; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.service.engine.event.ApexEventException; import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsServerRunner.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsServerRunner.java new file mode 100644 index 000000000..02d913de4 --- /dev/null +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsServerRunner.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2022-2023 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.testsuites.integration.uservice.adapt.jms; + +import static org.awaitility.Awaitility.await; + +import java.util.concurrent.TimeUnit; +import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl; +import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class JmsServerRunner implements Runnable { + private static final Logger LOGGER = LoggerFactory.getLogger(JmsServerRunner.class); + + // Embedded JMS server + private EmbeddedActiveMQ embedded; + + // Thread to run the JMS server in + private Thread jmsServerRunnerThread; + + // Config fields + private final String serverName; + private final String serverUri; + + /** + * Create the JMS Server. + * + * @param serverName Name of the server + * @param serverUri URI for the server + * @throws Exception on errors + */ + public JmsServerRunner(String serverName, String serverUri) throws Exception { + this.serverName = serverName; + this.serverUri = serverUri; + + ConfigurationImpl config = new ConfigurationImpl(); + + config.addAcceptorConfiguration(serverName, serverUri); + config.setSecurityEnabled(false); + config.setJournalDirectory("target/artemisActiveMq/data/journal"); + config.setBindingsDirectory("target/artemisActiveMq/data/bindings"); + config.setLargeMessagesDirectory("target/artemisActiveMq/data/largemessages"); + config.setPagingDirectory("target/artemisActiveMq/data/paging"); + + embedded = new EmbeddedActiveMQ(); + embedded.setConfiguration(config); + + LOGGER.debug("starting JMS Server " + serverName + " on URI " + serverUri + " . . ."); + + jmsServerRunnerThread = new Thread(this); + jmsServerRunnerThread.start(); + + LOGGER.debug("requested start on JMS Server " + serverName + " on URI " + serverUri); + } + + @Override + public void run() { + try { + LOGGER.debug("starting JMS Server thread " + serverName + " on URI " + serverUri + " . . ."); + embedded.start(); + + await().atMost(30, TimeUnit.SECONDS).until(() -> embedded.getActiveMQServer().isActive()); + + LOGGER.debug("started JMS Server thread " + serverName + " on URI " + serverUri); + } catch (Exception e) { + LOGGER.warn("failed to start JMS Server thread " + serverName + " on URI " + serverUri, e); + } + } + + /** + * Stop the JMS server. + * + * @throws Exception on stop errors + */ + public void stop() throws Exception { + LOGGER.debug("stopping JMS Server " + serverName + " on URI " + serverUri + " . . ."); + + if (!embedded.getActiveMQServer().isActive()) { + LOGGER.debug("JMS Server " + serverName + " already stopped on URI " + serverUri + " . . ."); + return; + } + + embedded.stop(); + + LOGGER.debug("waiting on JMS Server " + serverName + " to stop on URI " + serverUri + " . . ."); + + await().atMost(30, TimeUnit.SECONDS) + .until(() -> !embedded.getActiveMQServer().isActive() && !jmsServerRunnerThread.isAlive()); + + LOGGER.debug("stopping JMS Server " + serverName + " on URI " + serverUri + " . . ."); + } +} \ No newline at end of file diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestContext.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestContext.java index 876981f71..f27162a65 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestContext.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestContext.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +25,6 @@ import static org.onap.policy.apex.testsuites.integration.uservice.adapt.jms.Tes import static org.onap.policy.apex.testsuites.integration.uservice.adapt.jms.TestJms2Jms.JMS_TOPIC_APEX_IN; import static org.onap.policy.apex.testsuites.integration.uservice.adapt.jms.TestJms2Jms.JMS_TOPIC_APEX_OUT; import static org.onap.policy.apex.testsuites.integration.uservice.adapt.jms.TestJms2Jms.PORT; -import static org.onap.policy.apex.testsuites.integration.uservice.adapt.jms.TestJms2Jms.connectionFactory; import java.util.HashMap; import java.util.Hashtable; @@ -37,7 +37,8 @@ import javax.naming.NameClassPair; import javax.naming.NameParser; import javax.naming.NamingEnumeration; import javax.naming.NamingException; -import org.apache.activemq.command.ActiveMQTopic; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.jms.client.ActiveMQTopic; import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException; /** @@ -59,7 +60,7 @@ public class TestContext implements Context { final Map params = new HashMap(); params.put("host", HOST); params.put("port", PORT); - testProperties.put("ConnectionFactory", connectionFactory); + testProperties.put("ConnectionFactory", new ActiveMQConnectionFactory(TestJms2Jms.SERVER_URI)); testProperties.put(JMS_TOPIC_APEX_IN, new ActiveMQTopic(JMS_TOPIC_APEX_IN)); testProperties.put(JMS_TOPIC_APEX_OUT, new ActiveMQTopic(JMS_TOPIC_APEX_OUT)); } catch (final Exception e) { diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestJms2Jms.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestJms2Jms.java index b060179cb..91417a57a 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestJms2Jms.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestJms2Jms.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020, 2023 Nordix Foundation. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,75 +25,49 @@ package org.onap.policy.apex.testsuites.integration.uservice.adapt.jms; import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; +import jakarta.jms.JMSException; import java.io.IOException; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; import java.util.concurrent.TimeUnit; -import javax.jms.JMSException; -import org.apache.activemq.ActiveMQConnectionFactory; -import org.apache.activemq.broker.BrokerPlugin; -import org.apache.activemq.broker.BrokerService; -import org.apache.activemq.security.AuthenticationUser; -import org.apache.activemq.security.SimpleAuthenticationPlugin; +import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.service.engine.main.ApexMain; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The Class TestJms2Jms. */ public class TestJms2Jms { - public static final String PORT = "5445"; - public static final String HOST = "localhost"; - public static final String JMS_TOPIC_APEX_IN = "jms/topic/apexIn"; - public static final String JMS_TOPIC_APEX_OUT = "jms/topic/apexOut"; + private static final Logger LOGGER = LoggerFactory.getLogger(TestJms2Jms.class); - private static final String GROUP_ROLE = "guests"; - private static final String PACKAGE_NAME = "org.onap.policy.apex.testsuites.integration.common.testclasses"; - private static final String USERNAME = "guest"; - private static final String PASSWORD = "IAmAGuest"; - private static final String URL = "tcp://" + HOST + ":" + PORT; - - private static final String DATA_PARENT_DIR = Paths.get("target", "activemq-data").toString(); - - private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestJms2Jms.class); + protected static final String SERVER_NAME = "JmsTestServer"; + protected static final String PORT = "5445"; + protected static final String HOST = "localhost"; + protected static final String JMS_TOPIC_APEX_IN = "jms/topic/apexIn"; + protected static final String JMS_TOPIC_APEX_OUT = "jms/topic/apexOut"; + protected static final String SERVER_URI = "tcp://" + HOST + ":" + PORT; private static final int EVENT_COUNT = 100; private static final int EVENT_INTERVAL = 20; - private static BrokerService broker; - - public static ActiveMQConnectionFactory connectionFactory; + // Embedded JMS server for testing + private static JmsServerRunner jmsServerRunner; /** - * Setup embedded jms server. + * Setup embedded JMS server. * * @throws Exception the exception */ @BeforeClass public static void setupEmbeddedJmsServer() throws Exception { - final ArrayList plugins = new ArrayList(); - final BrokerPlugin authenticationPlugin = getAuthenticationBrokerPlugin(); - plugins.add(authenticationPlugin); - - broker = new BrokerService(); - broker.setUseJmx(false); - broker.setPersistent(false); - broker.addConnector(URL); - broker.setDeleteAllMessagesOnStartup(true); - broker.setPlugins(plugins.toArray(new BrokerPlugin[0])); - broker.setDataDirectory(DATA_PARENT_DIR); - broker.start(); - broker.waitUntilStarted(); - connectionFactory = new ActiveMQConnectionFactory(URL); - connectionFactory.setTrustedPackages(Arrays.asList(PACKAGE_NAME)); + jmsServerRunner = new JmsServerRunner(SERVER_NAME, SERVER_URI); + + await().pollDelay(3L, TimeUnit.SECONDS).until(() -> new AtomicBoolean(true).get() == true); } /** @@ -104,18 +78,6 @@ public class TestJms2Jms { System.clearProperty("APEX_RELATIVE_FILE_ROOT"); } - /** - * Gets the authentication broker plugin. - * - * @return the authentication broker plugin - */ - private static BrokerPlugin getAuthenticationBrokerPlugin() { - final List users = new ArrayList(); - users.add(new AuthenticationUser(USERNAME, PASSWORD, GROUP_ROLE)); - final SimpleAuthenticationPlugin authenticationPlugin = new SimpleAuthenticationPlugin(users); - return authenticationPlugin; - } - /** * Shutdown embedded jms server. * @@ -124,8 +86,8 @@ public class TestJms2Jms { @AfterClass public static void shutdownEmbeddedJmsServer() throws IOException { try { - if (broker != null) { - broker.stop(); + if (jmsServerRunner != null) { + jmsServerRunner.stop(); } } catch (final Exception e) { LOGGER.warn("Failed to stop JMS server", e); @@ -141,7 +103,9 @@ public class TestJms2Jms { */ @Test public void testJmsObjectEvents() throws ApexException, JMSException { - final String[] args = {"-rfr", "target", "-p", "target/examples/config/JMS/JMS2JMSObjectEvent.json"}; + final String[] args = { + "-rfr", "target", "-p", "target/examples/config/JMS/JMS2JMSObjectEvent.json" + }; testJmsEvents(args, true); } @@ -153,7 +117,9 @@ public class TestJms2Jms { */ @Test public void testJmsJsonEvents() throws ApexException, JMSException { - final String[] args = {"-rfr", "target", "-p", "target/examples/config/JMS/JMS2JMSJsonEvent.json"}; + final String[] args = { + "-rfr", "target", "-p", "target/examples/config/JMS/JMS2JMSJsonEvent.json" + }; testJmsEvents(args, false); } @@ -167,10 +133,11 @@ public class TestJms2Jms { */ private void testJmsEvents(final String[] args, final Boolean sendObjects) throws ApexException, JMSException { final JmsEventSubscriber subscriber = - new JmsEventSubscriber(JMS_TOPIC_APEX_OUT, connectionFactory, USERNAME, PASSWORD); + new JmsEventSubscriber(JMS_TOPIC_APEX_OUT, new ActiveMQConnectionFactory(SERVER_URI), null, null); - final JmsEventProducer producer = new JmsEventProducer(JMS_TOPIC_APEX_IN, connectionFactory, USERNAME, PASSWORD, - EVENT_COUNT, sendObjects, EVENT_INTERVAL); + final JmsEventProducer producer = + new JmsEventProducer(JMS_TOPIC_APEX_IN, new ActiveMQConnectionFactory(SERVER_URI), null, null, + EVENT_COUNT, sendObjects, EVENT_INTERVAL); final ApexMain apexMain = new ApexMain(args); @@ -188,4 +155,4 @@ public class TestJms2Jms { assertEquals(EVENT_COUNT, producer.getEventsSentCount()); assertEquals(producer.getEventsSentCount(), subscriber.getEventsReceivedCount()); } -} +} \ No newline at end of file diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestExecutionPropertyRest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestExecutionPropertyRest.java index d1488df86..593ddd03e 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestExecutionPropertyRest.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestExecutionPropertyRest.java @@ -26,12 +26,12 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertTrue; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.core.Response; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.concurrent.TimeUnit; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.core.Response; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java index 5683b48b2..737065638 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java @@ -28,14 +28,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import com.google.gson.Gson; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.core.Response; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.Map; import java.util.concurrent.TimeUnit; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.core.Response; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRestClientEndpoint.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRestClientEndpoint.java index dc8d962dd..389545542 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRestClientEndpoint.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRestClientEndpoint.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019, 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,14 +25,13 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import com.google.gson.Gson; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.PUT; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.Response; import java.util.Map; import java.util.Random; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.core.Response; - /** * The Class TestRestClientEndpoint. diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java index 7f460bb15..8a506e16b 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2023 Nordix Foundation. * Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -29,16 +29,16 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import com.google.gson.Gson; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.core.Response; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.Map; import java.util.Random; import java.util.concurrent.TimeUnit; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.Response; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/taskparameters/RestClientEndpointForTaskParameters.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/taskparameters/RestClientEndpointForTaskParameters.java index f0b670008..35cd3ca5a 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/taskparameters/RestClientEndpointForTaskParameters.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/taskparameters/RestClientEndpointForTaskParameters.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. + * Copyright (C) 2020, 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +20,11 @@ package org.onap.policy.apex.testsuites.integration.uservice.taskparameters; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.core.Response; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.core.Response; /** * The Class RestClientEndpointForTaskParameters. diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/taskparameters/TestTaskParameters.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/taskparameters/TestTaskParameters.java index 655538349..f78fd12cd 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/taskparameters/TestTaskParameters.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/taskparameters/TestTaskParameters.java @@ -24,10 +24,10 @@ package org.onap.policy.apex.testsuites.integration.uservice.taskparameters; import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertTrue; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.core.Response; import java.util.concurrent.TimeUnit; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.core.Response; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; diff --git a/testsuites/integration/integration-uservice-test/src/test/resources/logback-test.xml b/testsuites/integration/integration-uservice-test/src/test/resources/logback-test.xml index 1fa56526f..ce77b7852 100644 --- a/testsuites/integration/integration-uservice-test/src/test/resources/logback-test.xml +++ b/testsuites/integration/integration-uservice-test/src/test/resources/logback-test.xml @@ -2,7 +2,7 @@ > "); - switch (code) { - case CloseFrame.NORMAL: + CloseCodes reasonCloseCode = CloseCodes.valueOf(reason.getCloseCode().toString()); + switch (reasonCloseCode) { + case NORMAL_CLOSURE: outStream.println("normal"); break; - case CloseFrame.GOING_AWAY: + case GOING_AWAY: outStream.println("APEX going away"); break; - case CloseFrame.PROTOCOL_ERROR: + case PROTOCOL_ERROR: outStream.println("some protocol error"); break; - case CloseFrame.REFUSE: + case CANNOT_ACCEPT: outStream.println("received unacceptable type of data"); break; - case CloseFrame.NO_UTF8: + case CLOSED_ABNORMALLY: outStream.println("expected UTF-8, found something else"); break; - case CloseFrame.TOOBIG: + case TOO_BIG: outStream.println("message too big"); break; - case CloseFrame.UNEXPECTED_CONDITION: + case UNEXPECTED_CONDITION: outStream.println("unexpected server condition"); break; default: @@ -101,19 +125,32 @@ public class SimpleConsole extends WebSocketClient { outStream.print(" ==-->> " + reason); } - @Override + + @OnError public void onError(final Exception ex) { errStream.println(this.appName + ": " + ex.getMessage()); } - @Override - public void onMessage(final String message) { + /** + * Callback hook for Message Events. This method will be invoked when a client send a message. + * + * @param message The text message + */ + @OnMessage + public void onMessage(String message) { // this client does not expect messages } - @Override - public void onOpen(final ServerHandshake handshakedata) { - outStream.println(this.appName + ": opened connection to APEX (" + handshakedata.getHttpStatusMessage() + ")"); + /** + * Callback hook for Connection open events. + * + * @param userSession the userSession which is opened. + */ + @OnOpen + public void onOpen(Session userSession) { + outStream.println(this.appName + ": opened connection to APEX (" + userSession.getRequestURI() + ")"); + + this.userSession = userSession; } /** @@ -124,15 +161,6 @@ public class SimpleConsole extends WebSocketClient { * @throws IOException on an IO problem on standard in */ public void runClient() throws IOException { - final Thread thread = new Thread() { - @Override - public void run() { - connect(); - } - }; - thread.setName("ClientThread"); - thread.start(); - final var in = new BufferedReader(new InputStreamReader(System.in)); var event = new StringBuilder(); String line; @@ -143,15 +171,15 @@ public class SimpleConsole extends WebSocketClient { final String current = line.trim(); if ("".equals(current)) { - this.send(event.toString()); + this.userSession.getBasicRemote().sendText(event.toString()); event = new StringBuilder(); } else { event.append(current); } } - thread.interrupt(); - this.close(CloseFrame.NORMAL); + this.userSession.close(new CloseReason(CloseReason.CloseCodes.NORMAL_CLOSURE, "Normal Closure")); } + } diff --git a/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/SimpleEcho.java b/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/SimpleEcho.java index 672594c52..8c7aec008 100644 --- a/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/SimpleEcho.java +++ b/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/SimpleEcho.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,20 +21,30 @@ package org.onap.policy.apex.tools.simple.wsclient; +import jakarta.websocket.ClientEndpoint; +import jakarta.websocket.CloseReason; +import jakarta.websocket.CloseReason.CloseCodes; +import jakarta.websocket.ContainerProvider; +import jakarta.websocket.DeploymentException; +import jakarta.websocket.OnClose; +import jakarta.websocket.OnError; +import jakarta.websocket.OnMessage; +import jakarta.websocket.OnOpen; +import jakarta.websocket.Session; +import jakarta.websocket.WebSocketContainer; +import java.io.IOException; import java.io.PrintStream; import java.net.URI; import java.net.URISyntaxException; import org.apache.commons.lang3.Validate; -import org.java_websocket.client.WebSocketClient; -import org.java_websocket.framing.CloseFrame; -import org.java_websocket.handshake.ServerHandshake; /** * Simple WS client as an echo. * * @author Sven van der Meer (sven.van.der.meer@ericsson.com) */ -public class SimpleEcho extends WebSocketClient { +@ClientEndpoint +public class SimpleEcho { /** Application name, used as prompt. */ private final String appName; @@ -51,42 +62,54 @@ public class SimpleEcho extends WebSocketClient { * @param outStream the stream for message output * @param errStream the stream for error messages * @throws URISyntaxException is URI could not be created from server/port settings + * @throws IOException on IO exceptions + * @throws DeploymentException on deployment exceptions * @throws RuntimeException if server or port where blank */ public SimpleEcho(final String server, final String port, final String appName, PrintStream outStream, - PrintStream errStream) throws URISyntaxException { - super(new URI("ws://" + server + ":" + port)); + PrintStream errStream) throws URISyntaxException, DeploymentException, IOException { + Validate.notBlank(appName, "SimpleEcho: given application name was blank"); - + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + container.connectToServer(this, new URI("ws://" + server + ":" + port)); + this.appName = appName; this.outStream = outStream; this.errStream = errStream; } - @Override - public void onClose(final int code, final String reason, final boolean remote) { - outStream.println(this.appName + ": Connection closed by " + (remote ? "APEX" : "me")); + /** + * Callback hook for Connection close events. + * + * @param userSession the userSession which is getting closed. + * @param reason the reason for connection close + */ + @OnClose + public void onClose(Session userSession, CloseReason reason) { + outStream.println(this.appName + ": Connection closed"); outStream.print(" ==-->> "); - switch (code) { - case CloseFrame.NORMAL: + + CloseCodes reasonCloseCode = CloseCodes.valueOf(reason.getCloseCode().toString()); + switch (reasonCloseCode) { + case NORMAL_CLOSURE: outStream.println("normal"); break; - case CloseFrame.GOING_AWAY: + case GOING_AWAY: outStream.println("APEX going away"); break; - case CloseFrame.PROTOCOL_ERROR: + case PROTOCOL_ERROR: outStream.println("some protocol error"); break; - case CloseFrame.REFUSE: + case CANNOT_ACCEPT: outStream.println("received unacceptable type of data"); break; - case CloseFrame.NO_UTF8: + case CLOSED_ABNORMALLY: outStream.println("expected UTF-8, found something else"); break; - case CloseFrame.TOOBIG: + case TOO_BIG: outStream.println("message too big"); break; - case CloseFrame.UNEXPECTED_CONDITION: + case UNEXPECTED_CONDITION: outStream.println("unexpected server condition"); break; default: @@ -96,13 +119,18 @@ public class SimpleEcho extends WebSocketClient { outStream.print(" ==-->> " + reason); } - @Override + @OnError public void onError(final Exception ex) { errStream.println(this.appName + ": " + ex.getMessage()); } - @Override - public void onMessage(final String message) { + /** + * Callback hook for Message Events. This method will be invoked when a client send a message. + * + * @param message The text message + */ + @OnMessage + public void onMessage(String message) { outStream.println(this.appName + ": received"); outStream.println("---------------------------------"); outStream.println(message); @@ -110,9 +138,13 @@ public class SimpleEcho extends WebSocketClient { outStream.println(); } - @Override - public void onOpen(final ServerHandshake handshakedata) { - outStream.println(this.appName + ": opened connection to APEX (" + handshakedata.getHttpStatusMessage() + ")"); + /** + * Callback hook for Connection open events. + * + * @param userSession the userSession which is opened. + */ + @OnOpen + public void onOpen(Session userSession) { + outStream.println(this.appName + ": opened connection to APEX (" + userSession.getRequestURI() + ")"); } - } diff --git a/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/WsClientMain.java b/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/WsClientMain.java index e3af4dcc1..405013be4 100644 --- a/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/WsClientMain.java +++ b/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/WsClientMain.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +22,7 @@ package org.onap.policy.apex.tools.simple.wsclient; +import jakarta.websocket.DeploymentException; import java.io.IOException; import java.io.PrintStream; import java.io.PrintWriter; @@ -141,8 +143,7 @@ public final class WsClientMain { outStream.println(); try { - final var simpleEcho = new SimpleEcho(server, port, APP_NAME, outStream, outStream); - simpleEcho.connect(); + new SimpleEcho(server, port, APP_NAME, outStream, outStream); } catch (final URISyntaxException uex) { String message = APP_NAME + ": URI exception, could not create URI from server and port settings"; outStream.println(message); @@ -155,6 +156,18 @@ public final class WsClientMain { String message = APP_NAME + ": illegal argument, server or port were blank"; outStream.println(message); LOGGER.warn(message, iex); + } catch (DeploymentException dex) { + String message = APP_NAME + ": could not deploy client"; + outStream.println(message); + LOGGER.warn(message, dex); + } catch (IOException iox) { + String message = APP_NAME + ": illegal argument, IO execption on client"; + outStream.println(message); + LOGGER.warn(message, iox); + } catch (Exception xex) { + String message = APP_NAME + ": Unknown execption on client"; + outStream.println(message); + LOGGER.warn(message, xex); } } @@ -199,10 +212,18 @@ public final class WsClientMain { String message = APP_NAME + ": not yet connected, connection to server took too long"; outStream.println(message); LOGGER.warn(message, nex); + } catch (DeploymentException dex) { + String message = APP_NAME + ": could not deploy client"; + outStream.println(message); + LOGGER.warn(message, dex); } catch (final IOException ioe) { String message = APP_NAME + ": IO exception, something went wrong on the standard input"; outStream.println(message); LOGGER.warn(message, ioe); + } catch (Exception xex) { + String message = APP_NAME + ": Unknown execption on client"; + outStream.println(message); + LOGGER.warn(message, xex); } }