diff options
author | liamfallon <liam.fallon@est.tech> | 2020-01-23 16:50:47 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2020-01-23 16:50:51 +0000 |
commit | f8000a9d35928f136216be504828ef9074dfb42a (patch) | |
tree | 5e81379c3eef8af54ff557cd641ab94faa426713 /testsuites | |
parent | 755eb9df282d80273043a2e902e2a51bf6eaab24 (diff) |
Remove apex-pdp TextFileUtils class
This class was moved to policy-common some time ago. Removing it in
apex-pdp.
Issue-ID: POLICY-1913
Change-Id: I982fbd799334b34f1526e19f339236b52205b91e
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'testsuites')
9 files changed, 124 insertions, 129 deletions
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 index 9199d2a98..021707141 100644 --- 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 @@ -1,19 +1,20 @@ /*- * ============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========================================================= */ @@ -27,8 +28,8 @@ import java.io.IOException; import org.apache.commons.lang3.StringUtils; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; -import org.onap.policy.apex.model.utilities.TextFileUtils; 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; @@ -38,7 +39,7 @@ public class BaseEventTest { long startWaitTime = System.currentTimeMillis(); long lastTotalSize = 0; - + do { long totalSize = 0; @@ -49,13 +50,13 @@ public class BaseEventTest { 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); @@ -63,18 +64,18 @@ public class BaseEventTest { 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 { + throws Exception { final ApexMain apexMain = new ApexMain(args); waitForOutFiles(expectedFileNames, expectedFileSize); diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2File.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2File.java index 709c67c87..0c500d5ae 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2File.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2File.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-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========================================================= */ @@ -30,8 +31,8 @@ import org.junit.Test; import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.utilities.TextFileUtils; import org.onap.policy.apex.service.engine.main.ApexMain; +import org.onap.policy.common.utils.resources.TextFileUtils; public class TestFile2File { /** @@ -83,18 +84,13 @@ public class TestFile2File { /** * Strip variable length text from file string. - * + * * @param textFileAsString the file to read and strip * @return the stripped string * @throws IOException on out file read exceptions */ private String stripVariableLengthText(final String outFile) throws IOException { - return TextFileUtils.getTextFileAsString(outFile) - .replaceAll("\\s+", "") - .replaceAll(":\\d*\\.?\\d*,", ":0,") - .replaceAll(":\\d*}", ":0}") - .replaceAll("<value>\\d*\\.?\\d*</value>", "<value>0</value>"); + return TextFileUtils.getTextFileAsString(outFile).replaceAll("\\s+", "").replaceAll(":\\d*\\.?\\d*,", ":0,") + .replaceAll(":\\d*}", ":0}").replaceAll("<value>\\d*\\.?\\d*</value>", "<value>0</value>"); } } - - diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileFiltered.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileFiltered.java index 59d36374a..45938cbe4 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileFiltered.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileFiltered.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-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========================================================= */ @@ -30,8 +31,8 @@ import org.junit.Test; import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.utilities.TextFileUtils; import org.onap.policy.apex.service.engine.main.ApexMain; +import org.onap.policy.common.utils.resources.TextFileUtils; public class TestFile2FileFiltered { /** @@ -44,6 +45,7 @@ public class TestFile2FileFiltered { @Test public void testJsonFilteredFileInOutEvents() throws MessagingException, ApexException, IOException { + // @formatter:off final String[] args = { "-rfr", "target", "-c", "target/examples/config/SampleDomain/File2FileFilteredInOutJsonEvent.json" }; @@ -55,10 +57,12 @@ public class TestFile2FileFiltered { { 22366, 19834 }; testFilteredFileEvents(args, outFilePaths, expectedFileSizes); + // @formatter:on } @Test public void testJsonFilteredFileOutEvents() throws MessagingException, ApexException, IOException { + // @formatter:off final String[] args = { "-rfr", "target", "-c", "target/examples/config/SampleDomain/File2FileFilteredOutJsonEvent.json" }; @@ -70,10 +74,12 @@ public class TestFile2FileFiltered { { 22366, 19834 }; testFilteredFileEvents(args, outFilePaths, expectedFileSizes); + // @formatter:on } @Test public void testJsonFilteredFileInEvents() throws MessagingException, ApexException, IOException { + // @formatter:off final String[] args = { "-rfr", "target", "-c", "target/examples/config/SampleDomain/File2FileFilteredInJsonEvent.json" }; @@ -84,10 +90,11 @@ public class TestFile2FileFiltered { { 22366 }; testFilteredFileEvents(args, outFilePaths, expectedFileSizes); + // @formatter:on } private void testFilteredFileEvents(final String[] args, final String[] outFilePaths, - final long[] expectedFileSizes) throws MessagingException, ApexException, IOException { + final long[] expectedFileSizes) throws MessagingException, ApexException, IOException { final ApexMain apexMain = new ApexMain(args); final File outFile0 = new File(outFilePaths[0]); @@ -125,16 +132,13 @@ public class TestFile2FileFiltered { /** * Strip variable length text from file string. - * + * * @param textFileAsString the file to read and strip * @return the stripped string * @throws IOException on out file read exceptions */ private String stripVariableLengthText(final String outFile) throws IOException { - return TextFileUtils.getTextFileAsString(outFile) - .replaceAll("\\s+", "") - .replaceAll(":\\d*\\.?\\d*,", ":0,") - .replaceAll(":\\d*}", ":0}") - .replaceAll("<value>\\d*\\.?\\d*</value>", "<value>0</value>"); + return TextFileUtils.getTextFileAsString(outFile).replaceAll("\\s+", "").replaceAll(":\\d*\\.?\\d*,", ":0,") + .replaceAll(":\\d*}", ":0}").replaceAll("<value>\\d*\\.?\\d*</value>", "<value>0</value>"); } } diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileIgnore.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileIgnore.java index b3fa512d5..6aa73fb07 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileIgnore.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileIgnore.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-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========================================================= */ @@ -28,8 +29,8 @@ import java.io.IOException; import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.utilities.TextFileUtils; import org.onap.policy.apex.service.engine.main.ApexMain; +import org.onap.policy.common.utils.resources.TextFileUtils; /** * The Class TestFile2FileIgnore. @@ -91,22 +92,16 @@ public class TestFile2FileIgnore { outFile.delete(); assertEquals(outFileSize, expectedFileSize); } - /** * Strip variable length text from file string. - * + * * @param textFileAsString the file to read and strip * @return the stripped string * @throws IOException on out file read exceptions */ private static String stripVariableLengthText(final String outFile) throws IOException { - return TextFileUtils.getTextFileAsString(outFile) - .replaceAll("\\s+", "") - .replaceAll(":\\d*\\.?\\d*,", ":0,") - .replaceAll(":\\d*}", ":0}") - .replaceAll("<value>\\d*\\.?\\d*</value>", "<value>0</value>"); + return TextFileUtils.getTextFileAsString(outFile).replaceAll("\\s+", "").replaceAll(":\\d*\\.?\\d*,", ":0,") + .replaceAll(":\\d*}", ":0}").replaceAll("<value>\\d*\\.?\\d*</value>", "<value>0</value>"); } } - - diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/TestKafka2Kafka.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/TestKafka2Kafka.java index 7afef538b..b35b961e4 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/TestKafka2Kafka.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/TestKafka2Kafka.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-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========================================================= */ @@ -34,8 +35,8 @@ import org.junit.Test; import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.utilities.TextFileUtils; import org.onap.policy.apex.service.engine.main.ApexMain; +import org.onap.policy.common.utils.resources.TextFileUtils; /** * The Class TestKafka2Kafka tests Kafka event sending and reception. @@ -56,10 +57,10 @@ public class TestKafka2Kafka { @ClassRule public static final SharedKafkaTestResource sharedKafkaTestResource = new SharedKafkaTestResource() - // Start a cluster with 1 brokers. - .withBrokers(1) - // Disable topic auto-creation. - .withBrokerProperty("auto.create.topics.enable", "false"); + // Start a cluster with 1 brokers. + .withBrokers(1) + // Disable topic auto-creation. + .withBrokerProperty("auto.create.topics.enable", "false"); /** * Test json kafka events. @@ -70,9 +71,8 @@ public class TestKafka2Kafka { @Test public void testJsonKafkaEvents() throws MessagingException, ApexException { final String conditionedConfigFile = getConditionedConfigFile( - "target" + File.separator + "examples/config/SampleDomain/Kafka2KafkaJsonEvent.json"); - final String[] args = - { "-rfr", "target", "-c", conditionedConfigFile }; + "target" + File.separator + "examples/config/SampleDomain/Kafka2KafkaJsonEvent.json"); + final String[] args = {"-rfr", "target", "-c", conditionedConfigFile}; testKafkaEvents(args, false, "json"); } @@ -85,9 +85,8 @@ public class TestKafka2Kafka { @Test public void testXmlKafkaEvents() throws MessagingException, ApexException { final String conditionedConfigFile = getConditionedConfigFile( - "target" + File.separator + "examples/config/SampleDomain/Kafka2KafkaXmlEvent.json"); - final String[] args = - { "-rfr", "target", "-c", conditionedConfigFile }; + "target" + File.separator + "examples/config/SampleDomain/Kafka2KafkaXmlEvent.json"); + final String[] args = {"-rfr", "target", "-c", conditionedConfigFile}; testKafkaEvents(args, true, "xml"); } @@ -102,19 +101,19 @@ public class TestKafka2Kafka { * @throws ApexException the apex exception */ private void testKafkaEvents(String[] args, final Boolean xmlEvents, final String topicSuffix) - throws MessagingException, ApexException { + throws MessagingException, ApexException { sharedKafkaTestResource.getKafkaTestUtils().createTopic("apex-out-" + topicSuffix, 1, (short) 1); sharedKafkaTestResource.getKafkaTestUtils().createTopic("apex-in-" + topicSuffix, 1, (short) 1); - final KafkaEventSubscriber subscriber = new KafkaEventSubscriber("apex-out-" + topicSuffix, - sharedKafkaTestResource); + final KafkaEventSubscriber subscriber = + new KafkaEventSubscriber("apex-out-" + topicSuffix, sharedKafkaTestResource); final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(3000); final KafkaEventProducer producer = new KafkaEventProducer("apex-in-" + topicSuffix, sharedKafkaTestResource, - EVENT_COUNT, xmlEvents, EVENT_INTERVAL); + EVENT_COUNT, xmlEvents, EVENT_INTERVAL); producer.sendEvents(); @@ -122,12 +121,12 @@ public class TestKafka2Kafka { // Wait for the producer to send all tis events while (System.currentTimeMillis() < testStartTime + MAX_TEST_LENGTH - && producer.getEventsSentCount() < EVENT_COUNT) { + && producer.getEventsSentCount() < EVENT_COUNT) { ThreadUtilities.sleep(EVENT_INTERVAL); } while (System.currentTimeMillis() < testStartTime + MAX_TEST_LENGTH - && subscriber.getEventsReceivedCount() < EVENT_COUNT) { + && subscriber.getEventsReceivedCount() < EVENT_COUNT) { ThreadUtilities.sleep(EVENT_INTERVAL); } @@ -145,7 +144,7 @@ public class TestKafka2Kafka { File tempConfigFile = File.createTempFile("Kafka_", ".json"); tempConfigFile.deleteOnExit(); String configAsString = TextFileUtils.getTextFileAsString(configurationFileName) - .replaceAll("localhost:39902", sharedKafkaTestResource.getKafkaConnectString()); + .replaceAll("localhost:39902", sharedKafkaTestResource.getKafkaConnectString()); TextFileUtils.putStringAsFile(configAsString, tempConfigFile.getCanonicalFile()); return tempConfigFile.getCanonicalPath(); diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java index 1a0570c1f..e799f5973 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-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. @@ -35,12 +35,12 @@ import org.junit.Test; import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.utilities.TextFileUtils; import org.onap.policy.apex.service.engine.main.ApexMain; import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.common.gson.GsonMessageBodyHandler; import org.onap.policy.common.utils.network.NetworkUtil; +import org.onap.policy.common.utils.resources.TextFileUtils; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -74,8 +74,8 @@ public class TestRest2File { */ @Before public void setUp() throws Exception { - server = HttpServletServerFactoryInstance.getServerFactory().build( - "TestRest2File", false, null, PORT, "/TestRest2File", false, false); + server = HttpServletServerFactoryInstance.getServerFactory().build("TestRest2File", false, null, PORT, + "/TestRest2File", false, false); server.addServletClass(null, TestRestClientEndpoint.class.getName()); server.setSerializationProvider(GsonMessageBodyHandler.class.getName()); @@ -116,18 +116,18 @@ public class TestRest2File { */ @Test public void testRestEventsIn() throws MessagingException, ApexException, IOException { - final String[] args = { "-rfr", "target", "-c", "target/examples/config/SampleDomain/REST2FileJsonEvent.json" }; + final String[] args = {"-rfr", "target", "-c", "target/examples/config/SampleDomain/REST2FileJsonEvent.json"}; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(5000); apexMain.shutdown(); - final String outputEventText = TextFileUtils - .getTextFileAsString("target/examples/events/SampleDomain/EventsOut.json"); + final String outputEventText = + TextFileUtils.getTextFileAsString("target/examples/events/SampleDomain/EventsOut.json"); checkRequiredString(outputEventText, - "04\",\n" + " \"version\": \"0.0.1\",\n" + " \"nameSpace\": \"org.onap.policy.apex.sample.events\""); + "04\",\n" + " \"version\": \"0.0.1\",\n" + " \"nameSpace\": \"org.onap.policy.apex.sample.events\""); } /** @@ -142,7 +142,7 @@ public class TestRest2File { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - final String[] args = { "src/test/resources/prodcons/REST2FileJsonEmptyEvents.json" }; + final String[] args = {"src/test/resources/prodcons/REST2FileJsonEmptyEvents.json"}; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(5000); @@ -153,8 +153,8 @@ public class TestRest2File { System.setOut(stdout); System.setErr(stderr); - checkRequiredString(outString, - "received an empty event from URL " + "\"http://localhost:32801/TestRest2File/apex/event/GetEmptyEvent\""); + checkRequiredString(outString, "received an empty event from URL " + + "\"http://localhost:32801/TestRest2File/apex/event/GetEmptyEvent\""); } /** @@ -169,7 +169,7 @@ public class TestRest2File { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - final String[] args = { "src/test/resources/prodcons/REST2FileJsonEventNoURL.json" }; + final String[] args = {"src/test/resources/prodcons/REST2FileJsonEventNoURL.json"}; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(5000); @@ -195,7 +195,7 @@ public class TestRest2File { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - final String[] args = { "src/test/resources/prodcons/REST2FileJsonEventBadURL.json" }; + final String[] args = {"src/test/resources/prodcons/REST2FileJsonEventBadURL.json"}; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(5000); @@ -207,7 +207,7 @@ public class TestRest2File { System.setErr(stderr); checkRequiredString(outString, "reception of event from URL " - + "\"http://localhost:32801/TestRest2File/apex/event/Bad\" failed with status code 404"); + + "\"http://localhost:32801/TestRest2File/apex/event/Bad\" failed with status code 404"); } /** @@ -222,7 +222,7 @@ public class TestRest2File { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - final String[] args = { "src/test/resources/prodcons/REST2FileJsonEventBadHTTPMethod.json" }; + final String[] args = {"src/test/resources/prodcons/REST2FileJsonEventBadHTTPMethod.json"}; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(5000); @@ -234,7 +234,7 @@ public class TestRest2File { System.setErr(stderr); checkRequiredString(outString, "specified HTTP method of \"POST\" is invalid, " - + "only HTTP method \"GET\" is supported for event reception on REST client consumer"); + + "only HTTP method \"GET\" is supported for event reception on REST client consumer"); } /** @@ -249,7 +249,7 @@ public class TestRest2File { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - final String[] args = { "src/test/resources/prodcons/REST2FileJsonEventBadResponse.json" }; + final String[] args = {"src/test/resources/prodcons/REST2FileJsonEventBadResponse.json"}; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(5000); @@ -261,8 +261,9 @@ public class TestRest2File { System.setErr(stderr); checkRequiredString(outString, - "reception of event from URL " + "\"http://localhost:32801/TestRest2File/apex/event/GetEventBadResponse\" " - + "failed with status code 400 and message \""); + "reception of event from URL " + + "\"http://localhost:32801/TestRest2File/apex/event/GetEventBadResponse\" " + + "failed with status code 400 and message \""); } /** diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/context/EventAlbumContextTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/context/EventAlbumContextTest.java index d57f280ed..18b8f37cb 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/context/EventAlbumContextTest.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/context/EventAlbumContextTest.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-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========================================================= */ @@ -33,9 +34,9 @@ import org.junit.rules.TemporaryFolder; import org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.utilities.TextFileUtils; import org.onap.policy.apex.service.engine.main.ApexMain; import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.common.utils.resources.TextFileUtils; public class EventAlbumContextTest { private File tempCommandFile; @@ -48,7 +49,7 @@ public class EventAlbumContextTest { @Rule public TemporaryFolder tempTestDir = new TemporaryFolder(); - + /** * Clear relative file root environment variable. */ @@ -68,7 +69,7 @@ public class EventAlbumContextTest { configFile = "src/test/resources/prodcons/Context_JavaEventAlbum_file2file.json"; outputFile = "target/Context_JavaEventAlbum_EventOut.json"; compareFile = "src/test/resources/events/Context_JavaEventAlbum_EventOutCompare.json"; - + testEventAlbumContextTest(); } @@ -83,19 +84,19 @@ public class EventAlbumContextTest { configFile = "src/test/resources/prodcons/Context_AvroEventAlbum_file2file.json"; outputFile = "target/Context_AvroEventAlbum_EventOut.json"; compareFile = "src/test/resources/events/Context_AvroEventAlbum_EventOutCompare.json"; - + testEventAlbumContextTest(); } private void testEventAlbumContextTest() throws IOException, ApexException { TextFileUtils.putStringAsFile(eventContextString, tempCommandFile); - final String[] cliArgs = new String[] { "-c", tempCommandFile.getCanonicalPath(), "-l", - tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath() }; + final String[] cliArgs = new String[] {"-c", tempCommandFile.getCanonicalPath(), "-l", + tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()}; new ApexCommandLineEditorMain(cliArgs); - final String[] args = new String[] { "-m", tempModelFile.getAbsolutePath(), "-c", configFile }; + final String[] args = new String[] {"-m", tempModelFile.getAbsolutePath(), "-c", configFile}; final ApexMain apexMain = new ApexMain(args); // The output event will be in this file @@ -104,8 +105,8 @@ public class EventAlbumContextTest { for (int tenthsOfSecondsToWait = 100; tenthsOfSecondsToWait > 0; tenthsOfSecondsToWait--) { if (outputEventFile.exists() && outputEventFile.length() > 0) { // The output event is in this file - receivedApexOutputString = TextFileUtils.getTextFileAsString(outputEventFile.getCanonicalPath()) - .replaceAll("\\s+", ""); + receivedApexOutputString = + TextFileUtils.getTextFileAsString(outputEventFile.getCanonicalPath()).replaceAll("\\s+", ""); break; } @@ -121,8 +122,7 @@ public class EventAlbumContextTest { assertTrue("Test failed, the output event file was empty", receivedApexOutputString.length() > 0); // We compare the output to what we expect to get - final String expectedFileContent = TextFileUtils - .getTextFileAsString(compareFile); + final String expectedFileContent = TextFileUtils.getTextFileAsString(compareFile); final String outputEventCompareString = expectedFileContent.replaceAll("\\s+", ""); assertEquals(outputEventCompareString, receivedApexOutputString); diff --git a/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGenerator.java b/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGenerator.java index 40bab1173..36d6add43 100644 --- a/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGenerator.java +++ b/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGenerator.java @@ -1,6 +1,7 @@ /*- * ============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. @@ -29,7 +30,7 @@ import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; import org.glassfish.jersey.server.ResourceConfig; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; -import org.onap.policy.apex.model.utilities.TextFileUtils; +import org.onap.policy.common.utils.resources.TextFileUtils; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -103,8 +104,7 @@ public class EventGenerator { if (parameters.getOutFile() != null) { try { TextFileUtils.putStringAsTextFile(getEventGenerationStats(), parameters.getOutFile()); - } - catch (IOException ioe) { + } catch (IOException ioe) { LOGGER.warn("could not output statistics to file \"" + parameters.getOutFile() + "\"", ioe); } } @@ -150,8 +150,7 @@ public class EventGenerator { try { parameters = parameterHandler.parse(args); - } - catch (ParseException pe) { + } catch (ParseException pe) { LOGGER.trace("Event generator start exception", pe); LOGGER.info("Start of event generator failed: {}", pe.getMessage()); return; @@ -172,7 +171,6 @@ public class EventGenerator { ThreadUtilities.sleep(200); } - // Shut down the server eventGenerator.tearDown(); diff --git a/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParameterHandler.java b/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParameterHandler.java index 4cc94712f..5a2f2384f 100644 --- a/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParameterHandler.java +++ b/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParameterHandler.java @@ -1,6 +1,7 @@ /*- * ============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. @@ -33,7 +34,7 @@ import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; -import org.onap.policy.apex.model.utilities.TextFileUtils; +import org.onap.policy.common.utils.resources.TextFileUtils; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -64,32 +65,32 @@ public class EventGeneratorParameterHandler { public EventGeneratorParameterHandler() { options = new Options(); options.addOption(Option.builder("h").longOpt(HELP).desc("outputs the usage of this command").required(false) - .type(Boolean.class).build()); + .type(Boolean.class).build()); options.addOption(Option.builder("H").longOpt(HOST) - .desc("the host name on which to start the event generation server, defaults to \"localhost\"") - .hasArg().argName(HOST).required(false).type(String.class).build()); + .desc("the host name on which to start the event generation server, defaults to \"localhost\"").hasArg() + .argName(HOST).required(false).type(String.class).build()); options.addOption(Option.builder("p").longOpt(PORT) - .desc("the port on which to start the event generation server, defaults to 42339").hasArg() - .argName(PORT).required(false).type(Number.class).build()); + .desc("the port on which to start the event generation server, defaults to 42339").hasArg() + .argName(PORT).required(false).type(Number.class).build()); options.addOption(Option.builder("c").longOpt(CONFIGURATION_FILE) - .desc("name of a file containing the parameters for the event generations server, " - + "this option must appear on its own") - .hasArg().argName(CONFIGURATION_FILE).required(false).type(String.class).build()); + .desc("name of a file containing the parameters for the event generations server, " + + "this option must appear on its own") + .hasArg().argName(CONFIGURATION_FILE).required(false).type(String.class).build()); options.addOption(Option.builder("o").longOpt(OUTPUT_FILE) - .desc("path and name of a file to which output will be written," - + " if not specified no output is written") - .hasArg().argName(OUTPUT_FILE).required(false).type(String.class).build()); + .desc("path and name of a file to which output will be written," + + " if not specified no output is written") + .hasArg().argName(OUTPUT_FILE).required(false).type(String.class).build()); options.addOption(Option.builder("bc").longOpt(BATCH_COUNT) - .desc("the number of batches of events to send, must be 0 or more, " - + "0 means send event batches forever, defaults to 1") - .hasArg().argName(BATCH_COUNT).required(false).type(Number.class).build()); + .desc("the number of batches of events to send, must be 0 or more, " + + "0 means send event batches forever, defaults to 1") + .hasArg().argName(BATCH_COUNT).required(false).type(Number.class).build()); options.addOption(Option.builder("bs").longOpt(BATCH_SIZE) - .desc("the number of events to send in an event batch, must be 1 or more, defaults to 1") - .hasArg().argName(BATCH_SIZE).required(false).type(Number.class).build()); + .desc("the number of events to send in an event batch, must be 1 or more, defaults to 1").hasArg() + .argName(BATCH_SIZE).required(false).type(Number.class).build()); options.addOption(Option.builder("bd").longOpt(BATCH_DELAY) - .desc("the delay in milliseconds between event batches, must be zero or more, " - + "defaults to 10,000 (10 seconds)") - .hasArg().argName(BATCH_DELAY).required(false).type(Number.class).build()); + .desc("the delay in milliseconds between event batches, must be zero or more, " + + "defaults to 10,000 (10 seconds)") + .hasArg().argName(BATCH_DELAY).required(false).type(Number.class).build()); } /** @@ -173,7 +174,7 @@ public class EventGeneratorParameterHandler { parameterJsonString = TextFileUtils.getTextFileAsString(configurationFile); } catch (IOException ioe) { String errorMessage = "Could not read parameters from configuration file \"" + configurationFile + "\": " - + ioe.getMessage(); + + ioe.getMessage(); LOGGER.warn(errorMessage, ioe); throw new ParseException(errorMessage); } @@ -188,7 +189,7 @@ public class EventGeneratorParameterHandler { return new Gson().fromJson(parameterJsonString, EventGeneratorParameters.class); } catch (Exception ge) { String errorMessage = "Error parsing JSON parameters from configuration file \"" + configurationFile - + "\": " + ge.getMessage(); + + "\": " + ge.getMessage(); LOGGER.warn(errorMessage, ge); throw new ParseException(errorMessage); } @@ -206,7 +207,7 @@ public class EventGeneratorParameterHandler { final HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp(stringPrintWriter, MAX_HELP_LINE_LENGTH, mainClassName + " [options...] ", "", options, - 0, 0, ""); + 0, 0, ""); return stringWriter.toString(); } |