From 99d54e1598f3f00573bf022d066a69f4b619c07b Mon Sep 17 00:00:00 2001 From: "arkadiusz.adamski" Date: Wed, 24 Mar 2021 16:55:39 +0000 Subject: Fix sonar issues - change test method name to avoid triggering SQ warning Issue-ID: POLICY-3093 Signed-off-by: arkadiusz.adamski Change-Id: Id2997319e9986582a85f383c1f737340f4b4ea2c --- .../adapt/events/syncasync/AsyncEventMimoTest.java | 3 +- .../adapt/events/syncasync/AsyncEventMisoTest.java | 3 +- .../adapt/events/syncasync/AsyncEventSimoTest.java | 3 +- .../adapt/events/syncasync/AsyncEventSisoTest.java | 3 +- .../adapt/events/syncasync/BaseEventTest.java | 87 ---------------------- .../adapt/events/syncasync/SyncEventMimoTest.java | 3 +- .../adapt/events/syncasync/SyncEventSisoTest.java | 3 +- .../adapt/events/syncasync/TestEventBase.java | 87 ++++++++++++++++++++++ 8 files changed, 99 insertions(+), 93 deletions(-) delete mode 100644 testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/BaseEventTest.java create mode 100644 testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/TestEventBase.java (limited to 'testsuites/integration/integration-uservice-test/src/test/java') diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/AsyncEventMimoTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/AsyncEventMimoTest.java index 07b63770d..cf6efdd91 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/AsyncEventMimoTest.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/AsyncEventMimoTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021 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,7 +26,7 @@ import java.io.File; import org.junit.After; import org.junit.Test; -public class AsyncEventMimoTest extends BaseEventTest { +public class AsyncEventMimoTest extends TestEventBase { private final String[] outFilePaths = { "target/examples/events/SampleDomain/EventsOutMulti0.json", "target/examples/events/SampleDomain/EventsOutMulti1.json", diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/AsyncEventMisoTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/AsyncEventMisoTest.java index d7a462290..2da4f5bd9 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/AsyncEventMisoTest.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/AsyncEventMisoTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021 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,7 +26,7 @@ import java.io.File; import org.junit.After; import org.junit.Test; -public class AsyncEventMisoTest extends BaseEventTest { +public class AsyncEventMisoTest extends TestEventBase { private final String[] outFilePaths = { "target/examples/events/SampleDomain/EventsOutSingle.json" }; diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/AsyncEventSimoTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/AsyncEventSimoTest.java index c176b69f2..5e63b38ba 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/AsyncEventSimoTest.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/AsyncEventSimoTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021 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,7 +26,7 @@ import java.io.File; import org.junit.After; import org.junit.Test; -public class AsyncEventSimoTest extends BaseEventTest { +public class AsyncEventSimoTest extends TestEventBase { private final String[] outFilePaths = { "target/examples/events/SampleDomain/EventsOutMulti0.json", "target/examples/events/SampleDomain/EventsOutMulti1.json", diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/AsyncEventSisoTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/AsyncEventSisoTest.java index 64b4b3850..412d4be06 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/AsyncEventSisoTest.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/AsyncEventSisoTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021 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,7 +26,7 @@ import java.io.File; import org.junit.After; import org.junit.Test; -public class AsyncEventSisoTest extends BaseEventTest { +public class AsyncEventSisoTest extends TestEventBase { private final String[] outFilePaths = { "target/examples/events/SampleDomain/EventsOutSingle.json" }; diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/BaseEventTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/BaseEventTest.java deleted file mode 100644 index 4e7636cde..000000000 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/BaseEventTest.java +++ /dev/null @@ -1,87 +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.testsuites.integration.uservice.adapt.events.syncasync; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.IOException; -import org.apache.commons.lang3.StringUtils; -import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; -import org.onap.policy.apex.service.engine.main.ApexMain; -import org.onap.policy.common.utils.resources.TextFileUtils; - -public class BaseEventTest { - private static final long TIME_OUT_IN_MS = 10000; - - private void waitForOutFiles(final String[] expectedFileNames, final long expectedFileSize) throws IOException { - final long totalExpectedSize = expectedFileSize * expectedFileNames.length; - - long startWaitTime = System.currentTimeMillis(); - long lastTotalSize = 0; - - do { - long totalSize = 0; - - for (String expectedFileName : expectedFileNames) { - totalSize += getEventCount(expectedFileName); - } - - if (totalSize >= totalExpectedSize) { - return; - } - - // We're making progress, extend the timeout - if (totalSize > lastTotalSize) { - lastTotalSize = totalSize; - startWaitTime = System.currentTimeMillis(); - } - - ThreadUtilities.sleep(100); - } while (TIME_OUT_IN_MS >= System.currentTimeMillis() - startWaitTime); - } - - private int getEventCount(final String expectedFileName) throws IOException { - File expectedFile = new File(expectedFileName); - - if (!expectedFile.exists()) { - return 0; - } - - String expectedFileContents = TextFileUtils.getTextFileAsString(expectedFileName); - - return StringUtils.countMatches(expectedFileContents, "{"); - } - - protected void testFileEvents(final String[] args, final String[] expectedFileNames, final long expectedFileSize) - throws Exception { - final ApexMain apexMain = new ApexMain(args); - - waitForOutFiles(expectedFileNames, expectedFileSize); - - apexMain.shutdown(); - - for (final String expectedFileName : expectedFileNames) { - assertEquals(expectedFileSize, getEventCount(expectedFileName)); - } - } -} diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/SyncEventMimoTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/SyncEventMimoTest.java index 95e589bf4..482656071 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/SyncEventMimoTest.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/SyncEventMimoTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021 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,7 +26,7 @@ import java.io.File; import org.junit.After; import org.junit.Test; -public class SyncEventMimoTest extends BaseEventTest { +public class SyncEventMimoTest extends TestEventBase { private final String[] outFilePaths = { "target/examples/events/SampleDomain/EventsOutMulti0.json", "target/examples/events/SampleDomain/EventsOutMulti1.json", diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/SyncEventSisoTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/SyncEventSisoTest.java index 1d536cea9..596bcbc25 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/SyncEventSisoTest.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/SyncEventSisoTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021 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,7 +26,7 @@ import java.io.File; import org.junit.After; import org.junit.Test; -public class SyncEventSisoTest extends BaseEventTest { +public class SyncEventSisoTest extends TestEventBase { private final String[] outFilePaths = { "target/examples/events/SampleDomain/EventsOutSingle.json" }; diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/TestEventBase.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/TestEventBase.java new file mode 100644 index 000000000..39603c540 --- /dev/null +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/syncasync/TestEventBase.java @@ -0,0 +1,87 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020-2021 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.events.syncasync; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.IOException; +import org.apache.commons.lang3.StringUtils; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.onap.policy.apex.service.engine.main.ApexMain; +import org.onap.policy.common.utils.resources.TextFileUtils; + +public class TestEventBase { + private static final long TIME_OUT_IN_MS = 10000; + + private void waitForOutFiles(final String[] expectedFileNames, final long expectedFileSize) throws IOException { + final long totalExpectedSize = expectedFileSize * expectedFileNames.length; + + long startWaitTime = System.currentTimeMillis(); + long lastTotalSize = 0; + + do { + long totalSize = 0; + + for (String expectedFileName : expectedFileNames) { + totalSize += getEventCount(expectedFileName); + } + + if (totalSize >= totalExpectedSize) { + return; + } + + // We're making progress, extend the timeout + if (totalSize > lastTotalSize) { + lastTotalSize = totalSize; + startWaitTime = System.currentTimeMillis(); + } + + ThreadUtilities.sleep(100); + } while (TIME_OUT_IN_MS >= System.currentTimeMillis() - startWaitTime); + } + + private int getEventCount(final String expectedFileName) throws IOException { + File expectedFile = new File(expectedFileName); + + if (!expectedFile.exists()) { + return 0; + } + + String expectedFileContents = TextFileUtils.getTextFileAsString(expectedFileName); + + return StringUtils.countMatches(expectedFileContents, "{"); + } + + protected void testFileEvents(final String[] args, final String[] expectedFileNames, final long expectedFileSize) + throws Exception { + final ApexMain apexMain = new ApexMain(args); + + waitForOutFiles(expectedFileNames, expectedFileSize); + + apexMain.shutdown(); + + for (final String expectedFileName : expectedFileNames) { + assertEquals(expectedFileSize, getEventCount(expectedFileName)); + } + } +} -- cgit 1.2.3-korg