From 51f1fffd687e53c858685ec41fd3ab8cfd4fcdf1 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 1 Sep 2021 11:45:05 -0400 Subject: Fix sonars in apex-pdp #3 Fixed: - use "var" - use assertEquals instead of assertTrue(xxx.equals()) - separate assertions Issue-ID: POLICY-3093 Change-Id: Id4db62626948681cd267e68a56dda65fa355c6f8 Signed-off-by: Jim Hahn --- .../messaging/MessagingUtilsTest.java | 5 +- .../apex/core/protocols/SupportMessageTest.java | 102 +++++++++++++++++++++ .../apex/core/protocols/SupportMessageTester.java | 102 --------------------- .../apex/examples/servlet/ApexServletListener.java | 6 +- .../engine/event/impl/EventConsumerFactory.java | 4 +- .../engine/event/impl/EventProducerFactory.java | 4 +- .../context/test/concepts/TestContextDateItem.java | 3 +- .../context/distribution/ContextInstantiation.java | 12 ++- .../context/distribution/ContextUpdate.java | 6 +- .../benchmark/eventgenerator/EventBatch.java | 10 +- .../benchmark/eventgenerator/EventBatchStats.java | 5 +- .../benchmark/eventgenerator/EventGenerator.java | 6 +- .../eventgenerator/EventGeneratorEndpoint.java | 4 +- .../EventGeneratorParameterHandler.java | 11 ++- 14 files changed, 143 insertions(+), 137 deletions(-) create mode 100644 core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTest.java delete mode 100644 core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTester.java diff --git a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java index a3c7ea419..6d5915ce8 100644 --- a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java +++ b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (c) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,7 +41,7 @@ public class MessagingUtilsTest { @Test(expected = IllegalArgumentException.class) public void testIllegalArgumentException() { - assertEquals(1, MessagingUtils.findPort(65536)); + MessagingUtils.findPort(65536); } @Test @@ -58,7 +59,7 @@ public class MessagingUtilsTest { @Test(expected = IllegalArgumentException.class) public void testInvalidAllocateAddress() { - assertEquals(1, MessagingUtils.allocateAddress(1)); + MessagingUtils.allocateAddress(1); } @Test diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTest.java new file mode 100644 index 000000000..8b19059b5 --- /dev/null +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTest.java @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.core.protocols; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; + +/** + * Test of the abstract Message class. + */ +public class SupportMessageTest { + + @Test + public void testMessage() { + assertNotNull(new DummyMessage(new DummyAction(null), new AxArtifactKey())); + assertNotNull(new DummyMessage(new DummyAction(null), new AxArtifactKey(), "Message Data")); + + DummyMessage dummyMessage = new DummyMessage(new DummyAction(null), new AxArtifactKey("Target:0.0.1")); + assertEquals(new DummyAction(null), dummyMessage.getAction()); + assertThat(dummyMessage.toString()) + .startsWith("Message(action=org.onap.policy.apex.core.protocols.DummyAction@") + .endsWith("targetKey=AxArtifactKey:(name=Target,version=0.0.1), messageData=null)"); + + dummyMessage.setMessageData("Message Data"); + assertEquals("Message Data", dummyMessage.getMessageData()); + dummyMessage.appendMessageData("\nMore Message Data"); + assertEquals("Message Data\nMore Message Data", dummyMessage.getMessageData()); + dummyMessage.setMessageData(null); + dummyMessage.appendMessageData("\nMore Message Data"); + assertEquals("\nMore Message Data", dummyMessage.getMessageData()); + + dummyMessage.setReplyTimeout(123); + assertEquals(123, dummyMessage.getReplyTimeout()); + assertEquals(new AxArtifactKey("Target:0.0.1"), dummyMessage.getTarget()); + assertEquals("Target", dummyMessage.getTargetName()); + + assertNotEquals(0, dummyMessage.hashCode()); + dummyMessage.setMessageData(null); + assertNotEquals(0, dummyMessage.hashCode()); + dummyMessage = new DummyMessage(null, null, null); + assertNotEquals(0, dummyMessage.hashCode()); + + // disabling sonar because this code tests the equals() method + assertEquals(dummyMessage, dummyMessage); // NOSONAR + assertNotNull(dummyMessage); + + dummyMessage = new DummyMessage(new DummyAction(null), null, null); + DummyMessage otherDummyMessage = new DummyMessage(null, null, null); + assertNotEquals(dummyMessage, otherDummyMessage); + otherDummyMessage = new DummyMessage(new DummyAction(null), null, null); + assertEquals(dummyMessage, otherDummyMessage); + dummyMessage = new DummyMessage(null, null, null); + assertNotEquals(dummyMessage, otherDummyMessage); + otherDummyMessage = new DummyMessage(null, null, null); + assertEquals(dummyMessage, otherDummyMessage); + + dummyMessage = new DummyMessage(null, new AxArtifactKey(), null); + otherDummyMessage = new DummyMessage(null, null, null); + assertNotEquals(dummyMessage, otherDummyMessage); + otherDummyMessage = new DummyMessage(null, new AxArtifactKey(), null); + assertEquals(dummyMessage, otherDummyMessage); + dummyMessage = new DummyMessage(null, null, null); + assertNotEquals(dummyMessage, otherDummyMessage); + otherDummyMessage = new DummyMessage(null, null, null); + assertEquals(dummyMessage, otherDummyMessage); + + dummyMessage = new DummyMessage(null, null, "Message"); + otherDummyMessage = new DummyMessage(null, null, null); + assertNotEquals(dummyMessage, otherDummyMessage); + otherDummyMessage = new DummyMessage(null, null, "Message"); + assertEquals(dummyMessage, otherDummyMessage); + dummyMessage = new DummyMessage(null, null, null); + assertNotEquals(dummyMessage, otherDummyMessage); + otherDummyMessage = new DummyMessage(null, null, null); + assertEquals(dummyMessage, otherDummyMessage); + } +} diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTester.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTester.java deleted file mode 100644 index 7bc352025..000000000 --- a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTester.java +++ /dev/null @@ -1,102 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.core.protocols; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; - -/** - * Test of the abstract Message class. - */ -public class SupportMessageTester { - - @Test - public void testMessage() { - assertNotNull(new DummyMessage(new DummyAction(null), new AxArtifactKey())); - assertNotNull(new DummyMessage(new DummyAction(null), new AxArtifactKey(), "Message Data")); - - DummyMessage dummyMessage = new DummyMessage(new DummyAction(null), new AxArtifactKey("Target:0.0.1")); - assertEquals(new DummyAction(null), dummyMessage.getAction()); - assertThat(dummyMessage.toString()) - .startsWith("Message(action=org.onap.policy.apex.core.protocols.DummyAction@") - .endsWith("targetKey=AxArtifactKey:(name=Target,version=0.0.1), messageData=null)"); - - dummyMessage.setMessageData("Message Data"); - assertEquals("Message Data", dummyMessage.getMessageData()); - dummyMessage.appendMessageData("\nMore Message Data"); - assertEquals("Message Data\nMore Message Data", dummyMessage.getMessageData()); - dummyMessage.setMessageData(null); - dummyMessage.appendMessageData("\nMore Message Data"); - assertEquals("\nMore Message Data", dummyMessage.getMessageData()); - - dummyMessage.setReplyTimeout(123); - assertEquals(123, dummyMessage.getReplyTimeout()); - assertEquals(new AxArtifactKey("Target:0.0.1"), dummyMessage.getTarget()); - assertEquals("Target", dummyMessage.getTargetName()); - - assertNotEquals(0, dummyMessage.hashCode()); - dummyMessage.setMessageData(null); - assertNotEquals(0, dummyMessage.hashCode()); - dummyMessage = new DummyMessage(null, null, null); - assertNotEquals(0, dummyMessage.hashCode()); - - // disabling sonar because this code tests the equals() method - assertEquals(dummyMessage, dummyMessage); // NOSONAR - assertNotNull(dummyMessage); - - dummyMessage = new DummyMessage(new DummyAction(null), null, null); - DummyMessage otherDummyMessage = new DummyMessage(null, null, null); - assertNotEquals(dummyMessage, otherDummyMessage); - otherDummyMessage = new DummyMessage(new DummyAction(null), null, null); - assertEquals(dummyMessage, otherDummyMessage); - dummyMessage = new DummyMessage(null, null, null); - assertNotEquals(dummyMessage, otherDummyMessage); - otherDummyMessage = new DummyMessage(null, null, null); - assertEquals(dummyMessage, otherDummyMessage); - - dummyMessage = new DummyMessage(null, new AxArtifactKey(), null); - otherDummyMessage = new DummyMessage(null, null, null); - assertNotEquals(dummyMessage, otherDummyMessage); - otherDummyMessage = new DummyMessage(null, new AxArtifactKey(), null); - assertEquals(dummyMessage, otherDummyMessage); - dummyMessage = new DummyMessage(null, null, null); - assertNotEquals(dummyMessage, otherDummyMessage); - otherDummyMessage = new DummyMessage(null, null, null); - assertEquals(dummyMessage, otherDummyMessage); - - dummyMessage = new DummyMessage(null, null, "Message"); - otherDummyMessage = new DummyMessage(null, null, null); - assertNotEquals(dummyMessage, otherDummyMessage); - otherDummyMessage = new DummyMessage(null, null, "Message"); - assertEquals(dummyMessage, otherDummyMessage); - dummyMessage = new DummyMessage(null, null, null); - assertNotEquals(dummyMessage, otherDummyMessage); - otherDummyMessage = new DummyMessage(null, null, null); - assertEquals(dummyMessage, otherDummyMessage); - } -} diff --git a/examples/examples-servlet/src/main/java/org/onap/policy/apex/examples/servlet/ApexServletListener.java b/examples/examples-servlet/src/main/java/org/onap/policy/apex/examples/servlet/ApexServletListener.java index 80ef7354b..c1b7fbc11 100644 --- a/examples/examples-servlet/src/main/java/org/onap/policy/apex/examples/servlet/ApexServletListener.java +++ b/examples/examples-servlet/src/main/java/org/onap/policy/apex/examples/servlet/ApexServletListener.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,7 +58,7 @@ public class ApexServletListener implements ServletContextListener { // Check that a configuration file have been specified if (servletContextEvent.getServletContext().getInitParameter("config-file") == null) { - final String errorMessage = + final var errorMessage = "Apex servlet start failed, servlet parameter \"config-file\" has not been specified"; LOGGER.error("Apex servlet start failed, servlet parameter \"config-file\" has not been specified"); throw new ApexRuntimeException(errorMessage); @@ -89,8 +90,7 @@ public class ApexServletListener implements ServletContextListener { apexMain.shutdown(); apexMain = null; } catch (final ApexException e) { - final String errorMessage = "Apex servlet stop did not execute normally"; - LOGGER.error(errorMessage, e); + LOGGER.error("Apex servlet stop did not execute normally", e); } LOGGER.info("Apex Servliet has been stopped"); diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactory.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactory.java index 2f6922a2b..acf49e385 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactory.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactory.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +24,6 @@ package org.onap.policy.apex.service.engine.event.impl; import org.onap.policy.apex.service.engine.event.ApexEventConsumer; import org.onap.policy.apex.service.engine.event.ApexEventException; -import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -48,7 +48,7 @@ public class EventConsumerFactory { public ApexEventConsumer createConsumer(final String name, final EventHandlerParameters consumerParameters) throws ApexEventException { // Get the carrier technology parameters - final CarrierTechnologyParameters technologyParameters = consumerParameters.getCarrierTechnologyParameters(); + final var technologyParameters = consumerParameters.getCarrierTechnologyParameters(); // Get the class for the event consumer using reflection final String consumerPluginClass = technologyParameters.getEventConsumerPluginClass(); diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactory.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactory.java index e87e2fd78..7139625ab 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactory.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactory.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +24,6 @@ package org.onap.policy.apex.service.engine.event.impl; import org.onap.policy.apex.service.engine.event.ApexEventException; import org.onap.policy.apex.service.engine.event.ApexEventProducer; -import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -48,7 +48,7 @@ public class EventProducerFactory { public ApexEventProducer createProducer(final String name, final EventHandlerParameters producerParameters) throws ApexEventException { // Get the carrier technology parameters - final CarrierTechnologyParameters technologyParameters = producerParameters.getCarrierTechnologyParameters(); + final var technologyParameters = producerParameters.getCarrierTechnologyParameters(); // Get the class for the event producer using reflection final String producerPluginClass = technologyParameters.getEventProducerPluginClass(); diff --git a/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateItem.java b/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateItem.java index 13cefaa58..a62d348f2 100644 --- a/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateItem.java +++ b/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateItem.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -101,7 +102,7 @@ public class TestContextDateItem implements Serializable { public void setDateValue(final long dateValue) { this.time = dateValue; - final Calendar calendar = Calendar.getInstance(); + final var calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.setTimeInMillis(time); diff --git a/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextInstantiation.java b/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextInstantiation.java index 5561dbece..fa3612fe9 100644 --- a/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextInstantiation.java +++ b/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextInstantiation.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +22,7 @@ package org.onap.policy.apex.testsuites.integration.context.distribution; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -274,16 +276,16 @@ public class ContextInstantiation { externalContextOther.setTestExternalContextItem002(new TestContextIntItem()); externalContextOther.getTestExternalContextItem002().setIntValue(INT_VAL_2); - assertTrue(externalContextAlbum.put(EXTERNAL_CONTEXT, externalContextOther).equals(externalContext)); + assertThat(externalContextAlbum.put(EXTERNAL_CONTEXT, externalContextOther)).isEqualTo(externalContext); externalContextItem = (TestExternalContextItem) externalContextAlbum.get(EXTERNAL_CONTEXT); assertEquals(INT_VAL_2, externalContextItem.getTestExternalContextItem002().getIntValue()); - assertTrue(externalContextAlbum.put(EXTERNAL_CONTEXT, externalContext).equals(externalContextOther)); + assertThat(externalContextAlbum.put(EXTERNAL_CONTEXT, externalContext)).isEqualTo(externalContextOther); externalContextItem = (TestExternalContextItem) externalContextAlbum.get(EXTERNAL_CONTEXT); assertEquals(INT_VAL_3, externalContextItem.getTestExternalContextItem002().getIntValue()); assertThatThrownBy(() -> externalContextAlbum.put("TestExternalContextItem00A", null)) .hasMessageContaining(NULL_ILLEGAL + "\"TestExternalContextItem00A\" for put()"); - assertTrue(externalContextAlbum.get(EXTERNAL_CONTEXT).equals(externalContext)); + assertThat(externalContextAlbum.get(EXTERNAL_CONTEXT)).isEqualTo(externalContext); assertThatThrownBy(() -> externalContextAlbum.put("TestExternalContextItemFFF", null)) .hasMessageContaining(NULL_ILLEGAL + "\"TestExternalContextItemFFF\" for put()"); @@ -477,11 +479,11 @@ public class ContextInstantiation { } private void assertFloat(final float actual, final float expected) { - assertTrue(Float.compare(actual, expected) == 0); + assertThat(actual).isEqualTo(expected); } private void assertDouble(final double actual, final double expected) { - assertTrue(Double.compare(actual, expected) == 0); + assertThat(actual).isEqualTo(expected); } private Distributor getDistributor() throws ContextException { diff --git a/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextUpdate.java b/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextUpdate.java index ae662f293..b0370c5d9 100644 --- a/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextUpdate.java +++ b/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextUpdate.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +22,7 @@ package org.onap.policy.apex.testsuites.integration.context.distribution; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -97,10 +99,10 @@ public class ContextUpdate { .hasMessage("album \"LongContextAlbum:0.0.1\" null keys are illegal on keys for put()"); assertNull(dateContextAlbum.put("date0", tciA)); - assertTrue(dateContextAlbum.put("date0", tciA).equals(tciA)); + assertThat(dateContextAlbum.put("date0", tciA)).isEqualTo(tciA); assertNull(mapContextAlbum.put("map0", tciC)); - assertTrue(mapContextAlbum.put("map0", tciC).equals(tciC)); + assertThat(mapContextAlbum.put("map0", tciC)).isEqualTo(tciC); contextDistributor.clear(); } diff --git a/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventBatch.java b/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventBatch.java index 99f480b6c..3e3658349 100644 --- a/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventBatch.java +++ b/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventBatch.java @@ -55,8 +55,8 @@ public class EventBatch { this.apexClient = apexClient; // Create the events for the batch of events - for (int eventNumber = 0; eventNumber < batchSize; eventNumber++) { - InputEvent inputEvent = new InputEvent(); + for (var eventNumber = 0; eventNumber < batchSize; eventNumber++) { + var inputEvent = new InputEvent(); inputEvent.setTestSlogan(getEventSlogan(eventNumber)); inputEventMap.put(eventNumber, inputEvent); } @@ -72,9 +72,9 @@ public class EventBatch { return inputEventMap.get(0).asJson(); } - StringBuilder jsonBuilder = new StringBuilder(); + var jsonBuilder = new StringBuilder(); jsonBuilder.append("[\n"); - boolean first = true; + var first = true; for (InputEvent inputEvent : inputEventMap.values()) { if (first) { first = false; @@ -95,7 +95,7 @@ public class EventBatch { * @return the event slogan */ private String getEventSlogan(final int eventNumber) { - StringBuilder testSloganBuilder = new StringBuilder(); + var testSloganBuilder = new StringBuilder(); testSloganBuilder.append(batchNumber); testSloganBuilder.append('-'); testSloganBuilder.append(eventNumber); diff --git a/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventBatchStats.java b/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventBatchStats.java index fa5083ed0..d7b9daf14 100644 --- a/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventBatchStats.java +++ b/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventBatchStats.java @@ -26,7 +26,6 @@ import java.util.List; import lombok.Getter; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; -import org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator.events.OutputEvent; /** * This POJO class returns statistics on a event batch execution in Apex. @@ -85,7 +84,7 @@ public class EventBatchStats { long accumulatedRoundTripTime = 0; long accumulatedApexExecutionTime = 0; - for (int eventNo = 0; eventNo < batchSize; eventNo++) { + for (var eventNo = 0; eventNo < batchSize; eventNo++) { Pair eventTimings = calculateEventTimings(eventBatch, eventNo); if (eventTimings == null) { // The event has not been sent yet or the response has not been received yet @@ -154,7 +153,7 @@ public class EventBatchStats { // If an event is in a batch, it has been sent eventsSent++; - OutputEvent outputEvent = eventBatch.getOutputEvent(eventNo); + var outputEvent = eventBatch.getOutputEvent(eventNo); if (outputEvent == null) { eventsNotReceived++; 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 91f84b66b..51b6c7cae 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 @@ -65,7 +65,7 @@ public class EventGenerator { LOGGER.info("Event generator REST server starting"); - final ResourceConfig rc = new ResourceConfig(EventGeneratorEndpoint.class); + final var rc = new ResourceConfig(EventGeneratorEndpoint.class); eventGeneratorServer = GrizzlyHttpServerFactory.createHttpServer(getBaseUri(), rc); // Wait for the HTTP server to come up @@ -147,7 +147,7 @@ public class EventGenerator { LOGGER.info("Starting event generator with arguments: {}", Arrays.toString(args)); } - EventGeneratorParameterHandler parameterHandler = new EventGeneratorParameterHandler(); + var parameterHandler = new EventGeneratorParameterHandler(); EventGeneratorParameters parameters = null; @@ -166,7 +166,7 @@ public class EventGenerator { } // Start the event generator - EventGenerator eventGenerator = new EventGenerator(parameters); + var eventGenerator = new EventGenerator(parameters); LOGGER.info("Event generator started"); // Wait for event generation to finish diff --git a/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpoint.java b/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpoint.java index 6cbee6935..53e57f295 100644 --- a/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpoint.java +++ b/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpoint.java @@ -115,7 +115,7 @@ public class EventGeneratorEndpoint { return Response.status(204).build(); } - EventBatch batch = new EventBatch(parameters.get().getBatchSize(), getApexClient()); + var batch = new EventBatch(parameters.get().getBatchSize(), getApexClient()); batchMap.put(batch.getBatchNumber(), batch); return Response.status(200).entity(batch.getBatchAsJsonString()).build(); @@ -130,7 +130,7 @@ public class EventGeneratorEndpoint { @Path("/PostEvent") @POST public Response postEventResponse(final String jsonString) { - final OutputEvent outputEvent = new Gson().fromJson(jsonString, OutputEvent.class); + final var outputEvent = new Gson().fromJson(jsonString, OutputEvent.class); EventBatch batch = batchMap.get(outputEvent.findBatchNumber()); 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 912290097..16e72a2b9 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 @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -99,7 +100,7 @@ public class EventGeneratorParameterHandler { * @throws ParseException on parse errors */ public EventGeneratorParameters parse(final String[] args) throws ParseException { - CommandLine commandLine = new DefaultParser().parse(options, args); + var commandLine = new DefaultParser().parse(options, args); final String[] remainingArgs = commandLine.getArgs(); if (remainingArgs.length > 0) { @@ -110,7 +111,7 @@ public class EventGeneratorParameterHandler { return null; } - EventGeneratorParameters parameters = new EventGeneratorParameters(); + var parameters = new EventGeneratorParameters(); if (commandLine.hasOption('c')) { parameters = getParametersFromJsonFile(commandLine.getOptionValue(CONFIGURATION_FILE)); @@ -200,10 +201,10 @@ public class EventGeneratorParameterHandler { * @return help string */ public String getHelp(final String mainClassName) { - final StringWriter stringWriter = new StringWriter(); - final PrintWriter stringPrintWriter = new PrintWriter(stringWriter); + final var stringWriter = new StringWriter(); + final var stringPrintWriter = new PrintWriter(stringWriter); - final HelpFormatter helpFormatter = new HelpFormatter(); + final var helpFormatter = new HelpFormatter(); helpFormatter.printHelp(stringPrintWriter, MAX_HELP_LINE_LENGTH, mainClassName + " [options...] ", "", options, 0, 0, ""); -- cgit 1.2.3-korg